Package org.exist.xquery

Examples of org.exist.xquery.NameTest


    }
   
    @Test
    public void selectFollowingSiblings() throws XPathException, SAXException, PermissionDeniedException {
        Sequence largeSet = executeQuery(broker, "//SPEECH/LINE[fn:contains(., 'love')]/ancestor::SPEECH/SPEAKER", 187, null);
        NameTest test = new NameTest(Type.ELEMENT, new QName("LINE", ""));
        NodeSet lines = broker.getStructuralIndex().findElementsByTagName(ElementValue.ELEMENT, docs, test.getName(), null);
       
        NodeSet result = ((AbstractNodeSet) lines).selectFollowingSiblings(largeSet.toNodeSet(), -1);
        assertEquals(1689, result.getLength());
    }
View Full Code Here


        assertEquals(1689, result.getLength());
    }
   
    @Test
    public void selectPrecedingSiblings() throws XPathException, SAXException, PermissionDeniedException {
        NameTest test = new NameTest(Type.ELEMENT, new QName("SPEAKER", ""));
        NodeSet speakers = broker.getStructuralIndex().findElementsByTagName(ElementValue.ELEMENT, docs, test.getName(), null);
        Sequence largeSet = executeQuery(broker, "//SPEECH/LINE[fn:contains(., 'love')]/ancestor::SPEECH/LINE[1]", 187, null);
       
        NodeSet result = ((AbstractNodeSet) speakers).selectPrecedingSiblings(largeSet.toNodeSet(), -1);
        assertEquals(187, result.getLength());
    }
View Full Code Here

    }
   
    @Test
    public void extArrayNodeSet_selectParentChild_1() throws XPathException, SAXException, PermissionDeniedException {
        Sequence nestedSet = executeQuery(broker, "//section[@n = ('1.1', '1.1.1')]", 2, null);
        NameTest test = new NameTest(Type.ELEMENT, new QName("para", ""));
        NodeSet children = broker.getStructuralIndex().findElementsByTagName(ElementValue.ELEMENT, docs, test.getName(), null);
       
        NodeSet result = children.selectParentChild(nestedSet.toNodeSet(), NodeSet.DESCENDANT);
        assertEquals(3, result.getLength());
    }
View Full Code Here

    }
   
    @Test
    public void extArrayNodeSet_selectParentChild_2() throws XPathException, SAXException, PermissionDeniedException {
        Sequence nestedSet = executeQuery(broker, "//section[@n = ('1.1', '1.1.2', '1.2')]", 3, null);
        NameTest test = new NameTest(Type.ELEMENT, new QName("para", ""));
        NodeSet children = broker.getStructuralIndex().findElementsByTagName(ElementValue.ELEMENT, docs, test.getName(), null);
       
        NodeSet result = children.selectParentChild(nestedSet.toNodeSet(), NodeSet.DESCENDANT);
        assertEquals(2, result.getLength());
    }
View Full Code Here

    }
   
    @Test
    public void extArrayNodeSet_selectParentChild_3() throws XPathException, SAXException, PermissionDeniedException {
        Sequence nestedSet = executeQuery(broker, "//section[@n = ('1.1', '1.1.1', '1.2')]", 3, null);
        NameTest test = new NameTest(Type.ELEMENT, new QName("para", ""));
        NodeSet children = broker.getStructuralIndex().findElementsByTagName(ElementValue.ELEMENT, docs, test.getName(), null);
       
        NodeSet result = children.selectParentChild(nestedSet.toNodeSet(), NodeSet.DESCENDANT);
        assertEquals(4, result.getLength());
    }
View Full Code Here

    }
   
    @Test
    public void extArrayNodeSet_selectParentChild_4() throws XPathException, SAXException, PermissionDeniedException {
        Sequence nestedSet = executeQuery(broker, "//para[@n = ('1.1.2.1')]", 1, null);
        NameTest test = new NameTest(Type.ELEMENT, new QName("section", ""));
        NodeSet sections = broker.getStructuralIndex().findElementsByTagName(ElementValue.ELEMENT, docs, test.getName(), null);
       
        NodeSet result = ((NodeSet) nestedSet).selectParentChild(sections.toNodeSet(), NodeSet.DESCENDANT);
        assertEquals(1, result.getLength());
    }
View Full Code Here

   
    private void declareExternalAndXQJVariables(final XQueryContext context,
        final ElementImpl variables) throws XPathException {

        final ValueSequence varSeq = new ValueSequence();
        variables.selectChildren(new NameTest(Type.ELEMENT, new QName(Variable.xmlKey(), Namespaces.EXIST_NS)), varSeq);
        for (final SequenceIterator i = varSeq.iterate(); i.hasNext();) {
            final ElementImpl variable = (ElementImpl) i.nextItem();
            // get the QName of the variable
            final ElementImpl qname = (ElementImpl) variable.getFirstChild(new NameTest(Type.ELEMENT, new QName("qname", Namespaces.EXIST_NS)));
            String localname = null, prefix = null, uri = null;
            NodeImpl child = (NodeImpl) qname.getFirstChild();
            while (child != null) {
                if ("localname".equals(child.getLocalName())) {
                    localname = child.getStringValue();

                } else if ("namespace".equals(child.getLocalName())) {
                    uri = child.getStringValue();

                } else if ("prefix".equals(child.getLocalName())) {
                    prefix = child.getStringValue();

                }
                child = (NodeImpl) child.getNextSibling();
            }

            if (uri != null && prefix != null) {
                context.declareNamespace(prefix, uri);
            }

            if (localname == null) {
                continue;
            }

            final QName q;
            if (prefix != null && localname != null) {
                q = new QName(localname, uri, prefix);
            } else {
                q = new QName(localname, uri, XMLConstants.DEFAULT_NS_PREFIX);
            }

            // get serialized sequence
            final NodeImpl value = variable.getFirstChild(new NameTest(Type.ELEMENT, Marshaller.ROOT_ELEMENT_QNAME));
            final Sequence sequence;
            try {
                sequence = value == null ? Sequence.EMPTY_SEQUENCE : Marshaller.demarshall(value);
            } catch (final XMLStreamException xe) {
                throw new XPathException(xe.toString());
View Full Code Here

            {throw new XMLStreamException("Root element is not in the correct namespace. Expected: " + NAMESPACE);}
        if (!SEQ_ELEMENT.equals(node.getLocalName()))
            {throw new XMLStreamException("Root element should be a " + SEQ_ELEMENT_QNAME);}
        final ValueSequence result = new ValueSequence();
        final InMemoryNodeSet values = new InMemoryNodeSet();
        node.selectChildren(new NameTest(Type.ELEMENT, VALUE_QNAME), values);
        for (final SequenceIterator i = values.iterate(); i.hasNext();) {
            final ElementImpl child = (ElementImpl) i.nextItem();
            final String typeName = child.getAttribute(ATTR_TYPE);
            if (typeName != null) {
                final int type = Type.getType(typeName);
View Full Code Here

TOP

Related Classes of org.exist.xquery.NameTest

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.