Search in sources :

Example 6 with ResourceIterator

use of org.xmldb.api.base.ResourceIterator in project exist by eXist-db.

the class LocalXMLResourceDOMTest method testEnhancer02.

@Test
public void testEnhancer02() throws XMLDBException {
    final ResourceSet rs1 = existEmbeddedServer.executeQuery("doc('" + TestConstants.TEST_COLLECTION_URI.getRawCollectionPath() + "/" + TEST_RESOURCE_NAME + "')//properties/property[@key='type' and text()='Table']");
    for (final ResourceIterator i1 = rs1.getIterator(); i1.hasMoreResources(); ) {
        final XMLResource r1 = (XMLResource) i1.nextResource();
        final Map<String, Object> variables = new HashMap<>();
        variables.put("local:document", r1.getContentAsDOM());
        final String query = "xquery version \"1.0\";" + "declare namespace xmldb=\"http://exist-db.org/xquery/xmldb\";" + "declare variable $local:document external;" + "$local:document";
        final ResourceSet rs2 = existEmbeddedServer.executeQuery(query, variables);
        for (final ResourceIterator i2 = rs2.getIterator(); i2.hasMoreResources(); ) {
            final XMLResource r2 = (XMLResource) i2.nextResource();
            final Node content2 = r2.getContentAsDOM();
            assertNotNull(content2);
        }
    }
}
Also used : HashMap(java.util.HashMap) Node(org.w3c.dom.Node) ResourceSet(org.xmldb.api.base.ResourceSet) ResourceIterator(org.xmldb.api.base.ResourceIterator) XMLResource(org.xmldb.api.modules.XMLResource) Test(org.junit.Test)

Example 7 with ResourceIterator

use of org.xmldb.api.base.ResourceIterator in project exist by eXist-db.

the class LocalXMLResourceDOMTest method testEnhancer01.

@Test
public void testEnhancer01() throws XMLDBException {
    final String query = "doc('" + TestConstants.TEST_COLLECTION_URI.getRawCollectionPath() + "/" + TEST_RESOURCE_NAME + "')//properties[property[@key eq 'type'][text() eq 'Table']]";
    final ResourceSet rs1 = existEmbeddedServer.executeQuery(query);
    final ResourceSet rs2 = existEmbeddedServer.executeQuery(query);
    final ResourceIterator i1 = rs1.getIterator();
    final ResourceIterator i2 = rs2.getIterator();
    for (; i1.hasMoreResources() && i1.hasMoreResources(); ) {
        final XMLResource r1 = (XMLResource) i1.nextResource();
        final XMLResource r2 = (XMLResource) i2.nextResource();
        assertEquals(r1.getContentAsDOM(), r2.getContentAsDOM());
    }
}
Also used : ResourceSet(org.xmldb.api.base.ResourceSet) ResourceIterator(org.xmldb.api.base.ResourceIterator) XMLResource(org.xmldb.api.modules.XMLResource) Test(org.junit.Test)

Aggregations

ResourceIterator (org.xmldb.api.base.ResourceIterator)7 ResourceSet (org.xmldb.api.base.ResourceSet)7 XMLResource (org.xmldb.api.modules.XMLResource)6 Test (org.junit.Test)3 XMLDBException (org.xmldb.api.base.XMLDBException)3 XPathQueryService (org.xmldb.api.modules.XPathQueryService)3 Node (org.w3c.dom.Node)2 SAXException (org.xml.sax.SAXException)2 Collection (org.xmldb.api.base.Collection)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 List (java.util.List)1 UnsynchronizedByteArrayInputStream (org.apache.commons.io.input.UnsynchronizedByteArrayInputStream)1 BuildException (org.apache.tools.ant.BuildException)1 PropertyHelper (org.apache.tools.ant.PropertyHelper)1 DocumentBuilderReceiver (org.exist.dom.memtree.DocumentBuilderReceiver)1 MemTreeBuilder (org.exist.dom.memtree.MemTreeBuilder)1 NodeImpl (org.exist.dom.memtree.NodeImpl)1 AVLTreeNodeSet (org.exist.dom.persistent.AVLTreeNodeSet)1 NodeProxy (org.exist.dom.persistent.NodeProxy)1