本文整理汇总了Java中net.sf.saxon.s9api.XQueryExecutable类的典型用法代码示例。如果您正苦于以下问题:Java XQueryExecutable类的具体用法?Java XQueryExecutable怎么用?Java XQueryExecutable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XQueryExecutable类属于net.sf.saxon.s9api包,在下文中一共展示了XQueryExecutable类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: tryQueryCache
import net.sf.saxon.s9api.XQueryExecutable; //导入依赖的package包/类
public XQueryExecutable tryQueryCache(String xqueryPath,
ErrorListener errorListener, boolean tracing) throws Exception {
String key = FilenameUtils.normalize(xqueryPath);
XQueryExecutable xquery = xqueryExecutableCache.get(key);
if (xquery == null) {
logger.info("Compiling and caching xquery \"" + xqueryPath + "\" ...");
try {
XQueryCompiler comp = processor.newXQueryCompiler();
comp.setErrorListener(errorListener);
comp.setCompileWithTracing(tracing);
xquery = comp.compile(new File(xqueryPath));
} catch (Exception e) {
logger.error("Could not compile XQuery \"" + xqueryPath + "\"", e);
throw e;
}
if (!developmentMode) {
xqueryExecutableCache.put(key, xquery);
}
}
return xquery;
}
示例2: evaluateXQuery
import net.sf.saxon.s9api.XQueryExecutable; //导入依赖的package包/类
/**
* Executes a given XQuery expression on the given XML.
* @param xml is the XQuery data source
* @param query is the query expression
* @return with the query result as String
* @throws SaxonApiException was thrown when the XQuery execution is failed
*/
public String evaluateXQuery(final String xml, final String query) throws SaxonApiException {
Processor processor = processorFactory.createProcessor();
XQueryCompiler xqueryCompiler = processor.newXQueryCompiler();
xqueryCompiler.setErrorListener(errorListener);
XQueryExecutable xqueryExec = xqueryCompiler.compile(query);
XQueryEvaluator xqueryEval = xqueryExec.load();
xqueryEval.setErrorListener(errorListener);
SAXSource requestXml = saxSourceFactory.createSAXSource(inputSourceFactory.createInputSource(xml));
xqueryEval.setSource(requestXml);
ByteArrayOutputStream baos = byteArrayOutputStreamFactory.createByteArrayOutputStream();
Serializer ser = serializerFactory.createSerializer(baos);
xqueryEval.setDestination(ser);
xqueryEval.run();
return baos.toString();
}
示例3: evaluateXQueryFile
import net.sf.saxon.s9api.XQueryExecutable; //导入依赖的package包/类
/**
* Executes an XQuery file (on the classpath) under a given version of
* XQuery
* @param filename
* Filename as it appears on the classpath
* @param xqueryVersion
* Must be "1.0" or "3.0"
* @return Returns result of execution
* @throws XQueryException
*/
public final XdmValue evaluateXQueryFile (String filename, String xqueryVersion) throws XQueryException {
try {
XQueryCompiler comp = this.processor.newXQueryCompiler();
comp.setLanguageVersion(xqueryVersion);
String query = fromResource(filename);
XQueryExecutable exp = comp.compile(query);
XQueryEvaluator ev = exp.load();
return ev.evaluate();
}
catch (SaxonApiException | IOException e) {
throw new XQueryException("An error occurred during execution of the document " + filename, e);
}
}
示例4: runApp
import net.sf.saxon.s9api.XQueryExecutable; //导入依赖的package包/类
@Override
public void runApp() throws Exception {
doAdditionalConfiguration(processor);
Serializer out = prepareSerializer();
XQueryCompiler compiler = processor.newXQueryCompiler();
XQueryExecutable executable = compiler.compile(new File(config.getMainFile()));
setMainModule(executable.getUnderlyingCompiledQuery().getMainModule());
XQueryEvaluator evaluator = executable.load();
bindContextItem(evaluator);
bindVariables(evaluator);
evaluator.run(out);
}
示例5: XSPARQLQueryHandler
import net.sf.saxon.s9api.XQueryExecutable; //导入依赖的package包/类
public XSPARQLQueryHandler(ContentHandler handler, Metadata metadata,
/*ParseContext context,*/ Reader xquery, Map<String, StreamSource> includes)
throws ParserException {
// this.matcher = new XPathParser("rdf", RDF.NAMESPACE).parse("/rdf:RDF/descendant::node()");
this.handler = handler;
super.setContentHandler(this.handler);
// this.context = context;
this.metadata = metadata;
// this.turtleParser = new TurtleParser();
this.stack = new Stack<String>();
try {
XSPARQLProcessor xp = new XSPARQLProcessor();
String q = xp.process(xquery);
// logger.info(q);
// TODO: This is nasty, but we need the namespaces from our XSPARQL query.
// Matcher matcher = Pattern.compile(".*PREFIX ([a-zA-Z]+): <(.*)>").matcher(q);
// while (matcher.find()) {
// super.startPrefixMapping(matcher.group(1), matcher.group(2));
// }
// super.startElement("http://www.w3.org/1999/02/22-rdf-syntax-ns#", "RDF", "rdf:RDF", new AttributesImpl());
Configuration config = new Configuration();
// XSPARQL specific functions (see: https://sourceforge.net/mailarchive/message.php?msg_id=29435521).
config.registerExtensionFunction(new sparqlQueryExtFunction());
config.registerExtensionFunction(new turtleGraphToURIExtFunction());
config.registerExtensionFunction(new createScopedDatasetExtFunction());
config.registerExtensionFunction(new sparqlScopedDatasetExtFunction());
config.registerExtensionFunction(new deleteScopedDatasetExtFunction());
config.registerExtensionFunction(new scopedDatasetPopResultsExtFunction());
config.registerExtensionFunction(new jsonDocExtFunction());
// Custom XSPARQL functions.
config.registerExtensionFunction(new ParseDateTimeFunction());
config.registerExtensionFunction(new ParseDateFunction());
config.registerExtensionFunction(new ObjectUriFunction());
config.registerExtensionFunction(new ClassUriFunction());
config.registerExtensionFunction(new AddressUriFunction());
config.registerExtensionFunction(new ParseDecimalFunction());
config.registerExtensionFunction(new ParseLocaleFunction());
config.registerExtensionFunction(new ParseStringFunction());
config.registerExtensionFunction(new ParseBooleanFunction());
config.registerExtensionFunction(new ParseHttpUrlFunction());
config.registerExtensionFunction(new ParseNonZeroNumber());
config.registerExtensionFunction(new UpperCaseFirstFunction());
config.registerExtensionFunction(new PostalCodeFunction());
config.registerExtensionFunction(new LocalityFunction());
config.registerExtensionFunction(new StreetAddressFunction());
config.registerExtensionFunction(new StreetNumberFunction());
config.registerExtensionFunction(new StreetNameFunction());
config.registerExtensionFunction(new ExtractStreetNumberFunction());
config.registerExtensionFunction(new ExtractStreetNameFunction());
config.registerExtensionFunction(new WKTGeometryFunction());
config.registerExtensionFunction(new WebContentTypeFunction());
config.registerExtensionFunction(new ParseCidnFunction());
config.registerExtensionFunction(new UrlConcatFunction());
Processor processor = new Processor(config);
XQueryCompiler compiler = processor.newXQueryCompiler();
XQueryExecutable compiled = compiler.compile(q);
evaluator = compiled.load();
if (includes != null) {
DocumentBuilder docBuilder = processor.newDocumentBuilder();
for (Entry<String, StreamSource> item : includes.entrySet()) {
evaluator.setExternalVariable(
new QName(item.getKey()),
docBuilder.build(item.getValue()));
}
}
} catch (Exception e) {
e.printStackTrace();
throw new ParserException(e);
}
}
示例6: getQuery
import net.sf.saxon.s9api.XQueryExecutable; //导入依赖的package包/类
public XQueryExecutable getQuery(String path, ErrorListener errorListener, boolean tracing) throws Exception {
if (new File(path).isAbsolute()) {
return tryQueryCache(path, errorListener, tracing);
}
return tryQueryCache(new File(getHomeDir(), "xquery" + "/" + path).getAbsolutePath(), errorListener, tracing);
}