Search in sources :

Example 16 with NodeInfo

use of net.sf.saxon.om.NodeInfo in project teiid by teiid.

the class SaxonXQueryExpression method createXMLType.

public XMLType createXMLType(final SequenceIterator iter, BufferManager bufferManager, boolean emptyOnEmpty, CommandContext context) throws XPathException, TeiidComponentException, TeiidProcessingException {
    final Item item = iter.next();
    if (item == null && !emptyOnEmpty) {
        return null;
    }
    XMLType.Type type = Type.CONTENT;
    if (item instanceof NodeInfo) {
        NodeInfo info = (NodeInfo) item;
        type = getType(info);
    }
    final Item next = iter.next();
    if (next != null) {
        type = Type.CONTENT;
    }
    SQLXMLImpl xml = XMLSystemFunctions.saveToBufferManager(bufferManager, new XMLTranslator() {

        @Override
        public void translate(Writer writer) throws TransformerException, IOException {
            QueryResult.serializeSequence(new PushBackSequenceIterator(iter, item, next), config, writer, DEFAULT_OUTPUT_PROPERTIES);
        }
    }, context);
    XMLType value = new XMLType(xml);
    value.setType(type);
    return value;
}
Also used : Item(net.sf.saxon.om.Item) NamespaceItem(org.teiid.query.sql.symbol.XMLNamespaces.NamespaceItem) XMLType(org.teiid.core.types.XMLType) SQLXMLImpl(org.teiid.core.types.SQLXMLImpl) NodeInfo(net.sf.saxon.om.NodeInfo) Type(org.teiid.core.types.XMLType.Type) IOException(java.io.IOException) XMLTranslator(org.teiid.core.types.XMLTranslator) Writer(java.io.Writer) TransformerException(javax.xml.transform.TransformerException)

Example 17 with NodeInfo

use of net.sf.saxon.om.NodeInfo in project checkstyle by checkstyle.

the class ElementNode method compareCommonAncestorChildrenOrder.

/**
 * Walks up the hierarchy until a common ancestor is found.
 * Then compares topmost sibling nodes.
 *
 * @param first {@code NodeInfo} to compare
 * @param second {@code NodeInfo} to compare
 * @return the value {@code 0} if {@code first == second};
 *         a value less than {@code 0} if {@code first} should be first;
 *         a value greater than {@code 0} if {@code second} should be first.
 */
private static int compareCommonAncestorChildrenOrder(NodeInfo first, NodeInfo second) {
    NodeInfo child1 = first;
    NodeInfo child2 = second;
    while (!child1.getParent().equals(child2.getParent())) {
        child1 = child1.getParent();
        child2 = child2.getParent();
    }
    final int index1 = ((ElementNode) child1).indexAmongSiblings;
    final int index2 = ((ElementNode) child2).indexAmongSiblings;
    return Integer.compare(index1, index2);
}
Also used : NodeInfo(net.sf.saxon.om.NodeInfo)

Example 18 with NodeInfo

use of net.sf.saxon.om.NodeInfo in project checkstyle by checkstyle.

the class PrecedingIterator method next.

/**
 * Get the next item in the sequence.
 *
 * @return the next Item. If there are no more nodes, return null.
 */
@Override
public NodeInfo next() {
    NodeInfo result = null;
    while (result == null) {
        if (descendantEnum != null) {
            result = descendantEnum.next();
        }
        if (result == null && previousSiblingEnum != null) {
            result = previousSiblingEnum.next();
            if (result == null) {
                previousSiblingEnum = null;
            } else {
                descendantEnum = new ReverseDescendantIterator(result);
            }
        }
        if (result == null) {
            result = ancestorEnum.next();
            if (result == null) {
                break;
            }
            previousSiblingEnum = result.iterateAxis(AxisInfo.PRECEDING_SIBLING);
        }
    }
    return result;
}
Also used : NodeInfo(net.sf.saxon.om.NodeInfo)

Example 19 with NodeInfo

use of net.sf.saxon.om.NodeInfo in project checkstyle by checkstyle.

the class ReverseDescendantIterator method pushToStack.

/**
 * Pushes all children to the stack.
 *
 * @param iterateAxis {@link AxisInfo#CHILD} axis iterator.
 */
private void pushToStack(AxisIterator iterateAxis) {
    NodeInfo nodeInfo = iterateAxis.next();
    while (nodeInfo != null) {
        stack.addLast(nodeInfo);
        nodeInfo = iterateAxis.next();
    }
}
Also used : NodeInfo(net.sf.saxon.om.NodeInfo)

Example 20 with NodeInfo

use of net.sf.saxon.om.NodeInfo in project checkstyle by checkstyle.

the class XpathMapperTest method testQueryAllMethodDefinitionsInContext.

@Test
public void testQueryAllMethodDefinitionsInContext() throws Exception {
    final String objectXpath = "//CLASS_DEF[./IDENT[@text='InputXpathMapperAst']]//OBJBLOCK";
    final RootNode rootNode = getRootNode("InputXpathMapperAst.java");
    final List<NodeInfo> objectNodes = getXpathItems(objectXpath, rootNode);
    assertWithMessage("Invalid number of nodes").that(objectNodes).hasSize(1);
    final AbstractNode objNode = (AbstractNode) objectNodes.get(0);
    final String methodsXpath = "METHOD_DEF";
    final List<NodeInfo> methodsNodes = getXpathItems(methodsXpath, objNode);
    assertWithMessage("Invalid number of nodes").that(methodsNodes).hasSize(2);
    final DetailAST[] actual = convertToArray(methodsNodes);
    final DetailAST expectedMethodDefNode = getSiblingByType(rootNode.getUnderlyingNode(), TokenTypes.COMPILATION_UNIT).findFirstToken(TokenTypes.CLASS_DEF).findFirstToken(TokenTypes.OBJBLOCK).findFirstToken(TokenTypes.METHOD_DEF);
    final DetailAST[] expected = { expectedMethodDefNode, expectedMethodDefNode.getNextSibling() };
    assertWithMessage("Result nodes differ from expected").that(actual).isEqualTo(expected);
    assertWithMessage("Invalid token type").that(actual[0].getType()).isEqualTo(TokenTypes.METHOD_DEF);
    assertWithMessage("Invalid token type").that(actual[1].getType()).isEqualTo(TokenTypes.METHOD_DEF);
}
Also used : NodeInfo(net.sf.saxon.om.NodeInfo) DetailAST(com.puppycrawl.tools.checkstyle.api.DetailAST) Test(org.junit.jupiter.api.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