Package org.xmldb.api.modules

Examples of org.xmldb.api.modules.XQueryService


    }

    @Test
    public void quotes() throws XMLDBException {

        final XQueryService service =
                storeXMLStringAndGetQueryService("quotes.xml", quotes);

        queryResource(service, "quotes.xml", "/test[title = '"Hello"']", 1);

        service.declareVariable("content", ""Hello"");
        queryResource(service, "quotes.xml", "/test[title = $content]", 1);
    }
View Full Code Here


    @Test
    public void booleans() throws XMLDBException {

        System.out.println("Testing effective boolean value of expressions ...");

        final XQueryService service =
                storeXMLStringAndGetQueryService("numbers.xml", numbers);

        ResourceSet result = queryResource(service, "numbers.xml", "boolean(1.0)", 1);
        assertEquals("boolean value of 1.0 should be true", "true", result.getResource(0).getContent().toString());
View Full Code Here

    }

    @Test
    public void not() throws XMLDBException {

        final XQueryService service =
                storeXMLStringAndGetQueryService("strings.xml", strings);

        queryResource(service, "strings.xml", "/test/string[not(@value)]", 2);

        ResourceSet result = queryResource(service, "strings.xml""not(/test/abcd)", 1);
View Full Code Here

        queryResource(service, "strings.xml", "//*[blah][not(@blah)]", 0);
    }

    @Test
    public void logicalOr() throws XMLDBException, IOException, SAXException {
        final XQueryService service =
                storeXMLStringAndGetQueryService("strings.xml", strings);
           
        ResourceSet result = queryResource(service, "strings.xml""<test>{() or ()}</test>", 1);
        Resource r = result.getResource(0);
        assertXMLEqual("<test>false</test>", r.getContent().toString());
View Full Code Here

        assertEquals("false", r.getContent().toString());
    }
   
    @Test
    public void logicalAnd() throws XMLDBException, IOException, SAXException {
        final XQueryService service =
                storeXMLStringAndGetQueryService("strings.xml", strings);

        ResourceSet result = queryResource(service, "strings.xml""<test>{() and ()}</test>", 1);
        Resource r = result.getResource(0);
        assertXMLEqual("<test>false</test>", r.getContent().toString());
View Full Code Here

        assertEquals("false", r.getContent().toString());
    }    
   
    @Test
    public void ids() throws XMLDBException {
        final XQueryService service =
                storeXMLStringAndGetQueryService("ids.xml", ids);

        queryResource(service, "ids.xml", "//a/id(@ref)", 1);
        queryResource(service, "ids.xml", "/test/id(//a/@ref)", 1);
View Full Code Here

    @Test
    public void idsOnEmptyCollection() throws XMLDBException {
        final Collection root = DatabaseManager.getCollection(uri, "admin", null);
        final CollectionManagementService service = (CollectionManagementService) root.getService("CollectionManagementService", "1.0");
    final Collection emptyCollection = service.createCollection("empty");
        final XQueryService queryService = (XQueryService) emptyCollection.getService("XPathQueryService", "1.0");
       queryAndAssert(queryService, "/*", 0, null);
       queryAndAssert(queryService, "/id('foo')", 0, null);
    }
View Full Code Here

       queryAndAssert(queryService, "/id('foo')", 0, null);
    }
   
    @Test
    public void idRefs() throws XMLDBException {
       final XQueryService service =
          storeXMLStringAndGetQueryService("ids.xml", ids);
 
       queryResource(service, "ids.xml", "/idref('id2')", 1);
       queryResource(service, "ids.xml", "/idref('id1')", 2);
       queryResource(service, "ids.xml", "/idref(('id2', 'id1'))", 3);
View Full Code Here

       queryResource(service, "ids.xml", "<results>{/idref('id2')}</results>", 1);
    }
   
    @Test
    public void externalVars() throws XMLDBException {
        XQueryService service =
            storeXMLStringAndGetQueryService("strings.xml", strings);

        String query =
            "declare variable $x external;" +
            "$x";
        CompiledExpression expr = service.compile(query);
        //Do not declare the variable...
        boolean exceptionThrown = false;
        try {
            service.execute(expr);
        } catch (XMLDBException e) {
            exceptionThrown = true;
        }
        assertTrue("Expected XPTY0002", exceptionThrown);

        query =
            "declare variable $local:string external;" +
            "/test/string[. = $local:string]";
        expr = service.compile(query);
        service.declareVariable("local:string", "Hello");

        ResourceSet result = service.execute(expr);

        final XMLResource r = (XMLResource) result.getResource(0);
        Node node = r.getContentAsDOM();
        if (node.getNodeType() == Node.DOCUMENT_NODE) {
            node = node.getFirstChild();
        }
        assertEquals("string", node.getNodeName());


        //Instanciate a new service to prevent variable reuse
        //TODO : consider auto-reset ?
        service = storeXMLStringAndGetQueryService("strings.xml", strings);

        query =
            "declare variable $local:string as xs:string external;" +
            "$local:string";
        expr = service.compile(query);
        //TODO : we should virtually pass any kind of value
        service.declareVariable("local:string", new Integer(1));

        String message = "";
        try {
            service.execute(expr);
            System.out.println(query);
        } catch (XMLDBException e) {
            e.printStackTrace();
            message = e.getMessage();
        }
        assertTrue(message.indexOf("XPTY0004") > -1);

        service = storeXMLStringAndGetQueryService("strings.xml", strings);

        query =
            "declare variable $x as xs:integer external; " +
            "$x";
        expr = service.compile(query);
        //TODO : we should virtually pass any kind of value
        service.declareVariable("x", "1");

        message = "";
        try {
            System.out.println(query);
            service.execute(expr);
        } catch (XMLDBException e) {
            e.printStackTrace();
            message = e.getMessage();
        }
        assertTrue(message.indexOf("XPTY0004") > -1);
View Full Code Here

        XMLResource doc =
            (XMLResource) testCollection.createResource(
                documentName, "XMLResource" );
        doc.setContent(content);
        testCollection.storeResource(doc);
        XQueryService service =
            (XQueryService) testCollection.getService(
                "XPathQueryService",
                "1.0");
        return service;
    }
View Full Code Here

TOP

Related Classes of org.xmldb.api.modules.XQueryService

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.