Java Code Examples for org.apache.xpath.XPath#SELECT
The following examples show how to use
org.apache.xpath.XPath#SELECT .
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: StylesheetRoot.java From j2objc with Apache License 2.0 | 6 votes |
/** * Uses an XSL stylesheet document. * @throws TransformerConfigurationException if the baseIdentifier can not be resolved to a URL. */ public StylesheetRoot(ErrorListener errorListener) throws TransformerConfigurationException { super(null); setStylesheetRoot(this); try { m_selectDefault = new XPath("node()", this, this, XPath.SELECT, errorListener); initDefaultRule(errorListener); } catch (TransformerException se) { throw new TransformerConfigurationException(XSLMessages.createMessage(XSLTErrorResources.ER_CANNOT_INIT_DEFAULT_TEMPLATES, null), se); //"Can't init default templates!", se); } }
Example 2
Source File: SqlXmlHelperXalan.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * Take the received string, which is an XML query expression, compile it, and * store the compiled query locally. Note that for now, we only support XPath * because that's what Xalan supports. * * @param queryExpr * The XPath expression to compile */ public void compileXQExpr(final String queryExpr, final String opName, final DocumentBuilder dBuilder) throws StandardException { try { /* The following XPath constructor compiles the expression * as part of the construction process. We have to pass * in a PrefixResolver object in order to avoid NPEs when * invalid/unknown functions are used, so we just create * a dummy one, which means prefixes will not be resolved * in the query (Xalan will just throw an error if a prefix * is used). In the future we may want to revisit this * to make it easier for users to query based on namespaces. */ query = new XPath(queryExpr, null, new PrefixResolverDefault( dBuilder.newDocument()), XPath.SELECT); } catch (Throwable te) { /* Something went wrong during compilation of the * expression; wrap the error and re-throw it. * Note: we catch "Throwable" here to catch as many * Xalan-produced errors as possible in order to * minimize the chance of an uncaught Xalan error * (such as a NullPointerException) causing Derby * to fail in a more serious way. In particular, an * uncaught Java exception like NPE can result in * Derby throwing "ERROR 40XT0: An internal error was * identified by RawStore module" for all statements on * the connection after the failure--which we clearly * don't want. If we catch the error and wrap it, * though, the statement will fail but Derby will * continue to run as normal. */ throw StandardException.newException(SQLState.LANG_XML_QUERY_ERROR, te, opName, te.getMessage()); } }
Example 3
Source File: SqlXmlHelperXalan.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * Take the received string, which is an XML query expression, compile it, and * store the compiled query locally. Note that for now, we only support XPath * because that's what Xalan supports. * * @param queryExpr * The XPath expression to compile */ public void compileXQExpr(final String queryExpr, final String opName, final DocumentBuilder dBuilder) throws StandardException { try { /* The following XPath constructor compiles the expression * as part of the construction process. We have to pass * in a PrefixResolver object in order to avoid NPEs when * invalid/unknown functions are used, so we just create * a dummy one, which means prefixes will not be resolved * in the query (Xalan will just throw an error if a prefix * is used). In the future we may want to revisit this * to make it easier for users to query based on namespaces. */ query = new XPath(queryExpr, null, new PrefixResolverDefault( dBuilder.newDocument()), XPath.SELECT); } catch (Throwable te) { /* Something went wrong during compilation of the * expression; wrap the error and re-throw it. * Note: we catch "Throwable" here to catch as many * Xalan-produced errors as possible in order to * minimize the chance of an uncaught Xalan error * (such as a NullPointerException) causing Derby * to fail in a more serious way. In particular, an * uncaught Java exception like NPE can result in * Derby throwing "ERROR 40XT0: An internal error was * identified by RawStore module" for all statements on * the connection after the failure--which we clearly * don't want. If we catch the error and wrap it, * though, the statement will fail but Derby will * continue to run as normal. */ throw StandardException.newException(SQLState.LANG_XML_QUERY_ERROR, te, opName, te.getMessage()); } }
Example 4
Source File: AVTPartXPath.java From j2objc with Apache License 2.0 | 3 votes |
/** * Construct a simple AVT part. * * @param val A pure string section of an AVT. * @param nsNode An object which can be used to determine the * Namespace Name (URI) for any Namespace prefix used in the XPath. * Usually this is based on the context where the XPath was specified, * such as a node within a Stylesheet. * @param xpathProcessor XPath parser * @param factory XPath factory * @param liaison An XPathContext object, providing infomation specific * to this invocation and this thread. Maintains SAX output state, * variables, error handler and so on, so the transformation/XPath * object itself can be simultaneously invoked from multiple threads. * * @throws javax.xml.transform.TransformerException * TODO: Fix or remove this unused c'tor. */ public AVTPartXPath( String val, org.apache.xml.utils.PrefixResolver nsNode, XPathParser xpathProcessor, XPathFactory factory, XPathContext liaison) throws javax.xml.transform.TransformerException { m_xpath = new XPath(val, null, nsNode, XPath.SELECT, liaison.getErrorListener()); }
Example 5
Source File: StylesheetHandler.java From j2objc with Apache License 2.0 | 3 votes |
/** * Process an expression string into an XPath. * Must be public for access by the AVT class. * * @param str A non-null reference to a valid or invalid XPath expression string. * * @return A non-null reference to an XPath object that represents the string argument. * * @throws javax.xml.transform.TransformerException if the expression can not be processed. * @see <a href="http://www.w3.org/TR/xslt#section-Expressions">Section 4 Expressions in XSLT Specification</a> */ public XPath createXPath(String str, ElemTemplateElement owningTemplate) throws javax.xml.transform.TransformerException { ErrorListener handler = m_stylesheetProcessor.getErrorListener(); XPath xpath = new XPath(str, owningTemplate, this, XPath.SELECT, handler, m_funcTable); // Visit the expression, registering namespaces for any extension functions it includes. xpath.callVisitors(xpath, new ExpressionVisitor(getStylesheetRoot())); return xpath; }