Package org.exist.xquery

Examples of org.exist.xquery.XQueryContext


       assertEquals("0750", result.itemAt(0).toString());
    }
   
    @Test(expected=XPathException.class)
    public void modeToOctal_invalidMode() throws XPathException {
       final XQueryContext mckContext = EasyMock.createMock(XQueryContext.class);

       final PermissionsFunction permissionsFunctions = new PermissionsFunction(mckContext, PermissionsFunction.FNS_MODE_TO_OCTAL);
       Sequence args[] = {
           new StringValue("invalid")
       };
View Full Code Here


      if (collection == null)
        {throw new BadRequestException("Collection " + request.getPath() + " does not exist.");}

      final XQuery xquery = broker.getXQueryService();

      final XQueryContext context = xquery.newContext(AccessContext.REST);
      context.setModuleLoadPath(getContext().getModuleLoadPath());

      String contentType = request.getHeader("Content-Type");
      String charset = getContext().getDefaultCharset();

      MimeType mime = MimeType.XML_TYPE;
      if (contentType != null) {
        final int semicolon = contentType.indexOf(';');
        if (semicolon > 0) {
          contentType = contentType.substring(0, semicolon).trim();
        }
        mime = MimeTable.getInstance().getContentType(contentType);
        final int equals = contentType.indexOf('=', semicolon);
        if (equals > 0) {
          final String param = contentType.substring(semicolon + 1, equals).trim();
          if (param.compareToIgnoreCase("charset=") == 0) {
            charset = param.substring(equals + 1).trim();
          }
        }
      }

      if (!mime.isXMLType() && !mime.equals(xqueryMimeType)) {
        throw new BadRequestException(
            "The xquery mime type is not an XML mime type nor application/xquery");
      }

      CompiledXQuery compiledQuery = null;
      try {
        final StringBuilder builder = new StringBuilder();
        final Reader r = new InputStreamReader(request.getInputStream(), charset);
        final char[] buffer = new char[4096];
        int len;
        long count = 0;
        final long contentLength = request.getContentLength();
        while ((len = r.read(buffer)) >= 0 && count < contentLength) {
          count += len;
          builder.append(buffer, 0, len);
        }
        compiledQuery = xquery.compile(context, new StringSource(builder.toString()));
     
      } catch (final XPathException ex) {
        throw new EXistException("Cannot compile xquery.", ex);
      } catch (final IOException ex) {
        throw new EXistException(
            "I/O exception while compiling xquery.", ex);
      }

      context.setStaticallyKnownDocuments(
        new XmldbURI[] {
          XmldbURI.create(request.getPath()).append(AtomProtocol.FEED_DOCUMENT_NAME)
        }
      );
View Full Code Here

       permissionsFunctions.eval(args, null);
    }
   
    @Test
    public void octalToMode() throws XPathException {
       final XQueryContext mckContext = EasyMock.createMock(XQueryContext.class);

       final PermissionsFunction permissionsFunctions = new PermissionsFunction(mckContext, PermissionsFunction.FNS_OCTAL_TO_MODE);
       Sequence args[] = {
           new StringValue("0750")
       };
View Full Code Here

      {throw new BadRequestException("Collection " + request.getPath() + " does not exist.");}

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

    XQueryContext context;
    if (feedQuery == null) {
      context = xquery.newContext(AccessContext.REST);
      context.setModuleLoadPath(getContext().getModuleLoadPath());
      try {
        feedQuery = xquery.compile(context, config.querySource);
      } catch (final XPathException ex) {
        throw new EXistException("Cannot compile xquery "
            + config.querySource.getURL(), ex);
      } catch (final IOException ex) {
        throw new EXistException(
            "I/O exception while compiling xquery "
                + config.querySource.getURL(), ex);
      }
    } else {
      context = feedQuery.getContext();
      context.setModuleLoadPath(getContext().getModuleLoadPath());
    }

    context.setStaticallyKnownDocuments(new XmldbURI[] { XmldbURI.create(
        request.getPath()).append(AtomProtocol.FEED_DOCUMENT_NAME) });

    try {
      declareVariables(context, request.getRequest(), response.getResponse());
View Full Code Here

     * Test of eval method, of class IdFunction.
     * when real and effective users are different
     */
    @Test
    public void differingRealAndEffectiveUsers() throws XPathException, XpathException {
        final XQueryContext mckContext = createMockBuilder(XQueryContext.class)
                .addMockedMethod("getRealUser")
                .addMockedMethod("getEffectiveUser")
                .createMock();

        final Subject mckRealUser = EasyMock.createMock(Subject.class);
        final String realUsername = "real";
        expect(mckContext.getRealUser()).andReturn(mckRealUser).times(2);
        expect(mckRealUser.getName()).andReturn(realUsername);
        expect(mckRealUser.getGroups()).andReturn(new String[]{"realGroup1", "realGroup2"});
        expect(mckRealUser.getId()).andReturn(1);

        final Subject mckEffectiveUser = EasyMock.createMock(Subject.class);
        final String effectiveUsername = "effective";
        expect(mckContext.getEffectiveUser()).andReturn(mckEffectiveUser).times(2);
        expect(mckEffectiveUser.getId()).andReturn(2);
        expect(mckEffectiveUser.getName()).andReturn(effectiveUsername);
        expect(mckEffectiveUser.getGroups()).andReturn(new String[]{"effectiveGroup1", "effectiveGroup2"});

        replay(mckEffectiveUser, mckRealUser, mckContext);
View Full Code Here

     * Test of eval method, of class IdFunction.
     * when real and effective users are the same
     */
    @Test
    public void sameRealAndEffectiveUsers() throws XPathException, XpathException {
        final XQueryContext mckContext = createMockBuilder(XQueryContext.class)
                .addMockedMethod("getRealUser")
                .addMockedMethod("getEffectiveUser")
                .createMock();

        final Subject mckUser = EasyMock.createMock(Subject.class);
        final String username = "user1";
        expect(mckContext.getRealUser()).andReturn(mckUser).times(2);
        expect(mckUser.getName()).andReturn(username);
        expect(mckUser.getGroups()).andReturn(new String[]{"group1", "group2"});
        expect(mckUser.getId()).andReturn(1);

        expect(mckContext.getEffectiveUser()).andReturn(mckUser);
        expect(mckUser.getId()).andReturn(1);

        replay(mckUser, mckContext);

        final IdFunction idFunctions = new IdFunction(mckContext, IdFunction.FNS_ID);
View Full Code Here

    if(!TriggerStatePerThread.verifyUniqueTriggerPerThreadBeforePrepare(this, src)) {
      return;
    }
    TriggerStatePerThread.setTransaction(transaction);
   
    final XQueryContext context = service.newContext(AccessContext.TRIGGER);
         //TODO : further initialisations ?
        CompiledXQuery compiledQuery;
        try
        {
          //compile the XQuery
          compiledQuery = service.compile(context, query);

          //declare external variables
          context.declareVariable(bindingPrefix + "type", EVENT_TYPE_PREPARE);
          context.declareVariable(bindingPrefix + "event", new StringValue(eventToString(event)));
         
          if (isCollection)
            {context.declareVariable(bindingPrefix + "collection", new AnyURIValue(src));}
          else
            {context.declareVariable(bindingPrefix + "collection", new AnyURIValue(src.removeLastSegment()));}

          context.declareVariable(bindingPrefix + "uri", new AnyURIValue(src));
          if (dst == null)
            {context.declareVariable(bindingPrefix + "new-uri", Sequence.EMPTY_SEQUENCE);}
          else
            {context.declareVariable(bindingPrefix + "new-uri", new AnyURIValue(dst));}
         
          // For backward compatibility
          context.declareVariable(bindingPrefix + "eventType", EVENT_TYPE_PREPARE);
          context.declareVariable(bindingPrefix + "triggerEvent", new StringValue(eventToString(event)));

          if (isCollection)
            {context.declareVariable(bindingPrefix + "collectionName", new AnyURIValue(src));}
          else {
            context.declareVariable(bindingPrefix + "collectionName", new AnyURIValue(src.removeLastSegment()));
            context.declareVariable(bindingPrefix + "documentName", new AnyURIValue(src));
          }
         
          //declare user defined parameters as external variables
          for(final Iterator itUserVarName = userDefinedVariables.keySet().iterator(); itUserVarName.hasNext();)
          {
            final String varName = (String)itUserVarName.next();
            final String varValue = userDefinedVariables.getProperty(varName);
         
            context.declareVariable(bindingPrefix + varName, new StringValue(varValue));
          }
         
        } catch(final XPathException e) {
        TriggerStatePerThread.setTriggerRunningState(TriggerStatePerThread.NO_TRIGGER_RUNNING, this, null);
        TriggerStatePerThread.setTransaction(null);
View Full Code Here

     
    // avoid infinite recursion by allowing just one trigger per thread
    if(!TriggerStatePerThread.verifyUniqueTriggerPerThreadBeforeFinish(this, src))
      {return;}
   
        final XQueryContext context = service.newContext(AccessContext.TRIGGER);
        CompiledXQuery compiledQuery = null;
        try {
          //compile the XQuery
          compiledQuery = service.compile(context, query);
         
          //declare external variables
          context.declareVariable(bindingPrefix + "type", EVENT_TYPE_FINISH);
          context.declareVariable(bindingPrefix + "event", new StringValue(eventToString(event)));
         
          if (isCollection)
            {context.declareVariable(bindingPrefix + "collection", new AnyURIValue(src));}
          else
            {context.declareVariable(bindingPrefix + "collection", new AnyURIValue(src.removeLastSegment()));}
       
          context.declareVariable(bindingPrefix + "uri", new AnyURIValue(src));
          if (dst == null)
            {context.declareVariable(bindingPrefix + "new-uri", Sequence.EMPTY_SEQUENCE);}
          else
            {context.declareVariable(bindingPrefix + "new-uri", new AnyURIValue(dst));}
         
          // For backward compatibility
          context.declareVariable(bindingPrefix + "eventType", EVENT_TYPE_FINISH);
          context.declareVariable(bindingPrefix + "triggerEvent", new StringValue(eventToString(event)));
          if (isCollection)
            {context.declareVariable(bindingPrefix + "collectionName", new AnyURIValue(src));}
          else {
            context.declareVariable(bindingPrefix + "collectionName", new AnyURIValue(src.removeLastSegment()));
            context.declareVariable(bindingPrefix + "documentName", new AnyURIValue(src));
          }
         
          //declare user defined parameters as external variables
          for(final Iterator itUserVarName = userDefinedVariables.keySet().iterator(); itUserVarName.hasNext();)
          {
            final String varName = (String)itUserVarName.next();
            final String varValue = userDefinedVariables.getProperty(varName);
         
            context.declareVariable(bindingPrefix + varName, new StringValue(varValue));
          }
         
        } catch(final XPathException e) {
          //Should never be reached
          LOG.error(e);
View Full Code Here

//        DocumentSet docs = collection.getCollection().allDocs(broker, new DocumentSet(), true, true);
        final XmldbURI[] docs = new XmldbURI[] { XmldbURI.create(collection.getName()) };

        final XQuery xquery = broker.getXQueryService();
        final XQueryPool pool = xquery.getXQueryPool();
        XQueryContext context;
        CompiledXQuery compiled = pool.borrowCompiledXQuery(broker, source);
        if(compiled == null)
            {context = xquery.newContext(accessCtx);}
        else
            {context = compiled.getContext();}
        //context.setBackwardsCompatibility(xpathCompatible);
        context.setStaticallyKnownDocuments(docs);

        if (variableDecls.containsKey(Debuggee.PREFIX+":session")) {
          context.declareVariable(Debuggee.SESSION, variableDecls.get(Debuggee.PREFIX+":session"));
          variableDecls.remove(Debuggee.PREFIX+":session");
        }

        setupContext(source, context);
       
View Full Code Here

        DBBroker broker = null;
        try {
            final long start = System.currentTimeMillis();
            broker = brokerPool.get(user);
            final XQuery xquery = broker.getXQueryService();
            final XQueryContext context = xquery.newContext(accessCtx);
            setupContext(null, context);
            final CompiledXQuery expr = xquery.compile(context, query);
//            checkPragmas(context);
            LOG.debug("compilation took "  (System.currentTimeMillis() - start));
            return expr;
View Full Code Here

TOP

Related Classes of org.exist.xquery.XQueryContext

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.