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

Java XQueryExpression类代码示例

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

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



XQueryExpression类属于net.sf.saxon.query包,在下文中一共展示了XQueryExpression类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: isQueryReadOnly

import net.sf.saxon.query.XQueryExpression; //导入依赖的package包/类
@Override
public boolean isQueryReadOnly(final String query, Properties props) throws XQException {
	boolean result = super.isQueryReadOnly(query);
	if (result) {
		int qKey = getQueryManagement().getQueryKey(query);
		XQueryExpression xqExp;
		try {
			xqExp = getXQuery(qKey, query, props);
		} catch (XPathException xpe) {
        	logger.error("isQueryReadOnly.error: ", xpe);
       		throw convertXPathException(xpe);
		}
		result = !isUpdatingExpression(xqExp.getExpression());
  	    }
  	    return result;
}
 
开发者ID:dsukhoroslov,项目名称:bagri,代码行数:17,代码来源:XQProcessorServer.java


示例2: getXQuery

import net.sf.saxon.query.XQueryExpression; //导入依赖的package包/类
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);
		}
   	    sqc.setModuleURIResolver(config.getModuleURIResolver());
     xqExp = sqc.compileQuery(query);
     if (logger.isTraceEnabled()) {
     	logger.trace("getXQuery; query: \n{}; \nexpression: {}", explainQuery(xqExp), 
     			xqExp.getExpression().getExpressionName());
     }
    	queries.put(queryKey, xqExp);
	} 
	return xqExp;
}
 
开发者ID:dsukhoroslov,项目名称:bagri,代码行数:17,代码来源:XQProcessorServer.java


示例3: getModuleExpression

import net.sf.saxon.query.XQueryExpression; //导入依赖的package包/类
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);
	}
}
 
开发者ID:dsukhoroslov,项目名称:bagri,代码行数:20,代码来源:XQCompilerImpl.java


示例4: prepareXQuery

import net.sf.saxon.query.XQueryExpression; //导入依赖的package包/类
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());
        }
    }
 
开发者ID:dsukhoroslov,项目名称:bagri,代码行数:21,代码来源:XQProcessorImpl.java


示例5: testPersonQuery

import net.sf.saxon.query.XQueryExpression; //导入依赖的package包/类
@Test
public void testPersonQuery() throws XPathException, XQException {

       Configuration config = Configuration.newConfiguration();
       StaticQueryContext sqc = config.newStaticQueryContext();
  	    DynamicQueryContext dqc = new DynamicQueryContext(config);
       dqc.setApplyFunctionConversionRulesToExternalVariables(false);

	String query = "declare base-uri \"../../etc/samples/xmark/\";\n" +
			"let $auction := fn:doc(\"auction.xml\") return\n" +
			"for $b in $auction/site/people/person[@id = 'person0'] return $b/name/text()";
  	    
	//dqc.setParameter(new StructuredQName("", "", "v"), objectToItem(Boolean.TRUE, config));
  	    XQueryExpression xqExp = sqc.compileQuery(query);
       SequenceIterator itr = xqExp.iterator(dqc);
       Item item = itr.next();
  	    assertNotNull(item);
  	    String val = item.getStringValue();
	assertEquals("Huei Demke", val);
	assertNull(itr.next());
}
 
开发者ID:dsukhoroslov,项目名称:bagri,代码行数:22,代码来源:SaxonQueryTest.java


示例6: testCollationQuery

import net.sf.saxon.query.XQueryExpression; //导入依赖的package包/类
@Test
public void testCollationQuery() throws XPathException {
       Configuration config = Configuration.newConfiguration();
       StaticQueryContext sqc = config.newStaticQueryContext();
       // this causes Saxon throw NPE and query processing!
       //sqc.declareDefaultCollation("");
  	    DynamicQueryContext dqc = new DynamicQueryContext(config);
       dqc.setApplyFunctionConversionRulesToExternalVariables(false);

	String query = "declare base-uri \"../../etc/samples/xmark/\";\n" +
			"let $auction := fn:doc(\"auction.xml\") return\n" +
			"for $i in $auction/site//item\n" +
			"where contains(string(exactly-one($i/description)), \"gold\")\n" +
			"return $i/name/text()";
			
  	    XQueryExpression xqExp = sqc.compileQuery(query);
       SequenceIterator itr = xqExp.iterator(dqc);
       Item item = itr.next();
  	    assertNotNull(item);
  	    assertNotNull(item.getStringValue());
}
 
