Search in sources :

Example 76 with XPathQueryService

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

the class XQueryTest method userEscalationForInMemoryNodes.

@Test
public void userEscalationForInMemoryNodes() throws XMLDBException {
    String query = "xmldb:login(\"xmldb:exist:///db\", \"guest\", \"guest\"), sm:id()/sm:id/sm:effective/sm:username/text(), let $node := <node id=\"1\">value</node>, $null := $node[@id eq '1'] return sm:id()/sm:id/sm:effective/sm:username/text()";
    XPathQueryService service = (XPathQueryService) getTestCollection().getService("XPathQueryService", "1.0");
    ResourceSet result = service.query(query);
    Resource loggedIn = result.getResource(0);
    Resource currentUser = result.getResource(1);
    Resource currentUserAfterInMemoryOp = result.getResource(2);
    // check the login as guest worked
    assertEquals("Logged in as quest: " + loggedIn.getContent().toString(), "true", loggedIn.getContent().toString());
    // check that we are guest
    assertEquals("After Login as guest, User should be guest and is: " + currentUser.getContent().toString(), "guest", currentUser.getContent().toString());
    // check that we are still guest
    assertEquals("After Query, User should still be guest and is: " + currentUserAfterInMemoryOp.getContent().toString(), "guest", currentUserAfterInMemoryOp.getContent().toString());
}
Also used : 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) ResourceSet(org.xmldb.api.base.ResourceSet)

Example 77 with XPathQueryService

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

the class XQueryTest method serialization.

@Test
public void serialization() throws XMLDBException {
    @SuppressWarnings("unused") ResourceSet result;
    String query;
    @SuppressWarnings("unused") boolean exceptionThrown;
    String message;
    XPathQueryService service = storeXMLStringAndGetQueryService(NUMBERS_XML, numbers);
    query = "let $a := <test><foo name='bar'/><foo name='bar'/></test>" + "return <attribute>{$a/foo/@name}</attribute>";
    try {
        message = "";
        result = service.query(query);
    } catch (XMLDBException e) {
        message = e.getMessage();
    }
    assertTrue(message.indexOf("XQDY0025") > -1);
    query = "let $a := <foo name='bar'/> return $a/@name";
    try {
        message = "";
        result = service.query(query);
    } catch (XMLDBException e) {
        message = e.getMessage();
    }
// TODO : how toserialize this resultand get the error ? -pb
// assertTrue(message.indexOf("XQDY0025") > -1);
}
Also used : XPathQueryService(org.xmldb.api.modules.XPathQueryService) EXistXPathQueryService(org.exist.xmldb.EXistXPathQueryService) XMLDBException(org.xmldb.api.base.XMLDBException) ResourceSet(org.xmldb.api.base.ResourceSet)

Example 78 with XPathQueryService

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

the class XQueryTest method descendantOrSelf_1460791.

/**
 * @see http://sourceforge.net/support/tracker.php?aid=1460791
 */
@Test
public void descendantOrSelf_1460791() throws XMLDBException {
    String query = "declare option exist:serialize 'indent=no';" + "let $test:=<z> <a> aaa </a> <z> zzz </z> </z> " + "return " + "( " + "<one> {$test//z} </one>, " + "<two> {$test/descendant-or-self::node()/child::z} </two> " + "(: note that these should be the same *by definition* :) " + ")";
    XPathQueryService service = (XPathQueryService) getTestCollection().getService("XPathQueryService", "1.0");
    ResourceSet result = service.query(query);
    assertEquals(2, result.getSize());
    assertEquals(query, result.getResource(0).getContent().toString(), "<one><z> zzz </z></one>");
    assertEquals(query, result.getResource(1).getContent().toString(), "<two><z> zzz </z></two>");
}
Also used : XPathQueryService(org.xmldb.api.modules.XPathQueryService) EXistXPathQueryService(org.exist.xmldb.EXistXPathQueryService) ResourceSet(org.xmldb.api.base.ResourceSet)

Example 79 with XPathQueryService

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

the class XQueryTest method constructedAttributeValue.

@Test
public void constructedAttributeValue() throws XMLDBException {
    String query = "let $attr := attribute d { \"xxx\" } " + "return string($attr)";
    XPathQueryService service = (XPathQueryService) getTestCollection().getService("XPathQueryService", "1.0");
    ResourceSet result = service.query(query);
    assertEquals(1, result.getSize());
    assertEquals("xxx", 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 80 with XPathQueryService

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

the class XQueryTest method noNamepaceDefinedForPrefix_1959010.

/**
 * @see http://sourceforge.net/support/tracker.php?aid=1959010
 */
@Test
public void noNamepaceDefinedForPrefix_1959010() 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(query, "<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