Package org.exist.dom

Examples of org.exist.dom.DocumentImpl


      try {
           source = broker.openCollection(uri.removeLastSegment(), Lock.WRITE_LOCK);
          if(source == null) {
            return false;
              }
          final DocumentImpl doc = source.getDocument(broker, uri.lastSegment());
              if(doc == null) {
                  return false;
              }
              destination = broker.openCollection(destinationPath.removeLastSegment(), Lock.WRITE_LOCK);
              if(destination == null) {
View Full Code Here


            try {
                source = broker.openCollection(uri.removeLastSegment(), Lock.WRITE_LOCK);
                if(source == null) {
                    return false;
                }
                final DocumentImpl doc = source.getDocument(broker, uri.lastSegment());
                if(doc == null) {
                    return false;
                }
                destination = broker.openCollection(destinationPath.removeLastSegment(), Lock.WRITE_LOCK);
                if(destination == null) {
View Full Code Here

                  return false;
              }
              // keep the write lock in the transaction
              //transaction.registerLock(collection.getLock(), Lock.WRITE_LOCK);
 
              final DocumentImpl doc = collection.getDocument(broker, uri.lastSegment());
              if (doc == null) {
                return true;
              }
             
              txn = tm.beginTransaction();
              if(doc.getResourceType() == DocumentImpl.BINARY_FILE)
                  {collection.removeBinaryResource(txn, broker, doc);}
              else
                  {collection.removeXMLResource(txn, broker, uri.lastSegment());}
             
              tm.commit(txn);
View Full Code Here

              for (final Iterator<XmldbURI> i = collection.collectionIterator(broker); i.hasNext(); j++)
                children[j] = new Resource(collection.getURI().append(i.next()));
 
              //collections
              final List<XmldbURI> allresources = new ArrayList<XmldbURI>();
              DocumentImpl doc = null;
              for (final Iterator<DocumentImpl> i = collection.iterator(broker); i.hasNext(); ) {
                  doc = i.next();
                 
                  // Include only when (1) locktoken is present or (2)
                  // locktoken indicates that it is not a null resource
                  final LockToken lock = doc.getMetadata().getLockToken();
                  if(lock==null || (!lock.isNullResource()) ){
                      allresources.add( doc.getURI() );
                  }
              }
             
              // Copy content of list into String array.
              for(final Iterator<XmldbURI> i = allresources.iterator(); i.hasNext(); j++){
View Full Code Here

  protected File getFile() throws FileNotFoundException {
    if (isDirectory())
      {throw new FileNotFoundException("unsupported operation for collection.");}

    DocumentImpl doc;
    try {
      if (!exists())
        {createNewFile();}
     
      doc = getDocument();
View Full Code Here

        if((pool == null) || (xqueryresource == null) || (user == null)) {
            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 {

            //get the xquery
            broker = pool.get(user);

            if(xqueryresource.indexOf(':') > 0) {
                source = SourceFactory.getSource(broker, "", xqueryresource, true);
            } else {
                final XmldbURI pathUri = XmldbURI.create(xqueryresource);
                resource = broker.getXMLResource(pathUri, Lock.READ_LOCK);

                if(resource != null) {
                    source = new DBSource(broker, (BinaryDocument)resource, true);
                }
            }

            if(source != null) {

                //execute the xquery
                final XQuery xquery = broker.getXQueryService();
                xqPool = xquery.getXQueryPool();

                //try and get a pre-compiled query from the pool
                compiled = xqPool.borrowCompiledXQuery(broker, source);

                if(compiled == null) {
                    context = xquery.newContext(AccessContext.REST); //TODO should probably have its own AccessContext.SCHEDULER
                } else {
                    context = compiled.getContext();
                }

                //TODO: don't hardcode this?
                if(resource != null) {
                    context.setModuleLoadPath(XmldbURI.EMBEDDED_SERVER_URI.append(resource.getCollection().getURI()).toString());
                    context.setStaticallyKnownDocuments(new XmldbURI[] {
                        resource.getCollection().getURI()
                    });
                }

                if(compiled == null) {

                    try {
                        compiled = xquery.compile(context, source);
                    }
                    catch(final IOException e) {
                        abort("Failed to read query from " + xqueryresource);
                    }
                }

                //declare any parameters as external variables
                if(params != null) {
                    String bindingPrefix = params.getProperty("bindingPrefix");

                    if(bindingPrefix == null) {
                        bindingPrefix = "local";
                    }
                   

                    for(final Entry param : params.entrySet()) {
                        final String key = (String)param.getKey();
                        final String value = (String)param.getValue();
                        context.declareVariable( bindingPrefix + ":" + key, new StringValue(value));
                    }
                }

                xquery.execute(compiled, null);

            } else {
                LOG.warn("XQuery User Job not found: " + xqueryresource + ", job not scheduled");
            }
        } catch(final EXistException ee) {
            abort("Could not get DBBroker!");
        } catch(final PermissionDeniedException pde) {
            abort("Permission denied for the scheduling user: " + user.getName() + "!");
        } catch(final XPathException xpe) {
            abort("XPathException in the Job: " + xpe.getMessage() + "!", unschedule);
        } catch(final MalformedURLException e) {
            abort("Could not load XQuery: " + e.getMessage());
        } catch(final IOException e) {
            abort("Could not load XQuery: " + e.getMessage());
        } finally {

            if(context != null) {
                context.runCleanupTasks();
            }
           
            //return the compiled query to the pool
            if(xqPool != null && source != null && compiled != null) {
                xqPool.returnCompiledXQuery(source, compiled);
            }

            //release the lock on the xquery resource
            if(resource != null) {
                resource.getUpdateLock().release(Lock.READ_LOCK);
            }

            // Release the DBBroker
            if(pool != null && broker != null) {
                pool.release(broker);
View Full Code Here

        }
   }
 
  private Source getQuerySource(DBBroker broker, String scriptURI, String script) {
    if(scriptURI != null) {
          DocumentImpl resource = null;
          try {
        final XmldbURI pathUri = XmldbURI.create(scriptURI);
       
        resource = broker.getXMLResource(pathUri, Lock.READ_LOCK);
        if (resource != null)
          {return new DBSource(broker, (BinaryDocument)resource, true);}
       
          } catch (final PermissionDeniedException e) {
            //XXX: log
        e.printStackTrace();
      } finally {
        if(resource != null)
          {resource.getUpdateLock().release(Lock.READ_LOCK);}
      }

//      try {
//        querySource = SourceFactory.getSource(broker, null, scriptURI, false);
//      } catch(Exception e) {
View Full Code Here

                    compressFile(os, file, useHierarchy, stripOffset, method, resourceName);

                } else {

                    // try for a doc
                    DocumentImpl doc = null;
                    try
                    {
                        XmldbURI xmldburi = XmldbURI.create(uri);
                        doc = context.getBroker().getXMLResource(xmldburi, Lock.READ_LOCK);

                        if(doc == null)
                        {
                            // no doc, try for a collection
                            Collection col = context.getBroker().getCollection(xmldburi);

                            if(col != null)
                            {
                                // got a collection
                                compressCollection(os, col, useHierarchy, stripOffset);
                            }
                            else
                            {
                                // no doc or collection
                                throw new XPathException(this, "Invalid URI: " + uri.toString());
                            }
                        }
                        else
                        {
                            // got a doc
                            compressResource(os, doc, useHierarchy, stripOffset, method, resourceName);
                        }
                    }
                    catch(PermissionDeniedException pde)
                    {
                        throw new XPathException(this, pde.getMessage());
                    }
                    catch(IOException ioe)
                    {
                        throw new XPathException(this, ioe.getMessage());
                    }
                    catch(SAXException saxe)
                    {
                        throw new XPathException(this, saxe.getMessage());
                    }
                    catch(LockException le)
                    {
                        throw new XPathException(this, le.getMessage());
                    }
                    finally
                    {
                        if(doc != null)
                            doc.getUpdateLock().release(Lock.READ_LOCK);
                    }
                }

            } catch (IOException e) {
                throw new XPathException(this, e.getMessage());
View Full Code Here

    // iterate over child documents
    MutableDocumentSet childDocs = new DefaultDocumentSet();
    col.getDocuments(context.getBroker(), childDocs);
    for (Iterator<DocumentImpl> itChildDocs = childDocs.getDocumentIterator(); itChildDocs
        .hasNext();) {
      DocumentImpl childDoc = (DocumentImpl) itChildDocs.next();
      childDoc.getUpdateLock().acquire(Lock.READ_LOCK);
      try {
        compressResource(os, childDoc, useHierarchy, stripOffset, "", null);
      } finally {
        childDoc.getUpdateLock().release(Lock.READ_LOCK);
      }
    }
    // iterate over child collections
    for (Iterator<XmldbURI> itChildCols = col.collectionIterator(context.getBroker()); itChildCols.hasNext();) {
      // get the child collection
View Full Code Here

    /* (non-Javadoc)
     * @see org.exist.source.Source#isValid()
     */
    @Override
    public int isValid(final DBBroker broker) {
        DocumentImpl d = null;
        int result;
        try {
            d = broker.getXMLResource(key, Lock.READ_LOCK);
           
            if(d == null) {
                result = INVALID;
            } else if(d.getMetadata().getLastModified() > lastModified) {
                result = INVALID;
            } else {
                result = VALID;
            }
        } catch(final PermissionDeniedException pde) {
            result = INVALID;
        } finally {
            if(d != null) {
                d.getUpdateLock().release(Lock.READ_LOCK);
            }
        }
       
        return result;
    }
View Full Code Here

TOP

Related Classes of org.exist.dom.DocumentImpl

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.