Examples of XQueryContext


Examples of org.exist.xquery.XQueryContext

     * @param broker eXist database broker
     * @param path path to query, formatted as xmldb:exist:///db/...
     */
    private void executeQuery(DBBroker broker, String path) {

        XQueryContext context = null;
        try {
            // Get path to xquery
            Source source = SourceFactory.getSource(broker, null, path, false);

            if (source == null) {
                LOG.info(String.format("No Xquery found at '%s'", path));

            } else {
                // Setup xquery service
                XQuery service = broker.getXQueryService();
                context = service.newContext(AccessContext.TRIGGER);

                // Allow use of modules with relative paths
                String moduleLoadPath = StringUtils.substringBeforeLast(path, "/");
                context.setModuleLoadPath(moduleLoadPath);

                // Compile query
                CompiledXQuery compiledQuery = service.compile(context, source);

                LOG.info(String.format("Starting Xquery at '%s'", path));

                // Finish preparation
                context.prepareForExecution();

                // Execute
                Sequence result = service.execute(compiledQuery, null);

                // Log results
                LOG.info(String.format("Result xquery: '%s'", result.getStringValue()));

            }

        } catch (Throwable t) {
            // Dirty, catch it all
            LOG.error(String.format("An error occured during preparation/execution of the xquery script %s: %s", path, t.getMessage()), t);

        } finally {
            if (context != null) {
                context.runCleanupTasks();
            }
        }
    }
View Full Code Here

Examples of org.exist.xquery.XQueryContext

                    return;
                }

                final XQueryPool xqpool = xquery.getXQueryPool();
                CompiledXQuery compiled = xqpool.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()));

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

                final Properties outputProperties = new Properties();
                Sequence result = null;
View Full Code Here

Examples of org.exist.xquery.XQueryContext

    //disconnected already
    if (compiledXQuery == null)
      return;
   
    //disconnect debuggee & compiled source
    XQueryContext context = compiledXQuery.getContext();
    context.setDebuggeeJoint(null);
    compiledXQuery = null;
   
    if (command != null && disconnect)
      command.disconnect();
   
View Full Code Here

