@Override public void process(final InputStream rawIn) throws IOException { try (final InputStream in = new BufferedInputStream(rawIn)) { XQueryEvaluator qe = slashExpression.load(); qe.setSource(new SAXSource(xmlReader, new InputSource(in))); DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance(); dfactory.setNamespaceAware(true); Document dom = dfactory.newDocumentBuilder().newDocument(); qe.run(new DOMDestination(dom)); XdmNode rootNode = proc.newDocumentBuilder().wrap(dom); sourceRef.set(rootNode); } catch (final Exception e) { error.set(e); } } });
out.setOutputProperty(Serializer.Property.SAXON_INDENT_SPACES, "2"); exp.explain(out); exp.getUnderlyingCompiledQuery().setAllowDocumentProjection(projection); final XQueryEvaluator evaluator = exp.load(); evaluator.setTraceFunctionDestination(traceDestination); if (options.getOptionValue("now") != null) { quit(e.getMessage(), 2); if (updating && exp.isUpdateQuery()) { serializer.setOutputProperties( exp.getUnderlyingCompiledQuery().getExecutable().getPrimarySerializationProperties().getProperties()); runUpdate(exp, evaluator, serializer); } else {
/** * 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); } }
evaluator.run(); try { exp.getUnderlyingCompiledQuery().runUpdate(evaluator.getUnderlyingQueryContext(), agent); } catch (XPathException e) { throw new SaxonApiException(e); if (evaluator.getContextItem() != null) { Set<MutableNodeInfo> affectedDocuments = exp.getUnderlyingCompiledQuery().runUpdate(evaluator.getUnderlyingQueryContext()); Item initial = evaluator.getContextItem().getUnderlyingValue().head();
if (sourceInput != null && !streaming) { DocumentBuilder builder = processor.newDocumentBuilder(); if (exp.isUpdateQuery()) { builder.setTreeModel(TreeModel.LINKED_TREE); System.err.println("Processing " + sourceInput.getSystemId()); if (!exp.getUnderlyingCompiledQuery().usesContextItem()) { System.err.println("Source document ignored - query does not access the context item"); return; builder.setDocumentProjectionQuery(exp); if (explain) { exp.getUnderlyingCompiledQuery().explainPathMap();
out.setOutputProperty(Serializer.Property.SAXON_INDENT_SPACES, "2"); exp.explain(out); exp.getUnderlyingCompiledQuery().setAllowDocumentProjection(projection); final XQueryEvaluator evaluator = exp.load(); evaluator.setTraceFunctionDestination(traceDestination); if (options.getOptionValue("now") != null) { quit(e.getMessage(), 2); if (updating && exp.isUpdateQuery()) { serializer.setOutputProperties( exp.getUnderlyingCompiledQuery().getExecutable().getPrimarySerializationProperties().getProperties()); runUpdate(exp, evaluator, serializer); } else {
/** * 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); } }
evaluator.run(); try { exp.getUnderlyingCompiledQuery().runUpdate(evaluator.getUnderlyingQueryContext(), agent); } catch (XPathException e) { throw new SaxonApiException(e); if (evaluator.getContextItem() != null) { Set<MutableNodeInfo> affectedDocuments = exp.getUnderlyingCompiledQuery().runUpdate(evaluator.getUnderlyingQueryContext()); Item initial = evaluator.getContextItem().getUnderlyingValue().head();
if (sourceInput != null && !streaming) { DocumentBuilder builder = processor.newDocumentBuilder(); if (exp.isUpdateQuery()) { builder.setTreeModel(TreeModel.LINKED_TREE); System.err.println("Processing " + sourceInput.getSystemId()); if (!exp.getUnderlyingCompiledQuery().usesContextItem()) { System.err.println("Source document ignored - query does not access the context item"); return; builder.setDocumentProjectionQuery(exp); if (explain) { exp.getUnderlyingCompiledQuery().explainPathMap();
XQueryEvaluator qe = entry.getValue().load(); qe.setContextItem(sourceRef.get()); XdmValue result = qe.evaluate();
/** * 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); } }
XQueryExpression saxonQuery = xquery.getUnderlyingCompiledQuery(); queryModule = saxonQuery.getStaticContext(); Iterator<?> moduleIter = queryModule.getExecutable().getQueryLibraryModules();
@Override public void process(final InputStream rawIn) throws IOException { try (final InputStream in = new BufferedInputStream(rawIn)) { XQueryEvaluator qe = slashExpression.load(); qe.setSource(new SAXSource(xmlReader, new InputSource(in))); DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance(); dfactory.setNamespaceAware(true); Document dom = dfactory.newDocumentBuilder().newDocument(); qe.run(new DOMDestination(dom)); XdmNode rootNode = proc.newDocumentBuilder().wrap(dom); sourceRef.set(rootNode); } catch (final Exception e) { error.set(e); } } });
/** * 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); } }
private void bindRequestVariables(ResponseBuilder rb, SolrQueryRequest req, XQueryExecutable expr, Compiler compiler, Evaluator evaluator, SolrQueryContext context) { Iterator<GlobalVariable> decls = expr.getUnderlyingCompiledQuery().getStaticContext().getModuleVariables(); boolean hasLuxHttp = false, hasEXpathRequest = false; while (decls.hasNext()) { GlobalVariable decl = decls.next(); StructuredQName varName = decl.getVariableQName(); if (varName.equals(new StructuredQName("", EXPATH_HTTP_NS, "input"))) { hasEXpathRequest = true; } else if (varName.equals(new StructuredQName("", LUX_HTTP.getNamespaceURI(), LUX_HTTP.getLocalPart()))) { hasLuxHttp = true; } } if (hasLuxHttp) { context.bindVariable(LUX_HTTP, buildHttpParams (evaluator, req, queryPath != null ? queryPath : "/xquery" )); } if (hasEXpathRequest) { try { context.bindVariable(new QName(EXPATH_HTTP_NS, "input", ""), buildEXPathRequest(compiler, evaluator, req)); } catch (XPathException e) { throw new LuxException (e); } } }
private String getSchemaTNS(XdmItem schema) throws SaxonApiException { XQueryEvaluator e = processor.newXQueryCompiler().compile("declare namespace xsd = \"http://www.w3.org/2001/XMLSchema\"; xsd:string(xsd:schema/@targetNamespace)").load(); e.setContextItem(schema); XdmValue v = e.evaluate(); if (v instanceof XdmEmptySequence) return null; else return v.toString(); }
/** * 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); } }
if (wrap) { try { XQueryExpression e = exp.getUnderlyingCompiledQuery(); SequenceIterator results = e.iterator(evaluator.getUnderlyingQueryContext()); DocumentInfo resultDoc = QueryResult.wrap(results, config);
Processor saxon = new Processor(false); saxon.registerExtensionFunction(new MyExtension()); XQueryCompiler compiler = saxon.newXQueryCompiler(); XQueryExecutable exec = compiler.compile(new File("input/names.xq")); XQueryEvaluator query = exec.load(); DocumentBuilder builder = saxon.newDocumentBuilder(); String students = "<xml>...</xml>"; Source src = new StreamSource(new StringReader(students)); XdmNode doc = builder.build(src); query.setExternalVariable(new QName("student_list"), doc); XdmValue result = query.evaluate();
/** * 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); } }