Search in sources :

Example 16 with Item

use of org.exist.xquery.value.Item in project exist by eXist-db.

the class IndexerTest method store_and_retrieve_ws_mixed_content_value.

private String store_and_retrieve_ws_mixed_content_value(final boolean preserve, final String typeXml, final String typeXquery) throws EXistException, IOException, LockException, AuthenticationException, PermissionDeniedException, SAXException, XPathException {
    store_preserve_ws_mixed_content_value(preserve, typeXml);
    final BrokerPool pool = existEmbeddedServer.getBrokerPool();
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()))) {
        final XQuery xquery = pool.getXQueryService();
        final Sequence result = xquery.execute(broker, typeXquery, null);
        try (final StringWriter out = new StringWriter()) {
            final Properties props = new Properties();
            props.setProperty(OutputKeys.INDENT, "yes");
            final SAXSerializer serializer = new SAXSerializer(out, props);
            serializer.startDocument();
            for (final SequenceIterator i = result.iterate(); i.hasNext(); ) {
                final Item next = i.nextItem();
                next.toSAX(broker, serializer, props);
            }
            serializer.endDocument();
            return out.toString();
        }
    }
}
Also used : Item(org.exist.xquery.value.Item) DBBroker(org.exist.storage.DBBroker) StringWriter(java.io.StringWriter) SequenceIterator(org.exist.xquery.value.SequenceIterator) XQuery(org.exist.xquery.XQuery) Sequence(org.exist.xquery.value.Sequence) Properties(java.util.Properties) SAXSerializer(org.exist.util.serializer.SAXSerializer) BrokerPool(org.exist.storage.BrokerPool)

Example 17 with Item

use of org.exist.xquery.value.Item in project exist by eXist-db.

the class IndexerTest3 method store_and_retrieve_suppress_type.

private String store_and_retrieve_suppress_type(final String type, final String typeXml, final String typeXquery) throws EXistException, IOException, LockException, AuthenticationException, PermissionDeniedException, SAXException, XPathException {
    store_suppress_type(type, typeXml);
    final BrokerPool pool = existEmbeddedServer.getBrokerPool();
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
        final StringWriter out = new StringWriter()) {
        final XQuery xquery = pool.getXQueryService();
        final Sequence result = xquery.execute(broker, typeXquery, null);
        final Properties props = new Properties();
        props.setProperty(OutputKeys.INDENT, "no");
        final SAXSerializer serializer = new SAXSerializer(out, props);
        serializer.startDocument();
        for (final SequenceIterator i = result.iterate(); i.hasNext(); ) {
            final Item next = i.nextItem();
            next.toSAX(broker, serializer, props);
        }
        serializer.endDocument();
        return out.toString();
    }
}
Also used : Item(org.exist.xquery.value.Item) DBBroker(org.exist.storage.DBBroker) StringWriter(java.io.StringWriter) SequenceIterator(org.exist.xquery.value.SequenceIterator) XQuery(org.exist.xquery.XQuery) Sequence(org.exist.xquery.value.Sequence) Properties(java.util.Properties) SAXSerializer(org.exist.util.serializer.SAXSerializer) BrokerPool(org.exist.storage.BrokerPool)

Example 18 with Item

use of org.exist.xquery.value.Item in project exist by eXist-db.

the class IntersectTest method memtree_intersect_memtree.

/**
 * Tests the XQuery `intersect` operator against an
 * in-memory node on both the left and right sides
 */
@Test
public void memtree_intersect_memtree() throws XPathException, NoSuchMethodException {
    final XQueryContext mockContext = createMock(XQueryContext.class);
    final PathExpr mockLeft = createMock(PathExpr.class);
    final PathExpr mockRight = createMock(PathExpr.class);
    final Sequence mockContextSequence = createMock(Sequence.class);
    final Item mockContextItem = createMock(Item.class);
    final Profiler mockProfiler = createMock(Profiler.class);
    expect(mockContext.nextExpressionId()).andReturn(1);
    expect(mockContext.getProfiler()).andReturn(mockProfiler);
    final org.exist.dom.memtree.ElementImpl memElement = (org.exist.dom.memtree.ElementImpl) createInMemoryDocument().getDocumentElement();
    // memtree node
    expect(mockLeft.eval(mockContextSequence, mockContextItem)).andReturn(memElement);
    // same memtree node
    expect(mockRight.eval(mockContextSequence, mockContextItem)).andReturn(memElement);
    expect(mockContext.getProfiler()).andReturn(mockProfiler);
    replay(mockRight, mockLeft, mockContext);
    // test
    final Intersect intersect = new Intersect(mockContext, mockLeft, mockRight);
    final Sequence result = intersect.eval(mockContextSequence, mockContextItem);
    assertEquals(1, ((ValueSequence) result).size());
    verify(mockRight, mockLeft, mockContext);
}
Also used : Item(org.exist.xquery.value.Item) ValueSequence(org.exist.xquery.value.ValueSequence) Sequence(org.exist.xquery.value.Sequence) Test(org.junit.Test)

Example 19 with Item

use of org.exist.xquery.value.Item in project exist by eXist-db.

the class IntersectTest method memtree_intersect_persistent.

