Search in sources :

Example 31 with XPathQueryService

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);
}
Also used : XPathQueryService(org.xmldb.api.modules.XPathQueryService) Test(org.junit.Test)

Example 32 with XPathQueryService

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()));
}
Also used : XPathQueryService(org.xmldb.api.modules.XPathQueryService) ResourceSet(org.xmldb.api.base.ResourceSet) XMLResource(org.xmldb.api.modules.XMLResource)

Example 33 with XPathQueryService

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()) + " &amp; " + 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;
}
Also used : XUpdateQueryService(org.xmldb.api.modules.XUpdateQueryService) XPathQueryService(org.xmldb.api.modules.XPathQueryService) Collection(org.xmldb.api.base.Collection) ResourceSet(org.xmldb.api.base.ResourceSet)

Example 34 with XPathQueryService

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");
    }
}
Also used : XUpdateQueryService(org.xmldb.api.modules.XUpdateQueryService) XPathQueryService(org.xmldb.api.modules.XPathQueryService) ResourceSet(org.xmldb.api.base.ResourceSet)

Example 35 with XPathQueryService

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>");
}
Also used : XPathQueryService(org.xmldb.api.modules.XPathQueryService) EXistXPathQueryService(org.exist.xmldb.EXistXPathQueryService) ResourceSet(org.xmldb.api.base.ResourceSet)

Aggregations

XPathQueryService (org.xmldb.api.modules.XPathQueryService)148 ResourceSet (org.xmldb.api.base.ResourceSet)123 EXistXPathQueryService (org.exist.xmldb.EXistXPathQueryService)92 XMLResource (org.xmldb.api.modules.XMLResource)60 Collection (org.xmldb.api.base.Collection)31 Test (org.junit.Test)22 Resource (org.xmldb.api.base.Resource)18 XMLDBException (org.xmldb.api.base.XMLDBException)14 EXistResource (org.exist.xmldb.EXistResource)10 CollectionManagementService (org.xmldb.api.modules.CollectionManagementService)9 XUpdateQueryService (org.xmldb.api.modules.XUpdateQueryService)8 IndexQueryService (org.exist.xmldb.IndexQueryService)6 IOException (java.io.IOException)3 ResourceIterator (org.xmldb.api.base.ResourceIterator)3 BinaryResource (org.xmldb.api.modules.BinaryResource)3 MalformedURLException (java.net.MalformedURLException)2 Path (java.nio.file.Path)2 Node (org.w3c.dom.Node)2 HttpURLConnection (java.net.HttpURLConnection)1 URL (java.net.URL)1