Package org.exist.dom

Examples of org.exist.dom.DocumentImpl


      if (collection == null) {
        reportError(output, "Collection not found: " + collectionPath);
        return;
      }
      for (Iterator<DocumentImpl> i = collection.iterator(context.getBroker()); i.hasNext(); ) {
        DocumentImpl doc = i.next();
        if (startDate == null || doc.getMetadata().getLastModified() > startDate.getTime()) {
          if (doc.getResourceType() == DocumentImpl.BINARY_FILE) {
            saveBinary(targetDir, (BinaryDocument) doc, output);
          } else {
            saveXML(targetDir, doc, output);
          }
        }
View Full Code Here


            source = new BinarySource(data, true);
        } else {
            String uri = args[0].getStringValue();
            if (uri.startsWith(XmldbURI.XMLDB_URI_PREFIX)) {
                Collection collection = null;
                DocumentImpl doc = null;
                try {
                    XmldbURI resourceURI = XmldbURI.xmldbUriFor(uri);
                    collection = context.getBroker().openCollection(resourceURI.removeLastSegment(), Lock.READ_LOCK);
                    if (collection == null) {
                        LOG.warn("collection not found: " + resourceURI.getCollectionPath());
                        return Sequence.EMPTY_SEQUENCE;
                    }
                    doc = collection.getDocumentWithLock(context.getBroker(), resourceURI.lastSegment(), Lock.READ_LOCK);
                    if (doc == null)
                        return Sequence.EMPTY_SEQUENCE;
                    if (doc.getResourceType() != DocumentImpl.BINARY_FILE ||
                            !doc.getMetadata().getMimeType().equals("application/xquery")) {
                        throw new XPathException(this, "XQuery resource: " + uri + " is not an XQuery or " +
                                "declares a wrong mime-type");
                    }
                    source = new DBSource(context.getBroker(), (BinaryDocument) doc, false);
                    name = doc.getFileURI().toString();
                } catch (URISyntaxException e) {
                    throw new XPathException(this, "invalid module uri: " + uri + ": " + e.getMessage(), e);
                } catch (LockException e) {
                    throw new XPathException(this, "internal lock error: " + e.getMessage());
                } catch(PermissionDeniedException pde) {
                    throw new XPathException(this, pde.getMessage(), pde);
                } finally {
                    if (doc != null)
                        doc.getUpdateLock().release(Lock.READ_LOCK);
                    if(collection != null)
                        collection.release(Lock.READ_LOCK);
                }
            } else {
                // first check if the URI points to a registered module
View Full Code Here

    @Test
    public void nodes() {
        DBBroker broker = null;
        try {
            broker = pool.get(pool.getSecurityManager().getSystemSubject());
            DocumentImpl doc = (DocumentImpl) broker.getXMLResource(TEST_COLLECTION_URI.append("test.xml"));
            NodeProxy p = new NodeProxy(doc, pool.getNodeFactory().createFromString("1.1"));

            StringWriter writer = new StringWriter();
            SAXSerializer serializer = new SAXSerializer(writer, new Properties());
            Marshaller.marshall(broker, p, serializer);
View Full Code Here

            assertNotNull(broker);

            Collection col = broker.getCollection(col1uri);
          assertNotNull(col);
         
          DocumentImpl doc = getDoc(broker, col, doc01uri.lastSegment());
          assertEquals(XML1, serializer(broker, doc));

          doc = getDoc(broker, col, doc02uri.lastSegment());
          assertEquals(XML2_PROPER, serializer(broker, doc));
View Full Code Here

       
        BrokerPool.stopAll(false);
  }
 
  private DocumentImpl getDoc(DBBroker broker, Collection col, XmldbURI uri) throws PermissionDeniedException {
        DocumentImpl doc = col.getDocument(broker, uri);
      assertNotNull(doc);
   
      return doc;
  }
View Full Code Here

            transaction = transact.beginTransaction();
            System.out.println("Transaction started ...");

            System.out.println("Removing documents one by one ...");
            for (Iterator<DocumentImpl> i = test.iterator(broker); i.hasNext(); ) {
                DocumentImpl doc = i.next();
                broker.removeXMLResource(transaction, doc);
            }
            broker.saveCollection(transaction, test);
            transact.commit(transaction);
View Full Code Here

            System.out.println("Generating " + COUNT + " files...");
            File[] files = generator.generate(broker, test, generateXQ);

            int j = 0;
            for (Iterator<DocumentImpl> i = test.iterator(broker); i.hasNext() && j < files.length; j++) {
                DocumentImpl doc = i.next();
                InputSource is = new InputSource(files[j].toURI().toASCIIString());
                assertNotNull(is);
                IndexInfo info = test.validateXMLResource(transaction, broker, doc.getURI(), is);
                assertNotNull(info);
                test.store(transaction, broker, info, is, false);
            }
            generator.releaseAll();
            transact.commit(transaction);
View Full Code Here

    public void recover(boolean checkResource) {
        BrokerPool.FORCE_CORRUPTION = false;
        DBBroker broker = null;
        BrokerPool pool = startDB();
        assertNotNull(pool);
        DocumentImpl doc = null;
        try {
          System.out.println("testRead() ...\n");
          assertNotNull(pool);
            broker = pool.get(pool.getSecurityManager().getSystemSubject());
            if (checkResource) {
                doc = broker.getXMLResource(TestConstants.TEST_COLLECTION_URI.append("hamlet.xml"), Lock.READ_LOCK);
                assertNull("Resource should have been removed", doc);
            }
        } catch (Exception e) {
            e.printStackTrace();
            fail(e.getMessage());
      } finally {
            if (doc != null)
                doc.getUpdateLock().release(Lock.READ_LOCK);
            if (pool != null) pool.release(broker);
            stopDB();
        }
    }
View Full Code Here

          lockedDocuments.lock(broker, true, false);
         
        final StoredNode ql[] = new StoredNode[nl.getLength()];       
      for (int i = 0; i < ql.length; i++) {
        ql[i] = (StoredNode)nl.item(i);
        final DocumentImpl doc = (DocumentImpl)ql[i].getOwnerDocument();
       
        // call the eventual triggers
        // TODO -jmv separate loop on docs and not on nodes
     
        //prepare Trigger
View Full Code Here

        int fragmentationLimit = -1;
        final Object property = broker.getBrokerPool().getConfiguration().getProperty(DBBroker.PROPERTY_XUPDATE_FRAGMENTATION_FACTOR);
        if (property != null)
          {fragmentationLimit = ((Integer)property).intValue();}   
      for(final Iterator<DocumentImpl> i = docs.getDocumentIterator(); i.hasNext(); ) {
          final DocumentImpl next = i.next();
          if(next.getMetadata().getSplitCount() > fragmentationLimit)
              {broker.defragXMLResource(transaction, next);}
          broker.checkXMLResourceConsistency(next);
      }
  }
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.