Package org.exist.source

Examples of org.exist.source.Source


            abort("BrokerPool or XQueryResource or User was null!");
        }

        DBBroker broker = null;
        DocumentImpl resource = null;
        Source source = null;
        XQueryPool xqPool  = null;
        CompiledXQuery compiled = null;
        XQueryContext context = null;

        try {
View Full Code Here


    final Database db = getDatabase();
        DBBroker broker = null;
        try {
            broker = db.get(subject);

            final Source source = getQuerySource(broker, scriptURI, script);
            if(source == null) {return;}

            final XQuery xquery = broker.getXQueryService();
            final XQueryContext context = xquery.newContext(AccessContext.XMLDB);
View Full Code Here

                    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 ) ) {
View Full Code Here

   
  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

            if (requestUser != null)
              {user = requestUser;}
          }
        }
       
        Source source = null;
        final Object sourceAttrib = request.getAttribute(ATTR_XQUERY_SOURCE);
        final Object urlAttrib = request.getAttribute(ATTR_XQUERY_URL);
        if (sourceAttrib != null) {
            String s;
            if (sourceAttrib instanceof Item)
                try {
                    s = ((Item) sourceAttrib).getStringValue();
                } catch (final XPathException e) {
                    throw new ServletException("Failed to read XQuery source string from " +
                        "request attribute '" + ATTR_XQUERY_SOURCE + "': " + e.getMessage(), e);
                }
            else
                {s = sourceAttrib.toString();}
           
            source = new StringSource(s);
           
        } else if (urlAttrib != null) {
            DBBroker broker = null;
            try {
              broker = getPool().get(user);
                source = SourceFactory.getSource(broker, moduleLoadPath, urlAttrib.toString(), true);
            } catch (final Exception e) {
                getLog().error(e.getMessage(), e);
                response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
                sendError(output, "Error", e.getMessage());
            } finally {
                getPool().release(broker);
            }
           
        } else {
            final File f = new File(path);
            if(!f.canRead()) {
                response.setStatus(HttpServletResponse.SC_NOT_FOUND);
                sendError(output, "Cannot read source file", path);
                return;
            }
            source = new FileSource(f, encoding, true);
        }
       
        if (source == null) {
            response.setStatus(HttpServletResponse.SC_NOT_FOUND);
            sendError(output, "Source not found", path);
        }
       
        boolean reportErrors = false;
        final String errorOpt = (String) request.getAttribute(ATTR_XQUERY_REPORT_ERRORS);
        if (errorOpt != null)
            {reportErrors = errorOpt.equalsIgnoreCase("YES");}
       
        //allow source viewing for GET?
        if("GET".equals(request.getMethod().toUpperCase())) {
            String option;
            boolean allowSource = false;
            if((option = request.getParameter("_source")) != null)
                allowSource = "yes".equals(option);
           
            //Should we display the source of the XQuery or execute it
            if(allowSource && descriptor != null) {
                //show the source
               
                //check are we allowed to show the xquery source - descriptor.xml
//                System.out.println("path="+path);
                if(descriptor.allowSource(path)) {
                 
                  try {
            source.validate(user, Permission.READ);
          } catch (final PermissionDeniedException e) {
            if (getDefaultUser().equals(user)) {
              getAuthenticator().sendChallenge(request, response);
            } else {
              response.sendError(HttpServletResponse.SC_FORBIDDEN, "Permission to view XQuery source for: " + path + " denied. (no read access)");
            }
            return;
          }
                   
          //Show the source of the XQuery
                    //writeResourceAs(resource, broker, stylesheet, encoding, "text/plain", outputProperties, response);
                    response.setContentType("text/plain; charset=" + getFormEncoding());
                    output.write(source.getContent());
                    output.flush();
                    return;
                } else {
                  
                   response.sendError(HttpServletResponse.SC_FORBIDDEN, "Permission to view XQuery source for: " + path + " denied. Must be explicitly defined in descriptor.xml");
View Full Code Here

            final Iterator<Module> itModule = xqyCtx.getModules();
            while(itModule.hasNext()) {
                final Module module = itModule.next();
                if(module instanceof ExternalModule) {
                    final ExternalModule extModule = (ExternalModule)module;
                    final Source source = extModule.getSource();
                    if(source instanceof DBSource) {
                        final String moduleUri = getDbUri(source);
                        if(depSet == null) {
                            depSet = new HashSet<String>();
                        }
View Full Code Here

  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();
View Full Code Here

          XQuery xquery = broker.getXQueryService();
         
          XQueryContext context = xquery.newContext(AccessContext.TEST);
          //context.setModuleLoadPath();
         
            Source query = new ClassLoaderSource(source);
           
            CompiledXQuery compiledQuery = xquery.compile(context, query);
           
      for(Iterator<UserDefinedFunction> i = context.localFunctions(); i.hasNext(); ) {
        UserDefinedFunction func = i.next();
View Full Code Here

        BrokerPool pool = null;
        DBBroker broker = null;

        try {
            DocumentImpl resource = null;
            Source source = null;

            pool = BrokerPool.getInstance();

            broker = pool.get(principal);
            if (broker == null) {
View Full Code Here

                if(metadata.getMimeType().equals(XQUERY_MIME_TYPE)){
           
                    //compile the query
                    final XQuery xquery = broker.getXQueryService();
                    final XQueryContext context = xquery.newContext(AccessContext.REST);
                    final Source source = new DBSource(broker, (BinaryDocument)document, true);

                    //set the module load path for any module imports that are relative
                    context.setModuleLoadPath(XmldbURI.EMBEDDED_SERVER_URI_PREFIX + ((XmldbURI)source.getKey()).removeLastSegment());
                   
                    return broker.getXQueryService().compile(context, source);
                } else {
                    throw new RestXqServiceCompilationException("Invalid mimetype '" +  metadata.getMimeType() + "' for XQuery: "  + document.getURI().toString().toString());
                }
View Full Code Here

TOP

Related Classes of org.exist.source.Source

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.