org.w3c.css.sac.SelectorList Java Examples

The following examples show how to use org.w3c.css.sac.SelectorList. 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: StyleDefinitionEditorDialog.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
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 #2
Source File: CSSParser.java    From tm4e with Eclipse Public License 1.0 6 votes vote down vote up
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: StyleSheetHandler.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * 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 #4
Source File: CssParser.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
public void startSelector( SelectorList selectors ) throws CSSException
{
	// Create the style rule and add it to the rule list

	StyleRule sr = new StyleRule( selectors );
	if ( !nodeStack.empty( ) )
	{
		( (StyleSheet) nodeStack.peek( ) ).add( sr );
	}

	// Create the style declaration
	StyleDeclaration decl = new StyleDeclaration( );
	sr.setStyle( decl );
	nodeStack.push( sr );
	nodeStack.push( decl );
}
 
Example #5
Source File: CssParser.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public void endSelector( SelectorList selectors ) throws CSSException
{

	// Pop both the style declaration and the style rule nodes
	nodeStack.pop( );
	root = nodeStack.pop( );
}
 
Example #6
Source File: StyleSelectorParserTest.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
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 ) );
  }
}
 
Example #7
Source File: StyleSelectorParserTest.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
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 #8
Source File: StyleSelectorReadHandler.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
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 #9
Source File: Parser.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
final public SelectorList _parseSelectors() throws ParseException {
  SelectorList p = null;
  try {
    label_75:
    while ( true ) {
      switch( ( jj_ntk == -1 ) ? jj_ntk() : jj_ntk ) {
        case S:
          ;
          break;
        default:
          jj_la1[ 116 ] = jj_gen;
          break label_75;
      }
      jj_consume_token( S );
    }
    p = selectorList();
    {
      if ( true ) {
        return p;
      }
    }
  } catch ( ThrowedParseException e ) {
    {
      if ( true ) {
        throw (ParseException) e.e;
      }
    }//.fillInStackTrace();

  }
  throw new Error( "Missing return statement in function" );
}
 
Example #10
Source File: Parser.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
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 #11
Source File: Parser.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public SelectorList parseSelectors( InputSource source )
  throws CSSException, IOException {
  this.source = source;
  ReInit( getCharStreamWithLurk( source ) );

  if ( selectorFactory == null ) {
    selectorFactory = new SelectorFactoryImpl();
  }
  if ( conditionFactory == null ) {
    conditionFactory = new ConditionFactoryImpl();
  }
  return _parseSelectors();
}
 
Example #12
Source File: CSSDocumentHandler.java    From tm4e with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void endSelector(SelectorList selector) throws CSSException {
	currentStyle = null;
}
 
Example #13
Source File: StyleRule.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Gets the selector list of the style rule.
 * 
 * @return the selector list of the style rule
 */

public SelectorList getSelectorList( )
{
	return this.selectors;
}
 
Example #14
Source File: StyleRule.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public StyleRule( SelectorList selectors )
{
	this.selectors = selectors;
}
 
Example #15
Source File: CSSEngine.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * <b>SAC</b>: Implements {@link
 * DocumentHandler#endSelector(SelectorList)}.
 */
public void endSelector( SelectorList selectors ) throws CSSException
{
	throw new InternalError( );
}
 
Example #16
Source File: CSSEngine.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * <b>SAC</b>: Implements {@link
 * DocumentHandler#startSelector(SelectorList)}.
 */
public void startSelector( SelectorList selectors ) throws CSSException
{
	throw new InternalError( );
}
 
Example #17
Source File: CSSStyle.java    From tm4e with Eclipse Public License 1.0 4 votes vote down vote up
public SelectorList getSelectorList() {
	return selector;
}
 
Example #18
Source File: CSSStyle.java    From tm4e with Eclipse Public License 1.0 4 votes vote down vote up
public CSSStyle(SelectorList selector) {
	this.selector = selector;
}
 
Example #19
Source File: CSSDocumentHandler.java    From tm4e with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void startSelector(SelectorList selector) throws CSSException {
	currentStyle = new CSSStyle(selector);
	list.add(currentStyle);
}
 
Example #20
Source File: StyleSheetHandler.java    From pentaho-reporting with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Receive notification of the beginning of a rule statement.
 *
 * @param selectors All intended selectors for all declarations.
 * @throws CSSException Any CSS exception, possibly wrapping another exception.
 */
public void startSelector( SelectorList selectors )
  throws CSSException {
  styleRule = new CSSStyleRule( styleSheet, getParentRule() );
}