Search in sources :

Example 1 with NamedEvent

use of org.exist.stax.EmbeddedXMLStreamReaderTest.NamedEvent in project exist by eXist-db.

the class EmbeddedXMLStreamReaderTest method assertNodesIn.

public void assertNodesIn(final NamedEvent[] expected, final Function<Document, NodeHandle> initialNodeFun, final Optional<Function<Document, NodeHandle>> containerFun) throws EXistException, PermissionDeniedException, IOException, XMLStreamException {
    final BrokerPool pool = existEmbeddedServer.getBrokerPool();
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
        final Txn transaction = pool.getTransactionManager().beginTransaction()) {
        try (final LockedDocument lockedDocument = broker.getXMLResource(TEST_MIXED_XML_COLLECTION.append(MIXED_XML_NAME), Lock.LockMode.WRITE_LOCK)) {
            assertNotNull(lockedDocument);
            final Document document = lockedDocument.getDocument();
            assertNotNull(document);
            final NodeHandle initialNode = initialNodeFun.apply(document);
            final Optional<NodeHandle> maybeContainerNode = containerFun.map(f -> f.apply(document));
            final IEmbeddedXMLStreamReader xmlStreamReader = broker.getXMLStreamReader(initialNode, false);
            final NamedEvent[] actual = readAllEvents(maybeContainerNode, xmlStreamReader);
            assertArrayEquals(formatExpectedActual(expected, actual), expected, actual);
        }
        transaction.commit();
    }
}
Also used : DBBroker(org.exist.storage.DBBroker) NodeHandle(org.exist.dom.persistent.NodeHandle) LockedDocument(org.exist.dom.persistent.LockedDocument) Txn(org.exist.storage.txn.Txn) Document(org.w3c.dom.Document) LockedDocument(org.exist.dom.persistent.LockedDocument) NamedEvent(org.exist.stax.EmbeddedXMLStreamReaderTest.NamedEvent) BrokerPool(org.exist.storage.BrokerPool)

Example 2 with NamedEvent

use of org.exist.stax.EmbeddedXMLStreamReaderTest.NamedEvent in project exist by eXist-db.

the class EmbeddedXMLStreamReaderTest method readAllEvents.

private NamedEvent[] readAllEvents(final Optional<NodeHandle> maybeContainerNode, final IEmbeddedXMLStreamReader xmlStreamReader) throws XMLStreamException {
    final List<NamedEvent> events = new ArrayList<>();
    while (xmlStreamReader.hasNext()) {
        final NamedEvent namedEvent = NamedEvent.fromEvent(xmlStreamReader.next());
        // filter for descendant-or-self if specified
        if (maybeContainerNode.isPresent() && !descendantOrSelf(maybeContainerNode.get(), xmlStreamReader)) {
            // exit-while
            break;
        }
        events.add(namedEvent);
    }
    return events.toArray(new NamedEvent[events.size()]);
}
Also used : NamedEvent(org.exist.stax.EmbeddedXMLStreamReaderTest.NamedEvent)

Aggregations

NamedEvent (org.exist.stax.EmbeddedXMLStreamReaderTest.NamedEvent)2 LockedDocument (org.exist.dom.persistent.LockedDocument)1 NodeHandle (org.exist.dom.persistent.NodeHandle)1 BrokerPool (org.exist.storage.BrokerPool)1 DBBroker (org.exist.storage.DBBroker)1 Txn (org.exist.storage.txn.Txn)1 Document (org.w3c.dom.Document)1