开发者ID:dsukhoroslov,项目名称:bagri,代码行数:22,代码来源:SaxonQueryTest.java


示例7: createListOfXmlNodes

import net.sf.saxon.query.XQueryExpression; //导入依赖的package包/类
/**
 * Creates list variable of resulting XML nodes.
 * @param exp
 * @param dynamicContext
 * @return
 * @throws XPathException
 */
public static ListVariable createListOfXmlNodes(XQueryExpression exp, DynamicQueryContext dynamicContext) throws XPathException {
    final SequenceIterator iter = exp.iterator(dynamicContext);

    ListVariable listVariable = new ListVariable();
    while (true) {
        Item item = iter.next();
        if (item == null) {
            break;
        }

        XmlNodeWrapper value = new XmlNodeWrapper(item);
        listVariable.addVariable( new NodeVariable(value) );
    }

    return listVariable;
}
 
开发者ID:huajun2013,项目名称:ablaze,代码行数:24,代码来源:XmlUtil.java


示例8: xquery

import net.sf.saxon.query.XQueryExpression; //导入依赖的package包/类
public static XQueryBuilder xquery(final String queryText) {
    return new XQueryBuilder() {
        protected XQueryExpression createQueryExpression(StaticQueryContext staticQueryContext)
            throws XPathException {
            return staticQueryContext.compileQuery(queryText);
        }
    };
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:9,代码来源:XQueryBuilder.java


示例9: execQuery

import net.sf.saxon.query.XQueryExpression; //导入依赖的package包/类
private Iterator<Object> execQuery(final String query) throws XQException {
    logger.trace("execQuery.enter; this: {}", this);
	long stamp = System.currentTimeMillis();
  	    
  	    QueryManagement qMgr = (QueryManagement) getQueryManagement();
  	    Query xQuery = qMgr.getQuery(query);
    Integer qKey = qMgr.getQueryKey(query);
  	    try {
  	   	    XQueryExpression xqExp = getXQuery(qKey, query, null);
       	Map<String, Object> params = getObjectParams();
   	    if (xQuery == null) {
        	clnFinder.setQuery(null);
        } else {
   	    	QueryBuilder xdmQuery = xQuery.getXdmQuery();
   	    	if (!(params == null || params.isEmpty())) {
       	    	xdmQuery.resetParams(params);
   	    	}
    		clnFinder.setQuery(xdmQuery);
   	    }
       	clnFinder.setExpression(xqExp);

        stamp = System.currentTimeMillis() - stamp;
	    logger.trace("execQuery; xQuery: {}; params: {}; time taken: {}", xQuery, params, stamp);
	    stamp = System.currentTimeMillis();
        SequenceIterator itr = xqExp.iterator(dqc);
        //Result r = new StreamResult();
        //xqExp.run(dqc, r, null);
        stamp = System.currentTimeMillis() - stamp;
	    logger.trace("execQuery.exit; time taken: {}", stamp);
        return new XQIterator(getXQDataFactory(), itr); 
       } catch (XPathException xpe) {
       	logger.error("execQuery.error: ", xpe);
       	throw convertXPathException(xpe);
       }
}
 
开发者ID:dsukhoroslov,项目名称:bagri,代码行数:36,代码来源:XQProcessorServer.java


示例10: explainQuery

import net.sf.saxon.query.XQueryExpression; //导入依赖的package包/类
protected String explainQuery(XQueryExpression exp) throws XPathException {
  	ByteArrayOutputStream baos = new ByteArrayOutputStream();
  	PrintStream ps = new PrintStream(baos);
  	Logger log = new StandardLogger(ps);
      exp.getExpression().explain(log);
      String res = new String(baos.toByteArray(), Charset.defaultCharset());
      log.close();
      ps.close();
      try {
	baos.close();
} catch (IOException ex) {
	throw new XPathException(ex);
}
      return res;
  }
 
开发者ID:dsukhoroslov,项目名称:bagri,代码行数:16,代码来源:XQProcessorImpl.java


示例11: parseXQuery

import net.sf.saxon.query.XQueryExpression; //导入依赖的package包/类
public void parseXQuery(String query) throws XQException {

        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());
        }
    }
 
开发者ID:dsukhoroslov,项目名称:bagri,代码行数:15,代码来源:XQProcessorImpl.java


示例12: testMapQuery

