Package org.exist.xquery

Examples of org.exist.xquery.XQueryContext$ContextUpdateListener


      } finally {
        context.popDocumentContext();
      }
    } else {
      final ValueSequence resultSeq = new ValueSequence();
            final XQueryContext tempContext = new XQueryContext(context.getBroker().getBrokerPool(), AccessContext.XMLDB);
      for(final Iterator<Module> i = tempContext.getRootModules(); i.hasNext(); ) {
        final Module module = i.next();
        resultSeq.add(new StringValue(module.getNamespaceURI()));
      }
            for (final URI uri : tempContext.getRepository().getJavaModules()) {
                resultSeq.add(new StringValue(uri.toString()));
            }
      return resultSeq;
    }
  }
View Full Code Here


   
    String error = null;
    ErrorCodes.ErrorCode code = null;
    int line = -1, column = -1;
   
    final XQueryContext pContext =
      new XQueryContext(context.getBroker().getBrokerPool(), AccessContext.VALIDATION_INTERNAL);
   
    if (getArgumentCount() == 2 && args[1].hasOne()) {
      pContext.setModuleLoadPath(args[1].getStringValue());
    }
    final XQueryLexer lexer = new XQueryLexer(pContext, new StringReader(expr));
    final XQueryParser parser = new XQueryParser(lexer);
    // shares the context of the outer expression
    final XQueryTreeParser astParser = new XQueryTreeParser(pContext);
