org.w3c.css.sac.Selector Java Examples
The following examples show how to use
org.w3c.css.sac.Selector.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StyleSheetHandler.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 6 votes |
/** * Receive notification of the end of a rule statement. * * @param selectors All intended selectors for all declarations. * @throws CSSException Any CSS exception, possibly wrapping another exception. */ public void endSelector( SelectorList selectors ) throws CSSException { if ( styleRule.isEmpty() ) { return; } int length = selectors.getLength(); for ( int i = 0; i < length; i++ ) { final Selector selector = selectors.item( i ); try { final CSSStyleRule rule = (CSSStyleRule) styleRule.clone(); rule.setSelector( (CSSSelector) selector ); styleSheet.addRule( rule ); } catch ( CloneNotSupportedException e ) { // should not happen } } }
Example #2
Source File: CSSParser.java From tm4e with Eclipse Public License 1.0 | 6 votes |
public IStyle getBestStyle(String... names) { int bestSpecificity = 0; IStyle bestStyle = null; for (IStyle style : handler.getList()) { SelectorList list = ((CSSStyle) style).getSelectorList(); for (int i = 0; i < list.getLength(); i++) { Selector selector = list.item(i); if (selector instanceof ExtendedSelector) { ExtendedSelector s = ((ExtendedSelector) selector); int nbMatch = s.nbMatch(names); if (nbMatch > 0 && nbMatch == s.nbClass()) { if (bestStyle == null || (nbMatch >= bestSpecificity)) { bestStyle = style; bestSpecificity = nbMatch; } } } } } return bestStyle; }
Example #3
Source File: SimpleStyleRuleMatcher.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 6 votes |
private boolean isPseudoElementRule( final CSSStyleRule rule ) { final CSSSelector selector = rule.getSelector(); if ( selector == null ) { return false; } if ( selector.getSelectorType() != Selector.SAC_CONDITIONAL_SELECTOR ) { return false; } final ConditionalSelector cs = (ConditionalSelector) selector; final Condition condition = cs.getCondition(); if ( condition.getConditionType() != Condition.SAC_PSEUDO_CLASS_CONDITION ) { return false; } return true; }
Example #4
Source File: SimpleStyleRuleMatcher.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 6 votes |
private boolean isPseudoElementRule( final ElementStyleRule rule ) { final List<CSSSelector> selectorList = rule.getSelectorList(); for ( int i = 0; i < selectorList.size(); i += 1 ) { final CSSSelector selector = selectorList.get( i ); if ( selector == null ) { continue; } if ( selector.getSelectorType() != Selector.SAC_CONDITIONAL_SELECTOR ) { continue; } final ConditionalSelector cs = (ConditionalSelector) selector; final Condition condition = cs.getCondition(); if ( condition.getConditionType() != Condition.SAC_PSEUDO_CLASS_CONDITION ) { continue; } return true; } return false; }
Example #5
Source File: HtmlHelper.java From FairEmail with GNU General Public License v3.0 | 5 votes |
private static String processStyles(String tag, String clazz, String style, CSSRuleList rules, int stype) { for (int i = 0; rules != null && i < rules.getLength(); i++) { CSSRule rule = rules.item(i); switch (rule.getType()) { case CSSRule.STYLE_RULE: CSSStyleRuleImpl srule = (CSSStyleRuleImpl) rule; for (int j = 0; j < srule.getSelectors().getLength(); j++) { Selector selector = srule.getSelectors().item(j); if (selector.getSelectorType() != stype) continue; switch (selector.getSelectorType()) { case Selector.SAC_ELEMENT_NODE_SELECTOR: ElementSelectorImpl eselector = (ElementSelectorImpl) selector; if (tag == null ? eselector.getLocalName() == null : tag.equals(eselector.getLocalName())) style = mergeStyles(style, srule.getStyle().getCssText()); break; case Selector.SAC_CONDITIONAL_SELECTOR: ConditionalSelectorImpl cselector = (ConditionalSelectorImpl) selector; if (cselector.getCondition().getConditionType() == SAC_CLASS_CONDITION) { ClassConditionImpl ccondition = (ClassConditionImpl) cselector.getCondition(); if (clazz.equals(ccondition.getValue())) style = mergeStyles(style, srule.getStyle().getCssText()); } break; } } break; case CSSRule.MEDIA_RULE: CSSMediaRuleImpl mrule = (CSSMediaRuleImpl) rule; if (isScreenMedia(mrule.getMedia())) style = processStyles(tag, clazz, style, mrule.getCssRules(), stype); break; } } return style; }
Example #6
Source File: HtmlHelper.java From FairEmail with GNU General Public License v3.0 | 5 votes |
private static String processStyles(String tag, String clazz, String style, List<CSSStyleSheet> sheets) { for (CSSStyleSheet sheet : sheets) if (isScreenMedia(sheet.getMedia())) { style = processStyles(null, clazz, style, sheet.getCssRules(), Selector.SAC_ELEMENT_NODE_SELECTOR); style = processStyles(tag, clazz, style, sheet.getCssRules(), Selector.SAC_ELEMENT_NODE_SELECTOR); style = processStyles(tag, clazz, style, sheet.getCssRules(), Selector.SAC_CONDITIONAL_SELECTOR); } return style; }
Example #7
Source File: FixNamespaceSelectorFactory.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
public SiblingSelector createDirectAdjacentSelector( final short nodeType, final Selector child, final SimpleSelector directAdjacent ) throws CSSException { return parent.createDirectAdjacentSelector( nodeType, child, directAdjacent ); }
Example #8
Source File: SelectorFactoryImpl.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
/** * Creates a direct adjacent selector. * * @param child the child selector * @param adjacent the direct adjacent selector * @return the combinator selector. * @throws CSSException If this selector is not supported. */ public SiblingSelector createDirectAdjacentSelector( short nodeType, Selector child, SimpleSelector directAdjacent ) throws CSSException { if ( nodeType != 1 ) { throw new CSSException( CSSException.SAC_NOT_SUPPORTED_ERR ); } else { return new DirectAdjacentSelectorImpl( child, directAdjacent ); } }
Example #9
Source File: SimpleStyleRuleMatcher.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
private boolean isDescendantMatch( final LayoutElement node, final Selector selector ) { LayoutElement parent = node.getParentLayoutElement(); while ( parent != null ) { if ( isMatch( parent, selector ) ) { return true; } parent = parent.getParentLayoutElement(); } return false; }
Example #10
Source File: CSSDescendantSelector.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
public CSSDescendantSelector( final SimpleSelector simpleSelector, final Selector anchestorSelector, final boolean childRelation ) { this.simpleSelector = simpleSelector; this.anchestorSelector = anchestorSelector; this.childRelation = childRelation; }
Example #11
Source File: CSSDescendantSelector.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
/** * An integer indicating the type of <code>Selector</code> */ public short getSelectorType() { if ( childRelation ) { return Selector.SAC_CHILD_SELECTOR; } else { return Selector.SAC_DESCENDANT_SELECTOR; } }
Example #12
Source File: CSSSilblingSelector.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
public CSSSilblingSelector( final short nodeType, final Selector selector, final SimpleSelector silblingSelector ) { this.nodeType = nodeType; this.selector = selector; this.silblingSelector = silblingSelector; }
Example #13
Source File: CSSSelectorFactory.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
/** * Creates an element selector. * * @param namespaceURI the <a href="http://www.w3.org/TR/REC-xml-names/#dt-NSName">namespace URI</a> of the element * selector. * @param tagName the <a href="http://www.w3.org/TR/REC-xml-names/#NT-LocalPart">local part</a> of the element * name. <code>NULL</code> if this element selector can match any element.</p> * @return the element selector * @throws CSSException If this selector is not supported. */ public ElementSelector createElementSelector( String namespaceURI, String tagName ) throws CSSException { if ( namespaceURI == null ) { namespaceURI = CSSParserContext.getContext().getDefaultNamespace(); } return new CSSElementSelector ( Selector.SAC_ELEMENT_NODE_SELECTOR, namespaceURI, tagName ); }
Example #14
Source File: CSSSelectorFactory.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
/** * Creates a pseudo element selector. * * @param pseudoName the pseudo element name. <code>NULL</code> if this element selector can match any pseudo * element.</p> * @return the element selector * @throws CSSException If this selector is not supported. */ public ElementSelector createPseudoElementSelector( String namespaceURI, String pseudoName ) throws CSSException { if ( namespaceURI == null ) { namespaceURI = CSSParserContext.getContext().getDefaultNamespace(); } return new CSSElementSelector ( Selector.SAC_PSEUDO_ELEMENT_SELECTOR, namespaceURI, pseudoName ); }
Example #15
Source File: Selectors.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
void addSelector( Selector selector ) { if ( current == selectors.length ) { Selector[] old = selectors; selectors = new Selector[ old.length + old.length ]; System.arraycopy( old, 0, selectors, 0, old.length ); } selectors[ current++ ] = selector; }
Example #16
Source File: Parser.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
final public SelectorList selectorList() throws ParseException { SelectorListImpl selectors = new SelectorListImpl(); Selector selector; selector = selector(); label_47: while ( true ) { switch( ( jj_ntk == -1 ) ? jj_ntk() : jj_ntk ) { case COMMA: ; break; default: jj_la1[ 65 ] = jj_gen; break label_47; } jj_consume_token( COMMA ); label_48: while ( true ) { switch( ( jj_ntk == -1 ) ? jj_ntk() : jj_ntk ) { case S: ; break; default: jj_la1[ 66 ] = jj_gen; break label_48; } jj_consume_token( S ); } selectors.addSelector( selector ); selector = selector(); } selectors.addSelector( selector ); { if ( true ) { return selectors; } } throw new Error( "Missing return statement in function" ); }
Example #17
Source File: SelectorListImpl.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
void addSelector( Selector selector ) { if ( current == selectors.length ) { Selector[] old = selectors; selectors = new Selector[ old.length + old.length ]; System.arraycopy( old, 0, selectors, 0, old.length ); } selectors[ current++ ] = selector; }
Example #18
Source File: SimpleStyleRuleMatcher.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
private boolean isDescendantMatch( final ReportElement node, final Selector selector ) { ReportElement parent = node.getParentSection(); while ( parent != null ) { if ( isMatch( parent, selector ) ) { return true; } parent = parent.getParentSection(); } return false; }
Example #19
Source File: CSSDescendantSelector.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
/** * An integer indicating the type of <code>Selector</code> */ public short getSelectorType() { if ( childRelation ) { return Selector.SAC_CHILD_SELECTOR; } else { return Selector.SAC_DESCENDANT_SELECTOR; } }
Example #20
Source File: FixNamespaceSelectorFactory.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 4 votes |
public DescendantSelector createChildSelector( final Selector parent, final SimpleSelector child ) throws CSSException { return this.parent.createChildSelector( parent, child ); }
Example #21
Source File: FixNamespaceSelectorFactory.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 4 votes |
public DescendantSelector createDescendantSelector( final Selector parent, final SimpleSelector descendant ) throws CSSException { return this.parent.createDescendantSelector( parent, descendant ); }
Example #22
Source File: FixNamespaceSelectorFactory.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 4 votes |
public SiblingSelector createDirectAdjacentSelector( final short nodeType, final Selector child, final SimpleSelector directAdjacent ) throws CSSException { return parent.createDirectAdjacentSelector( nodeType, child, directAdjacent ); }
Example #23
Source File: CSSSilblingSelector.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 4 votes |
/** * Returns the first selector. */ public Selector getSelector() { return selector; }
Example #24
Source File: CSSDescendantSelector.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 4 votes |
/** * Returns the parent selector. */ public Selector getAncestorSelector() { return anchestorSelector; }
Example #25
Source File: CSSDescendantSelector.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 4 votes |
public CSSDescendantSelector( final SimpleSelector simpleSelector, final Selector anchestorSelector, final boolean childRelation ) { this.simpleSelector = simpleSelector; this.anchestorSelector = anchestorSelector; this.childRelation = childRelation; }
Example #26
Source File: CSSDescendantSelector.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 4 votes |
/** * Returns the parent selector. */ public Selector getAncestorSelector() { return anchestorSelector; }
Example #27
Source File: CSSSilblingSelector.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 4 votes |
public CSSSilblingSelector( final short nodeType, final Selector selector, final SimpleSelector silblingSelector ) { this.nodeType = nodeType; this.selector = selector; this.silblingSelector = silblingSelector; }
Example #28
Source File: FixNamespaceSelectorFactory.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 4 votes |
public DescendantSelector createChildSelector( final Selector parent, final SimpleSelector child ) throws CSSException { return this.parent.createChildSelector( parent, child ); }
Example #29
Source File: CSSSilblingSelector.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 4 votes |
/** * Returns the first selector. */ public Selector getSelector() { return selector; }
Example #30
Source File: FixNamespaceSelectorFactory.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 4 votes |
public DescendantSelector createDescendantSelector( final Selector parent, final SimpleSelector descendant ) throws CSSException { return this.parent.createDescendantSelector( parent, descendant ); }