com.sun.org.apache.xml.internal.utils.PrefixResolver Java Examples
The following examples show how to use
com.sun.org.apache.xml.internal.utils.PrefixResolver.
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: XPathEvaluatorImpl.java From JDKSourceCode1.8 with MIT License | 6 votes |
/** * Creates a parsed XPath expression with resolved namespaces. This is * useful when an expression will be reused in an application since it * makes it possible to compile the expression string into a more * efficient internal form and preresolve all namespace prefixes which * occur within the expression. * * @param expression The XPath expression string to be parsed. * @param resolver The <code>resolver</code> permits translation of * prefixes within the XPath expression into appropriate namespace URIs * . If this is specified as <code>null</code>, any namespace prefix * within the expression will result in <code>DOMException</code> * being thrown with the code <code>NAMESPACE_ERR</code>. * @return The compiled form of the XPath expression. * @exception XPathException * INVALID_EXPRESSION_ERR: Raised if the expression is not legal * according to the rules of the <code>XPathEvaluator</code>i * @exception DOMException * NAMESPACE_ERR: Raised if the expression contains namespace prefixes * which cannot be resolved by the specified * <code>XPathNSResolver</code>. * * @see org.w3c.dom.xpath.XPathEvaluator#createExpression(String, XPathNSResolver) */ public XPathExpression createExpression( String expression, XPathNSResolver resolver) throws XPathException, DOMException { try { // If the resolver is null, create a dummy prefix resolver XPath xpath = new XPath(expression,null, ((null == resolver) ? new DummyPrefixResolver() : ((PrefixResolver)resolver)), XPath.SELECT); return new XPathExpressionImpl(xpath, m_doc); } catch (TransformerException e) { // Need to pass back exception code DOMException.NAMESPACE_ERR also. // Error found in DOM Level 3 XPath Test Suite. if(e instanceof XPathStylesheetDOM3Exception) throw new DOMException(DOMException.NAMESPACE_ERR,e.getMessageAndLocation()); else throw new XPathException(XPathException.INVALID_EXPRESSION_ERR,e.getMessageAndLocation()); } }
Example #2
Source File: XPathEvaluatorImpl.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
/** * Creates a parsed XPath expression with resolved namespaces. This is * useful when an expression will be reused in an application since it * makes it possible to compile the expression string into a more * efficient internal form and preresolve all namespace prefixes which * occur within the expression. * * @param expression The XPath expression string to be parsed. * @param resolver The <code>resolver</code> permits translation of * prefixes within the XPath expression into appropriate namespace URIs * . If this is specified as <code>null</code>, any namespace prefix * within the expression will result in <code>DOMException</code> * being thrown with the code <code>NAMESPACE_ERR</code>. * @return The compiled form of the XPath expression. * @exception XPathException * INVALID_EXPRESSION_ERR: Raised if the expression is not legal * according to the rules of the <code>XPathEvaluator</code>i * @exception DOMException * NAMESPACE_ERR: Raised if the expression contains namespace prefixes * which cannot be resolved by the specified * <code>XPathNSResolver</code>. * * @see org.w3c.dom.xpath.XPathEvaluator#createExpression(String, XPathNSResolver) */ public XPathExpression createExpression( String expression, XPathNSResolver resolver) throws XPathException, DOMException { try { // If the resolver is null, create a dummy prefix resolver XPath xpath = new XPath(expression,null, ((null == resolver) ? new DummyPrefixResolver() : ((PrefixResolver)resolver)), XPath.SELECT); return new XPathExpressionImpl(xpath, m_doc); } catch (TransformerException e) { // Need to pass back exception code DOMException.NAMESPACE_ERR also. // Error found in DOM Level 3 XPath Test Suite. if(e instanceof XPathStylesheetDOM3Exception) throw new DOMException(DOMException.NAMESPACE_ERR,e.getMessageAndLocation()); else throw new XPathException(XPathException.INVALID_EXPRESSION_ERR,e.getMessageAndLocation()); } }
Example #3
Source File: XPathEvaluatorImpl.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
/** * Creates a parsed XPath expression with resolved namespaces. This is * useful when an expression will be reused in an application since it * makes it possible to compile the expression string into a more * efficient internal form and preresolve all namespace prefixes which * occur within the expression. * * @param expression The XPath expression string to be parsed. * @param resolver The <code>resolver</code> permits translation of * prefixes within the XPath expression into appropriate namespace URIs * . If this is specified as <code>null</code>, any namespace prefix * within the expression will result in <code>DOMException</code> * being thrown with the code <code>NAMESPACE_ERR</code>. * @return The compiled form of the XPath expression. * @exception XPathException * INVALID_EXPRESSION_ERR: Raised if the expression is not legal * according to the rules of the <code>XPathEvaluator</code>i * @exception DOMException * NAMESPACE_ERR: Raised if the expression contains namespace prefixes * which cannot be resolved by the specified * <code>XPathNSResolver</code>. * * @see org.w3c.dom.xpath.XPathEvaluator#createExpression(String, XPathNSResolver) */ public XPathExpression createExpression( String expression, XPathNSResolver resolver) throws XPathException, DOMException { try { // If the resolver is null, create a dummy prefix resolver XPath xpath = new XPath(expression,null, ((null == resolver) ? new DummyPrefixResolver() : ((PrefixResolver)resolver)), XPath.SELECT); return new XPathExpressionImpl(xpath, m_doc); } catch (TransformerException e) { // Need to pass back exception code DOMException.NAMESPACE_ERR also. // Error found in DOM Level 3 XPath Test Suite. if(e instanceof XPathStylesheetDOM3Exception) throw new DOMException(DOMException.NAMESPACE_ERR,e.getMessageAndLocation()); else throw new XPathException(XPathException.INVALID_EXPRESSION_ERR,e.getMessageAndLocation()); } }
Example #4
Source File: XPathEvaluatorImpl.java From jdk1.8-source-analysis with Apache License 2.0 | 6 votes |
/** * Creates a parsed XPath expression with resolved namespaces. This is * useful when an expression will be reused in an application since it * makes it possible to compile the expression string into a more * efficient internal form and preresolve all namespace prefixes which * occur within the expression. * * @param expression The XPath expression string to be parsed. * @param resolver The <code>resolver</code> permits translation of * prefixes within the XPath expression into appropriate namespace URIs * . If this is specified as <code>null</code>, any namespace prefix * within the expression will result in <code>DOMException</code> * being thrown with the code <code>NAMESPACE_ERR</code>. * @return The compiled form of the XPath expression. * @exception XPathException * INVALID_EXPRESSION_ERR: Raised if the expression is not legal * according to the rules of the <code>XPathEvaluator</code>i * @exception DOMException * NAMESPACE_ERR: Raised if the expression contains namespace prefixes * which cannot be resolved by the specified * <code>XPathNSResolver</code>. * * @see org.w3c.dom.xpath.XPathEvaluator#createExpression(String, XPathNSResolver) */ public XPathExpression createExpression( String expression, XPathNSResolver resolver) throws XPathException, DOMException { try { // If the resolver is null, create a dummy prefix resolver XPath xpath = new XPath(expression,null, ((null == resolver) ? new DummyPrefixResolver() : ((PrefixResolver)resolver)), XPath.SELECT); return new XPathExpressionImpl(xpath, m_doc); } catch (TransformerException e) { // Need to pass back exception code DOMException.NAMESPACE_ERR also. // Error found in DOM Level 3 XPath Test Suite. if(e instanceof XPathStylesheetDOM3Exception) throw new DOMException(DOMException.NAMESPACE_ERR,e.getMessageAndLocation()); else throw new XPathException(XPathException.INVALID_EXPRESSION_ERR,e.getMessageAndLocation()); } }
Example #5
Source File: LocPathIterator.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
/** * Create a LocPathIterator object. * * @param nscontext The namespace context for this iterator, * should be OK if null. */ protected LocPathIterator(PrefixResolver nscontext) { setLocPathIterator(this); m_prefixResolver = nscontext; }
Example #6
Source File: Lexer.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
/** * Create a Lexer object. * * @param compiler The owning compiler for this lexer. * @param resolver The prefix resolver for mapping qualified name prefixes * to namespace URIs. * @param xpathProcessor The parser that is processing strings to opcodes. */ Lexer(Compiler compiler, PrefixResolver resolver, XPathParser xpathProcessor) { m_compiler = compiler; m_namespaceContext = resolver; m_processor = xpathProcessor; }
Example #7
Source File: XPath.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
/** * Construct an XPath object. * * (Needs review -sc) This method initializes an XPathParser/ * Compiler and compiles the expression. * @param exprString The XPath expression. * @param locator The location of the expression, may be null. * @param prefixResolver A prefix resolver to use to resolve prefixes to * namespace URIs. * @param type one of {@link #SELECT} or {@link #MATCH}. * @param errorListener The error listener, or null if default should be used. * * @throws javax.xml.transform.TransformerException if syntax or other error. */ public XPath( String exprString, SourceLocator locator, PrefixResolver prefixResolver, int type, ErrorListener errorListener) throws javax.xml.transform.TransformerException { initFunctionTable(); if(null == errorListener) errorListener = new com.sun.org.apache.xml.internal.utils.DefaultErrorHandler(); m_patternString = exprString; XPathParser parser = new XPathParser(errorListener, locator); Compiler compiler = new Compiler(errorListener, locator, m_funcTable); if (SELECT == type) parser.initXPath(compiler, exprString, prefixResolver); else if (MATCH == type) parser.initMatchPattern(compiler, exprString, prefixResolver); else throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_CANNOT_DEAL_XPATH_TYPE, new Object[]{Integer.toString(type)})); //"Can not deal with XPath type: " + type); // System.out.println("----------------"); Expression expr = compiler.compile(0); // System.out.println("expr: "+expr); this.setExpression(expr); if((null != locator) && locator instanceof ExpressionNode) { expr.exprSetParent((ExpressionNode)locator); } }
Example #8
Source File: XPath.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
/** * Construct an XPath object. * * (Needs review -sc) This method initializes an XPathParser/ * Compiler and compiles the expression. * @param exprString The XPath expression. * @param locator The location of the expression, may be null. * @param prefixResolver A prefix resolver to use to resolve prefixes to * namespace URIs. * @param type one of {@link #SELECT} or {@link #MATCH}. * @param errorListener The error listener, or null if default should be used. * * @throws javax.xml.transform.TransformerException if syntax or other error. */ public XPath( String exprString, SourceLocator locator, PrefixResolver prefixResolver, int type, ErrorListener errorListener) throws javax.xml.transform.TransformerException { initFunctionTable(); if(null == errorListener) errorListener = new com.sun.org.apache.xml.internal.utils.DefaultErrorHandler(); m_patternString = exprString; XPathParser parser = new XPathParser(errorListener, locator); Compiler compiler = new Compiler(errorListener, locator, m_funcTable); if (SELECT == type) parser.initXPath(compiler, exprString, prefixResolver); else if (MATCH == type) parser.initMatchPattern(compiler, exprString, prefixResolver); else throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_CANNOT_DEAL_XPATH_TYPE, new Object[]{Integer.toString(type)})); //"Can not deal with XPath type: " + type); // System.out.println("----------------"); Expression expr = compiler.compile(0); // System.out.println("expr: "+expr); this.setExpression(expr); if((null != locator) && locator instanceof ExpressionNode) { expr.exprSetParent((ExpressionNode)locator); } }
Example #9
Source File: XPath.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
/** * Construct an XPath object. * * (Needs review -sc) This method initializes an XPathParser/ * Compiler and compiles the expression. * @param exprString The XPath expression. * @param locator The location of the expression, may be null. * @param prefixResolver A prefix resolver to use to resolve prefixes to * namespace URIs. * @param type one of {@link #SELECT} or {@link #MATCH}. * @param errorListener The error listener, or null if default should be used. * * @throws javax.xml.transform.TransformerException if syntax or other error. */ public XPath( String exprString, SourceLocator locator, PrefixResolver prefixResolver, int type, ErrorListener errorListener, FunctionTable aTable) throws javax.xml.transform.TransformerException { m_funcTable = aTable; if(null == errorListener) errorListener = new com.sun.org.apache.xml.internal.utils.DefaultErrorHandler(); m_patternString = exprString; XPathParser parser = new XPathParser(errorListener, locator); Compiler compiler = new Compiler(errorListener, locator, m_funcTable); if (SELECT == type) parser.initXPath(compiler, exprString, prefixResolver); else if (MATCH == type) parser.initMatchPattern(compiler, exprString, prefixResolver); else throw new RuntimeException(XSLMessages.createXPATHMessage( XPATHErrorResources.ER_CANNOT_DEAL_XPATH_TYPE, new Object[]{Integer.toString(type)})); //"Can not deal with XPath type: " + type); // System.out.println("----------------"); Expression expr = compiler.compile(0); // System.out.println("expr: "+expr); this.setExpression(expr); if((null != locator) && locator instanceof ExpressionNode) { expr.exprSetParent((ExpressionNode)locator); } }
Example #10
Source File: XPath.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
/** * Construct an XPath object. * * (Needs review -sc) This method initializes an XPathParser/ * Compiler and compiles the expression. * @param exprString The XPath expression. * @param locator The location of the expression, may be null. * @param prefixResolver A prefix resolver to use to resolve prefixes to * namespace URIs. * @param type one of {@link #SELECT} or {@link #MATCH}. * @param errorListener The error listener, or null if default should be used. * * @throws javax.xml.transform.TransformerException if syntax or other error. */ public XPath( String exprString, SourceLocator locator, PrefixResolver prefixResolver, int type, ErrorListener errorListener, FunctionTable aTable) throws javax.xml.transform.TransformerException { m_funcTable = aTable; if(null == errorListener) errorListener = new com.sun.org.apache.xml.internal.utils.DefaultErrorHandler(); m_patternString = exprString; XPathParser parser = new XPathParser(errorListener, locator); Compiler compiler = new Compiler(errorListener, locator, m_funcTable); if (SELECT == type) parser.initXPath(compiler, exprString, prefixResolver); else if (MATCH == type) parser.initMatchPattern(compiler, exprString, prefixResolver); else throw new RuntimeException(XSLMessages.createXPATHMessage( XPATHErrorResources.ER_CANNOT_DEAL_XPATH_TYPE, new Object[]{Integer.toString(type)})); //"Can not deal with XPath type: " + type); // System.out.println("----------------"); Expression expr = compiler.compile(0); // System.out.println("expr: "+expr); this.setExpression(expr); if((null != locator) && locator instanceof ExpressionNode) { expr.exprSetParent((ExpressionNode)locator); } }
Example #11
Source File: Lexer.java From JDKSourceCode1.8 with MIT License | 5 votes |
/** * Create a Lexer object. * * @param compiler The owning compiler for this lexer. * @param resolver The prefix resolver for mapping qualified name prefixes * to namespace URIs. * @param xpathProcessor The parser that is processing strings to opcodes. */ Lexer(Compiler compiler, PrefixResolver resolver, XPathParser xpathProcessor) { m_compiler = compiler; m_namespaceContext = resolver; m_processor = xpathProcessor; }
Example #12
Source File: Lexer.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
/** * Create a Lexer object. * * @param compiler The owning compiler for this lexer. * @param resolver The prefix resolver for mapping qualified name prefixes * to namespace URIs. * @param xpathProcessor The parser that is processing strings to opcodes. */ Lexer(Compiler compiler, PrefixResolver resolver, XPathParser xpathProcessor) { m_compiler = compiler; m_namespaceContext = resolver; m_processor = xpathProcessor; }
Example #13
Source File: LocPathIterator.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * Create a LocPathIterator object. * * @param nscontext The namespace context for this iterator, * should be OK if null. */ protected LocPathIterator(PrefixResolver nscontext) { setLocPathIterator(this); m_prefixResolver = nscontext; }
Example #14
Source File: XPath.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
/** * Construct an XPath object. * * (Needs review -sc) This method initializes an XPathParser/ * Compiler and compiles the expression. * @param exprString The XPath expression. * @param locator The location of the expression, may be null. * @param prefixResolver A prefix resolver to use to resolve prefixes to * namespace URIs. * @param type one of {@link #SELECT} or {@link #MATCH}. * @param errorListener The error listener, or null if default should be used. * * @throws javax.xml.transform.TransformerException if syntax or other error. */ public XPath( String exprString, SourceLocator locator, PrefixResolver prefixResolver, int type, ErrorListener errorListener) throws javax.xml.transform.TransformerException { initFunctionTable(); if(null == errorListener) errorListener = new com.sun.org.apache.xml.internal.utils.DefaultErrorHandler(); m_patternString = exprString; XPathParser parser = new XPathParser(errorListener, locator); Compiler compiler = new Compiler(errorListener, locator, m_funcTable); if (SELECT == type) parser.initXPath(compiler, exprString, prefixResolver); else if (MATCH == type) parser.initMatchPattern(compiler, exprString, prefixResolver); else throw new RuntimeException(XSLMessages.createXPATHMessage( XPATHErrorResources.ER_CANNOT_DEAL_XPATH_TYPE, new Object[]{Integer.toString(type)})); // System.out.println("----------------"); Expression expr = compiler.compileExpression(0); // System.out.println("expr: "+expr); this.setExpression(expr); if((null != locator) && locator instanceof ExpressionNode) { expr.exprSetParent((ExpressionNode)locator); } }
Example #15
Source File: XPath.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * Construct an XPath object. * * (Needs review -sc) This method initializes an XPathParser/ * Compiler and compiles the expression. * @param exprString The XPath expression. * @param locator The location of the expression, may be null. * @param prefixResolver A prefix resolver to use to resolve prefixes to * namespace URIs. * @param type one of {@link #SELECT} or {@link #MATCH}. * @param errorListener The error listener, or null if default should be used. * * @throws javax.xml.transform.TransformerException if syntax or other error. */ public XPath( String exprString, SourceLocator locator, PrefixResolver prefixResolver, int type, ErrorListener errorListener) throws javax.xml.transform.TransformerException { initFunctionTable(); if(null == errorListener) errorListener = new com.sun.org.apache.xml.internal.utils.DefaultErrorHandler(); m_patternString = exprString; XPathParser parser = new XPathParser(errorListener, locator); Compiler compiler = new Compiler(errorListener, locator, m_funcTable); if (SELECT == type) parser.initXPath(compiler, exprString, prefixResolver); else if (MATCH == type) parser.initMatchPattern(compiler, exprString, prefixResolver); else throw new RuntimeException(XSLMessages.createXPATHMessage( XPATHErrorResources.ER_CANNOT_DEAL_XPATH_TYPE, new Object[]{Integer.toString(type)})); // System.out.println("----------------"); Expression expr = compiler.compileExpression(0); // System.out.println("expr: "+expr); this.setExpression(expr); if((null != locator) && locator instanceof ExpressionNode) { expr.exprSetParent((ExpressionNode)locator); } }
Example #16
Source File: LocPathIterator.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
/** * Create a LocPathIterator object. * * @param nscontext The namespace context for this iterator, * should be OK if null. */ protected LocPathIterator(PrefixResolver nscontext) { setLocPathIterator(this); m_prefixResolver = nscontext; }
Example #17
Source File: XPath.java From JDKSourceCode1.8 with MIT License | 5 votes |
/** * Construct an XPath object. * * (Needs review -sc) This method initializes an XPathParser/ * Compiler and compiles the expression. * @param exprString The XPath expression. * @param locator The location of the expression, may be null. * @param prefixResolver A prefix resolver to use to resolve prefixes to * namespace URIs. * @param type one of {@link #SELECT} or {@link #MATCH}. * @param errorListener The error listener, or null if default should be used. * * @throws javax.xml.transform.TransformerException if syntax or other error. */ public XPath( String exprString, SourceLocator locator, PrefixResolver prefixResolver, int type, ErrorListener errorListener) throws javax.xml.transform.TransformerException { initFunctionTable(); if(null == errorListener) errorListener = new com.sun.org.apache.xml.internal.utils.DefaultErrorHandler(); m_patternString = exprString; XPathParser parser = new XPathParser(errorListener, locator); Compiler compiler = new Compiler(errorListener, locator, m_funcTable); if (SELECT == type) parser.initXPath(compiler, exprString, prefixResolver); else if (MATCH == type) parser.initMatchPattern(compiler, exprString, prefixResolver); else throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_CANNOT_DEAL_XPATH_TYPE, new Object[]{Integer.toString(type)})); //"Can not deal with XPath type: " + type); // System.out.println("----------------"); Expression expr = compiler.compile(0); // System.out.println("expr: "+expr); this.setExpression(expr); if((null != locator) && locator instanceof ExpressionNode) { expr.exprSetParent((ExpressionNode)locator); } }
Example #18
Source File: XPathParser.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
/** * Given an string, init an XPath object for pattern matches, * in order that a parse doesn't * have to be done each time the expression is evaluated. * @param compiler The XPath object to be initialized. * @param expression A String representing the XPath. * @param namespaceContext An object that is able to resolve prefixes in * the XPath to namespaces. * * @throws javax.xml.transform.TransformerException */ public void initMatchPattern( 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_MATCHPATTERN); m_ops.setOp(OpMap.MAPINDEX_LENGTH, 2); nextToken(); try { Pattern(); } catch (StackOverflowError sof) { error(XPATHErrorResources.ER_PREDICATE_TOO_MANY_OPEN, new Object[]{m_token, m_queueMark, countPredicate}); } 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); } // Terminate for safety. m_ops.setOp(m_ops.getOp(OpMap.MAPINDEX_LENGTH), OpCodes.ENDOP); m_ops.setOp(OpMap.MAPINDEX_LENGTH, m_ops.getOp(OpMap.MAPINDEX_LENGTH)+1); m_ops.shrink(); }
Example #19
Source File: XPathAPI.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
/** * Evaluate XPath string to an XObject. * XPath namespace prefixes are resolved from the namespaceNode. * The implementation of this is a little slow, since it creates * a number of objects each time it is called. This could be optimized * to keep the same objects around, but then thread-safety issues would arise. * * @param contextNode The node to start searching from. * @param str A valid XPath string. * @param prefixResolver Will be called if the parser encounters namespace * prefixes, to resolve the prefixes to URLs. * @return An XObject, which can be used to obtain a string, number, nodelist, etc, should never be null. * @see com.sun.org.apache.xpath.internal.objects.XObject * @see com.sun.org.apache.xpath.internal.objects.XNull * @see com.sun.org.apache.xpath.internal.objects.XBoolean * @see com.sun.org.apache.xpath.internal.objects.XNumber * @see com.sun.org.apache.xpath.internal.objects.XString * @see com.sun.org.apache.xpath.internal.objects.XRTreeFrag * * @throws TransformerException */ public static XObject eval( Node contextNode, String str, PrefixResolver prefixResolver) throws TransformerException { // Since we don't have a XML Parser involved here, install some default support // for things like namespaces, etc. // (Changed from: XPathContext xpathSupport = new XPathContext(); // because XPathContext is weak in a number of areas... perhaps // XPathContext should be done away with.) // Create the XPath object. XPath xpath = new XPath(str, null, prefixResolver, XPath.SELECT, null); // Execute the XPath, and have it return the result XPathContext xpathSupport = new XPathContext(JdkXmlUtils.OVERRIDE_PARSER_DEFAULT); int ctxtNode = xpathSupport.getDTMHandleFromNode(contextNode); return xpath.execute(xpathSupport, ctxtNode, prefixResolver); }
Example #20
Source File: FilterExprIteratorSimple.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
/** * Execute the expression. Meant for reuse by other FilterExpr iterators * that are not derived from this object. */ public static XNodeSet executeFilterExpr(int context, XPathContext xctxt, PrefixResolver prefixResolver, boolean isTopLevel, int stackFrame, Expression expr ) throws com.sun.org.apache.xml.internal.utils.WrappedRuntimeException { PrefixResolver savedResolver = xctxt.getNamespaceContext(); XNodeSet result = null; try { xctxt.pushCurrentNode(context); xctxt.setNamespaceContext(prefixResolver); // The setRoot operation can take place with a reset operation, // and so we may not be in the context of LocPathIterator#nextNode, // so we have to set up the variable context, execute the expression, // and then restore the variable context. if (isTopLevel) { // System.out.println("calling m_expr.execute(getXPathContext())"); VariableStack vars = xctxt.getVarStack(); // These three statements need to be combined into one operation. int savedStart = vars.getStackFrame(); vars.setStackFrame(stackFrame); result = (com.sun.org.apache.xpath.internal.objects.XNodeSet) expr.execute(xctxt); result.setShouldCacheNodes(true); // These two statements need to be combined into one operation. vars.setStackFrame(savedStart); } else result = (com.sun.org.apache.xpath.internal.objects.XNodeSet) expr.execute(xctxt); } catch (javax.xml.transform.TransformerException se) { // TODO: Fix... throw new com.sun.org.apache.xml.internal.utils.WrappedRuntimeException(se); } finally { xctxt.popCurrentNode(); xctxt.setNamespaceContext(savedResolver); } return result; }
Example #21
Source File: XPathParser.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
/** * 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. * * @param compiler The compiler object. * @param expression A string conforming to the XPath grammar. * @param namespaceContext An object that is able to resolve prefixes in * the XPath to namespaces. * * @throws javax.xml.transform.TransformerException */ 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 (com.sun.org.apache.xpath.internal.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; } catch (StackOverflowError sof) { error(XPATHErrorResources.ER_PREDICATE_TOO_MANY_OPEN, new Object[]{m_token, m_queueMark, countPredicate}); } compiler.shrink(); }
Example #22
Source File: XPathParser.java From JDKSourceCode1.8 with MIT License | 4 votes |
/** * 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. * * @param compiler The compiler object. * @param expression A string conforming to the XPath grammar. * @param namespaceContext An object that is able to resolve prefixes in * the XPath to namespaces. * * @throws javax.xml.transform.TransformerException */ 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 (com.sun.org.apache.xpath.internal.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(); }
Example #23
Source File: PredicatedNodeTest.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
/** * Process the predicates. * * @param context The current context node. * @param xctxt The XPath runtime context. * * @return the result of executing the predicate expressions. * * @throws javax.xml.transform.TransformerException */ boolean executePredicates(int context, XPathContext xctxt) throws javax.xml.transform.TransformerException { int nPredicates = getPredicateCount(); // System.out.println("nPredicates: "+nPredicates); if (nPredicates == 0) return true; PrefixResolver savedResolver = xctxt.getNamespaceContext(); try { m_predicateIndex = 0; xctxt.pushSubContextList(this); xctxt.pushNamespaceContext(m_lpi.getPrefixResolver()); xctxt.pushCurrentNode(context); for (int i = 0; i < nPredicates; i++) { // System.out.println("Executing predicate expression - waiting count: "+m_lpi.getWaitingCount()); XObject pred = m_predicates[i].execute(xctxt); // System.out.println("\nBack from executing predicate expression - waiting count: "+m_lpi.getWaitingCount()); // System.out.println("pred.getType(): "+pred.getType()); if (XObject.CLASS_NUMBER == pred.getType()) { if (DEBUG_PREDICATECOUNTING) { System.out.flush(); System.out.println("\n===== start predicate count ========"); System.out.println("m_predicateIndex: " + m_predicateIndex); // System.out.println("getProximityPosition(m_predicateIndex): " // + getProximityPosition(m_predicateIndex)); System.out.println("pred.num(): " + pred.num()); } int proxPos = this.getProximityPosition(m_predicateIndex); int predIndex = (int) pred.num(); if (proxPos != predIndex) { if (DEBUG_PREDICATECOUNTING) { System.out.println("\nnode context: "+nodeToString(context)); System.out.println("index predicate is false: "+proxPos); System.out.println("\n===== end predicate count ========"); } return false; } else if (DEBUG_PREDICATECOUNTING) { System.out.println("\nnode context: "+nodeToString(context)); System.out.println("index predicate is true: "+proxPos); System.out.println("\n===== end predicate count ========"); } // If there is a proximity index that will not change during the // course of itteration, then we know there can be no more true // occurances of this predicate, so flag that we're done after // this. // // bugzilla 14365 // We can't set m_foundLast = true unless we're sure that -all- // remaining parameters are stable, or else last() fails. Fixed so // only sets m_foundLast if on the last predicate if(m_predicates[i].isStableNumber() && i == nPredicates - 1) { m_foundLast = true; } } else if (!pred.bool()) return false; countProximityPosition(++m_predicateIndex); } } finally { xctxt.popCurrentNode(); xctxt.popNamespaceContext(); xctxt.popSubContextList(); m_predicateIndex = -1; } return true; }
Example #24
Source File: PredicatedNodeTest.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
/** * Process the predicates. * * @param context The current context node. * @param xctxt The XPath runtime context. * * @return the result of executing the predicate expressions. * * @throws javax.xml.transform.TransformerException */ boolean executePredicates(int context, XPathContext xctxt) throws javax.xml.transform.TransformerException { int nPredicates = getPredicateCount(); // System.out.println("nPredicates: "+nPredicates); if (nPredicates == 0) return true; PrefixResolver savedResolver = xctxt.getNamespaceContext(); try { m_predicateIndex = 0; xctxt.pushSubContextList(this); xctxt.pushNamespaceContext(m_lpi.getPrefixResolver()); xctxt.pushCurrentNode(context); for (int i = 0; i < nPredicates; i++) { // System.out.println("Executing predicate expression - waiting count: "+m_lpi.getWaitingCount()); XObject pred = m_predicates[i].execute(xctxt); // System.out.println("\nBack from executing predicate expression - waiting count: "+m_lpi.getWaitingCount()); // System.out.println("pred.getType(): "+pred.getType()); if (XObject.CLASS_NUMBER == pred.getType()) { if (DEBUG_PREDICATECOUNTING) { System.out.flush(); System.out.println("\n===== start predicate count ========"); System.out.println("m_predicateIndex: " + m_predicateIndex); // System.out.println("getProximityPosition(m_predicateIndex): " // + getProximityPosition(m_predicateIndex)); System.out.println("pred.num(): " + pred.num()); } int proxPos = this.getProximityPosition(m_predicateIndex); int predIndex = (int) pred.num(); if (proxPos != predIndex) { if (DEBUG_PREDICATECOUNTING) { System.out.println("\nnode context: "+nodeToString(context)); System.out.println("index predicate is false: "+proxPos); System.out.println("\n===== end predicate count ========"); } return false; } else if (DEBUG_PREDICATECOUNTING) { System.out.println("\nnode context: "+nodeToString(context)); System.out.println("index predicate is true: "+proxPos); System.out.println("\n===== end predicate count ========"); } // If there is a proximity index that will not change during the // course of itteration, then we know there can be no more true // occurances of this predicate, so flag that we're done after // this. // // bugzilla 14365 // We can't set m_foundLast = true unless we're sure that -all- // remaining parameters are stable, or else last() fails. Fixed so // only sets m_foundLast if on the last predicate if(m_predicates[i].isStableNumber() && i == nPredicates - 1) { m_foundLast = true; } } else if (!pred.bool()) return false; countProximityPosition(++m_predicateIndex); } } finally { xctxt.popCurrentNode(); xctxt.popNamespaceContext(); xctxt.popSubContextList(); m_predicateIndex = -1; } return true; }
Example #25
Source File: XPathParser.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
/** * Given an string, init an XPath object for pattern matches, * in order that a parse doesn't * have to be done each time the expression is evaluated. * @param compiler The XPath object to be initialized. * @param expression A String representing the XPath. * @param namespaceContext An object that is able to resolve prefixes in * the XPath to namespaces. * * @throws javax.xml.transform.TransformerException */ public void initMatchPattern( 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_MATCHPATTERN); m_ops.setOp(OpMap.MAPINDEX_LENGTH, 2); nextToken(); try { Pattern(); } catch (StackOverflowError sof) { error(XPATHErrorResources.ER_PREDICATE_TOO_MANY_OPEN, new Object[]{m_token, m_queueMark, countPredicate}); } 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); } // Terminate for safety. m_ops.setOp(m_ops.getOp(OpMap.MAPINDEX_LENGTH), OpCodes.ENDOP); m_ops.setOp(OpMap.MAPINDEX_LENGTH, m_ops.getOp(OpMap.MAPINDEX_LENGTH)+1); m_ops.shrink(); }
Example #26
Source File: FilterExprIteratorSimple.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
/** * Execute the expression. Meant for reuse by other FilterExpr iterators * that are not derived from this object. */ public static XNodeSet executeFilterExpr(int context, XPathContext xctxt, PrefixResolver prefixResolver, boolean isTopLevel, int stackFrame, Expression expr ) throws com.sun.org.apache.xml.internal.utils.WrappedRuntimeException { PrefixResolver savedResolver = xctxt.getNamespaceContext(); XNodeSet result = null; try { xctxt.pushCurrentNode(context); xctxt.setNamespaceContext(prefixResolver); // The setRoot operation can take place with a reset operation, // and so we may not be in the context of LocPathIterator#nextNode, // so we have to set up the variable context, execute the expression, // and then restore the variable context. if (isTopLevel) { // System.out.println("calling m_expr.execute(getXPathContext())"); VariableStack vars = xctxt.getVarStack(); // These three statements need to be combined into one operation. int savedStart = vars.getStackFrame(); vars.setStackFrame(stackFrame); result = (com.sun.org.apache.xpath.internal.objects.XNodeSet) expr.execute(xctxt); result.setShouldCacheNodes(true); // These two statements need to be combined into one operation. vars.setStackFrame(savedStart); } else result = (com.sun.org.apache.xpath.internal.objects.XNodeSet) expr.execute(xctxt); } catch (javax.xml.transform.TransformerException se) { // TODO: Fix... throw new com.sun.org.apache.xml.internal.utils.WrappedRuntimeException(se); } finally { xctxt.popCurrentNode(); xctxt.setNamespaceContext(savedResolver); } return result; }
Example #27
Source File: CachedXPathAPI.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
/** * Evaluate XPath string to an XObject. * XPath namespace prefixes are resolved from the namespaceNode. * The implementation of this is a little slow, since it creates * a number of objects each time it is called. This could be optimized * to keep the same objects around, but then thread-safety issues would arise. * * @param contextNode The node to start searching from. * @param str A valid XPath string. * @param prefixResolver Will be called if the parser encounters namespace * prefixes, to resolve the prefixes to URLs. * @return An XObject, which can be used to obtain a string, number, nodelist, etc, should never be null. * @see com.sun.org.apache.xpath.internal.objects.XObject * @see com.sun.org.apache.xpath.internal.objects.XNull * @see com.sun.org.apache.xpath.internal.objects.XBoolean * @see com.sun.org.apache.xpath.internal.objects.XNumber * @see com.sun.org.apache.xpath.internal.objects.XString * @see com.sun.org.apache.xpath.internal.objects.XRTreeFrag * * @throws TransformerException */ public XObject eval( Node contextNode, String str, PrefixResolver prefixResolver) throws TransformerException { // Since we don't have a XML Parser involved here, install some default support // for things like namespaces, etc. // (Changed from: XPathContext xpathSupport = new XPathContext(); // because XPathContext is weak in a number of areas... perhaps // XPathContext should be done away with.) // Create the XPath object. XPath xpath = new XPath(str, null, prefixResolver, XPath.SELECT, null); // Execute the XPath, and have it return the result XPathContext xpathSupport = new XPathContext(JdkXmlUtils.OVERRIDE_PARSER_DEFAULT); int ctxtNode = xpathSupport.getDTMHandleFromNode(contextNode); return xpath.execute(xpathSupport, ctxtNode, prefixResolver); }
Example #28
Source File: CachedXPathAPI.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
/** * Evaluate XPath string to an XObject. * XPath namespace prefixes are resolved from the namespaceNode. * The implementation of this is a little slow, since it creates * a number of objects each time it is called. This could be optimized * to keep the same objects around, but then thread-safety issues would arise. * * @param contextNode The node to start searching from. * @param str A valid XPath string. * @param prefixResolver Will be called if the parser encounters namespace * prefixes, to resolve the prefixes to URLs. * @return An XObject, which can be used to obtain a string, number, nodelist, etc, should never be null. * @see com.sun.org.apache.xpath.internal.objects.XObject * @see com.sun.org.apache.xpath.internal.objects.XNull * @see com.sun.org.apache.xpath.internal.objects.XBoolean * @see com.sun.org.apache.xpath.internal.objects.XNumber * @see com.sun.org.apache.xpath.internal.objects.XString * @see com.sun.org.apache.xpath.internal.objects.XRTreeFrag * * @throws TransformerException */ public XObject eval( Node contextNode, String str, PrefixResolver prefixResolver) throws TransformerException { // Since we don't have a XML Parser involved here, install some default support // for things like namespaces, etc. // (Changed from: XPathContext xpathSupport = new XPathContext(); // because XPathContext is weak in a number of areas... perhaps // XPathContext should be done away with.) // Create the XPath object. XPath xpath = new XPath(str, null, prefixResolver, XPath.SELECT, null); // Execute the XPath, and have it return the result XPathContext xpathSupport = new XPathContext(JdkXmlUtils.OVERRIDE_PARSER_DEFAULT); int ctxtNode = xpathSupport.getDTMHandleFromNode(contextNode); return xpath.execute(xpathSupport, ctxtNode, prefixResolver); }
Example #29
Source File: XPathAPI.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
/** * Evaluate XPath string to an XObject. * XPath namespace prefixes are resolved from the namespaceNode. * The implementation of this is a little slow, since it creates * a number of objects each time it is called. This could be optimized * to keep the same objects around, but then thread-safety issues would arise. * * @param contextNode The node to start searching from. * @param str A valid XPath string. * @param prefixResolver Will be called if the parser encounters namespace * prefixes, to resolve the prefixes to URLs. * @return An XObject, which can be used to obtain a string, number, nodelist, etc, should never be null. * @see com.sun.org.apache.xpath.internal.objects.XObject * @see com.sun.org.apache.xpath.internal.objects.XNull * @see com.sun.org.apache.xpath.internal.objects.XBoolean * @see com.sun.org.apache.xpath.internal.objects.XNumber * @see com.sun.org.apache.xpath.internal.objects.XString * @see com.sun.org.apache.xpath.internal.objects.XRTreeFrag * * @throws TransformerException */ public static XObject eval( Node contextNode, String str, PrefixResolver prefixResolver) throws TransformerException { // Since we don't have a XML Parser involved here, install some default support // for things like namespaces, etc. // (Changed from: XPathContext xpathSupport = new XPathContext(); // because XPathContext is weak in a number of areas... perhaps // XPathContext should be done away with.) // Create the XPath object. XPath xpath = new XPath(str, null, prefixResolver, XPath.SELECT, null); // Execute the XPath, and have it return the result XPathContext xpathSupport = new XPathContext(); int ctxtNode = xpathSupport.getDTMHandleFromNode(contextNode); return xpath.execute(xpathSupport, ctxtNode, prefixResolver); }
Example #30
Source File: XPathParser.java From JDKSourceCode1.8 with MIT License | 4 votes |
/** * Given an string, init an XPath object for pattern matches, * in order that a parse doesn't * have to be done each time the expression is evaluated. * @param compiler The XPath object to be initialized. * @param expression A String representing the XPath. * @param namespaceContext An object that is able to resolve prefixes in * the XPath to namespaces. * * @throws javax.xml.transform.TransformerException */ public void initMatchPattern( 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_MATCHPATTERN); m_ops.setOp(OpMap.MAPINDEX_LENGTH, 2); nextToken(); Pattern(); 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); } // Terminate for safety. m_ops.setOp(m_ops.getOp(OpMap.MAPINDEX_LENGTH), OpCodes.ENDOP); m_ops.setOp(OpMap.MAPINDEX_LENGTH, m_ops.getOp(OpMap.MAPINDEX_LENGTH)+1); m_ops.shrink(); }