Search in sources :

Example 21 with XPathQueryService

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

the class ValueIndexTest method updatesQName.

@Test
public void updatesQName() throws Exception {
    configureCollection(CONFIG_QNAME);
    storeXMLFileAndGetQueryService(ITEMS_FILENAME, ITEMS_FILE);
    for (int i = 100; i <= 150; i++) {
        String append = "<xu:modifications xmlns:xu=\"http://www.xmldb.org/xupdate\" version=\"1.0\">" + "   <xu:append select=\"/items\">" + "       <item id=\"i" + i + "\">" + "           <itemno>" + i + "</itemno>" + "           <name>New Item</name>" + "           <price>55.50</price>" + "       </item>" + "   </xu:append>" + "</xu:modifications>";
        String remove = "<xu:modifications xmlns:xu=\"http://www.xmldb.org/xupdate\" version=\"1.0\">" + "   <xu:remove select=\"/items/item[itemno=" + i + "]\"/>" + "</xu:modifications>";
        XPathQueryService query = (XPathQueryService) testCollection.getService("XPathQueryService", "1.0");
        XUpdateQueryService update = (XUpdateQueryService) testCollection.getService("XUpdateQueryService", "1.0");
        long mods = update.updateResource(ITEMS_FILENAME, append);
        assertEquals(mods, 1);
        queryResource(query, ITEMS_FILENAME, "//((#exist:optimize#) { item[price = 55.50] })", 1);
        queryResource(query, ITEMS_FILENAME, "//((#exist:optimize#) { item[@id = 'i" + i + "']})", 1);
        queryResource(query, ITEMS_FILENAME, "//((#exist:optimize#) { item[itemno = " + i + "] })", 1);
        mods = update.updateResource(ITEMS_FILENAME, remove);
        assertEquals(mods, 1);
        queryResource(query, ITEMS_FILENAME, "//((#exist:optimize#) { item[itemno = " + i + "] })", 0);
    }
}
Also used : XUpdateQueryService(org.xmldb.api.modules.XUpdateQueryService) XPathQueryService(org.xmldb.api.modules.XPathQueryService) Test(org.junit.Test)

Example 22 with XPathQueryService

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

the class ValueIndexTest method strFunctionsQName.

@Test
public void strFunctionsQName() throws XMLDBException {
    configureCollection(CONFIG_QNAME);
    XMLResource resource = (XMLResource) testCollection.createResource("mondial-test.xml", "XMLResource");
    resource.setContent(CITY);
    testCollection.storeResource(resource);
    XPathQueryService service = (XPathQueryService) testCollection.getService("XPathQueryService", "1.0");
    queryResource(service, "mondial-test.xml", "//city[starts-with(name, 'Berl')]", 1);
    queryResource(service, "mondial-test.xml", "//city[starts-with(name, 'Berlin')]", 1);
    queryResource(service, "mondial-test.xml", "//city[starts-with(name, 'erlin')]", 0);
    queryResource(service, "mondial-test.xml", "//city[starts-with(name, 'Erl')]", 1);
    queryResource(service, "mondial-test.xml", "//city[contains(name, 'erl')]", 1);
    queryResource(service, "mondial-test.xml", "//city[contains(name, 'Berlin')]", 1);
    queryResource(service, "mondial-test.xml", "//city[contains(name, 'Erl')]", 1);
    queryResource(service, "mondial-test.xml", "//city[ends-with(name, 'Berlin')]", 1);
    queryResource(service, "mondial-test.xml", "//city[ends-with(name, 'erlin')]", 1);
    queryResource(service, "mondial-test.xml", "//city[ends-with(name, 'Ber')]", 0);
    queryResource(service, "mondial-test.xml", "//city[matches(name, 'erl', 'i')]", 2);
    queryResource(service, "mondial-test.xml", "//city[matches(name, 'Erl')]", 1);
    queryResource(service, "mondial-test.xml", "//city[matches(name, 'Berlin', 'i')]", 1);
    queryResource(service, "mondial-test.xml", "//city[matches(name, 'berlin', 'i')]", 1);
    queryResource(service, "mondial-test.xml", "//city[matches(name, 'berlin')]", 0);
    queryResource(service, "mondial-test.xml", "//city[matches(name, '^Berlin$')]", 1);
    queryResource(service, "mondial-test.xml", "//city[matches(name, 'lin$', 'i')]", 1);
    queryResource(service, "mondial-test.xml", "//city[matches(name, '.*lin$', 'i')]", 1);
    queryResource(service, "mondial-test.xml", "//city[matches(name, '^lin$', 'i')]", 0);
}
Also used : XPathQueryService(org.xmldb.api.modules.XPathQueryService) XMLResource(org.xmldb.api.modules.XMLResource) Test(org.junit.Test)

