use of net.sf.saxon.s9api.Processor in project sirix by sirixdb.
the class XQueryEvaluatorSAXHandler method call.
@Override
public Void call() throws Exception {
try {
final Processor proc = new Processor(false);
final Configuration config = proc.getUnderlyingConfiguration();
final NodeInfo doc = new DocumentWrapper(mSession, config);
final XQueryCompiler comp = proc.newXQueryCompiler();
final XQueryExecutable exp = comp.compile(mExpression);
final net.sf.saxon.s9api.XQueryEvaluator exe = exp.load();
exe.setSource(doc);
exe.run(new SAXDestination(mHandler));
return null;
} catch (final SaxonApiException e) {
LOGGER.error("Saxon Exception: " + e.getMessage(), e);
throw e;
}
}
use of net.sf.saxon.s9api.Processor in project sirix by sirixdb.
the class XSLTEvaluator method call.
@Override
public OutputStream call() {
final Processor proc = new Processor(false);
final XsltCompiler comp = proc.newXsltCompiler();
XsltExecutable exp;
XdmNode source;
try {
final Configuration config = proc.getUnderlyingConfiguration();
final NodeInfo doc = new DocumentWrapper(mSession, config);
exp = comp.compile(new StreamSource(mStylesheet));
source = proc.newDocumentBuilder().build(doc);
if (mSerializer == null) {
final Serializer out = new Serializer();
out.setOutputProperty(Serializer.Property.METHOD, "xml");
out.setOutputProperty(Serializer.Property.INDENT, "yes");
out.setOutputStream(mOut);
mSerializer = out;
} else {
mSerializer.setOutputStream(mOut);
}
final XsltTransformer trans = exp.load();
trans.setInitialContextNode(source);
trans.setDestination(mSerializer);
trans.transform();
} catch (final SaxonApiException e) {
LOGGER.error("Saxon exception: " + e.getMessage(), e);
} catch (final SirixException e) {
LOGGER.error("TT exception: " + e.getMessage(), e);
}
return mOut;
}
use of net.sf.saxon.s9api.Processor in project sirix by sirixdb.
the class XMLReduce method reduce.
@Override
public void reduce(final DateWritable paramKey, final Iterable<Text> paramValue, final Context paramContext) throws IOException, InterruptedException {
final StringBuilder builder = new StringBuilder("<root>");
for (final Text event : paramValue) {
System.out.println(event.toString());
builder.append(event.toString());
}
builder.append("</root>");
// System.out.println(builder.toString());
final Processor proc = new Processor(false);
final XsltCompiler compiler = proc.newXsltCompiler();
try {
final XsltExecutable exec = compiler.compile(new StreamSource(new File(STYLESHEET)));
final XsltTransformer transform = exec.load();
transform.setSource(new StreamSource(new StringReader(builder.toString())));
final ByteArrayOutputStream out = new ByteArrayOutputStream();
final Serializer serializer = new Serializer();
serializer.setOutputStream(out);
transform.setDestination(serializer);
transform.transform();
final String value = out.toString();
// System.out.println(value);
paramContext.write(null, new Text(value));
} catch (final SaxonApiException e) {
LOGWRAPPER.error(e);
}
}
use of net.sf.saxon.s9api.Processor in project jmeter by apache.
the class XPathUtilTest method testBug63033.
@Test
public void testBug63033() throws SaxonApiException {
Processor p = new Processor(false);
XPathCompiler c = p.newXPathCompiler();
c.declareNamespace("age", "http://www.w3.org/2003/01/geo/wgs84_pos#");
String xPathQuery = "//Employees/Employee[1]/age:ag";
XPathExecutable e = c.compile(xPathQuery);
XPathSelector selector = e.load();
selector.setContextItem(p.newDocumentBuilder().build(new StreamSource(new StringReader(xmlDoc))));
XdmValue nodes = selector.evaluate();
XdmItem item = nodes.itemAt(0);
assertEquals("<age:ag xmlns:age=\"http://www.w3.org/2003/01/geo/wgs84_pos#\">29</age:ag>", item.toString());
}
use of net.sf.saxon.s9api.Processor in project jmeter by apache.
the class XPathQueryCacheLoader method load.
@Override
public XPathExecutable load(ImmutablePair<String, String> key) throws Exception {
String xPathQuery = key.left;
String namespacesString = key.right;
Processor processor = XPathUtil.getProcessor();
XPathCompiler xPathCompiler = processor.newXPathCompiler();
List<String[]> namespacesList = XPathUtil.namespacesParse(namespacesString);
log.debug("Parsed namespaces:{} into list of namespaces:{}", namespacesString, namespacesList);
for (String[] namespaces : namespacesList) {
xPathCompiler.declareNamespace(namespaces[0], namespaces[1]);
}
log.debug("Declared namespaces:{}, now compiling xPathQuery:{}", namespacesList, xPathQuery);
return xPathCompiler.compile(xPathQuery);
}
Aggregations