@Test public void testParse() throws IOException { NodeMatcher matcher = ReportStructureMatcher.parse( "*" ); assertThat( matcher, is( instanceOf( AnyNodeMatcher.class ) ) ); matcher = ReportStructureMatcher.parse( "*>aaa.bbb #ccc *" ); assertThat( matcher.toString(), is( equalTo( "AndMatcher(ElementMatcher(*);Descendant(AndMatcher(ElementMatcher(aaa);ChildMatcher(ElementMatcher(*)))))" ) ) ); }
public static NodeMatcher parse( final String s ) throws IOException { final StreamTokenizer tokenizer = new StreamTokenizer( new StringReader( s ) ); tokenizer.wordChars( '0', '9' ); tokenizer.ordinaryChar( '.' ); tokenizer.ordinaryChar( ',' ); tokenizer.ordinaryChars( 0, ' ' ); ElementMatcher elementMatcher = null; NodeMatcher n = null; Type selectorType = Type.Start; int token; while ( ( token = tokenizer.nextToken() ) != StreamTokenizer.TT_EOF ) { if ( token == StreamTokenizer.TT_WORD || token == '*' ) { NodeMatcher matcher = null; switch ( selectorType ) { case Start: elementMatcher = createMatcher( tokenizer ); matcher = elementMatcher; break; case Child: n = new ChildMatcher( n ); elementMatcher = createMatcher( tokenizer ); matcher = elementMatcher; break; case Descendant: n = new DescendantMatcher( n ); elementMatcher = createMatcher( tokenizer ); matcher = elementMatcher; break; case Id: if ( elementMatcher == null ) { if ( n != null ) { n = new DescendantMatcher( n ); } elementMatcher = createMatcher( tokenizer ); matcher = elementMatcher; } elementMatcher.add( new AttributeMatcher( AttributeNames.Xml.NAMESPACE, AttributeNames.Xml.ID, tokenizer.sval ) ); break; case Class: if ( elementMatcher == null ) { if ( n != null ) { n = new DescendantMatcher( n ); } elementMatcher = createMatcher( tokenizer ); matcher = elementMatcher; } elementMatcher.add( new AttributeMatcher( AttributeNames.Core.NAMESPACE, AttributeNames.Core.STYLE_CLASS, tokenizer.sval ) ); break; default: throw new IOException(); } selectorType = Type.Element; if ( matcher != null ) { if ( n != null ) { n = new AndMatcher( matcher, n ); } else { n = matcher; } } } else { if ( token == '>' ) { selectorType = Type.Child; } if ( token == '.' ) { selectorType = Type.Class; } if ( token == '#' ) { selectorType = Type.Id; } if ( Character.isWhitespace( token ) ) { if ( selectorType == Type.Class || selectorType == Type.Id ) { throw new IllegalStateException(); } if ( selectorType != Type.Child ) { selectorType = Type.Descendant; } } } } return n; }
ReportStructureMatcher { public static NodeMatcher parse( final String s ) throws IOException { final StreamTokenizer tokenizer = new StreamTokenizer( new StringReader( s ) ); tokenizer.wordChars( '0', '9' ); tokenizer.ordinaryChar( '.' ); tokenizer.ordinaryChar( ',' ); tokenizer.ordinaryChars( 0, ' ' ); ElementMatcher elementMatcher = null; NodeMatcher n = null; Type selectorType = Type.Start; int token; while ( ( token = tokenizer.nextToken() ) != StreamTokenizer.TT_EOF ) { if ( token == StreamTokenizer.TT_WORD || token == '*' ) { NodeMatcher matcher = null; switch ( selectorType ) { case Start: elementMatcher = createMatcher( tokenizer ); matcher = elementMatcher; break; case Child: n = new ChildMatcher( n ); elementMatcher = createMatcher( tokenizer ); matcher = elementMatcher; break; case Descendant: n = new DescendantMatcher( n ); elementMatcher = createMatcher( tokenizer ); matcher = elementMatcher; break; case Id: if ( elementMatcher == null ) { if ( n != null ) { n = new DescendantMatcher( n ); } elementMatcher = createMatcher( tokenizer ); matcher = elementMatcher; } elementMatcher.add( new AttributeMatcher( AttributeNames.Xml.NAMESPACE, AttributeNames.Xml.ID, tokenizer.sval ) ); break; case Class: if ( elementMatcher == null ) { if ( n != null ) { n = new DescendantMatcher( n ); } elementMatcher = createMatcher( tokenizer ); matcher = elementMatcher; } elementMatcher.add( new AttributeMatcher( AttributeNames.Core.NAMESPACE, AttributeNames.Core.STYLE_CLASS, tokenizer.sval ) ); break; default: throw new IOException(); } selectorType = Type.Element; if ( matcher != null ) { if ( n != null ) { n = new AndMatcher( matcher, n ); } else { n = matcher; } } } else { if ( token == '>' ) { selectorType = Type.Child; } if ( token == '.' ) { selectorType = Type.Class; } if ( token == '#' ) { selectorType = Type.Id; } if ( Character.isWhitespace( token ) ) { if ( selectorType == Type.Class || selectorType == Type.Id ) { throw new IllegalStateException(); } if ( selectorType != Type.Child ) { selectorType = Type.Descendant; } } } } return n; } }
ReportStructureMatcher { public static NodeMatcher parse( final String s ) throws IOException { final StreamTokenizer tokenizer = new StreamTokenizer( new StringReader( s ) ); tokenizer.wordChars( '0', '9' ); tokenizer.ordinaryChar( '.' ); tokenizer.ordinaryChar( ',' ); tokenizer.ordinaryChars( 0, ' ' ); ElementMatcher elementMatcher = null; NodeMatcher n = null; Type selectorType = Type.Start; int token; while ( ( token = tokenizer.nextToken() ) != StreamTokenizer.TT_EOF ) { if ( token == StreamTokenizer.TT_WORD || token == '*' ) { NodeMatcher matcher = null; switch ( selectorType ) { case Start: elementMatcher = createMatcher( tokenizer ); matcher = elementMatcher; break; case Child: n = new ChildMatcher( n ); elementMatcher = createMatcher( tokenizer ); matcher = elementMatcher; break; case Descendant: n = new DescendantMatcher( n ); elementMatcher = createMatcher( tokenizer ); matcher = elementMatcher; break; case Id: if ( elementMatcher == null ) { if ( n != null ) { n = new DescendantMatcher( n ); } elementMatcher = createMatcher( tokenizer ); matcher = elementMatcher; } elementMatcher.add( new AttributeMatcher( AttributeNames.Xml.NAMESPACE, AttributeNames.Xml.ID, tokenizer.sval ) ); break; case Class: if ( elementMatcher == null ) { if ( n != null ) { n = new DescendantMatcher( n ); } elementMatcher = createMatcher( tokenizer ); matcher = elementMatcher; } elementMatcher.add( new AttributeMatcher( AttributeNames.Core.NAMESPACE, AttributeNames.Core.STYLE_CLASS, tokenizer.sval ) ); break; default: throw new IOException(); } selectorType = Type.Element; if ( matcher != null ) { if ( n != null ) { n = new AndMatcher( matcher, n ); } else { n = matcher; } } } else { if ( token == '>' ) { selectorType = Type.Child; } if ( token == '.' ) { selectorType = Type.Class; } if ( token == '#' ) { selectorType = Type.Id; } if ( Character.isWhitespace( token ) ) { if ( selectorType == Type.Class || selectorType == Type.Id ) { throw new IllegalStateException(); } if ( selectorType != Type.Child ) { selectorType = Type.Descendant; } } } } return n; }  }
ReportStructureMatcher { public static NodeMatcher parse( final String s ) throws IOException { final StreamTokenizer tokenizer = new StreamTokenizer( new StringReader( s ) ); tokenizer.wordChars( '0', '9' ); tokenizer.ordinaryChar( '.' ); tokenizer.ordinaryChar( ',' ); tokenizer.ordinaryChars( 0, ' ' ); ElementMatcher elementMatcher = null; NodeMatcher n = null; Type selectorType = Type.Start; int token; while ( ( token = tokenizer.nextToken() ) != StreamTokenizer.TT_EOF ) { if ( token == StreamTokenizer.TT_WORD || token == '*' ) { NodeMatcher matcher = null; switch ( selectorType ) { case Start: elementMatcher = createMatcher( tokenizer ); matcher = elementMatcher; break; case Child: n = new ChildMatcher( n ); elementMatcher = createMatcher( tokenizer ); matcher = elementMatcher; break; case Descendant: n = new DescendantMatcher( n ); elementMatcher = createMatcher( tokenizer ); matcher = elementMatcher; break; case Id: if ( elementMatcher == null ) { if ( n != null ) { n = new DescendantMatcher( n ); } elementMatcher = createMatcher( tokenizer ); matcher = elementMatcher; } elementMatcher.add( new AttributeMatcher( AttributeNames.Xml.NAMESPACE, AttributeNames.Xml.ID, tokenizer.sval ) ); break; case Class: if ( elementMatcher == null ) { if ( n != null ) { n = new DescendantMatcher( n ); } elementMatcher = createMatcher( tokenizer ); matcher = elementMatcher; } elementMatcher.add( new AttributeMatcher( AttributeNames.Core.NAMESPACE, AttributeNames.Core.STYLE_CLASS, tokenizer.sval ) ); break; default: throw new IOException(); } selectorType = Type.Element; if ( matcher != null ) { if ( n != null ) { n = new AndMatcher( matcher, n ); } else { n = matcher; } } } else { if ( token == '>' ) { selectorType = Type.Child; } if ( token == '.' ) { selectorType = Type.Class; } if ( token == '#' ) { selectorType = Type.Id; } if ( Character.isWhitespace( token ) ) { if ( selectorType == Type.Class || selectorType == Type.Id ) { throw new IllegalStateException(); } if ( selectorType != Type.Child ) { selectorType = Type.Descendant; } } } } return n; }  static NodeMatcher parse( final String s ); static ReportElement match( final MatcherContext context, final ReportElement base, final NodeMatcher parse ); static ReportElement[] matchAll( final MatcherContext context, final ReportElement base,
      final NodeMatcher parse ); static ReportElement match( final MatcherContext context, final ReportElement base, final String selector ); static ReportElement[] matchAll( final MatcherContext context, final ReportElement base, final String selector ); static ReportElement[] findElementsByName( final ReportElement section, final String name ); static ReportElement[] findElementsByAttribute( final ReportElement section, final String ns, final String name ); static ReportElement[] findElementsByAttribute( final ReportElement section, final String ns,
      final String name, final Object value ); static ReportElement[] findElementsByType( final ReportElement section, final ElementType type ); static ReportElement findElementByType( final Element element, final ElementType type ); }
