Search in sources :

Example 71 with ResourceSet

use of org.xmldb.api.base.ResourceSet in project exist by eXist-db.

the class UnionTest method unionInPredicate_withIndex.

@Test
public void unionInPredicate_withIndex() throws XMLDBException {
    storeCollectionConfig();
    final XQueryService service = storeXMLStringAndGetQueryService(PUBMED_DOC_NAME, PUBMED);
    final ResourceSet result = service.queryResource(PUBMED_DOC_NAME, XQUERY);
    assertEquals(1, result.getSize());
}
Also used : XQueryService(org.xmldb.api.modules.XQueryService) ResourceSet(org.xmldb.api.base.ResourceSet)

Example 72 with ResourceSet

use of org.xmldb.api.base.ResourceSet in project exist by eXist-db.

the class UnionTest method unionInPredicate_withoutIndex.

@Test
public void unionInPredicate_withoutIndex() throws XMLDBException {
    final XQueryService service = storeXMLStringAndGetQueryService(PUBMED_DOC_NAME, PUBMED);
    final ResourceSet result = service.queryResource(PUBMED_DOC_NAME, XQUERY);
    assertEquals(1, result.getSize());
}
Also used : XQueryService(org.xmldb.api.modules.XQueryService) ResourceSet(org.xmldb.api.base.ResourceSet)

Example 73 with ResourceSet

use of org.xmldb.api.base.ResourceSet in project exist by eXist-db.

the class ValueIndexTest method indexScan.

@Test
public void indexScan() throws XMLDBException, URISyntaxException {
    configureCollection(CONFIG_PATH);
    String queryBody = "declare namespace f=\'http://exist-db.org/xquery/test\';\n" + "declare namespace mods='http://www.loc.gov/mods/v3';\n" + "import module namespace u=\'http://exist-db.org/xquery/util\';\n" + "\n" + "declare function f:term-callback($term as item(), $data as xs:int+)\n" + "as element()+ {\n" + "    <item>\n" + "        <term>{$term}</term>\n" + "        <frequency>{$data[1]}</frequency>\n" + "    </item>\n" + "};\n" + "\n";
    XPathQueryService service = storeXMLFileAndGetQueryService(ITEMS_FILENAME, ITEMS_FILE);
    String query = queryBody + "u:index-keys(//item/name, \'\', util:function(xs:QName(\'f:term-callback\'), 2), 1000)";
    ResourceSet result = service.query(query);
    for (ResourceIterator i = result.getIterator(); i.hasMoreResources(); ) {
        i.nextResource().getContent();
    }
    assertEquals(7, result.getSize());
    query = queryBody + "u:index-keys(//item/stock, 0, util:function(xs:QName(\'f:term-callback\'), 2), 1000)";
    result = service.query(query);
    for (ResourceIterator i = result.getIterator(); i.hasMoreResources(); ) {
        i.nextResource().getContent();
    }
    assertEquals(5, result.getSize());
}
Also used : XPathQueryService(org.xmldb.api.modules.XPathQueryService) ResourceSet(org.xmldb.api.base.ResourceSet) ResourceIterator(org.xmldb.api.base.ResourceIterator) Test(org.junit.Test)

Example 74 with ResourceSet

use of org.xmldb.api.base.ResourceSet in project exist by eXist-db.

the class ValueIndexTest method strings.

