use of org.xmldb.api.modules.XPathQueryService in project exist by eXist-db.
the class AnnotationsTest method annotationInXPathFunctionsNamespaceFails.
@Test(expected = XMLDBException.class)
public void annotationInXPathFunctionsNamespaceFails() throws XMLDBException {
final String TEST_VALUE_CONSTANT = "hello world";
final String query = "declare namespace hello = 'http://www.w3.org/2005/xpath-functions';\n" + "declare\n" + "%hello:world\n" + "function local:hello() {\n" + "'" + TEST_VALUE_CONSTANT + "'\n" + "};\n" + "local:hello()";
final XPathQueryService service = getQueryService();
service.query(query);
}
use of org.xmldb.api.modules.XPathQueryService in project exist by eXist-db.
the class ComplexUpdateAction method query.
private void query(final Collection col, final int repeat) throws XMLDBException {
final XPathQueryService service = (XPathQueryService) col.getService("XPathQueryService", "1.0");
ResourceSet r = service.query("//USER-SESSION-DATA");
assertEquals(1, r.getSize());
for (long i = 0; i < r.getSize(); i++) {
XMLResource res = (XMLResource) r.getResource(i);
}
r = service.query("string(//USER-SESSION-DATA[1]/@version)");
assertEquals(1, r.getSize());
assertEquals(repeat, Integer.parseInt(r.getResource(0).getContent().toString()));
}
use of org.xmldb.api.modules.XPathQueryService in project exist by eXist-db.
the class TextUpdateAction method execute.
@Override
public boolean execute() throws XMLDBException {
final Collection col = DatabaseManager.getCollection(collectionPath, "admin", "");
final XUpdateQueryService service = (XUpdateQueryService) col.getService("XUpdateQueryService", "1.0");
// append a new section
long mods = service.update(APPEND);
assertEquals(1, mods);
// update paragraph content
String updateText = Integer.toString(rand.nextInt()) + " & " + Integer.toString(rand.nextInt());
final String update = UPDATE_START + updateText + UPDATE_END;
mods = service.update(update);
assertEquals(1, mods);
// query for section
final XPathQueryService query = (XPathQueryService) col.getService("XPathQueryService", "1.0");
ResourceSet result = query.query("/article/section/para/text()");
assertEquals(1, result.getSize());
updateText = result.getResource(0).getContent().toString();
result = query.query("/article/section/para[. = '" + updateText + "']");
assertEquals(1, result.getSize());
result.getResource(0).getContent();
mods = service.update(REMOVE);
assertEquals(1, mods);
return true;
}
use of org.xmldb.api.modules.XPathQueryService in project exist by eXist-db.
the class RemoveAppendTest method appendRemove.
@Test
public void appendRemove() throws XMLDBException, IOException {
XUpdateQueryService service = (XUpdateQueryService) testCol.getService("XUpdateQueryService", "1.0");
XPathQueryService query = (XPathQueryService) testCol.getService("XPathQueryService", "1.0");
for (int i = 1; i <= 100; i++) {
append(service, i);
ResourceSet result = query.query("/test/item[@id='" + i + "']");
assertEquals(result.getSize(), 1);
}
for (int i = 100; i > 10; i--) {
String xu = "<xu:modifications xmlns:xu=\"http://www.xmldb.org/xupdate\" version=\"1.0\">" + " <xu:remove select=\"/test/item[@id='" + i + "']\"/>" + "</xu:modifications>";
long mods = service.update(xu);
assertEquals(mods, 1);
ResourceSet result = query.query("/test/item/e0");
}
}
use of org.xmldb.api.modules.XPathQueryService in project exist by eXist-db.
the class XQueryTest method variableScopeBug_1817822.
/**
* @see http://sourceforge.net/support/tracker.php?aid=1817822
*/
@Test
public void variableScopeBug_1817822() throws XMLDBException {
String query = "declare namespace test = \"http://example.com\"; " + "declare function test:expression($expr) as xs:double? { " + " typeswitch($expr) " + " case element(Value) return test:value($expr) " + " case element(SomethingRandom) return test:product($expr/*) " + " default return () " + "}; " + "declare function test:value($expr) { " + " xs:double($expr) " + "}; " + "declare function test:product($expressions) { " + " test:expression($expressions[1]) " + " * " + " test:expression($expressions[2]) " + "}; " + "let $values := (<Value>2</Value>,<Value>3</Value>) " + "let $a := test:expression(<AnotherSomethingRandom/>) " + "let $b := test:product($values) " + "return <Result>{$b}</Result>";
XPathQueryService service = (XPathQueryService) getTestCollection().getService("XPathQueryService", "1.0");
ResourceSet result = service.query(query);
assertEquals(1, result.getSize());
assertEquals(query, result.getResource(0).getContent().toString(), "<Result>6</Result>");
}
Aggregations