本文整理汇总了Java中net.sf.saxon.s9api.XQueryCompiler.compile方法的典型用法代码示例。如果您正苦于以下问题:Java XQueryCompiler.compile方法的具体用法?Java XQueryCompiler.compile怎么用?Java XQueryCompiler.compile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.sf.saxon.s9api.XQueryCompiler
的用法示例。
在下文中一共展示了XQueryCompiler.compile方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: tryQueryCache
import net.sf.saxon.s9api.XQueryCompiler; //导入方法依赖的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.XQueryCompiler; //导入方法依赖的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.XQueryCompiler; //导入方法依赖的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.XQueryCompiler; //导入方法依赖的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.XQueryCompiler; //导入方法依赖的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: init
import net.sf.saxon.s9api.XQueryCompiler; //导入方法依赖的package包/类
/**
* Initialization to improve performance for repetitive invocations of evaluate expressions
*
* @throws XQueryException
*/
private void init() throws XQueryException {
try {
// Get the processor
proc = new Processor(false);
// Set any specified configuration properties for the processor
if (featureMappings != null) {
for (Entry<String, Object> entry : featureMappings.entrySet()) {
proc.setConfigurationProperty(entry.getKey(), entry.getValue());
}
}
// Get the XQuery compiler
XQueryCompiler xqueryCompiler = proc.newXQueryCompiler();
xqueryCompiler.setEncoding(CharEncoding.UTF_8);
// Set the namespace to prefix mappings
this.setPrefixNamespaceMappings(xqueryCompiler, namespaceMappings);
// Compile the XQuery expression and get an XQuery evaluator
exp = xqueryCompiler.compile(xQueryExpression);
eval = exp.load();
// Create and initialize the serializer
baos = new ByteArrayOutputStream();
serializer = proc.newSerializer(baos);
// Appears ok to always set output property to xml (even if we are just returning a text string)
serializer.setOutputProperty(Serializer.Property.METHOD, "xml");
serializer.setOutputProperty(Serializer.Property.OMIT_XML_DECLARATION,"yes");
serializer.setProcessor(proc);
} catch (SaxonApiException e) {
log.error("Problems creating an XQueryProcessor. " + e.getMessage(),e);
throw new XQueryException(e.getMessage());
}
}