Search in sources :

Example 1 with NodeInfo

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

the class NodeWrapper method getParent.

@Override
public NodeInfo getParent() {
    try {
        NodeInfo parent = null;
        final NodeReadTrx rtx = createRtxAndMove();
        if (rtx.hasParent()) {
            // Parent transaction.
            parent = new NodeWrapper(mDocWrapper, rtx.getParentKey());
        }
        rtx.close();
        return parent;
    } catch (final SirixException e) {
        LOGGER.error(e.getMessage(), e);
        return null;
    }
}
Also used : NodeReadTrx(org.sirix.api.NodeReadTrx) NodeInfo(net.sf.saxon.om.NodeInfo) SirixException(org.sirix.exception.SirixException)

Example 2 with NodeInfo

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

the class NodeWrapper method getBaseURI.

@Override
public String getBaseURI() {
    String baseURI = null;
    NodeInfo node = this;
    while (node != null) {
        baseURI = node.getAttributeValue(StandardNames.XML_BASE);
        if (baseURI == null) {
            // Search for baseURI in parent node (xml:base="").
            node = node.getParent();
        } else {
            break;
        }
    }
    if (baseURI == null) {
        baseURI = mDocWrapper.getBaseURI();
    }
    return baseURI;
}
Also used : NodeInfo(net.sf.saxon.om.NodeInfo)

Example 3 with NodeInfo

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

the class NodeWrapper method getAttributeValue.

@Override
public String getAttributeValue(final int fingerprint) {
    String attVal = null;
    final NameTest test = new NameTest(Type.ATTRIBUTE, fingerprint, getNamePool());
    final AxisIterator iterator = iterateAxis(Axis.ATTRIBUTE, test);
    final NodeInfo attribute = (NodeInfo) iterator.next();
    if (attribute != null) {
        attVal = attribute.getStringValue();
    }
    return attVal;
}
Also used : NameTest(net.sf.saxon.pattern.NameTest) NodeInfo(net.sf.saxon.om.NodeInfo) AxisIterator(net.sf.saxon.tree.iter.AxisIterator)

Example 4 with NodeInfo

use of net.sf.saxon.om.NodeInfo 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();
}
Also used : NameTest(net.sf.saxon.pattern.NameTest) Processor(net.sf.saxon.s9api.Processor) NodeInfo(net.sf.saxon.om.NodeInfo) NodeWriteTrx(org.sirix.api.NodeWriteTrx) XMLEventReader(javax.xml.stream.XMLEventReader) XMLShredder(org.sirix.service.xml.shredder.XMLShredder) File(java.io.File) AxisIterator(net.sf.saxon.tree.iter.AxisIterator) Session(org.sirix.api.Session) NameTest(net.sf.saxon.pattern.NameTest) Test(org.junit.Test)

Example 5 with NodeInfo

use of net.sf.saxon.om.NodeInfo 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;
}
Also used : DocumentWrapper(org.sirix.saxon.wrapper.DocumentWrapper) Processor(net.sf.saxon.s9api.Processor) Configuration(net.sf.saxon.Configuration) XPathCompiler(net.sf.saxon.s9api.XPathCompiler) DocumentBuilder(net.sf.saxon.s9api.DocumentBuilder) NodeInfo(net.sf.saxon.om.NodeInfo) XPathSelector(net.sf.saxon.s9api.XPathSelector) XdmItem(net.sf.saxon.s9api.XdmItem)

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