protected XQueryExpression compileQuery() throws XPathException, IOException { if (getQuery() != null) { return staticEnv.compileQuery(getQuery()); } else if (getResource() != null) { return staticEnv.compileQuery(getResource().getInputStream(), null); } return null; }
@Override public void compileQuery(String query) throws BagriException { long stamp = System.currentTimeMillis(); logger.trace("compileQuery.enter; got query: {}", query); StaticQueryContext sqc = null; try { sqc = prepareStaticContext(null); sqc.compileQuery(query); } catch (XPathException ex) { String error = getError(ex, sqc); logger.info("compileQuery.error; message: {}", error); throw new BagriException(error, BagriException.ecQueryCompile); } stamp = System.currentTimeMillis() - stamp; logger.trace("compileQuery.exit; time taken: {}", stamp); }
/** * Compile a query supplied as a string * @param query the text of the query * @return an XQueryExecutable representing the compiled query * @throws SaxonApiException if the query compilation fails with a static error */ public XQueryExecutable compile(String query) throws SaxonApiException { try { return new XQueryExecutable(processor, env.compileQuery(query)); } catch (XPathException e) { throw new SaxonApiException(e); } }
public void parseXQuery(String query) throws XQException { DynamicQueryContext dqc = getDynamicContext(); try { final XQueryExpression exp = sqc.compileQuery(query); // why do we do this? to populate dqc with params?? List results = exp.evaluate(dqc); for (Object result: results) { logger.trace("result: {}; class: {}", result, result.getClass().getName()); } } catch (XPathException ex) { logger.error("parseXQuery.error: ", ex); throw new XQException(ex.getMessage()); } }
/** * Compile a string containing a source query * transformations * * @param context the XPath dynamic evaluation context * @param query a string containing the query to be compiled * @return the compiled query */ public static XQueryExpression compileQuery(XPathContext context, String query) throws XPathException { if (query == null) { return null; } StaticQueryContext sqc = new StaticQueryContext(context.getConfiguration()); return sqc.compileQuery(query); }
/** * Compile a query supplied as an InputStream * <p>The base URI of the query should be supplied by calling {@link #setBaseURI(java.net.URI)} </p> * * @param query the input stream on which the query is supplied. This will be consumed by this method * @return an XQueryExecutable representing the compiled query * @throws SaxonApiException if the query compilation fails with a static error * @since 9.1 */ public XQueryExecutable compile(InputStream query) throws SaxonApiException { try { return new XQueryExecutable(processor, env.compileQuery(query, encoding)); } catch (XPathException e) { throw new SaxonApiException(e); } }
/** * Compile a string containing a source query * transformations * * @param context the XPath dynamic evaluation context * @param query a string containing the query to be compiled * @return the compiled query */ public static XQueryExpression compileQuery(XPathContext context, String query) throws XPathException { if (query == null) { return null; } StaticQueryContext sqc = new StaticQueryContext(context.getConfiguration()); return sqc.compileQuery(query); }
/** * Compile a string containing a source query * transformations * * @param context the XPath dynamic evaluation context * @param query a string containing the query to be compiled * @return the compiled query */ public static XQueryExpression compileQuery(XPathContext context, String query) throws XPathException { if (query == null) { return null; } StaticQueryContext sqc = new StaticQueryContext(context.getConfiguration()); return sqc.compileQuery(query); }
/** * Compile a query supplied as a Reader * <p>The base URI of the query should be supplied by calling {@link #setBaseURI(java.net.URI)} </p> * * @param query the input stream on which the query is supplied. This will be consumed by this method * @return an XQueryExecutable representing the compiled query * @throws SaxonApiException if the query compilation fails with a static error * @throws IOException if the file does not exist or cannot be read * @since 9.1 */ public XQueryExecutable compile(Reader query) throws SaxonApiException, IOException { try { return new XQueryExecutable(processor, env.compileQuery(query)); } catch (XPathException e) { throw new SaxonApiException(e); } }
/** * Compile a query supplied as an InputStream * <p>The base URI of the query should be supplied by calling {@link #setBaseURI(java.net.URI)} </p> * * @param query the input stream on which the query is supplied. This will be consumed by this method * @return an XQueryExecutable representing the compiled query * @throws SaxonApiException if the query compilation fails with a static error * @since 9.1 */ public XQueryExecutable compile(InputStream query) throws SaxonApiException { try { return new XQueryExecutable(processor, env.compileQuery(query, encoding)); } catch (XPathException e) { throw new SaxonApiException(e); } }
/** * Compile a query supplied as a string. * <p>The base URI of the query should be supplied by calling {@link #setBaseURI(java.net.URI)} </p> * <p>If the query contains static errors, these will be notified to the registered {@link ErrorListener}. * More than one static error may be reported. If any static errors have been reported, this method * will exit with an exception, but the exception will only contain a summary message. The default * {@link ErrorListener} writes details of each error to the <code>System.err</code> output stream.</p> * * @param query the text of the query * @return an XQueryExecutable representing the compiled query * @throws SaxonApiException if the query compilation fails with a static error * @since 9.0 */ public XQueryExecutable compile(String query) throws SaxonApiException { try { return new XQueryExecutable(processor, env.compileQuery(query)); } catch (XPathException e) { throw new SaxonApiException(e); } }
@Override public List<?> evaluate(XmlObject xmlObjectContextNode, String xqueryString) throws XQueryException { LOG.finest(String.format("Executing XQuery query '%s'.", xqueryString)); XQueryExpression exp; try { exp = staticQueryContext.compileQuery(xqueryString); DynamicQueryContext dynamicContext = new DynamicQueryContext(configuration); dynamicContext.setContextItem(new XmlObjectNodeInfo(xmlObjectContextNode, configuration)); List<?> result = exp.evaluate(dynamicContext); LOG.finest(String.format("Executed XQuery expression successfully.")); return result; } catch (XPathException xpe) { throw new XQueryException( String.format("Error while evaluating XQuery expression '%s'.", xqueryString), xpe); } }
/** * Compile a query supplied as a Reader * <p>The base URI of the query should be supplied by calling {@link #setBaseURI(java.net.URI)} </p> * * @param query the input stream on which the query is supplied. This will be consumed by this method * @return an XQueryExecutable representing the compiled query * @throws SaxonApiException if the query compilation fails with a static error * @throws IOException if the file does not exist or cannot be read * @since 9.1 */ public XQueryExecutable compile(Reader query) throws SaxonApiException, IOException { try { return new XQueryExecutable(processor, env.compileQuery(query)); } catch (XPathException e) { throw new SaxonApiException(e); } }
protected XQueryExpression createQuery(MessageExchange exchange, NormalizedMessage in) throws Exception { if (getExpression() != null) { Resource r = getDynamicResource(exchange, in); return staticEnv.compileQuery(r.getInputStream(), null); } else { if (isReload()) { return compileQuery(); } else { return exp; } } }
@Override public boolean getModuleState(Module module) { try { String query = "import module namespace test=\"" + module.getNamespace() + "\" at \"" + module.getName() + "\";\n\n"; query += "1213"; StaticQueryContext sqc = prepareStaticContext(module.getBody()); logger.trace("getModuleExpression; compiling query: {}", query); sqc.compileQuery(query); return true; } catch (XPathException ex) { return false; } }
public Collection<String> prepareXQuery(String query, XQStaticContext ctx) throws XQException { setStaticContext(sqc, ctx); try { final XQueryExpression exp = sqc.compileQuery(query); if (logger.isTraceEnabled()) { logger.trace("prepareXQuery; query: \n{}", explainQuery(exp)); } Set<String> result = new HashSet<>(); Iterator<GlobalVariable> itr = exp.getMainModule().getModuleVariables(); while (itr.hasNext()) { result.add(itr.next().getVariableQName().getClarkName()); } return result; } catch (XPathException ex) { logger.error("prepareXQuery.error: ", ex); throw new XQException(ex.getMessage()); } }
private XQueryExpression getXQuery(int queryKey, String query, Properties props) throws XPathException, XQException { XQueryExpression xqExp = queries.get(queryKey); if (xqExp == null) { if (props != null) { setStaticContext(sqc, props); } //logger.info("getXQuery; this: {}; queries: {}", this, queries.size()); sqc.setModuleURIResolver(config.getModuleURIResolver()); xqExp = sqc.compileQuery(query); if (logger.isTraceEnabled()) { logger.trace("getXQuery; query: \n{}; \nexpression: {}", explainQuery(xqExp), xqExp.getExpression().getExpressionName()); } queries.putIfAbsent(queryKey, xqExp); } return xqExp; }
private XQueryExpression getModuleExpression(Module module) throws BagriException { //logger.trace("getModuleExpression.enter; got namespace: {}, name: {}, body: {}", namespace, name, body); String query = "import module namespace test=\"" + module.getNamespace() + "\" at \"" + module.getName() + "\";\n\n1213"; StaticQueryContext sqc = null; try { //sqc.compileLibrary(query); - works in Saxon-EE only sqc = prepareStaticContext(module.getBody()); logger.trace("getModuleExpression; compiling query: {}", query); //logger.trace("getModuleExpression.exit; time taken: {}", stamp); return sqc.compileQuery(query); //sqc.getCompiledLibrary("test")... } catch (XPathException ex) { String error = getError(ex, sqc); logger.error("getModuleExpression.error; " + error, ex); //logger.info("getModuleExpression.error; message: {}", error); throw new BagriException(error, BagriException.ecQueryCompile); } }
/** * Load a query library module * @return the QueryModule object representing the loaded library module */ private QueryModule loadModule() throws XPathException { // Create a dummy main query module and compile it StaticQueryContext sqc = new StaticQueryContext(getConfiguration()); sqc.setExecutable(getExecutable()); sqc.setBaseURI(getBaseURI()); String mainModule = "import module namespace m = \"" + moduleURI + "\" at \"" + href + "\"; ()"; XQueryExpression exp = sqc.compileQuery(mainModule); return exp.getStaticContext(); }
/** * Load a query library module * @return the QueryModule object representing the loaded library module */ private QueryModule loadModule() throws XPathException { // Create a dummy main query module and compile it StaticQueryContext sqc = new StaticQueryContext(getConfiguration()); sqc.setExecutable(getExecutable()); sqc.setBaseURI(getBaseURI()); String mainModule = "import module namespace m = \"" + moduleURI + "\" at \"" + href + "\"; ()"; XQueryExpression exp = sqc.compileQuery(mainModule); return exp.getStaticContext(); }