Example 23 with XPathQueryService

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

the class ValueIndexTest method qnameIndexStringMatchingFunctions2.

@Test
public void qnameIndexStringMatchingFunctions2() throws XMLDBException {
    configureCollection(CONFIG_QNAME);
    XMLResource resource = (XMLResource) testCollection.createResource("mondial-test.xml", "XMLResource");
    resource.setContent(CITY);
    testCollection.storeResource(resource);
    XPathQueryService service = (XPathQueryService) testCollection.getService("XPathQueryService", "1.0");
    queryResource(service, "mondial-test.xml", "//city[ starts-with( name, '(*' ) ]", 0);
    queryResource(service, "mondial-test.xml", "//city[ contains( name, '*' ) ]", 0);
    queryResource(service, "mondial-test.xml", "//city[ ends-with( name, '(*' ) ]", 0);
}
Also used : XPathQueryService(org.xmldb.api.modules.XPathQueryService) XMLResource(org.xmldb.api.modules.XMLResource) Test(org.junit.Test)

Example 24 with XPathQueryService

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

the class XPathQueryTest method staticVariables.

@Test
public void staticVariables() throws XMLDBException {
    final XMLResource doc = (XMLResource) testCollection.createResource("numbers.xml", "XMLResource");
    doc.setContent(numbers);
    testCollection.storeResource(doc);
    XPathQueryService service = (XPathQueryService) testCollection.getService("XPathQueryService", "1.0");
    final EXistXPathQueryService service2 = (EXistXPathQueryService) service;
    service2.declareVariable("name", "MONTAGUE");
    service2.declareVariable("name", "43");
    // ResourceSet result = service.query("//SPEECH[SPEAKER=$name]");
    ResourceSet result = service2.query(doc, "//item[stock=$name]");
    result = service2.query("$name");
    assertEquals(1, result.getSize());
    result = service2.query(doc, "//item[stock=43]");
    assertEquals(1, result.getSize());
    result = service2.query(doc, "//item");
    assertEquals(4, result.getSize());
// assertEquals(10, result.getSize());
}
Also used : XPathQueryService(org.xmldb.api.modules.XPathQueryService) EXistXPathQueryService(org.exist.xmldb.EXistXPathQueryService) EXistXPathQueryService(org.exist.xmldb.EXistXPathQueryService) XMLResource(org.xmldb.api.modules.XMLResource)

Example 25 with XPathQueryService

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

the class XPathQueryTest method queryResource.

@Test
public void queryResource() throws XMLDBException {
    XMLResource doc = (XMLResource) testCollection.createResource("strings.xml", "XMLResource");
    doc.setContent(strings);
    testCollection.storeResource(doc);
    doc = (XMLResource) testCollection.createResource("strings2.xml", "XMLResource");
    doc.setContent(strings);
    testCollection.storeResource(doc);
    final XPathQueryService query = (XPathQueryService) testCollection.getService("XPathQueryService", "1.0");
    ResourceSet result = query.queryResource("strings2.xml", "/test/string[. = 'Hello World!']");
    assertEquals(1, result.getSize());
    result = query.query("/test/string[. = 'Hello World!']");
    assertEquals(2, result.getSize());
}
Also used : XPathQueryService(org.xmldb.api.modules.XPathQueryService) EXistXPathQueryService(org.exist.xmldb.EXistXPathQueryService) XMLResource(org.xmldb.api.modules.XMLResource)

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