XPathAnalyser { public boolean isPrefixfreeTransformedFastXPath() { for ( Step step : xpath.getRelativeLocationPaths() ) { if ( !step.getAxisSpecifier().getAxisName().toFullString().equals( "child" ) ) { return false; } if ( step.getAxisSpecifier().getNodeName() != null ) { return false; } if ( step.getAxisSpecifier().getNodeType() == null ) { return false; } if ( !step.getAxisSpecifier().getNodeType().getNodeTypeName().equals( "node" ) ) { return false; } List<Predicate> predicates = step.getPredicates(); if ( predicates.isEmpty() || predicates.size() > 3 ) { return false; } int positions = 0; int attributes = 0; int ln = 0; int uri = 0; for ( Predicate pred : step.getPredicates() ) { if ( pred.getOrExpressions().size() != 1 ) { return false; } if ( pred.getOrExpressions().get( 0 ).getAndExpressions().size() != 1 ) { List<AndExpression> andExpressions = pred.getOrExpressions().get( 0 ).getAndExpressions(); if ( andExpressions.size() > 2 || andExpressions.size() < 1 ) { return false; } for ( AndExpression and : andExpressions ) { if ( and instanceof LocalNameAndExpression ) { ++ln; } else if ( and instanceof NamespaceUriAndExpression ) { ++uri; } } } else { AndExpression and = pred.getOrExpressions().get( 0 ).getAndExpressions().get( 0 ); if ( and instanceof PositionAndExpression ) { ++positions; } else if ( and instanceof AttributeAndExpression ) { ++attributes; } } } if ( ln != 1 || uri != 1 || positions > 1 || attributes > 1 || ( attributes + positions ) == 0 ) { return false; } } return true; } XPathAnalyser( ReferringElementInterface ref, SignedElement signedElement, PayloadElement payloadElement,
                          SchemaAnalyzer schemaAnalyzer );  XPathAnalyser( String xpath, SignedElement signedElement, PayloadElement payloadElement,
                          SchemaAnalyzer schemaAnalyser ); List<XPathWeaknessInterface> getWeaknesses(); AbsoluteLocationPath getXPath(); int getMaxPossibilites(); void abuseWeakness( int possibility, SignedElement signedElement, PayloadElement payloadElement ); boolean isFastXPath(); boolean isPrefixfreeTransformedFastXPath(); static XPathWeaknessFactoryInterface xpathWeaknessFactory; }
@Test public void prefixFreeFastXPathTest() { XPathAnalyser a; String xpath; xpath = "/*[local-name()='e' and namespace-uri()='ns_e'][1]/*[local-name()=\"h\" and namespace-uri()=\"ns_h\"][@id='bla']"; a = new XPathAnalyser( xpath, null, null, null ); assertTrue( a.isPrefixfreeTransformedFastXPath() ); xpath = "/*[1][local-name()='e' and namespace-uri()='ns_e']/*[@id='bla'][local-name()=\"h\" and namespace-uri()=\"ns_h\"]"; a = new XPathAnalyser( xpath, null, null, null ); assertTrue( a.isPrefixfreeTransformedFastXPath() ); xpath = "/*[local-name()='e' and namespace-uri()='ns_e'][1] a = new XPathAnalyser( xpath, null, null, null ); assertFalse( a.isPrefixfreeTransformedFastXPath() ); xpath = "/*[local-name()='e' and namespace-uri()='ns_e']/*[local-name()=\"h\" and namespace-uri()=\"ns_h\"][@id='bla']"; a = new XPathAnalyser( xpath, null, null, null ); assertFalse( a.isPrefixfreeTransformedFastXPath() ); xpath = "/*[local-name()='e' and namespace-uri()='ns_e'][1]/*[local-name()=\"h\" and namespace-uri()=\"ns_h\"]"; a = new XPathAnalyser( xpath, null, null, null ); assertFalse( a.isPrefixfreeTransformedFastXPath() ); xpath = "/Envelope[1]/Body[1]/function[1]"; a = new XPathAnalyser( xpath, null, null, null ); assertFalse( a.isPrefixfreeTransformedFastXPath() ); }
@Test public void xspresXPaths() { XPathAnalyser a; String xpath; xpath = "/*[local-name()=\"Envelope\" and namespace-uri()=\"http: a = new XPathAnalyser( xpath, null, null, null ); assertTrue( a.isPrefixfreeTransformedFastXPath() ); xpath = "/*[local-name()=\"Envelope\" and namespace-uri()=\"http: a = new XPathAnalyser( xpath, null, null, null ); assertTrue( a.isPrefixfreeTransformedFastXPath() ); }