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());
}
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());
}
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());
}
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);
}
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());
}
Aggregations