/**
 * Tests the XQuery `intersect` operator against an
 * in-memory node on the left and a persistent node on the right
 */
@Test
public void memtree_intersect_persistent() throws XPathException, NoSuchMethodException {
    final XQueryContext mockContext = createMock(XQueryContext.class);
    final PathExpr mockLeft = createMock(PathExpr.class);
    final PathExpr mockRight = createMock(PathExpr.class);
    final Sequence mockContextSequence = createMock(Sequence.class);
    final Item mockContextItem = createMock(Item.class);
    final Profiler mockProfiler = createMock(Profiler.class);
    final DocumentImpl mockPersistentDoc = createMock(DocumentImpl.class);
    final NodeProxy mockPersistentNode = createMockBuilder(NodeProxy.class).withConstructor(DocumentImpl.class, NodeId.class).withArgs(mockPersistentDoc, new DLN(1)).addMockedMethods(NodeProxy.class.getMethod("isEmpty", new Class[] {}), NodeProxy.class.getMethod("getItemType", new Class[] {}), NodeProxy.class.getMethod("equals", new Class[] { Object.class })).createMock();
    expect(mockContext.nextExpressionId()).andReturn(1);
    expect(mockContext.getProfiler()).andReturn(mockProfiler);
    // memtree node
    expect(mockLeft.eval(mockContextSequence, mockContextItem)).andReturn((org.exist.dom.memtree.ElementImpl) createInMemoryDocument().getDocumentElement());
    // persistent node
    expect(mockRight.eval(mockContextSequence, mockContextItem)).andReturn(mockPersistentNode);
    expect(mockPersistentNode.isEmpty()).andReturn(false);
    expect(mockPersistentNode.getItemType()).andReturn(Type.NODE);
    expect(mockContext.getProfiler()).andReturn(mockProfiler);
    replay(mockPersistentDoc, mockPersistentNode, mockRight, mockLeft, mockContext);
    // test
    final Intersect intersect = new Intersect(mockContext, mockLeft, mockRight);
    final Sequence result = intersect.eval(mockContextSequence, mockContextItem);
    assertEquals(0, ((ValueSequence) result).size());
    verify(mockPersistentDoc, mockPersistentNode, mockRight, mockLeft, mockContext);
}
Also used : Item(org.exist.xquery.value.Item) DLN(org.exist.numbering.DLN) NodeId(org.exist.numbering.NodeId) ValueSequence(org.exist.xquery.value.ValueSequence) Sequence(org.exist.xquery.value.Sequence) DocumentImpl(org.exist.dom.persistent.DocumentImpl) NodeProxy(org.exist.dom.persistent.NodeProxy) Test(org.junit.Test)

Example 20 with Item

use of org.exist.xquery.value.Item in project exist by eXist-db.

the class SerializeAttrMatchesTest method expandAttr.

@Test
public void expandAttr() throws CollectionConfigurationException, LockException, IOException, SAXException, PermissionDeniedException, EXistException, XPathException {
    configureAndStore(COLLECTION_CONFIG, XML, "test1.xml");
    // query and expand
    final String query = "for $hit in collection(\"" + TestConstants.TEST_COLLECTION_URI.toString() + "\")//w[ft:query(@lemma, <query><regex>књиг.*</regex></query>)]\n" + "return util:expand($hit, \"highlight-matches=both\")";
    final BrokerPool pool = existEmbeddedServer.getBrokerPool();
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()))) {
        final XQuery xquery = pool.getXQueryService();
        final Sequence seq = xquery.execute(broker, query, null);
        assertEquals(1, seq.getItemCount());
        final Item item = seq.itemAt(0);
        assertTrue(item instanceof ElementImpl);
        assertEquals("lemma", ((ElementImpl) item).getAttribute("exist:matches"));
    }
}
Also used : Item(org.exist.xquery.value.Item) DBBroker(org.exist.storage.DBBroker) ElementImpl(org.exist.dom.memtree.ElementImpl) XQuery(org.exist.xquery.XQuery) Sequence(org.exist.xquery.value.Sequence) BrokerPool(org.exist.storage.BrokerPool)

Aggregations

Item (org.exist.xquery.value.Item)88 Sequence (org.exist.xquery.value.Sequence)69 SequenceIterator (org.exist.xquery.value.SequenceIterator)36 XPathException (org.exist.xquery.XPathException)26 DBBroker (org.exist.storage.DBBroker)18 NodeValue (org.exist.xquery.value.NodeValue)17 XQuery (org.exist.xquery.XQuery)16 ValueSequence (org.exist.xquery.value.ValueSequence)16 BrokerPool (org.exist.storage.BrokerPool)14 NumericValue (org.exist.xquery.value.NumericValue)12 SAXException (org.xml.sax.SAXException)11 Properties (java.util.Properties)10 StringValue (org.exist.xquery.value.StringValue)10 Node (org.w3c.dom.Node)10 MemTreeBuilder (org.exist.dom.memtree.MemTreeBuilder)9 AtomicValue (org.exist.xquery.value.AtomicValue)9 Txn (org.exist.storage.txn.Txn)8 IOException (java.io.IOException)7 StringWriter (java.io.StringWriter)7 EXistException (org.exist.EXistException)7