本文整理汇总了Java中net.sf.saxon.query.DynamicQueryContext类的典型用法代码示例。如果您正苦于以下问题:Java DynamicQueryContext类的具体用法?Java DynamicQueryContext怎么用?Java DynamicQueryContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DynamicQueryContext类属于net.sf.saxon.query包,在下文中一共展示了DynamicQueryContext类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: testPersonQuery
import net.sf.saxon.query.DynamicQueryContext; //导入依赖的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
示例2: testCollationQuery
import net.sf.saxon.query.DynamicQueryContext; //导入依赖的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
示例3: createListOfXmlNodes
import net.sf.saxon.query.DynamicQueryContext; //导入依赖的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
示例4: configureQuery
import net.sf.saxon.query.DynamicQueryContext; //导入依赖的package包/类
/**
* Configures the dynamic context with exchange specific parameters
*/
protected void configureQuery(DynamicQueryContext dynamicQueryContext, Exchange exchange)
throws Exception {
addParameters(dynamicQueryContext, exchange.getProperties());
addParameters(dynamicQueryContext, exchange.getIn().getHeaders(), "in.headers.");
dynamicQueryContext.setParameter("in.body", exchange.getIn().getBody());
addParameters(dynamicQueryContext, getParameters());
dynamicQueryContext.setParameter("exchange", exchange);
if (exchange.hasOut() && exchange.getPattern().isOutCapable()) {
dynamicQueryContext.setParameter("out.body", exchange.getOut().getBody());
addParameters(dynamicQueryContext, exchange.getOut().getHeaders(), "out.headers.");
}
}
开发者ID:HydAu,项目名称:Camel,代码行数:17,代码来源:XQueryBuilder.java
示例5: XQProcessorImpl
import net.sf.saxon.query.DynamicQueryContext; //导入依赖的package包/类
public XQProcessorImpl() {
config = Configuration.newConfiguration();
//config.setSchemaValidationMode(Validation.STRIP);
//config.setConfigurationProperty(FeatureKeys.PRE_EVALUATE_DOC_FUNCTION, Boolean.TRUE);
sqc = config.newStaticQueryContext();
// supported in Saxon-EE only
//sqc.setUpdatingEnabled(true);
dqc = new DynamicQueryContext(config);
dqc.setApplyFunctionConversionRulesToExternalVariables(false);
//sqc. cvr = new StandardObjectConverter();
//JPConverter.allocate(XQItem.class, null, config);
}
开发者ID:dsukhoroslov,项目名称:bagri,代码行数:13,代码来源:XQProcessorImpl.java
示例6: testMapQuery
import net.sf.saxon.query.DynamicQueryContext; //导入依赖的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
示例7: testJsonQuery
import net.sf.saxon.query.DynamicQueryContext; //导入依赖的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
示例8: evaluate
import net.sf.saxon.query.DynamicQueryContext; //导入依赖的package包/类
public void evaluate(Result result, Object... parameters) throws TransformerException {
DynamicQueryContext context = new DynamicQueryContext(configuration);
if (parameters.length % 2 != 0) {
throw new IllegalArgumentException();
}
for (int i = 0; i < parameters.length; i += 2) {
Object value = parameters[i + 1];
Sequence sequence = mapValue(value);
context.setParameter(new StructuredQName("", "", (String) parameters[i]), sequence);
}
evaluate(context, result, outputProperties);
}
开发者ID:camunda,项目名称:camunda-template-engines-jsr223,代码行数:16,代码来源:XQueryOperator.java
示例9: evaluateXPath
import net.sf.saxon.query.DynamicQueryContext; //导入依赖的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
示例10: createDynamicContext
import net.sf.saxon.query.DynamicQueryContext; //导入依赖的package包/类
/**
* Creates a dynamic context for the given exchange
*/
protected DynamicQueryContext createDynamicContext(Exchange exchange) throws Exception {
Configuration config = getConfiguration();
DynamicQueryContext dynamicQueryContext = new DynamicQueryContext(config);
Message in = exchange.getIn();
Item item = null;
if (ObjectHelper.isNotEmpty(getHeaderName())) {
item = in.getHeader(getHeaderName(), Item.class);
} else {
item = in.getBody(Item.class);
}
if (item != null) {
dynamicQueryContext.setContextItem(item);
} else {
Object body = null;
if (ObjectHelper.isNotEmpty(getHeaderName())) {
body = in.getHeader(getHeaderName());
} else {
body = in.getBody();
}
// the underlying input stream, which we need to close to avoid locking files or other resources
InputStream is = null;
try {
Source source;
// only convert to input stream if really needed
if (isInputStreamNeeded(exchange)) {
if (ObjectHelper.isNotEmpty(getHeaderName())) {
is = exchange.getIn().getHeader(getHeaderName(), InputStream.class);
} else {
is = exchange.getIn().getBody(InputStream.class);
}
source = getSource(exchange, is);
} else {
source = getSource(exchange, body);
}
// special for bean invocation
if (source == null) {
if (body instanceof BeanInvocation) {
// if its a null bean invocation then handle that
BeanInvocation bi = exchange.getContext().getTypeConverter().convertTo(BeanInvocation.class, body);
if (bi.getArgs() != null && bi.getArgs().length == 1 && bi.getArgs()[0] == null) {
// its a null argument from the bean invocation so use null as answer
source = null;
}
}
}
if (source == null) {
// indicate it was not possible to convert to a Source type
throw new NoTypeConversionAvailableException(body, Source.class);
}
DocumentInfo doc = config.buildDocument(source);
dynamicQueryContext.setContextItem(doc);
} finally {
// can deal if is is null
IOHelper.close(is);
}
}
configureQuery(dynamicQueryContext, exchange);
// call the reset if the in message body is StreamCache
MessageHelper.resetStreamCache(exchange.getIn());
return dynamicQueryContext;
}
开发者ID:HydAu,项目名称:Camel,代码行数:71,代码来源:XQueryBuilder.java
示例11: addParameters
import net.sf.saxon.query.DynamicQueryContext; //导入依赖的package包/类
protected void addParameters(DynamicQueryContext dynamicQueryContext, Map<String, Object> map) {
addParameters(dynamicQueryContext, map, "");
}
开发者ID:HydAu,项目名称:Camel,代码行数:4,代码来源:XQueryBuilder.java
示例12: execute
import net.sf.saxon.query.DynamicQueryContext; //导入依赖的package包/类
public Variable execute(Scraper scraper, ScraperContext context) {
BaseElementDef xqueryElementDef = xqueryDef.getXqDef();
Variable xq = getBodyTextContent(xqueryElementDef, scraper, context, true);
debug(xqueryElementDef, scraper, xq);
String xqExpression = xq.toString().trim();
XQueryExternalParamDef[] externalParamDefs = xqueryDef.getExternalParamDefs();
RuntimeConfig runtimeConfig = scraper.getRuntimeConfig();
final StaticQueryContext sqc = runtimeConfig.getStaticQueryContext();
final Configuration config = sqc.getConfiguration();
try {
final XQueryExpression exp = runtimeConfig.getXQueryExpressionPool().getCompiledExpression(xqExpression);
final DynamicQueryContext dynamicContext = new DynamicQueryContext(config);
// define external parameters
for (int i = 0; i < externalParamDefs.length; i++) {
XQueryExternalParamDef externalParamDef = externalParamDefs[i];
String externalParamName = BaseTemplater.execute( externalParamDef.getName(), scraper.getScriptEngine() );
String externalParamType = BaseTemplater.execute( externalParamDefs[i].getType(), scraper.getScriptEngine() );
if (externalParamType == null) {
externalParamType = DEFAULT_PARAM_TYPE;
}
// check if param type is one of allowed
if ( !ALLOWED_PARAM_TYPES.contains(externalParamType) ) {
throw new ScraperXQueryException("Type " + externalParamType + " is not allowed. Use one of " + ALLOWED_PARAM_TYPES.toString());
}
if ( externalParamType.endsWith("*") ) {
BodyProcessor bodyProcessor = new BodyProcessor(externalParamDef);
bodyProcessor.setProperty("Name", externalParamName);
bodyProcessor.setProperty("Type", externalParamType);
ListVariable listVar = (ListVariable) bodyProcessor.run(scraper, context);
debug(externalParamDef, scraper, listVar);
Iterator it = listVar.toList().iterator();
List paramList = new ArrayList();
while (it.hasNext()) {
Variable currVar = (Variable) it.next();
paramList.add( castSimpleValue(externalParamType, currVar, sqc) );
}
dynamicContext.setParameter(externalParamName, paramList);
} else {
KeyValuePair props[] = {new KeyValuePair("Name", externalParamName), new KeyValuePair("Type", externalParamType)};
Variable var = getBodyTextContent(externalParamDef, scraper, context, true, props);
debug(externalParamDef, scraper, var);
Object value = castSimpleValue(externalParamType, var, sqc);
dynamicContext.setParameter(externalParamName, value);
}
}
return XmlUtil.createListOfXmlNodes(exp, dynamicContext);
} catch (XPathException e) {
throw new ScraperXQueryException("Error executing XQuery expression (XQuery = [" + xqExpression + "])!", e);
}
}
开发者ID:huajun2013,项目名称:ablaze,代码行数:62,代码来源:XQueryProcessor.java
注:本文中的net.sf.saxon.query.DynamicQueryContext类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论