Search in sources :

Example 36 with XMLResource

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

the class ValueIndexTest method pathIndexStringMatchingFunctions.

/*
     * Bugfix
     *
     * These following two tests were put in place to demonstrate bugs in how the index matching functions work,
     * as a precursor to a fix, which was committed 2/3/2010. The issue was that the 2nd parameter
	 * to the string matching functions was incorrectly interpreted as a regex, 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 pathIndexStringMatchingFunctions() 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 37 with XMLResource

use of org.xmldb.api.modules.XMLResource 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 38 with XMLResource

use of org.xmldb.api.modules.XMLResource 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 39 with XMLResource

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

the class XPathQueryTest method storeXMLStringAndGetQueryService.

/**
 * stores XML String and get Query Service
 * @param documentName to be stored in the DB
 * @param content to be stored in the DB
 * @return the XQuery Service
 * @throws XMLDBException
 */
private XQueryService storeXMLStringAndGetQueryService(final String documentName, final String content) throws XMLDBException {
    final XMLResource doc = (XMLResource) testCollection.createResource(documentName, "XMLResource");
    doc.setContent(content);
    testCollection.storeResource(doc);
    final XQueryService service = (XQueryService) testCollection.getService("XPathQueryService", "1.0");
    return service;
}
Also used : EXistXQueryService(org.exist.xmldb.EXistXQueryService) XQueryService(org.xmldb.api.modules.XQueryService) XMLResource(org.xmldb.api.modules.XMLResource)

Example 40 with XMLResource

use of org.xmldb.api.modules.XMLResource 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)

Aggregations

XMLResource (org.xmldb.api.modules.XMLResource)142 Collection (org.xmldb.api.base.Collection)56 ResourceSet (org.xmldb.api.base.ResourceSet)56 XPathQueryService (org.xmldb.api.modules.XPathQueryService)49 Test (org.junit.Test)33 Resource (org.xmldb.api.base.Resource)24 XQueryService (org.xmldb.api.modules.XQueryService)23 Node (org.w3c.dom.Node)22 CollectionManagementService (org.xmldb.api.modules.CollectionManagementService)20 EXistXPathQueryService (org.exist.xmldb.EXistXPathQueryService)18 Document (org.w3c.dom.Document)16 XMLDBException (org.xmldb.api.base.XMLDBException)15 EXistResource (org.exist.xmldb.EXistResource)9 EXistXQueryService (org.exist.xmldb.EXistXQueryService)9 BinaryResource (org.xmldb.api.modules.BinaryResource)9 Path (java.nio.file.Path)8 Before (org.junit.Before)8 Element (org.w3c.dom.Element)8 Source (javax.xml.transform.Source)7 SAXSerializer (org.exist.util.serializer.SAXSerializer)7