ReportStructureMatcher { public static NodeMatcher parse( final String s ) throws IOException { final StreamTokenizer tokenizer = new StreamTokenizer( new StringReader( s ) ); tokenizer.wordChars( '0', '9' ); tokenizer.ordinaryChar( '.' ); tokenizer.ordinaryChar( ',' ); tokenizer.ordinaryChars( 0, ' ' ); ElementMatcher elementMatcher = null; NodeMatcher n = null; Type selectorType = Type.Start; int token; while ( ( token = tokenizer.nextToken() ) != StreamTokenizer.TT_EOF ) { if ( token == StreamTokenizer.TT_WORD || token == '*' ) { NodeMatcher matcher = null; switch ( selectorType ) { case Start: elementMatcher = createMatcher( tokenizer ); matcher = elementMatcher; break; case Child: n = new ChildMatcher( n ); elementMatcher = createMatcher( tokenizer ); matcher = elementMatcher; break; case Descendant: n = new DescendantMatcher( n ); elementMatcher = createMatcher( tokenizer ); matcher = elementMatcher; break; case Id: if ( elementMatcher == null ) { if ( n != null ) { n = new DescendantMatcher( n ); } elementMatcher = createMatcher( tokenizer ); matcher = elementMatcher; } elementMatcher.add( new AttributeMatcher( AttributeNames.Xml.NAMESPACE, AttributeNames.Xml.ID, tokenizer.sval ) ); break; case Class: if ( elementMatcher == null ) { if ( n != null ) { n = new DescendantMatcher( n ); } elementMatcher = createMatcher( tokenizer ); matcher = elementMatcher; } elementMatcher.add( new AttributeMatcher( AttributeNames.Core.NAMESPACE, AttributeNames.Core.STYLE_CLASS, tokenizer.sval ) ); break; default: throw new IOException(); } selectorType = Type.Element; if ( matcher != null ) { if ( n != null ) { n = new AndMatcher( matcher, n ); } else { n = matcher; } } } else { if ( token == '>' ) { selectorType = Type.Child; } if ( token == '.' ) { selectorType = Type.Class; } if ( token == '#' ) { selectorType = Type.Id; } if ( Character.isWhitespace( token ) ) { if ( selectorType == Type.Class || selectorType == Type.Id ) { throw new IllegalStateException(); } if ( selectorType != Type.Child ) { selectorType = Type.Descendant; } } } } return n; }  static NodeMatcher parse( final String s ); static ReportElement match( final MatcherContext context, final ReportElement base, final NodeMatcher parse ); static ReportElement[] matchAll( final MatcherContext context, final ReportElement base,
      final NodeMatcher parse ); static ReportElement match( final MatcherContext context, final ReportElement base, final String selector ); static ReportElement[] matchAll( final MatcherContext context, final ReportElement base, final String selector ); static ReportElement[] findElementsByName( final ReportElement section, final String name ); static ReportElement[] findElementsByAttribute( final ReportElement section, final String ns, final String name ); static ReportElement[] findElementsByAttribute( final ReportElement section, final String ns,
      final String name, final Object value ); static ReportElement[] findElementsByType( final ReportElement section, final ElementType type ); static ReportElement findElementByType( final Element element, final ElementType type );  }