Search in sources :

Example 71 with XPathQueryService

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

the class XQueryTest method modulesAndNS.

@Test
public void modulesAndNS() throws XMLDBException, IOException, SAXException {
    Collection testCollection = getTestCollection();
    Resource doc = testCollection.createResource(MODULE7_NAME, "BinaryResource");
    doc.setContent(module7);
    ((EXistResource) doc).setMimeType("application/xquery");
    testCollection.storeResource(doc);
    XPathQueryService service = (XPathQueryService) testCollection.getService("XPathQueryService", "1.0");
    service.setProperty(OutputKeys.INDENT, "no");
    String query = "xquery version \"1.0\";\n" + "import module namespace foo=\"foo\" at \"" + URI + "/test/" + MODULE7_NAME + "\";\n" + "<div xmlns='http://www.w3.org/1999/xhtml'>" + "{ foo:link() }" + "</div>";
    ResourceSet result = service.query(query);
    assertEquals(1, result.getSize());
    result.getResource(0).getContent();
    assertXMLEqual("<div xmlns='http://www.w3.org/1999/xhtml'><a xmlns=\"\" href='#'>Link</a></div>", result.getResource(0).getContent().toString());
    query = "xquery version \"1.0\";\n" + "import module namespace foo=\"foo\" at \"" + URI + "/test/" + MODULE7_NAME + "\";\n" + "<div xmlns='http://www.w3.org/1999/xhtml'>" + "{ foo:copy(<a>Link</a>) }" + "</div>";
    result = service.query(query);
    assertEquals(1, result.getSize());
    result.getResource(0).getContent();
    assertXMLEqual("<div xmlns='http://www.w3.org/1999/xhtml'><a>Link</a></div>", result.getResource(0).getContent().toString());
}
Also used : EXistResource(org.exist.xmldb.EXistResource) XPathQueryService(org.xmldb.api.modules.XPathQueryService) EXistXPathQueryService(org.exist.xmldb.EXistXPathQueryService) XMLResource(org.xmldb.api.modules.XMLResource) EXistResource(org.exist.xmldb.EXistResource) Resource(org.xmldb.api.base.Resource) Collection(org.xmldb.api.base.Collection) ResourceSet(org.xmldb.api.base.ResourceSet)

Example 72 with XPathQueryService

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

the class XQueryTest method attributeForNoResult.

/**
 * Tests that no result will be returned if an attribute's value is selected on a node which wasn't found
 */
@Test
public void attributeForNoResult() throws XMLDBException {
    String query = // 
    "let $a := <a><b>-1</b><b>-2</b></a> " + "return /a[./c]/@id/string()";
    XPathQueryService service = (XPathQueryService) getTestCollection().getService("XPathQueryService", "1.0");
    ResourceSet result = service.query(query);
    assertEquals(0, result.getSize());
}
Also used : XPathQueryService(org.xmldb.api.modules.XPathQueryService) EXistXPathQueryService(org.exist.xmldb.EXistXPathQueryService) ResourceSet(org.xmldb.api.base.ResourceSet)

Example 73 with XPathQueryService

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

the class XQueryTest method wrongAttributeTypeCheck_1805612.

/**
 * Regression
 *
 * @see http://sourceforge.net/support/tracker.php?aid=1805612
 *
 * Same as {@link #asDouble_1840775()}
 */
@Ignore
@Test
public void wrongAttributeTypeCheck_1805612() throws XMLDBException {
    // OK
    String query = "declare namespace tst = \"http://test\"; " + "declare function tst:foo($a as element()?) {   $a }; " + "tst:foo( <result/> )";
    XPathQueryService service = (XPathQueryService) getTestCollection().getService("XPathQueryService", "1.0");
    ResourceSet result = service.query(query);
    assertEquals(1, result.getSize());
    assertEquals(query, "<result/>", result.getResource(0).getContent().toString());
    // NOK
    query = "declare namespace tst = \"http://test\"; " + "declare function tst:foo($a as element()?) {   $a }; " + "tst:foo( " + "  let $a as xs:boolean := true()  " + "  return <result/> " + ")";
    service = (XPathQueryService) getTestCollection().getService("XPathQueryService", "1.0");
    result = service.query(query);
    assertEquals(1, result.getSize());
    assertEquals(query, "<result/>", result.getResource(0).getContent().toString());
}
Also used : XPathQueryService(org.xmldb.api.modules.XPathQueryService) EXistXPathQueryService(org.exist.xmldb.EXistXPathQueryService) ResourceSet(org.xmldb.api.base.ResourceSet)

Example 74 with XPathQueryService

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

the class XQueryTest method largeAttributeKeywordOperator.

@Test
public void largeAttributeKeywordOperator() throws XMLDBException {
    ResourceSet result;
    String query;
    @SuppressWarnings("unused") XMLResource resu;
    String large = createXMLContentWithLargeString();
    XPathQueryService service = storeXMLStringAndGetQueryService(file_name, xml);
    query = "doc('" + file_name + "') / details/metadata[ @docid = '" + large + "' ]";
    result = service.queryResource(file_name, query);
    assertEquals("XQuery: " + query, nbElem, result.getSize());
}
Also used : XPathQueryService(org.xmldb.api.modules.XPathQueryService) EXistXPathQueryService(org.exist.xmldb.EXistXPathQueryService) ResourceSet(org.xmldb.api.base.ResourceSet) XMLResource(org.xmldb.api.modules.XMLResource)

Example 75 with XPathQueryService

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

the class XQueryTest method attributeNamespace.

@Test
public void attributeNamespace() throws XMLDBException {
    String query = "declare function local:copy($nodes as node()*) as node()* {" + "for $n in $nodes return " + "if ($n instance of element()) then " + "  element {node-name($n)} {(local:copy($n/@*), local:copy($n/node()))} " + "else if ($n instance of attribute()) then " + "  attribute {node-name($n)} {$n} " + "else if ($n instance of text()) then " + "  text {$n} " + "else " + "  <Other/>" + "};" + "let $c :=" + "<c:C  xmlns:c=\"http://c\" xmlns:d=\"http://d\" d:d=\"ddd\">" + "ccc" + "</c:C>" + "return local:copy($c)";
    XPathQueryService service = (XPathQueryService) getTestCollection().getService("XPathQueryService", "1.0");
    ResourceSet result = service.query(query);
    assertEquals(1, result.getSize());
    assertEquals("<c:C xmlns:c=\"http://c\" xmlns:d=\"http://d\" d:d=\"ddd\">" + "ccc" + "</c:C>", result.getResource(0).getContent().toString());
}
Also used : XPathQueryService(org.xmldb.api.modules.XPathQueryService) EXistXPathQueryService(org.exist.xmldb.EXistXPathQueryService) ResourceSet(org.xmldb.api.base.ResourceSet)

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