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=\"{('&')}\"" + " string=\"{(string('&'))}\"" + " ltEntity=\"{('<')}\"" + " gtEntity=\"{('>')}\"" + " aposEntity=\"{(''')}\"" + " quotEntity=\"{('"')}\"" + "/>", 1, null);
// TODO: could check result
}
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);
}
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);
}
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();
}
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();
}
Aggregations