Search in sources :

Example 96 with XPathQueryService

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

the class AnnotationsTest method annotationInXMLSchemaInstanceNamespaceFails.

@Test(expected = XMLDBException.class)
public void annotationInXMLSchemaInstanceNamespaceFails() throws XMLDBException {
    final String TEST_VALUE_CONSTANT = "hello world";
    final String query = "declare namespace hello = 'http://www.w3.org/2001/XMLSchema-instance';\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 97 with XPathQueryService

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

the class ValueIndexTest method qnameIndexStringMatchingFunctions.

/*
     * Bugfix
     *
     * These following two tests were put in place to test a bug fix for QName matching functions, which was committed 2/19/2010. The issue was that the 2nd parameter
	 * to the string matching functions was incorrectly interpreted as a regex, for QName indexes, which causd an exception
	 * to be thrown if the string included characters that have special meaning in a regex, eg. '*' for contains.
	 *
	 * andrzej@chaeron.com
     */
@Test
public void qnameIndexStringMatchingFunctions() 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 98 with XPathQueryService

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

the class ValueIndexTest method pathIndexStringMatchingFunctions2.

@Test
public void pathIndexStringMatchingFunctions2() throws XMLDBException {
    configureCollection(CONFIG_PATH);
    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 99 with XPathQueryService

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

the class ValueIndexTest method storeXMLFileAndGetQueryService.

/**
 * @return
 * @throws XMLDBException
 */
protected XPathQueryService storeXMLFileAndGetQueryService(String documentName, final URL srcFile) throws XMLDBException, URISyntaxException {
    XMLResource doc = (XMLResource) testCollection.createResource(documentName, "XMLResource");
    Path f = Paths.get(srcFile.toURI());
    doc.setContent(f);
    testCollection.storeResource(doc);
    XPathQueryService service = (XPathQueryService) testCollection.getService("XPathQueryService", "1.0");
    return service;
}
Also used : Path(java.nio.file.Path) XPathQueryService(org.xmldb.api.modules.XPathQueryService) XMLResource(org.xmldb.api.modules.XMLResource)

Example 100 with XPathQueryService

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

the class ValueIndexTest method strFunctions.

@Test
public void strFunctions() throws XMLDBException {
    configureCollection(CONFIG_PATH);
    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)

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