Examples of XQueryService


Examples of org.exist.xmldb.XQueryService

                } else {
                    log( msg, Project.MSG_ERR );
                }

            } else {
                final XQueryService service = (XQueryService)base.getService( "XQueryService", "1.0" );

                // set pretty-printing on
                service.setProperty( OutputKeys.INDENT, "yes" );
                service.setProperty( OutputKeys.ENCODING, "UTF-8" );

                for( final Variable var : variables ) {
                    System.out.println( "Name: " + var.name );
                    System.out.println( "Value: " + var.value );
                    service.declareVariable( var.name, var.value );
                }

                ResourceSet results = null;
                Source      source  = null;

                if( queryUri != null ) {
                    log( "XQuery url " + queryUri, Project.MSG_DEBUG );

                    if( queryUri.startsWith( XmldbURI.XMLDB_URI_PREFIX ) ) {
                        final Resource resource = base.getResource( queryUri );
                        source = new BinarySource( (byte[])resource.getContent(), true );
                    } else {
                        source = new URLSource( new URL( queryUri ) );
                    }

                } else if( queryFile != null ) {
                    log( "XQuery file " + queryFile.getAbsolutePath(), Project.MSG_DEBUG );
                    source = new FileSource( queryFile, "UTF-8", true );

                } else {
                    log( "XQuery string: " + query, Project.MSG_DEBUG );
                    source = new StringSource( query );
                }

                results = service.execute( source );
                log( "Found " + results.getSize() + " results", Project.MSG_INFO );

                if( ( destDir != null ) && ( results != null ) ) {
                    log( "write results to directory " + destDir.getAbsolutePath(), Project.MSG_INFO );
                    final ResourceIterator iter = results.getIterator();
View Full Code Here

Examples of org.exist.xmldb.XQueryService

    }
   
  public static ResourceSet xquery(Collection collection, String xquery)
  throws XMLDBException
  {
    XQueryService service = getXQueryService(collection);
    Source source = new StringSource(xquery);
    return service.execute(source);
  }
View Full Code Here

Examples of org.exist.xmldb.XQueryService

   * */
  public static String[] wordList(Collection root) throws XMLDBException {
        final String query = "util:index-keys(//*, \"\", function($key, $options) {\n" +
                "    $key\n" +
                "}, 100, \"lucene-index\")";
        XQueryService service = getXQueryService(root);
        ResourceSet result = service.query(query);

        ArrayList<String> list = new ArrayList<String>();
        for (ResourceIterator iter = result.getIterator(); iter.hasMoreResources(); ) {
            Resource next = iter.nextResource();
            list.add(next.getContent().toString());
View Full Code Here

Examples of org.exist.xmldb.XQueryService

        final FileSource source = new FileSource(f, "UTF-8", true);

        try {
            // Prepare and execute the XQuery
            final Collection collection = DatabaseManager.getCollection(collectionURI.toString(), user, password);
            final XQueryService service = (XQueryService) collection.getService("XQueryService", "1.0");
            if(!((CollectionImpl)collection).isRemoteCollection()) {
                service.declareVariable(RequestModule.PREFIX + ":request", new HttpRequestWrapper(request, "UTF-8", "UTF-8"));
                service.declareVariable(ResponseModule.PREFIX + ":response", new HttpResponseWrapper(response));
                service.declareVariable(SessionModule.PREFIX + ":session", new HttpSessionWrapper(request.getSession( false )));
            }
            final ResourceSet result = service.execute(source);

            String redirectTo = null;
            String servletName = null;
            String path = null;
            RequestWrapper modifiedRequest = null;
View Full Code Here

Examples of org.exist.xmldb.XQueryService

    private void storeRemoveDocs(String collectionName) {
        try {
            storeDocs(collectionName);

            XQueryService xqs = (XQueryService) test.getService("XQueryService", "1.0");
            ResourceSet result = xqs.query("//SPEECH[ft:query(LINE, 'king')]");
            assertEquals(98, result.getSize());
            result = xqs.query("//SPEECH[ft:query(SPEAKER, 'juliet')]");
            assertEquals(118, result.getSize());

            String[] resources = test.listResources();
            for (int i = 0; i < resources.length; i++) {
                Resource resource = test.getResource(resources[i]);
                test.removeResource(resource);
            }
            result = xqs.query("//SPEECH[ft:query(LINE, 'king')]");
            assertEquals(0, result.getSize());
            result = xqs.query("//SPEECH[ft:query(SPEAKER, 'juliet')]");
            assertEquals(0, result.getSize());
        } catch (XMLDBException e) {
            e.printStackTrace();
            fail(e.getMessage());
        }
View Full Code Here

Examples of org.exist.xmldb.XQueryService

    private void xupdateDocs(String collectionName) {
        try {
            storeDocs(collectionName);

            XQueryService xqs = (XQueryService) test.getService("XQueryService", "1.0");
            ResourceSet result = xqs.query("//SPEECH[ft:query(SPEAKER, 'juliet')]");
            assertEquals(118, result.getSize());

            String xupdate =
                LuceneIndexTest.XUPDATE_START +
                "   <xu:remove select=\"//SPEECH[ft:query(SPEAKER, 'juliet')]\"/>" +
                LuceneIndexTest.XUPDATE_END;
            XUpdateQueryService xuqs = (XUpdateQueryService) test.getService("XUpdateQueryService", "1.0");
            xuqs.update(xupdate);

            result = xqs.query("//SPEECH[ft:query(SPEAKER, 'juliet')]");
            assertEquals(0, result.getSize());
            result = xqs.query("//SPEECH[ft:query(LINE, 'king')]");
            assertEquals(98, result.getSize());
        } catch (XMLDBException e) {
            e.printStackTrace();
            fail(e.getMessage());
        }
View Full Code Here

Examples of org.exist.xmldb.XQueryService

  public void test(String script) {
        try {
            StringBuilder fails = new StringBuilder();
            StringBuilder results = new StringBuilder();
            XQueryService xqs = (XQueryService) rootCollection.getService("XQueryService", "1.0");
            Source query = new StringSource(script);

            ResourceSet result = xqs.execute(query);
            XMLResource resource = (XMLResource) result.getResource(0);
            results.append(resource.getContent()).append('\n');
            Element root = (Element) resource.getContentAsDOM();
            NodeList tests = root.getElementsByTagName("result");
            for (int i = 0; i < tests.getLength(); i++) {
View Full Code Here

Examples of org.exist.xmldb.XQueryService

                root = DatabaseManager.getCollection(baseURI + XmldbURI.ROOT_COLLECTION, user, password);
                root = mkcol(root, baseURI, XmldbURI.ROOT_COLLECTION, path);
            } else
                root = DatabaseManager.getCollection(uri, user, password);

            XQueryService service = (XQueryService) root.getService("XQueryService", "1.0");
            Source source = new StringSource(XQUERY);
            service.declareVariable("collection", root.getName());
            service.declareVariable("uri", "");
            if (moduleURI != null) {
                service.declareVariable("uri", moduleURI);
                service.declareVariable("data", "");
                service.execute(source);
            } else {
                for(FileSet fileSet: fileSets) {
                    DirectoryScanner scanner = fileSet.getDirectoryScanner(getProject());
                    scanner.scan();
                    String[] files = scanner.getIncludedFiles();
                    log("Found " + files.length + " files to upload.\n");

                    File baseDir=scanner.getBasedir();
                    for (int i = 0; i < files.length; i++) {
                        File file = new File(baseDir , files[i]);
                        log("Storing " + files[i] + " ...\n");
                        byte[] data = read(file);
                        try {
                            service.declareVariable("name", file.getName());
                            service.declareVariable("data", data);
                            service.execute(source);
                        } catch (XMLDBException e) {
                            String msg="XMLDB exception caught: " + e.getMessage();
                            if(failonerror)
                                throw new BuildException(msg,e);
                            else
View Full Code Here

Examples of org.exist.xmldb.XQueryService

  private static Collection testCollection;

  @Test
  public void run() {
    try {
      XQueryService xqs = (XQueryService) testCollection.getService("XQueryService", "1.0");
      Source query = new FileSource(new File(TEST_QUERY), "UTF-8", false);
      for (File file : files) {
        xqs.declareVariable("doc", file.getName());
        ResourceSet result = xqs.execute(query);
        XMLResource resource = (XMLResource) result.getResource(0);
                System.out.println(resource.getContent());
        Element root = (Element) resource.getContentAsDOM();
        NodeList tests = root.getElementsByTagName("test");
        for (int i = 0; i < tests.getLength(); i++) {
View Full Code Here

Examples of org.exist.xmldb.XQueryService

  }

  private static void runTests(List<String> files, String id) {
    try {
      StringBuilder results = new StringBuilder();
      XQueryService xqs = (XQueryService) rootCollection.getService("XQueryService", "1.0");
      Source query = new FileSource(new File("test/src/xquery/runTests.xql"), "UTF-8", false);
      for (String fileName : files) {
        File file = new File(fileName);
        if (!file.canRead()) {
          System.console().printf("Test file not found: %s\n", fileName);
          return;
        }
       
        Document doc = TestRunner.parse(file);
       
        xqs.declareVariable("doc", doc);
       
        if (id != null) {
          xqs.declareVariable("id", id);
        } else {
          xqs.declareVariable("id", Sequence.EMPTY_SEQUENCE);
        }
       
        ResourceSet result = xqs.execute(query);
        XMLResource resource = (XMLResource) result.getResource(0);
                results.append(resource.getContent()).append('\n');
        Element root = (Element) resource.getContentAsDOM();
        NodeList tests = root.getElementsByTagName("test");
        for (int i = 0; i < tests.getLength(); i++) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.