Package org.exist.dom

Examples of org.exist.dom.DocumentImpl


                {throw new EXistException("Collection " + name + " not found");}
            if (!collection.getPermissionsNoLock().validate(user, Permission.READ))
                {throw new PermissionDeniedException(
                        "not allowed to read collection " + name);}
            final EntityPermissions[] result = new EntityPermissions[collection.getDocumentCount(broker)];
            DocumentImpl doc;
            Permission perm;
            int cnt = 0;
            for (final Iterator<DocumentImpl> i = collection.iterator(broker); i.hasNext(); ) {
                doc = i.next();
                perm = doc.getPermissions();
                result[cnt] = new EntityPermissions();
                result[cnt].setName(doc.getFileURI().toString());
                result[cnt].setOwner(perm.getOwner().getName());
                result[cnt].setGroup(perm.getGroup().getName());
                result[cnt].setPermissions(perm.getMode());
                cnt++;
            }
View Full Code Here


     */
    protected long findValue(DBBroker broker, NodeProxy node)
            throws IOException, BTreeException {
        if (!lock.hasLock())
            {LOG.warn("The file doesn't own a lock");}
        final DocumentImpl doc = node.getDocument();
        final NodeRef nodeRef = new NativeBroker.NodeRef(doc.getDocId(), node.getNodeId());
        // first try to find the node in the index
        final long pointer = findValue(nodeRef);
        if (pointer == KEY_NOT_FOUND) {
            // node not found in index: try to find the nearest available
            // ancestor and traverse it
            NodeId nodeID = node.getNodeId();
            long parentPointer = KEY_NOT_FOUND;
            do {
                nodeID = nodeID.getParentId();
                if (nodeID == null) {
                    SanityCheck.TRACE("Node " + node.getDocument().getDocId() + ":" +
                        nodeID + " not found.");
                    throw new BTreeException("Node " + nodeID + " not found.");
                }
                if (nodeID == NodeId.DOCUMENT_NODE) {
                    SanityCheck.TRACE("Node " + node.getDocument().getDocId() + ":" +
                            nodeID + " not found.");
                    throw new BTreeException("Node " + nodeID + " not found.");
                }
                final NativeBroker.NodeRef parentRef = new NativeBroker.NodeRef(doc.getDocId(), nodeID);
                try {
                    parentPointer = findValue(parentRef);
                } catch (final BTreeException bte) {
                    LOG.error("report me", bte);
                }
View Full Code Here

    public String getMimeType() throws XMLDBException {
        return mimeType;
    }
   
  protected DocumentImpl openDocument(DBBroker broker, int lockMode) throws XMLDBException {
      DocumentImpl document = null;
      org.exist.collections.Collection parentCollection = null;
      try {
        parentCollection = parent.getCollectionWithLock(lockMode);
        if(parentCollection == null)
          {throw new XMLDBException(ErrorCodes.INVALID_COLLECTION, "Collection " + parent.getPath() + " not found");}
View Full Code Here

           
        }
        // iterate through all docs and create the node set
        final NodeSet result = new NewArrayNodeSet(docs.getDocumentCount(), 1);
        Lock dlock;
        DocumentImpl doc;
        for (final Iterator<DocumentImpl> i = docs.getDocumentIterator(); i.hasNext();) {
            doc = i.next();
            dlock = doc.getUpdateLock();
            boolean lockAcquired = false;
            try {
                if (!context.inProtectedMode() && !dlock.hasLock()) {
                    dlock.acquire(Lock.READ_LOCK);
                    lockAcquired = true;
View Full Code Here

        DBBroker broker = null;
        try {
            broker = pool.get(session.getUser());
// TODO check XML/Binary resource
// DocumentImpl document = (DocumentImpl) broker.getDocument(name);
            final DocumentImpl document = broker.getResource(name, Permission.READ);
            if (document == null)
                {throw new RemoteException("resource " + name + " not found");}

            final Serializer serializer = broker.getSerializer();
            serializer.reset();
View Full Code Here

        }

        public Templates getTemplates(Subject user) throws ServletException {
            if (uri.startsWith("xmldb:exist://")) {
                final String docPath = uri.substring("xmldb:exist://".length());
                DocumentImpl doc = null;
                DBBroker broker = null;

                try {
                    broker = pool.get(user);
                    doc = broker.getXMLResource(XmldbURI.create(docPath), Lock.READ_LOCK);
                    if (doc == null) {
                        throw new ServletException("Stylesheet not found: " + docPath);
                    }
                   
                    if (!isCaching() || (doc != null && (templates == null
                                     || doc.getMetadata().getLastModified() > lastModified))) {
                        templates = getSource(broker, doc);
                    }
                   
                    lastModified = doc.getMetadata().getLastModified();

                } catch (final PermissionDeniedException e) {
                    throw new ServletException("Permission denied to read stylesheet: " + uri, e);

                } catch (final EXistException e) {
                    throw new ServletException("Error while reading stylesheet source from db: " + e.getMessage(), e);

                } finally {
                    pool.release(broker);
                    if (doc != null) {
                        doc.getUpdateLock().release(Lock.READ_LOCK);
                    }
                }
               
            } else {
                try {
View Full Code Here

                path = href;
            } else {
                path = collection.getURI() + "/" + href;
            }

            DocumentImpl xslDoc;
            try {
                xslDoc = (DocumentImpl) broker.getXMLResource(XmldbURI.create(path));
            } catch (final PermissionDeniedException e) {
                throw new TransformerException(e.getMessage(), e);
            }

            if(xslDoc == null) {
                LOG.debug("Document " + href + " not found in collection " + collection.getURI());
                return null;
            }

            if(!xslDoc.getPermissions().validate(broker.getSubject(), Permission.READ)){
                throw new TransformerException("Insufficient privileges to read resource " + path);
            }
           
            final DOMSource source = new DOMSource(xslDoc);
            return source;
View Full Code Here

            LOG.debug("Already initialized");
            return;
        }

        DBBroker broker = null;
        DocumentImpl document = null;
        try {
            broker = brokerPool.get(subject);

            // If it is not a collection, check if it is a document
            document = broker.getXMLResource(xmldbUri, Lock.READ_LOCK);

            if (document.getResourceType() == DocumentImpl.XML_FILE) {
                isXmlDocument = true;
            }

            // Get meta data        
            creationTime = document.getMetadata().getCreated();
            lastModified = document.getMetadata().getLastModified();
            mimeType = document.getMetadata().getMimeType();

            // Retrieve perssions
            permissions = document.getPermissions();
            readAllowed = permissions.validate(subject, Permission.READ);
            writeAllowed = permissions.validate(subject, Permission.WRITE);
            executeAllowed = permissions.validate(subject, Permission.EXECUTE);


            ownerUser = permissions.getOwner().getUsername();
            ownerGroup = permissions.getGroup().getName();

            // Get (estimated) file size
            contentLength = document.getContentLength();

        } catch (EXistException | PermissionDeniedException e) {
            LOG.error(e);

        } finally {

            // Cleanup resources
            if (document != null) {
                document.getUpdateLock().release(Lock.READ_LOCK);
            }

            if(broker != null) {
                brokerPool.release(broker);
            }
View Full Code Here

        }

        long startTime = System.currentTimeMillis();

        DBBroker broker = null;
        DocumentImpl document = null;
        try {
            broker = brokerPool.get(subject);

            // If it is not a collection, check if it is a document
            document = broker.getXMLResource(xmldbUri, Lock.READ_LOCK);

            if (document.getResourceType() == DocumentImpl.XML_FILE) {
                // Stream XML document
                Serializer serializer = broker.getSerializer();
                serializer.reset();
                try {
                    // Set serialization options
                    serializer.setProperties(configuration);

                    // Serialize document
                    try (Writer w = new OutputStreamWriter(os, "UTF-8")) {
                        serializer.serialize(document, w);
                        w.flush();
                    }

                    // don;t flush
                    if (!(os instanceof VirtualTempFile)) {
                        os.flush();
                    }

                } catch (SAXException e) {
                    LOG.error(e);
                    throw new IOException(String.format("Error while serializing XML document: %s", e.getMessage()), e);
                }

            } else {
                // Stream NON-XML document
                broker.readBinaryResource((BinaryDocument) document, os);
                os.flush();
            }

        } catch (EXistException e) {
            LOG.error(e);
            throw new IOException(e.getMessage());

        } catch (PermissionDeniedException e) {
            LOG.error(e);
            throw e;

        } finally {

            if (document != null) {
                document.getUpdateLock().release(Lock.READ_LOCK);
            }

            brokerPool.release(broker);

            if (LOG.isDebugEnabled()) {
View Full Code Here

            LOG.debug(String.format("Deleting %s", xmldbUri));
        }

        DBBroker broker = null;
        Collection collection = null;
        DocumentImpl resource = null;

        TransactionManager txnManager = brokerPool.getTransactionManager();
        Txn txn = txnManager.beginTransaction();

        try {
            broker = brokerPool.get(subject);

            // Need to split path into collection and document name
            XmldbURI collName = xmldbUri.removeLastSegment();
            XmldbURI docName = xmldbUri.lastSegment();

            // Open collection if possible, else abort
            collection = broker.openCollection(collName, Lock.WRITE_LOCK);
            if (collection == null) {
                LOG.debug("Collection does not exist");
                txnManager.abort(txn);
                return;
            }

            // Open document if possible, else abort
            resource = collection.getDocument(broker, docName);
            if (resource == null) {
                LOG.debug(String.format("No resource found for path: %s", xmldbUri));
                txnManager.abort(txn);
                return;
            }

            if (resource.getResourceType() == DocumentImpl.BINARY_FILE) {
                collection.removeBinaryResource(txn, broker, resource.getFileURI());

            } else {
                collection.removeXMLResource(txn, broker, resource.getFileURI());
            }

            // Commit change
            txnManager.commit(txn);
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.