• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java XQueryCompiler类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中net.sf.saxon.s9api.XQueryCompiler的典型用法代码示例。如果您正苦于以下问题:Java XQueryCompiler类的具体用法?Java XQueryCompiler怎么用?Java XQueryCompiler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



XQueryCompiler类属于net.sf.saxon.s9api包,在下文中一共展示了XQueryCompiler类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
 
开发者ID:Armatiek,项目名称:xslweb,代码行数:22,代码来源:WebApp.java


示例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();
}
 
开发者ID:epam,项目名称:Wilma,代码行数:23,代码来源:XQueryExpressionEvaluator.java


示例3: setPrefixNamespaceMappings

import net.sf.saxon.s9api.XQueryCompiler; //导入依赖的package包/类
/**
 * Set the namespaces in the XQueryCompiler.
 * 
 * @param xqueryCompiler
 * @param namespaceMappings Namespace prefix to Namespace uri mappings
 */
private  void setPrefixNamespaceMappings(XQueryCompiler xqueryCompiler, HashMap<String,String> namespaceMappings) {

	if (namespaceMappings != null) {
		
		// Get the mappings
		Set<Entry<String, String>> mappings = namespaceMappings.entrySet();

		// If mappings exist, set the namespaces
		if (mappings != null) {
		
			Iterator<Entry<String, String>> it = mappings.iterator();
			while (it.hasNext()) {
				Entry<String, String> entry = it.next();
				xqueryCompiler.declareNamespace(entry.getKey(),entry.getValue());
			}
		
		}	
		
	}
	
	// Add in the defaults
	xqueryCompiler.declareNamespace("xml",NamespaceConstant.XML);
	xqueryCompiler.declareNamespace("xs",NamespaceConstant.SCHEMA);
	xqueryCompiler.declareNamespace("fn",NamespaceConstant.FN);
	
}
 
开发者ID:elsevierlabs-os,项目名称:spark-xml-utils,代码行数:33,代码来源:XQueryProcessor.java


示例4: 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);
    }
}
 
开发者ID:SteveGodwin,项目名称:mock-xquery,代码行数:24,代码来源:XQueryContext.java


示例5: 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);
}
 
开发者ID:ligasgr,项目名称:intellij-xquery,代码行数:13,代码来源:SaxonRunnerApp.java


示例6: getXQueryCompiler

import net.sf.saxon.s9api.XQueryCompiler; //导入依赖的package包/类
/**
 * @return The global XQuery compiler for this FOX engine. This object is thread-safe.
 */
public static XQueryCompiler getXQueryCompiler() {
  return gXQueryCompiler;
}
 
开发者ID:Fivium,项目名称:FOXopen,代码行数:7,代码来源:SaxonEnvironment.java


示例7: 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);
		}		
	}
 
开发者ID:erfgoed-en-locatie,项目名称:artsholland-platform,代码行数:81,代码来源:XSPARQLQueryHandler.java


示例8: 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());

	}
	
}
 
开发者ID:elsevierlabs-os,项目名称:spark-xml-utils,代码行数:47,代码来源:XQueryProcessor.java



注:本文中的net.sf.saxon.s9api.XQueryCompiler类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java HttpResponse类代码示例发布时间:2022-05-22
下一篇:
Java DependencyNodeVisitor类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap