Search in sources :

Example 71 with XQueryService

use of org.xmldb.api.modules.XQueryService in project exist by eXist-db.

the class EntitiesTest method attributeConstructor.

@Test
public void attributeConstructor() throws XMLDBException {
    XQueryService service = getQueryService();
    @SuppressWarnings("unused") ResourceSet result;
    result = queryAndAssert(service, "<foo " + " ampEntity=\"{('&amp;')}\"" + " string=\"{(string('&amp;'))}\"" + " ltEntity=\"{('&lt;')}\"" + " gtEntity=\"{('&gt;')}\"" + " aposEntity=\"{('&apos;')}\"" + " quotEntity=\"{('&quot;')}\"" + "/>", 1, null);
// TODO: could check result
}
Also used : XQueryService(org.xmldb.api.modules.XQueryService) Test(org.junit.Test)

Example 72 with XQueryService

use of org.xmldb.api.modules.XQueryService in project exist by eXist-db.

the class NodeTypeTest method xupdateRemove.

/**
 * Updates the given xml fragment in the database using XUpdate.
 */
@SuppressWarnings("unused")
private void xupdateRemove(final String doc) throws XMLDBException {
    final StringBuilder query = new StringBuilder();
    query.append("declare namespace xmldb='http://exist-db.org/xquery/xmldb';");
    query.append("let $isLoggedIn := xmldb:login('" + XmldbURI.ROOT_COLLECTION_URI + "', '" + TestUtils.ADMIN_DB_USER + "', '" + TestUtils.ADMIN_DB_USER + "'),");
    query.append("$mods := xmldb:remove('" + XmldbURI.ROOT_COLLECTION + "', '" + doc + "')");
    query.append("return <modifications>{$mods}</modifications>");
    final XQueryService service = (XQueryService) server.getRoot().getService("XQueryService", "1.0");
    final CompiledExpression cQuery = service.compile(query.toString());
    service.execute(cQuery);
}
Also used : XQueryService(org.xmldb.api.modules.XQueryService)

Example 73 with XQueryService

use of org.xmldb.api.modules.XQueryService in project exist by eXist-db.

the class NodeTypeTest method prepareWorkVersion.

/**
 * Updates the given xml fragment in the database using XUpdate.
 */
private final void prepareWorkVersion() throws XMLDBException {
    final StringBuilder query = new StringBuilder();
    query.append("declare namespace xmldb='http://exist-db.org/xquery/xmldb';\n");
    query.append("declare namespace f='urn:weblounge';\n");
    // Returns a new with a given body and a new header
    query.append("declare function f:create($live as node(), $target as xs:string) as node() { \n");
    query.append("    <page partition='{$live/@partition}' path='{$live/@path}' version='{$target}'> \n");
    query.append("        {$live/*} \n");
    query.append("    </page> \n");
    query.append("}; \n");
    // Function "prepare". Checks if the work version already exists. If this is not the
    // case, it calls the "create" function to have a new page created with the live body
    // but with a "work" or "$target" header.
    query.append("declare function f:prepare($data as node(), $target as xs:string) as xs:string? { \n");
    query.append("    if (empty(xmldb:xcollection($collection)/page[@version eq $target])) then \n");
    query.append("        let $isLoggedIn := xmldb:login($collection, '" + TestUtils.ADMIN_DB_USER + "', '" + TestUtils.ADMIN_DB_PWD + "') \n");
    query.append("        return xmldb:store($collection, concat($target, '.xml'), f:create($data, $target)) \n");
    query.append("    else \n");
    query.append("    () \n");
    query.append("}; \n");
    // Main clause, tries to create a work from an existing live version
    query.append("let $live := xmldb:xcollection($collection)/page[@version eq 'live'],\n");
    query.append("     $log := util:log('DEBUG', $live),\n");
    query.append("     $w := f:prepare($live, 'work')\n");
    query.append("    return\n");
    query.append("		              ()\n");
    final XQueryService service = (XQueryService) server.getRoot().getService("XQueryService", "1.0");
    service.declareVariable("collection", XmldbURI.ROOT_COLLECTION);
    final CompiledExpression cQuery = service.compile(query.toString());
    service.execute(cQuery);
}
Also used : XQueryService(org.xmldb.api.modules.XQueryService)

Example 74 with XQueryService

use of org.xmldb.api.modules.XQueryService in project exist by eXist-db.

the class OptimizerTest method execute.

private long execute(String query, boolean optimize) throws XMLDBException {
    XQueryService service = (XQueryService) testCollection.getService("XQueryService", "1.0");
    if (optimize) {
        query = OPTIMIZE + query;
    } else {
        query = NO_OPTIMIZE + query;
    }
    query = NAMESPACES + query;
    ResourceSet result = service.query(query);
    return result.getSize();
}
Also used : XQueryService(org.xmldb.api.modules.XQueryService) ResourceSet(org.xmldb.api.base.ResourceSet)

Example 75 with XQueryService

use of org.xmldb.api.modules.XQueryService in project exist by eXist-db.

the class TransformTest method execQuery.

private String execQuery(String query) throws XMLDBException {
    XQueryService service = (XQueryService) testCollection.getService("XQueryService", "1.0");
    service.setProperty("indent", "no");
    ResourceSet result = service.query(query);
    assertEquals(result.getSize(), 1);
    return result.getResource(0).getContent().toString();
}
Also used : XQueryService(org.xmldb.api.modules.XQueryService) ResourceSet(org.xmldb.api.base.ResourceSet)

Aggregations

XQueryService (org.xmldb.api.modules.XQueryService)129 EXistXQueryService (org.exist.xmldb.EXistXQueryService)71 XMLResource (org.xmldb.api.modules.XMLResource)33 ResourceSet (org.xmldb.api.base.ResourceSet)29 Test (org.junit.Test)28 Resource (org.xmldb.api.base.Resource)8 Node (org.w3c.dom.Node)6 EXistResource (org.exist.xmldb.EXistResource)5 Document (org.w3c.dom.Document)5 Collection (org.xmldb.api.base.Collection)5 Source (javax.xml.transform.Source)4 IndexQueryService (org.exist.xmldb.IndexQueryService)4 CompiledExpression (org.xmldb.api.base.CompiledExpression)4 XMLDBException (org.xmldb.api.base.XMLDBException)4 Diff (org.xmlunit.diff.Diff)4 Path (java.nio.file.Path)2 XmlRpcTest (org.exist.xmlrpc.XmlRpcTest)2 StringWriter (java.io.StringWriter)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1