Java Code Examples for org.w3c.css.sac.SelectorList#getLength()
The following examples show how to use
org.w3c.css.sac.SelectorList#getLength() .
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: 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 2
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 3
Source File: StyleDefinitionEditorDialog.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 6 votes |
protected void handleChange( final DocumentEvent e ) { try { final NamespaceCollection nc = StyleSheetParserUtil.getInstance().getNamespaceCollection(); final String selectorText = textField.getText(); final SelectorList list = StyleSheetParserUtil.getInstance().parseSelector( nc, selectorText ); styleRule.clearSelectors(); textField.setBackground( color ); for ( int i = 0; i < list.getLength(); i++ ) { final CSSSelector selector = (CSSSelector) list.item( i ); styleRule.addSelector( selector ); } pane.setTitle( Messages.getString( "StyleDefinitionEditorDialog.RuleTitle", selectorText ) ); } catch ( CSSParseException e1 ) { textField.setBackground( errorColor ); } }
Example 4
Source File: StyleSelectorReadHandler.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
protected void doneParsing() throws SAXException { super.doneParsing(); try { final NamespaceCollection namespaceCollection = StyleSheetParserUtil.getInstance().getNamespaceCollection(); final SelectorList selectorList = StyleSheetParserUtil.getInstance().parseSelector( namespaceCollection, getResult() ); for ( int i = 0; i < selectorList.getLength(); i += 1 ) { selector.add( (CSSSelector) selectorList.item( i ) ); } } catch ( CSSParseException e ) { throw new ParseException( "Failed to parse selector", e, getLocator() ); } }
Example 5
Source File: StyleSelectorParserTest.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
public void testParsing() throws Exception { final NamespaceCollection namespaceCollection = StyleSheetParserUtil.getInstance().getNamespaceCollection(); final SelectorList selectorList = StyleSheetParserUtil.getInstance().parseSelector( namespaceCollection, "h1.test[x-lang=\"fr'\\\"\"]" ); for ( int i = 0; i < selectorList.getLength(); i += 1 ) { CSSSelector item = (CSSSelector) selectorList.item( i ); System.out.println( item.print( namespaceCollection ) ); } }
Example 6
Source File: StyleSelectorParserTest.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
public void testParsingClass() throws Exception { final NamespaceCollection namespaceCollection = StyleSheetParserUtil.getInstance().getNamespaceCollection(); final SelectorList selectorList = StyleSheetParserUtil.getInstance().parseSelector( namespaceCollection, ".\\aa test" ); for ( int i = 0; i < selectorList.getLength(); i += 1 ) { CSSSelector item = (CSSSelector) selectorList.item( i ); System.out.println( item.print( namespaceCollection ) ); } }