import net.sf.saxon.query.XQueryExpression; //导入依赖的package包/类
@Test
public void testMapQuery() throws XPathException {
       Configuration config = Configuration.newConfiguration();
       config.setDefaultCollection("");
       StaticQueryContext sqc = config.newStaticQueryContext();
  	    DynamicQueryContext dqc = new DynamicQueryContext(config);
       dqc.setApplyFunctionConversionRulesToExternalVariables(false);

       //String xml = "<map>\n" +
       //		"  <boolProp>false</boolProp>\n" +
       //		"  <strProp>XYZ</strProp>\n" +
       //		"  <intProp>1</intProp>\n" +
       //		"</map>";
   	//String baseURI = sqc.getBaseURI(); 
       //StringReader sr = new StringReader(xml);
       //InputSource is = new InputSource(sr);
       //is.setSystemId(baseURI);
       //Source source = new SAXSource(is);
       //source.setSystemId(baseURI);
       //config.getGlobalDocumentPool().add(config.buildDocumentTree(source), "map.xml");
       
	String query = "declare base-uri \"../../etc/samples/xdm/\";\n" +
			"declare variable $value external;\n" +
			"for $doc in fn:collection()/map\n" +
			"where $doc/intProp = $value\n" +
			//"where $doc[intProp = $value]\n" +
			"return $doc/strProp/text()";
       
  	    XQueryExpression xqExp = sqc.compileQuery(query);
  	    dqc.setParameter(new StructuredQName("", "", "value"), objectToItem(1, config));
       SequenceIterator itr = xqExp.iterator(dqc);
       Item item = itr.next();
  	    assertNotNull(item);
  	    String val = item.getStringValue();
	assertEquals("XYZ", val);
	assertNull(itr.next());
}
 
开发者ID:dsukhoroslov,项目名称:bagri,代码行数:38,代码来源:SaxonQueryTest.java


示例13: testJsonQuery

import net.sf.saxon.query.XQueryExpression; //导入依赖的package包/类
@Test
@Ignore
public void testJsonQuery() throws XPathException {
       Configuration config = Configuration.newConfiguration();
       config.setDefaultCollection("");
       StaticQueryContext sqc = config.newStaticQueryContext();
	sqc.setLanguageVersion(saxon_xquery_version); 
  	    DynamicQueryContext dqc = new DynamicQueryContext(config);
       dqc.setApplyFunctionConversionRulesToExternalVariables(false);

	String query = "declare base-uri \"../../etc/samples/json/\";\n" +
			//"declare base-uri \"C:/Work/Bagri/git/bagri/etc/samples/json/\";\n" +
			"declare namespace map=\"http://www.w3.org/2005/xpath-functions/map\";\n" +
			//"declare variable $value external;\n" +
			"for $map in fn:collection()\n" +
			//"where $map?Security?Symbol = $value\n" +
			"let $v := map:get($map, 'Security')\n" +
			//"where get($map, '-id') = '5621'\n" +
			"where map:get($v, 'Symbol') = 'IBM'\n" +
			"return $v?Name";
       
  	    XQueryExpression xqExp = sqc.compileQuery(query);
  	    //dqc.setParameter(new StructuredQName("", "", "value"), objectToItem("IBM", config));
       SequenceIterator itr = xqExp.iterator(dqc);
       Item item = itr.next();
  	    assertNotNull(item);
  	    String val = item.getStringValue();
	assertEquals("Internatinal Business Machines Corporation", val);
	assertNull(itr.next());
}
 
开发者ID:dsukhoroslov,项目名称:bagri,代码行数:31,代码来源:SaxonQueryTest.java


示例14: callXQueryFunction

import net.sf.saxon.query.XQueryExpression; //导入依赖的package包/类
public final Sequence callXQueryFunction (String filename, String namespaceURI, String functionName, Sequence[] args) throws XQueryException {
    Sequence[] actualArgs = (args == null) ? new Sequence[] {} : args;
    try {
        StaticQueryContext sqc = this.processor.getUnderlyingConfiguration().newStaticQueryContext();
        XQueryExpression exp = sqc.compileQuery(fromResource(filename));
        int numOfArgs = (args == null) ? 0 : args.length;
        UserFunction function = exp.getStaticContext().getUserDefinedFunction(namespaceURI, functionName, numOfArgs);
        return function.call(actualArgs, exp.newController());
    }
    catch (XPathException | IOException e) {
        throw new XQueryException("Unable to call function " + namespaceURI + ":" + functionName, e);
    }
}
 
开发者ID:SteveGodwin,项目名称:mock-xquery,代码行数:14,代码来源:XQueryContext.java


