public void initXPath ( Compiler compiler , String expression , PrefixResolver namespaceContext ) throws javax . xml . transform . TransformerException { m_ops = compiler ; m_namespaceContext = namespaceContext ; m_functionTable = compiler . getFunctionTable ( ) ; Lexer lexer = new Lexer ( compiler , namespaceContext , this ) ; lexer . tokenize ( expression ) ; m_ops . setOp ( 0 , OpCodes . OP_XPATH ) ; m_ops . setOp ( OpMap . MAPINDEX_LENGTH , 2 ) ; // Patch for Christine's gripe. She wants her errorHandler to return from // a fatal error and continue trying to parse, rather than throwing an exception. // Without the patch, that put us into an endless loop. // // %REVIEW% Is there a better way of doing this? // %REVIEW% Are there any other cases which need the safety net? // (and if so do we care right now, or should we rewrite the XPath // grammar engine and can fix it at that time?) try { nextToken ( ) ; Expr ( ) ; if ( null != m_token ) { String extraTokens = "" ; while ( null != m_token ) { extraTokens += "'" + m_token + "'" ; nextToken ( ) ; if ( null != m_token ) extraTokens += ", " ; } error ( XPATHErrorResources . ER_EXTRA_ILLEGAL_TOKENS , new Object [ ] { extraTokens } ) ; //"Extra illegal tokens: "+extraTokens); } } catch ( org . apache . xpath . XPathProcessorException e ) { if ( CONTINUE_AFTER_FATAL_ERROR . equals ( e . getMessage ( ) ) ) { // What I _want_ to do is null out this XPath. // I doubt this has the desired effect, but I'm not sure what else to do. // %REVIEW%!!! initXPath ( compiler , "/.." , namespaceContext ) ; } else throw e ; } compiler . shrink ( ) ; }
Given an string init an XPath object for selections in order that a parse doesn t have to be done each time the expression is evaluated .