use of net.sf.saxon.s9api.Processor in project sirix by sirixdb.
the class TestNodeWrapper method testGetBaseURI.
@Test
public void testGetBaseURI() throws Exception {
// Test with xml:base specified.
final File source = new File("src" + File.separator + "test" + File.separator + "resources" + File.separator + "data" + File.separator + "testBaseURI.xml");
final Session session = generateSession();
final NodeWriteTrx wtx = session.beginNodeWriteTrx();
final XMLEventReader reader = XMLShredder.createFileReader(source);
final XMLShredder shredder = new XMLShredder.Builder(wtx, reader, Insert.ASFIRSTCHILD).commitAfterwards().build();
shredder.call();
wtx.close();
final Processor proc = new Processor(false);
final NodeInfo doc = new DocumentWrapper(session, proc.getUnderlyingConfiguration());
doc.getNamePool().allocate("xml", "http://www.w3.org/XML/1998/namespace", "base");
doc.getNamePool().allocate("", "", "baz");
final NameTest test = new NameTest(Type.ELEMENT, "", "baz", doc.getNamePool());
final AxisIterator iterator = doc.iterateAxis(Axis.DESCENDANT, test);
final NodeInfo baz = (NodeInfo) iterator.next();
assertEquals("http://example.org", baz.getBaseURI());
session.close();
mDatabase.close();
}
use of net.sf.saxon.s9api.Processor in project sirix by sirixdb.
the class TestNodeWrapperS9ApiXSLT method saxonTransform.
/**
* Transform source document with the given stylesheet.
*
* @param xml
* Source xml file.
* @param stylesheet
* Stylesheet to transform sourc xml file.
* @throws SaxonApiException
* Exception from Saxon in case anything goes wrong.
*/
@Ignore("Not a test, utility method only")
public void saxonTransform(final File xml, final File stylesheet) throws SaxonApiException {
final Processor proc = new Processor(false);
final XsltCompiler comp = proc.newXsltCompiler();
final XsltExecutable exp = comp.compile(new StreamSource(stylesheet));
final XdmNode source = proc.newDocumentBuilder().build(new StreamSource(xml));
final Serializer out = new Serializer();
out.setOutputProperty(Serializer.Property.METHOD, "xml");
out.setOutputProperty(Serializer.Property.INDENT, "yes");
out.setOutputFile(new File(TestHelper.PATHS.PATH1.getFile(), "books1.html"));
final XsltTransformer trans = exp.load();
trans.setInitialContextNode(source);
trans.setDestination(out);
trans.transform();
}
use of net.sf.saxon.s9api.Processor in project sirix by sirixdb.
the class XPathEvaluator method call.
@Override
public XPathSelector call() throws Exception {
final Processor proc = new Processor(false);
final Configuration config = proc.getUnderlyingConfiguration();
final NodeInfo doc = new DocumentWrapper(mSession, mRevision, config);
final XPathCompiler xpath = proc.newXPathCompiler();
final DocumentBuilder builder = proc.newDocumentBuilder();
final XdmItem item = builder.wrap(doc);
final XPathSelector selector = xpath.compile(mExpression).load();
selector.setContextItem(item);
return selector;
}
use of net.sf.saxon.s9api.Processor in project sirix by sirixdb.
the class XQueryEvaluator method call.
@Override
public XdmValue call() throws Exception {
XdmValue value = null;
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);
value = exe.evaluate();
} catch (final SaxonApiException e) {
LOGGER.error("Saxon Exception: " + e.getMessage(), e);
throw e;
}
return value;
}
use of net.sf.saxon.s9api.Processor in project sirix by sirixdb.
the class XQueryEvaluatorOutputStream 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);
if (mSerializer == null) {
final Serializer out = new Serializer();
out.setOutputProperty(Serializer.Property.METHOD, "xml");
out.setOutputProperty(Serializer.Property.OMIT_XML_DECLARATION, "yes");
out.setOutputStream(mOut);
mSerializer = out;
}
final net.sf.saxon.s9api.XQueryEvaluator exe = exp.load();
exe.setSource(doc);
exe.run(mSerializer);
return null;
} catch (final SaxonApiException e) {
LOGGER.error("Saxon Exception: " + e.getMessage(), e);
throw e;
}
}
Aggregations