示例15: evaluateXPath

import net.sf.saxon.query.XQueryExpression; //导入依赖的package包/类
/**
 * Evaluates specified XPath expression against given XML text and using given runtime configuration.
 * @param xpath
 * @param xml
 * @param runtimeConfig
 * @return Instance of ListVariable that contains results.
 * @throws XPathException
 */
public static ListVariable evaluateXPath(String xpath, String xml, RuntimeConfig runtimeConfig) throws XPathException {
    StaticQueryContext sqc = runtimeConfig.getStaticQueryContext();
    Configuration config = sqc.getConfiguration();

    XQueryExpression exp = runtimeConfig.getXQueryExpressionPool().getCompiledExpression(xpath);
    DynamicQueryContext dynamicContext = new DynamicQueryContext(config);
    StringReader reader = new StringReader(xml);

    dynamicContext.setContextItem(sqc.buildDocument(new StreamSource(reader)));

    return createListOfXmlNodes(exp, dynamicContext);
}
 
开发者ID:huajun2013,项目名称:ablaze,代码行数:21,代码来源:XmlUtil.java


示例16: getCompiledExpression

import net.sf.saxon.query.XQueryExpression; //导入依赖的package包/类
public synchronized XQueryExpression getCompiledExpression(String query) throws XPathException {
    if ( pool.containsKey(query) ) {
        return (XQueryExpression) pool.get(query);
    } else {
        XQueryExpression exp = sqc.compileQuery(query);
        pool.put(query, exp);
        return exp;
    }
}
 
开发者ID:huajun2013,项目名称:ablaze,代码行数:10,代码来源:XQueryExpressionPool.java


示例17: getExpression

import net.sf.saxon.query.XQueryExpression; //导入依赖的package包/类
public XQueryExpression getExpression() throws IOException, XPathException {
    return expression;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:4,代码来源:XQueryBuilder.java


示例18: setExpression

import net.sf.saxon.query.XQueryExpression; //导入依赖的package包/类
void setExpression(XQueryExpression exp) {
	this.exp = exp;
}
 
开发者ID:dsukhoroslov,项目名称:bagri,代码行数:4,代码来源:CollectionFinderImpl.java


示例19: getModuleFunctions

import net.sf.saxon.query.XQueryExpression; //导入依赖的package包/类
@Override
public List<String> getModuleFunctions(Module module) throws BagriException {
	long stamp = System.currentTimeMillis();
	logger.trace("getModuleFunctions.enter; got module: {}", module);
	XQueryExpression exp = getModuleExpression(module);
	List<String> result = lookupFunctions(exp.getExecutable().getFunctionLibrary(), new FunctionExtractor<String>() {

		@Override
		public String extractFunction(UserFunction fn) {
			String decl = getFunctionDeclaration(fn); 
			AnnotationList atns = fn.getAnnotations(); 
			logger.trace("lookupFunctions; fn annotations: {}", atns);
			StringBuilder buff = new StringBuilder();
			for (Annotation atn: atns) {
				if (Annotation.PRIVATE.equals(atn.getAnnotationQName())) {
					// do not expose private functions
					return null;
				}
				buff.append(atn.getAnnotationQName().getDisplayName());
				if (atn.getAnnotationParameters() != null) {
					buff.append("(");
					int cnt = 0;
					for (AtomicValue av: atn.getAnnotationParameters()) {
						if (cnt > 0) {
							buff.append(", ");
						}
						buff.append("\"").append(av.getStringValue()).append("\"");
						cnt++;
					}
					buff.append(")");
				}
				buff.append("\n");
			}
			decl = buff.toString() + decl;
			return decl;
		}
		
	});
	stamp = System.currentTimeMillis() - stamp;
	logger.trace("getModuleFunctions.exit; time taken: {}; returning: {}", stamp, result);
	return result;
}
 
开发者ID:dsukhoroslov,项目名称:bagri,代码行数:43,代码来源:XQCompilerImpl.java


示例20: XQueryOperator

import net.sf.saxon.query.XQueryExpression; //导入依赖的package包/类
public XQueryOperator(Configuration configuration, XQueryExpression xQueryExpression, Properties outputProperties) {
  this.configuration = configuration;
  this.xQueryExpression = xQueryExpression;
  this.outputProperties = outputProperties;
}
 
开发者ID:camunda,项目名称:camunda-template-engines-jsr223,代码行数:6,代码来源:XQueryOperator.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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