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);
}
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());
}
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());
}
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());
}
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 > 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());
}
Aggregations