Search in sources :

Example 21 with ResourceSet

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

the class EvalTest method evalWithExternalVars.

@Test
public void evalWithExternalVars() throws XPathException, XMLDBException {
    final String query = "let $value := 'world' return\n" + "\tutil:eval(xs:anyURI('/db/" + INVOKABLE_QUERY_FILENAME + "'), false(), (xs:QName('" + INVOKABLE_QUERY_EXTERNAL_VAR_NAME + "'), $value))";
    final ResourceSet result = existEmbeddedServer.executeQuery(query);
    final LocalXMLResource res = (LocalXMLResource) result.getResource(0);
    final Node n = res.getContentAsDOM();
    assertEquals(n.getLocalName(), "hello");
    assertEquals("world", n.getFirstChild().getNodeValue());
}
Also used : Node(org.w3c.dom.Node) ResourceSet(org.xmldb.api.base.ResourceSet)

Example 22 with ResourceSet

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

the class EvalTest method testEvalSupplyingContext.

@Test
public void testEvalSupplyingContext() throws XPathException, XMLDBException {
    final String query = "let $xml := <test><a/></test>\n" + "let $context := <static-context>\n" + "<default-context>{$xml}</default-context>\n" + "</static-context>\n" + "let $query := 'count(.//*) mod 2 = 0'\n" + "return\n" + "util:eval-with-context($query, $context, false())";
    final ResourceSet result = existEmbeddedServer.executeQuery(query);
    final String r = (String) result.getResource(0).getContent();
    assertEquals("true", r);
}
Also used : ResourceSet(org.xmldb.api.base.ResourceSet)

Example 23 with ResourceSet

use of org.xmldb.api.base.ResourceSet 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 24 with ResourceSet

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

the class JaxpDtdCatalogTest method executeAndEvaluate.

private void executeAndEvaluate(final String query, final String expectedValue) throws XMLDBException, SAXException, IOException, XpathException {
    final ResourceSet results = existEmbeddedServer.executeQuery(query);
    assertEquals(1, results.getSize());
    final String r = (String) results.getResource(0).getContent();
    assertXpathEvaluatesTo(expectedValue, "//status/text()", r);
}
Also used : ResourceSet(org.xmldb.api.base.ResourceSet)

Example 25 with ResourceSet

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

the class JaxpDtdCatalogTest method clearGrammarCache.

@Before
public void clearGrammarCache() throws XMLDBException {
    final ResourceSet results = existEmbeddedServer.executeQuery("validation:clear-grammar-cache()");
    results.getResource(0).getContent();
}
Also used : ResourceSet(org.xmldb.api.base.ResourceSet)

Aggregations

ResourceSet (org.xmldb.api.base.ResourceSet)383 XPathQueryService (org.xmldb.api.modules.XPathQueryService)123 Test (org.junit.Test)117 EXistXPathQueryService (org.exist.xmldb.EXistXPathQueryService)100 XMLResource (org.xmldb.api.modules.XMLResource)80 Collection (org.xmldb.api.base.Collection)55 Resource (org.xmldb.api.base.Resource)45 XQueryService (org.xmldb.api.modules.XQueryService)29 XMLDBException (org.xmldb.api.base.XMLDBException)23 EXistResource (org.exist.xmldb.EXistResource)20 BinaryResource (org.xmldb.api.modules.BinaryResource)17 CollectionManagementService (org.xmldb.api.modules.CollectionManagementService)14 Node (org.w3c.dom.Node)11 IndexQueryService (org.exist.xmldb.IndexQueryService)9 Diff (org.xmlunit.diff.Diff)9 EXistCollectionManagementService (org.exist.xmldb.EXistCollectionManagementService)8 UserManagementService (org.exist.xmldb.UserManagementService)8 Source (javax.xml.transform.Source)7 ResourceIterator (org.xmldb.api.base.ResourceIterator)7 XUpdateQueryService (org.xmldb.api.modules.XUpdateQueryService)6