Search in sources :

Example 46 with Resource

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

the class SerializationTest method xqueryUpdateNsTest.

@Test
public void xqueryUpdateNsTest() throws XMLDBException {
    final XQueryService service = (XQueryService) testCollection.getService("XQueryService", "1.0");
    final ResourceSet result = service.query("xquery version \"1.0\";" + EOL + "declare namespace foo=\"http://foo.com\";" + EOL + "let $in-memory :=" + EOL + XML + EOL + "let $on-disk := doc('/db/" + TEST_COLLECTION_NAME + '/' + XML_DOC_NAME + "')" + EOL + "let $new-node := <entry xml:id='aargh'/>" + EOL + "let $update := update insert $new-node into $on-disk/foo:root" + EOL + "return" + EOL + "    (" + EOL + "        $in-memory," + EOL + "        $on-disk" + EOL + "    )" + EOL);
    assertEquals(2, result.getSize());
    final Resource inMemoryResource = result.getResource(0);
    assertXMLEquals(XML, inMemoryResource);
    final Resource onDiskResource = result.getResource(1);
    assertXMLEquals(XML_UPDATED_EXPECTED, onDiskResource);
}
Also used : XQueryService(org.xmldb.api.modules.XQueryService) XMLResource(org.xmldb.api.modules.XMLResource) Resource(org.xmldb.api.base.Resource) ResourceSet(org.xmldb.api.base.ResourceSet) Test(org.junit.Test)

Example 47 with Resource

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

the class EvalTest method evalAndSerializeSubsequence.

@Test
public void evalAndSerializeSubsequence() throws XMLDBException {
    final String query = "let $query := \"for $i in (1 to 10) return <i>{$i}</i>\"\n" + "return\n" + "util:eval-and-serialize($query, (), 1, 4)";
    final ResourceSet result = existEmbeddedServer.executeQuery(query);
    final Resource r = result.getResource(0);
    assertEquals("<i>1</i><i>2</i><i>3</i><i>4</i>", r.getContent());
}
Also used : BinaryResource(org.xmldb.api.modules.BinaryResource) Resource(org.xmldb.api.base.Resource) ResourceSet(org.xmldb.api.base.ResourceSet)

Example 48 with Resource

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

the class EvalTest method evalAndSerializeDefaultOptions.

@Test
public void evalAndSerializeDefaultOptions() throws XMLDBException {
    String query = "let $query := \"<elem1>hello</elem1>\"\n" + "return\n" + "util:eval-and-serialize($query, map { \"method\": \"adaptive\" })";
    ResourceSet result = existEmbeddedServer.executeQuery(query);
    Resource r = result.getResource(0);
    assertEquals("<elem1>hello</elem1>", r.getContent());
    // test that XQuery Prolog output options override the default provided options
    query = "xquery version \"3.1\";\n" + "declare namespace output = \"http://www.w3.org/2010/xslt-xquery-serialization\";\n" + "declare option output:method \"text\";\n" + "let $query := \"<elem1>hello</elem1>\"\n" + "return\n" + "util:eval-and-serialize($query, map { \"method\": \"adaptive\" })";
    result = existEmbeddedServer.executeQuery(query);
    r = result.getResource(0);
    assertEquals("hello", r.getContent());
}
Also used : BinaryResource(org.xmldb.api.modules.BinaryResource) Resource(org.xmldb.api.base.Resource) ResourceSet(org.xmldb.api.base.ResourceSet)

Example 49 with Resource

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

the class ExpandTest method expandPersistentDomAttr.

@Test
public void expandPersistentDomAttr() throws XMLDBException {
    final String query = "util:expand(doc('/db/expand-test/doc3.xml')/doc3/@foo)";
    final ResourceSet result = existEmbeddedServer.executeQuery(query);
    final Resource res = result.getResource(0);
    assertEquals(XMLResource.RESOURCE_TYPE, res.getResourceType());
    final XMLResource xmlRes = (XMLResource) res;
    final Node node = xmlRes.getContentAsDOM();
    assertEquals(Node.ATTRIBUTE_NODE, node.getNodeType());
    assertNull(node.getNamespaceURI());
    assertEquals("foo", node.getNodeName());
    assertEquals("bar", node.getNodeValue());
}
Also used : Node(org.w3c.dom.Node) XMLResource(org.xmldb.api.modules.XMLResource) Resource(org.xmldb.api.base.Resource) ResourceSet(org.xmldb.api.base.ResourceSet) XMLResource(org.xmldb.api.modules.XMLResource) Test(org.junit.Test)

Example 50 with Resource

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

the class MapResourceSet method removeResource.

/**
 * Removes the resource at a given position.
 *
 * @param pos position &gt; 0
 * @throws XMLDBException thrown if pos is out of range
 */
@Override
public void removeResource(final long pos) throws XMLDBException {
    final Resource r = resourcesVector.get((int) pos);
    resourcesVector.remove((int) pos);
    resources.remove(r.getId());
}
Also used : Resource(org.xmldb.api.base.Resource)

Aggregations

Resource (org.xmldb.api.base.Resource)173 XMLResource (org.xmldb.api.modules.XMLResource)126 Collection (org.xmldb.api.base.Collection)111 BinaryResource (org.xmldb.api.modules.BinaryResource)86 Test (org.junit.Test)77 UserManagementService (org.exist.xmldb.UserManagementService)52 ResourceSet (org.xmldb.api.base.ResourceSet)46 XMLDBException (org.xmldb.api.base.XMLDBException)38 EXistCollectionManagementService (org.exist.xmldb.EXistCollectionManagementService)32 EXistResource (org.exist.xmldb.EXistResource)27 CollectionManagementService (org.xmldb.api.modules.CollectionManagementService)25 XPathQueryService (org.xmldb.api.modules.XPathQueryService)18 EXistXPathQueryService (org.exist.xmldb.EXistXPathQueryService)16 Path (java.nio.file.Path)11 Database (org.xmldb.api.base.Database)11 XPathException (org.exist.xquery.XPathException)10 InputStream (java.io.InputStream)9 Source (javax.xml.transform.Source)9 BuildException (org.apache.tools.ant.BuildException)9 Diff (org.xmlunit.diff.Diff)9