@Test
public void strings() throws XMLDBException, URISyntaxException {
    configureCollection(CONFIG_PATH);
    XPathQueryService service = storeXMLFileAndGetQueryService(ITEMS_FILENAME, ITEMS_FILE);
    queryResource(service, ITEMS_FILENAME, "//item[@id = 'i2']", 1);
    queryResource(service, ITEMS_FILENAME, "//item[name = 'Racing Bicycle']", 1);
    queryResource(service, ITEMS_FILENAME, "//item[name > 'Racing Bicycle']", 4);
    queryResource(service, ITEMS_FILENAME, "//item[itemno = 3]", 1);
    queryResource(service, ITEMS_FILENAME, "//item[itemno eq 3]", 1);
    ResourceSet result = queryResource(service, ITEMS_FILENAME, "for $i in //item[stock <= 10] return $i/itemno", 5);
    for (long i = 0; i < result.getSize(); i++) {
        Resource res = result.getResource(i);
    }
    queryResource(service, ITEMS_FILENAME, "//item[stock > 20]", 1);
    queryResource(service, ITEMS_FILENAME, "declare namespace x=\"http://www.foo.com\"; //item[x:rating > 8.0]", 2);
    queryResource(service, ITEMS_FILENAME, "declare namespace xx=\"http://test.com\"; //item[@xx:test = 123]", 1);
    queryResource(service, ITEMS_FILENAME, "declare namespace xx=\"http://test.com\"; //item[@xx:test eq 123]", 1);
    queryResource(service, ITEMS_FILENAME, "//item[mixed = 'uneven']", 1);
    queryResource(service, ITEMS_FILENAME, "//item[mixed eq 'uneven']", 1);
    queryResource(service, ITEMS_FILENAME, "//item[mixed = 'external']", 1);
    queryResource(service, ITEMS_FILENAME, "//item[fn:matches(mixed, 'un.*')]", 2);
    queryResource(service, ITEMS_FILENAME, "//item[price/@specialprice = false()]", 2);
    queryResource(service, ITEMS_FILENAME, "//item[price/@specialprice = true()]", 1);
    queryResource(service, ITEMS_FILENAME, "//item[price/@specialprice eq true()]", 1);
}
Also used : XPathQueryService(org.xmldb.api.modules.XPathQueryService) XMLResource(org.xmldb.api.modules.XMLResource) Resource(org.xmldb.api.base.Resource) ResourceSet(org.xmldb.api.base.ResourceSet) Test(org.junit.Test)

Example 75 with ResourceSet

use of org.xmldb.api.base.ResourceSet in project exist by eXist-db.

the class XQueryFunctionsTest method escapeHTMLURI.

@Test
public void escapeHTMLURI() throws XMLDBException {
    String string = "http://www.example.com/00/Weather/CA/Los Angeles#ocean";
    String expected = "http://www.example.com/00/Weather/CA/Los Angeles#ocean";
    String query = "escape-html-uri(\"" + string + "\")";
    ResourceSet result = existEmbeddedServer.executeQuery(query);
    String r = (String) result.getResource(0).getContent();
    assertEquals(expected, r);
    string = "javascript:if (navigator.browserLanguage == 'fr') window.open('http://www.example.com/~b\u00e9b\u00e9');";
    expected = "javascript:if (navigator.browserLanguage == 'fr') window.open('http://www.example.com/~b%C3%A9b%C3%A9');";
    query = "escape-html-uri(\"" + string + "\")";
    result = existEmbeddedServer.executeQuery(query);
    r = (String) result.getResource(0).getContent();
    assertEquals(expected, r);
    query = "escape-html-uri('$')";
    result = existEmbeddedServer.executeQuery(query);
    r = (String) result.getResource(0).getContent();
    assertEquals("$", r);
    query = "let $a := <a><b>-1</b><b>-2</b></a> " + "return $a/b[escape-html-uri(.) ne '']";
    result = existEmbeddedServer.executeQuery(query);
    assertEquals(2, result.getSize());
}
Also used : ResourceSet(org.xmldb.api.base.ResourceSet)

Aggregations

ResourceSet (org.xmldb.api.base.ResourceSet)383 XPathQueryService (org.xmldb.api.modules.XPathQueryService)123 Test (org.junit.Test)117 EXistXPathQueryService (org.exist.xmldb.EXistXPathQueryService)100 XMLResource (org.xmldb.api.modules.XMLResource)80 Collection (org.xmldb.api.base.Collection)55 Resource (org.xmldb.api.base.Resource)45 XQueryService (org.xmldb.api.modules.XQueryService)29 XMLDBException (org.xmldb.api.base.XMLDBException)23 EXistResource (org.exist.xmldb.EXistResource)20 BinaryResource (org.xmldb.api.modules.BinaryResource)17 CollectionManagementService (org.xmldb.api.modules.CollectionManagementService)14 Node (org.w3c.dom.Node)11 IndexQueryService (org.exist.xmldb.IndexQueryService)9 Diff (org.xmlunit.diff.Diff)9 EXistCollectionManagementService (org.exist.xmldb.EXistCollectionManagementService)8 UserManagementService (org.exist.xmldb.UserManagementService)8 Source (javax.xml.transform.Source)7 ResourceIterator (org.xmldb.api.base.ResourceIterator)7 XUpdateQueryService (org.xmldb.api.modules.XUpdateQueryService)6