View Full Code Here

      } catch (final EXistException e) {
                throw new XPathException("Unable to get new broker: " + e.getMessage(), e);
      }
           
            try {
                final XQueryContext context = callersContext.copyContext(); //make a copy
                broker = db.get(subject); //get a new broker

                return doEval(context, contextSequence, args);
            } catch(final EXistException ex) {
                throw new XPathException("Unable to get new broker: " + ex.getMessage(), ex);
View Full Code Here

            final Source source = new StringSource(query);
            final XQuery xquery = broker.getXQueryService();
            final XQueryPool pool = xquery.getXQueryPool();
            CompiledXQuery compiled = pool.borrowCompiledXQuery(broker, source);

            XQueryContext context;
            if (compiled == null) {
                context = xquery.newContext(AccessContext.REST);
            } else {
                context = compiled.getContext();
            }

            context.setStaticallyKnownDocuments(new XmldbURI[]{pathUri});
            context.setBaseURI(new AnyURIValue(pathUri.toString()));

            declareNamespaces(context, namespaces);
            declareVariables(context, variables, request, response);

            if (compiled == null) {
                compiled = xquery.compile(context, source);
            } else {
                compiled.getContext().updateContext(context);
                context.getWatchDog().reset();
            }

            try {
                final long startTime = System.currentTimeMillis();
                final Sequence resultSequence = xquery.execute(compiled, null, outputProperties);
View Full Code Here

            throws XPathException, BadRequestException, PermissionDeniedException {

        final Source source = new DBSource(broker, (BinaryDocument) resource, true);
        final XQuery xquery = broker.getXQueryService();
        final XQueryPool pool = xquery.getXQueryPool();
        XQueryContext context;

        CompiledXQuery compiled = pool.borrowCompiledXQuery(broker, source);
        if (compiled == null) {
            // special header to indicate that the query is not returned from
            // cache
            response.setHeader("X-XQuery-Cached", "false");
            context = xquery.newContext(AccessContext.REST);

        } else {
            response.setHeader("X-XQuery-Cached", "true");
            context = compiled.getContext();
        }

        // TODO: don't hardcode this?
        context.setModuleLoadPath(
                XmldbURI.EMBEDDED_SERVER_URI.append(
                resource.getCollection().getURI()).toString());

        context.setStaticallyKnownDocuments(
                new XmldbURI[]{resource.getCollection().getURI()});

        final HttpRequestWrapper reqw = declareVariables(context, null, request, response);
        reqw.setServletPath(servletPath);
        reqw.setPathInfo(pathInfo);

        if (compiled == null) {
            try {
                compiled = xquery.compile(context, source);
            } catch (final IOException e) {
                throw new BadRequestException("Failed to read query from " + resource.getURI(), e);
            }
        }

        DebuggeeFactory.checkForDebugRequest(request, context);

        boolean wrap = outputProperties.getProperty("_wrap") != null
                && "yes".equals(outputProperties.getProperty("_wrap"));

        try {
            final Sequence result = xquery.execute(compiled, null, outputProperties);
            writeResults(response, broker, result, -1, 1, false, outputProperties, wrap);

        } finally {
            context.runCleanupTasks();
            pool.returnCompiledXQuery(source, compiled);
        }
    }
View Full Code Here

            throws XPathException, BadRequestException, PermissionDeniedException {

        final URLSource source = new URLSource(this.getClass().getResource("run-xproc.xq"));
        final XQuery xquery = broker.getXQueryService();
        final XQueryPool pool = xquery.getXQueryPool();
        XQueryContext context;
        CompiledXQuery compiled = pool.borrowCompiledXQuery(broker, source);
        if (compiled == null) {
            context = xquery.newContext(AccessContext.REST);
        } else {
            context = compiled.getContext();
        }

        context.declareVariable("pipeline", resource.getURI().toString());
       
        final String stdin = request.getParameter("stdin");
        context.declareVariable("stdin", stdin == null ? "" : stdin);

        final String debug = request.getParameter("debug");
        context.declareVariable("debug", debug == null ? "0" : "1");

        final String bindings = request.getParameter("bindings");
        context.declareVariable("bindings", bindings == null ? "<bindings/>" : bindings);

        final String autobind = request.getParameter("autobind");
        context.declareVariable("autobind", autobind == null ? "0" : "1");

        final String options = request.getParameter("options");
        context.declareVariable("options", options == null ? "<options/>" : options);

        // TODO: don't hardcode this?
        context.setModuleLoadPath(
                XmldbURI.EMBEDDED_SERVER_URI.append(
                resource.getCollection().getURI()).toString());

        context.setStaticallyKnownDocuments(
                new XmldbURI[]{resource.getCollection().getURI()});

        final HttpRequestWrapper reqw = declareVariables(context, null, request, response);
        reqw.setServletPath(servletPath);
        reqw.setPathInfo(pathInfo);
View Full Code Here

        builder.startElement( new QName( "xqueries", NAMESPACE_URI, PREFIX ), null );
       
        //Add all the running xqueries
        final XQueryWatchDog watchdogs[] = getContext().getBroker().getBrokerPool().getProcessMonitor().getRunningXQueries();
        for (int i = 0; i < watchdogs.length; i++) {
          final XQueryContext   context   = watchdogs[i].getContext();
         
          getRunningXQuery( builder, context, watchdogs[i] );
        }
       
        builder.endElement();
View Full Code Here

    }
       
        if( id != 0 ) {
            final XQueryWatchDog watchdogs[] = getContext().getBroker().getBrokerPool().getProcessMonitor().getRunningXQueries();
            for (int i = 0; i < watchdogs.length; i++) {
            final XQueryContext   context   = watchdogs[i].getContext();
           
            if( id == context.hashCode() ) {
              if( !watchdogs[i].isTerminating() ) {
                watchdogs[i].kill( waittime );
              }
              break;
            }
View Full Code Here

      BadRequestException, PermissionDeniedException {
    final XQuery xquery = broker.getXQueryService();
    CompiledXQuery feedQuery = xquery.getXQueryPool().borrowCompiledXQuery(
        broker, entryByIdSource);

    XQueryContext context;
    if (feedQuery == null) {
      context = xquery.newContext(AccessContext.REST);
      try {
        feedQuery = xquery.compile(context, entryByIdSource);
      } catch (final XPathException ex) {
        throw new EXistException("Cannot compile xquery "
            + entryByIdSource.getURL(), ex);
      } catch (final IOException ex) {
        throw new EXistException(
            "I/O exception while compiling xquery "
                + entryByIdSource.getURL(), ex);
      }
    } else {
      context = feedQuery.getContext();
    }
    context.setStaticallyKnownDocuments(new XmldbURI[] { XmldbURI.create(
        path).append(AtomProtocol.FEED_DOCUMENT_NAME) });

    try {
      context.declareVariable("id", id);
      final Sequence resultSequence = xquery.execute(feedQuery, null);
      if (resultSequence.isEmpty()) {
        throw new BadRequestException("No topic was found.");
      }
View Full Code Here

   
    final XQuery xquery = broker.getXQueryService();
    CompiledXQuery feedQuery = xquery.getXQueryPool().borrowCompiledXQuery(
        broker, getFeedSource);

    XQueryContext context;
    if (feedQuery == null) {
      context = xquery.newContext(AccessContext.REST);
      try {
        feedQuery = xquery.compile(context, getFeedSource);
      } catch (final XPathException ex) {
        throw new EXistException("Cannot compile xquery "
            + getFeedSource.getURL(), ex);
      } catch (final IOException ex) {
        throw new EXistException(
            "I/O exception while compiling xquery "
                + getFeedSource.getURL(), ex);
      }
    } else {
      context = feedQuery.getContext();
    }
    context.setStaticallyKnownDocuments(
      new XmldbURI[] {
          XmldbURI.create(path).append(AtomProtocol.FEED_DOCUMENT_NAME)
      }
    );
View Full Code Here

TOP

Related Classes of org.exist.xquery.XQueryContext$ContextUpdateListener

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.