Examples of org.exist.xquery.XQueryContext

    Database db = compiledXQuery.getContext().getDatabase();
    DBBroker broker = null;
    try {
      broker = db.getBroker(); //TODO: account required

      XQueryContext context = compiledXQuery.getContext().copyContext();
      context.setDebuggeeJoint(null);
      context.undeclareGlobalVariable(Debuggee.SESSION);
      context.undeclareGlobalVariable(Debuggee.IDEKEY);
     
      XQuery service = broker.getXQueryService();
      CompiledXQuery compiled = service.compile(context, script);
     
      Sequence resultSequence = service.execute(compiled, null);
View Full Code Here

Examples of org.exist.xquery.XQueryContext

      //link debugger session & script
      DebuggeeJointImpl joint = new DebuggeeJointImpl();

      joint.setCompiledScript(compiledXQuery);
      XQueryContext context = compiledXQuery.getContext();
      context.setDebuggeeJoint(joint);
     
      String idesession = "";
      if (context.isVarDeclared(Debuggee.SESSION)) {
        try {
          Variable var = context.resolveVariable(Debuggee.SESSION);
          idesession = var.getValue().toString();
        } catch (XPathException e) {
        }
      }
     
      String idekey = "";
      if (context.isVarDeclared(Debuggee.IDEKEY)) {
        try {
          Variable var = context.resolveVariable(Debuggee.IDEKEY);
          idekey = var.getValue().toString();
        } catch (XPathException e) {
        }
      }
     
View Full Code Here

Examples of org.exist.xquery.XQueryContext

 
          if (source == null) return null;
 
          XQuery xquery = broker.getXQueryService();
     
          XQueryContext queryContext = xquery.newContext(AccessContext.REST);
 
      // Find correct script load path
      queryContext.setModuleLoadPath(XmldbURI.create(uri).removeLastSegment().toString());
 
      CompiledXQuery compiled;
      try {
        compiled = xquery.compile(queryContext, source);
      } catch (IOException e) {
        e.printStackTrace();
        return null;
      }
         
      String sessionId = String.valueOf(queryContext.hashCode());
     
      //link debugger session & script
      DebuggeeJointImpl joint = new DebuggeeJointImpl();
      SessionImpl session = new SessionImpl();

      joint.setCompiledScript(compiled);
      queryContext.setDebuggeeJoint(joint);
      joint.continuation(new Init(session, sessionId, "eXist"));

      runner = new ScriptRunner(session, compiled);
      runner.start();
     
View Full Code Here

Examples of org.exist.xquery.XQueryContext

                    xpointer = checkNamespaces(xpointer);
                    source = new StringSource(xpointer);
                }
                final XQuery xquery = serializer.broker.getXQueryService();
                final XQueryPool pool = xquery.getXQueryPool();
                XQueryContext context;
                CompiledXQuery compiled = pool.borrowCompiledXQuery(serializer.broker, source);
                if (compiled != null)
                    {context = compiled.getContext();}
                else
                    {context = xquery.newContext(AccessContext.XINCLUDE);}
                context.declareNamespaces(namespaces);
                context.declareNamespace("xinclude", XINCLUDE_NS);
               
                //setup the http context if known
                if(serializer.httpContext != null)
                {
                  if(serializer.httpContext.getRequest() != null)
                    {context.declareVariable(RequestModule.PREFIX + ":request", serializer.httpContext.getRequest());}
                 
                  if(serializer.httpContext.getResponse() != null)
                    {context.declareVariable(ResponseModule.PREFIX + ":response", serializer.httpContext.getResponse());}
                 
                  if(serializer.httpContext.getSession() != null)
                    {context.declareVariable(SessionModule.PREFIX + ":session", serializer.httpContext.getSession());}
                }
               
                //TODO: change these to putting the XmldbURI in, but we need to warn users!
                if(document!=null){
                    context.declareVariable("xinclude:current-doc", document.getFileURI().toString());
                    context.declareVariable("xinclude:current-collection", document.getCollection().getURI().toString());
                }
               
                if (xpointer != null) {
                    if(doc != null)
                        {context.setStaticallyKnownDocuments(new XmldbURI[] { doc.getURI() } );}
                    else if (docUri != null)
                        {context.setStaticallyKnownDocuments(new XmldbURI[] { docUri });}
                }

                // pass parameters as variables
                if (params != null) {
                    for (final Map.Entry<String, String> entry : params.entrySet()) {
                        context.declareVariable(entry.getKey(), entry.getValue());
                    }
                }

                if(compiled == null) {
                    try {
View Full Code Here

Examples of org.exist.xquery.XQueryContext

    if (variables == null)
      return ""; //XXX: error?

    StringBuilder properties = new StringBuilder();

    XQueryContext ctx = getJoint().getContext();
    for (Variable variable : variables.values()) {
      properties.append(PropertyGet.getPropertyString(variable, ctx));
    }
    return properties.toString();
  }
View Full Code Here

Examples of org.exist.xquery.XQueryContext

        try {
            broker = brokerPool.get(user);
           
            CompiledXQuery compiled =null;
            final XQuery xquery = broker.getXQueryService();
            final XQueryContext context = xquery.newContext(AccessContext.INTERNAL_PREFIX_LOOKUP);
           
            if(collection!=null){
                context.declareVariable(COLLECTION, collection);
            }
           
            if(namespace!=null){
                context.declareVariable(TARGETNAMESPACE, namespace);
            }
           
            if(publicId!=null){
                context.declareVariable(PUBLICID, publicId);
            }
           
            if(catalogPath!=null){
                context.declareVariable(CATALOG, catalogPath);
            }
           
            compiled = xquery.compile(context, new ClassLoaderSource(queryPath) );
           
            result = xquery.execute(compiled, null);
View Full Code Here

Examples of org.exist.xquery.XQueryContext

    /**
     * Test of eval method, of class PermissionsFunctions.
     */
    @Test
    public void modeToOctal() throws XPathException {
       final XQueryContext mckContext = EasyMock.createMock(XQueryContext.class);

       final PermissionsFunction permissionsFunctions = new PermissionsFunction(mckContext, PermissionsFunction.FNS_MODE_TO_OCTAL);
       Sequence args[] = {
           new StringValue("rwxr-x---")
       };
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.