Search in sources :

Example 31 with NodeInfo

use of net.sf.saxon.om.NodeInfo in project sirix by sirixdb.

the class TestNodeWrapper method testGetAttributeValue.

@Test
public void testGetAttributeValue() throws SirixException {
    final Processor proc = new Processor(false);
    node = new NodeWrapper(new DocumentWrapper(mHolder.getSession(), proc.getUnderlyingConfiguration()), 1);
    final AxisIterator iterator = node.iterateAxis(Axis.ATTRIBUTE);
    final NodeInfo attribute = (NodeInfo) iterator.next();
    node.getNamePool().allocate(attribute.getPrefix(), attribute.getURI(), attribute.getLocalPart());
    // Only supported on element nodes.
    // node = (NodeWrapper) node.getParent();
    assertEquals("j", node.getAttributeValue(attribute.getFingerprint()));
}
Also used : Processor(net.sf.saxon.s9api.Processor) NodeInfo(net.sf.saxon.om.NodeInfo) AxisIterator(net.sf.saxon.tree.iter.AxisIterator) NameTest(net.sf.saxon.pattern.NameTest) Test(org.junit.Test)

Example 32 with NodeInfo

use of net.sf.saxon.om.NodeInfo 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;
    }
}
Also used : XQueryExecutable(net.sf.saxon.s9api.XQueryExecutable) DocumentWrapper(org.sirix.saxon.wrapper.DocumentWrapper) Processor(net.sf.saxon.s9api.Processor) Configuration(net.sf.saxon.Configuration) NodeInfo(net.sf.saxon.om.NodeInfo) XQueryCompiler(net.sf.saxon.s9api.XQueryCompiler) SAXDestination(net.sf.saxon.s9api.SAXDestination) SaxonApiException(net.sf.saxon.s9api.SaxonApiException)

Example 33 with NodeInfo

use of net.sf.saxon.om.NodeInfo 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;
}
Also used : DocumentWrapper(org.sirix.saxon.wrapper.DocumentWrapper) Processor(net.sf.saxon.s9api.Processor) Configuration(net.sf.saxon.Configuration) NodeInfo(net.sf.saxon.om.NodeInfo) StreamSource(javax.xml.transform.stream.StreamSource) XsltTransformer(net.sf.saxon.s9api.XsltTransformer) SirixException(org.sirix.exception.SirixException) XsltCompiler(net.sf.saxon.s9api.XsltCompiler) XdmNode(net.sf.saxon.s9api.XdmNode) SaxonApiException(net.sf.saxon.s9api.SaxonApiException) XsltExecutable(net.sf.saxon.s9api.XsltExecutable) Serializer(net.sf.saxon.s9api.Serializer)

Example 34 with NodeInfo

use of net.sf.saxon.om.NodeInfo in project sirix by sirixdb.

the class TestNodeWrapperXPath method testNamespaceAttributeValue.

@Test
public void testNamespaceAttributeValue() throws Exception {
    xpe.setNamespaceContext(new DocNamespaceContext());
    final XPathExpression findLine = xpe.compile("//p:a/@p:i");
    final NodeInfo doc = new DocumentWrapper(mHolder.getSession(), config);
    // Execute XPath.
    final String result = findLine.evaluate(doc, XPathConstants.STRING).toString();
    assertNotNull(result);
    assertEquals("", result);
}
Also used : XPathExpression(javax.xml.xpath.XPathExpression) NodeInfo(net.sf.saxon.om.NodeInfo) Test(org.junit.Test)

Example 35 with NodeInfo

use of net.sf.saxon.om.NodeInfo in project sirix by sirixdb.

the class TestNodeWrapperXPath method testNamespaceElementCount.

@Test
public void testNamespaceElementCount() throws Exception {
    xpe.setNamespaceContext(new DocNamespaceContext());
    final XPathExpression findLine = xpe.compile("count(//p:a)");
    final NodeInfo doc = new DocumentWrapper(mHolder.getSession(), config);
    // Execute XPath.
    final double result = Double.parseDouble(findLine.evaluate(doc, XPathConstants.NUMBER).toString());
    assertNotNull(result);
    assertEquals(1D, result, 0D);
}
Also used : XPathExpression(javax.xml.xpath.XPathExpression) NodeInfo(net.sf.saxon.om.NodeInfo) Test(org.junit.Test)

Aggregations

NodeInfo (net.sf.saxon.om.NodeInfo)52 Test (org.junit.Test)21 XPathExpression (javax.xml.xpath.XPathExpression)16 Test (org.junit.jupiter.api.Test)14 Processor (net.sf.saxon.s9api.Processor)8 Configuration (net.sf.saxon.Configuration)7 DetailAST (com.puppycrawl.tools.checkstyle.api.DetailAST)5 DocumentWrapper (org.sirix.saxon.wrapper.DocumentWrapper)5 NameTest (net.sf.saxon.pattern.NameTest)4 SaxonApiException (net.sf.saxon.s9api.SaxonApiException)4 XQueryCompiler (net.sf.saxon.s9api.XQueryCompiler)3 XQueryExecutable (net.sf.saxon.s9api.XQueryExecutable)3 AxisIterator (net.sf.saxon.tree.iter.AxisIterator)3 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 Item (net.sf.saxon.om.Item)2 Serializer (net.sf.saxon.s9api.Serializer)2 NodeReadTrx (org.sirix.api.NodeReadTrx)2 NodeList (org.w3c.dom.NodeList)2