Package org.exist.dom

Examples of org.exist.dom.DocumentImpl


        final Txn transaction = transact.beginTransaction();
        try {
            broker = pool.get(session.getUser());
// TODO check XML/Binary resource
//            DocumentImpl doc = (DocumentImpl)broker.getDocument(documentName);
            final DocumentImpl doc = broker.getXMLResource(documentName, Permission.READ);
            if (doc == null) {
                transact.abort(transaction);
                throw new RemoteException(
                        "document " + documentName + " not found");
            }
            final MutableDocumentSet docs = new DefaultDocumentSet();
            docs.add(doc);
            final XUpdateProcessor processor =
                    new XUpdateProcessor(broker, docs, AccessContext.SOAP);
            final Modification modifications[] =
                    processor.parse(new InputSource(new StringReader(xupdate)));
            long mods = 0;
            for (int i = 0; i < modifications.length; i++) {
                mods += modifications[i].process(transaction);
                broker.flush();
            }
            transact.commit(transaction);
           
            // Release lock, as reported http://markmail.org/message/pau6hoaeybg2bvch
            doc.getUpdateLock().release(Permission.READ);
           
            return (int) mods;
        } catch (final ParserConfigurationException e) {
            transact.abort(transaction);
            throw new RemoteException(e.getMessage(), e);
View Full Code Here


            collection = broker.openCollection(collectionUri, Lock.WRITE_LOCK);
            if (collection == null)
                {throw new EXistException("Collection " + collectionUri
                        + " not found");}
            if (!replace) {
                final DocumentImpl old = collection.getDocument(broker, docUri);
                if (old != null)
                    {throw new PermissionDeniedException(
                            "Old document exists and overwrite is not allowed");}
            }
            LOG.debug("Storing binary resource to collection " + collection.getURI());
View Full Code Here

      }
    }
    public byte[] getBinaryResource(java.lang.String sessionId, XmldbURI name) throws java.rmi.RemoteException {
        DBBroker broker = null;
        final Session session = getSession(sessionId);
        DocumentImpl doc = null;
        try {
            broker = pool.get(session.getUser());
            // TODO check XML/Binary resource
            doc = broker.getXMLResource(name, Lock.READ_LOCK);
            if (doc == null)
                {throw new EXistException("Resource " + name + " not found");}
            if (doc.getResourceType() != DocumentImpl.BINARY_FILE)
                {throw new EXistException("Document " + name
                        + " is not a binary resource");}
            if(!doc.getPermissions().validate(session.getUser(), Permission.READ))
                {throw new PermissionDeniedException("Insufficient privileges to read resource");}
            final InputStream is = broker.getBinaryResource((BinaryDocument) doc);
            final long resourceSize = broker.getBinaryResourceSize((BinaryDocument) doc);
            if(resourceSize > Integer.MAX_VALUE)
                {throw new RemoteException("Resource too big to be read using this port.");}
            final byte [] data = new byte[(int)resourceSize];
            is.read(data);
            is.close();
            return data;
        } catch (final Exception ex) {
            throw new RemoteException(ex.getMessage());
        } finally {
            if(doc != null)
                {doc.getUpdateLock().release(Lock.READ_LOCK);}
            pool.release(broker);
        }
    }
View Full Code Here

                        + " not found!");}
            final CollectionDesc desc = new CollectionDesc();
            final List<DocumentDesc> docs = new ArrayList<DocumentDesc>();
            final List<String> collections = new ArrayList<String>();
            if (collection.getPermissionsNoLock().validate(session.getUser(), Permission.READ)) {
                DocumentImpl doc;
//              Hashtable hash;
                Permission perms;
                for (final Iterator<DocumentImpl> i = collection.iterator(broker); i.hasNext(); ) {
                    doc = i.next();
                    perms = doc.getPermissions();
                    final DocumentDesc dd = new DocumentDesc();
//                    hash = new Hashtable(4);
                    dd.setName(doc.getFileURI().toString());
                    dd.setOwner(perms.getOwner().getName());
                    dd.setGroup(perms.getGroup().getName());
                    dd.setPermissions(perms.getMode());
                    dd.setType(doc.getResourceType() == DocumentImpl.BINARY_FILE
                            ? DocumentType.BinaryResource
                            : DocumentType.XMLResource);
                    docs.add(dd);
                }
                for(final Iterator<XmldbURI> i = collection.collectionIterator(broker); i.hasNext();) {
View Full Code Here

    }
    public void setPermissions(java.lang.String sessionId, XmldbURI resource, java.lang.String owner, java.lang.String ownerGroup, int permissions) throws java.rmi.RemoteException {
        DBBroker broker = null;
        final Session session = getSession(sessionId);
        Collection collection = null;
        DocumentImpl doc = null;
        final TransactionManager transact = pool.getTransactionManager();
        final Txn transaction = transact.beginTransaction();
        try {
            broker = pool.get(session.getUser());
            final org.exist.security.SecurityManager manager = pool.getSecurityManager();
            collection = broker.openCollection(resource, Lock.WRITE_LOCK);
            if (collection == null) {
                // TODO check XML/Binary resource
                doc = broker.getXMLResource(resource, Lock.WRITE_LOCK);
                if (doc == null)
                    {throw new RemoteException("document or collection "
                            + resource + " not found");}
                LOG.debug("changing permissions on document " + resource);
                final Permission perm = doc.getPermissions();
                if (perm.getOwner().equals(session.getUser())
                || manager.hasAdminPrivileges(session.getUser())) {
                    if (owner != null) {
                        perm.setOwner(owner);
                        perm.setGroup(ownerGroup);
                    }
                    perm.setMode(permissions);
// TODO check XML/Binary resource
//                    broker.storeDocument(transaction, doc);
                    broker.storeXMLResource(transaction, doc);
                    transact.commit(transaction);
                    broker.flush();
                    return;
//                    return true;
                }
                transact.abort(transaction);
                throw new PermissionDeniedException("not allowed to change permissions");
            }
            LOG.debug("changing permissions on collection " + resource);
            final Permission perm = collection.getPermissionsNoLock();
            if (perm.getOwner().equals(session.getUser())
            || manager.hasAdminPrivileges(session.getUser())) {
                perm.setMode(permissions);
                if (owner != null) {
                    perm.setOwner(owner);
                    perm.setGroup(ownerGroup);
                }
                transaction.registerLock(collection.getLock(), Lock.WRITE_LOCK);
                broker.saveCollection(transaction, collection);
                transact.commit(transaction);
                broker.flush();
                return;
            }
            transact.abort(transaction);
            throw new PermissionDeniedException("not allowed to change permissions");
        } catch (final IOException e) {
            transact.abort(transaction);
            throw new RemoteException(e.getMessage());
        } catch (final PermissionDeniedException e) {
            transact.abort(transaction);
            throw new RemoteException(e.getMessage());
        } catch (final TransactionException e) {
            throw new RemoteException(e.getMessage());
        } catch (final EXistException e) {
            throw new RemoteException(e.getMessage());
        } catch (final TriggerException e) {
            transact.abort(transaction);
            throw new RemoteException(e.getMessage());
    } finally {
            transact.close(transaction);
            if(doc != null)
                {doc.getUpdateLock().release(Lock.WRITE_LOCK);}
            pool.release(broker);
        }
    }
View Full Code Here

        final Txn transaction = transact.beginTransaction();
        DBBroker broker = null;
        final Session session = getSession(sessionId);
        Collection collection = null;
        Collection destination = null;
        DocumentImpl doc = null;
        try {
            broker = pool.get(session.getUser());
            final XmldbURI collectionUri = docPath.removeLastSegment();
            final XmldbURI docUri = docPath.lastSegment();
            if (collectionUri==null || docUri==null) {
                transact.abort(transaction);
                throw new EXistException("Illegal document path");
            }
            collection = broker.openCollection(collectionUri, move ? Lock.WRITE_LOCK : Lock.READ_LOCK);
            if (collection == null) {
                transact.abort(transaction);
                throw new RemoteException("Collection " + collectionUri
                        + " not found");
            }
            doc = collection.getDocumentWithLock(broker, docUri, Lock.WRITE_LOCK);
            if(doc == null) {
                transact.abort(transaction);
                throw new RemoteException("Document " + docUri + " not found");
            }
           
            // get destination collection
            destination = broker.openCollection(destinationPath, Lock.WRITE_LOCK);
            if(destination == null) {
                transact.abort(transaction);
                throw new RemoteException("Destination collection " + destinationPath + " not found");
            }
            if(move)
// TODO check XML/Binary resource
//                broker.moveResource(transaction, doc, destination, newName);
                {broker.moveResource(transaction, doc, destination, newName);}
            else
// TODO check XML/Binary resource
//                broker.copyResource(transaction, doc, destination, newName);
                {broker.copyResource(transaction, doc, destination, newName);}
            transact.commit(transaction);
//            documentCache.clear();
            return;
        } catch (final LockException e) {
            transact.abort(transaction);
            throw new RemoteException("Could not acquire lock on document " + docPath);
        } catch (final PermissionDeniedException e) {
            transact.abort(transaction);
            throw new RemoteException("Could not move/copy document " + docPath);
        } catch (final IOException e) {
            transact.abort(transaction);
            throw new RemoteException(e.getMessage());
        } catch (final TransactionException e) {
            throw new RemoteException("Error commiting transaction " + e.getMessage());
        } catch (final EXistException e) {
            throw new RemoteException(e.getMessage());
        } catch (final TriggerException e) {
            transact.abort(transaction);
            throw new RemoteException(e.getMessage());
    } finally {
            transact.close(transaction);
            if(destination != null)
                {destination.release(Lock.WRITE_LOCK);}
            if(doc != null)
                {doc.getUpdateLock().release(Lock.WRITE_LOCK);}
            if(collection != null)
                {collection.release(move ? Lock.WRITE_LOCK : Lock.READ_LOCK);}
            pool.release(broker);
        }
    }
View Full Code Here

    }
    public void lockResource(java.lang.String sessionId, XmldbURI path, java.lang.String userName) throws java.rmi.RemoteException {
        DBBroker broker = null;
        final Session session = getSession(sessionId);
        final Subject user = session.getUser();
        DocumentImpl doc = null;
        final TransactionManager transact = pool.getTransactionManager();
        final Txn transaction = transact.beginTransaction();
        try {
            broker = pool.get(user);
// TODO check XML/Binary resource
//            doc = (DocumentImpl) broker.openDocument(path, Lock.WRITE_LOCK);
            doc = broker.getXMLResource(path, Lock.WRITE_LOCK);
            if (doc == null) {
                throw new EXistException("Resource "
                        + path + " not found");
            }
            if (!doc.getPermissions().validate(user, Permission.WRITE))
                {throw new PermissionDeniedException("User is not allowed to lock resource " + path);}
           
            final org.exist.security.SecurityManager manager = pool.getSecurityManager();
            if (!(userName.equals(user.getName()) || manager.hasAdminPrivileges(user)))
                {throw new PermissionDeniedException("User " + user.getName() + " is not allowed " +
                        "to lock the resource for user " + userName);}
            final Account lockOwner = doc.getUserLock();
            if(lockOwner != null && (!lockOwner.equals(user)) && (!manager.hasAdminPrivileges(user)))
                {throw new PermissionDeniedException("Resource is already locked by user " +
                        lockOwner.getName());}
            final Account lo = manager.getAccount(userName);
            doc.setUserLock(lo);
// TODO check XML/Binary resource
//            broker.storeDocument(transaction, doc);
            broker.storeXMLResource(transaction, doc);
            transact.commit(transaction);
            return;
        } catch (final Exception e) {
            transact.abort(transaction);
            throw new RemoteException(e.getMessage());
        } finally {
            transact.close(transaction);
            if(doc != null)
                {doc.getUpdateLock().release(Lock.WRITE_LOCK);}
            pool.release(broker);
        }
    }
View Full Code Here

    }
    public void unlockResource(java.lang.String sessionId, XmldbURI path) throws java.rmi.RemoteException {
        DBBroker broker = null;
        final Session session = getSession(sessionId);
        final Subject user = session.getUser();
        DocumentImpl doc = null;
        final TransactionManager transact = pool.getTransactionManager();
        Txn transaction = null;
        try {
            broker = pool.get(user);
            // TODO check XML/Binary resource
            doc = broker.getXMLResource(path, Lock.WRITE_LOCK);
            if (doc == null)
                {throw new EXistException("Resource "
                        + path + " not found");}
            if (!doc.getPermissions().validate(user, Permission.WRITE))
                {throw new PermissionDeniedException("User is not allowed to lock resource " + path);}
            final org.exist.security.SecurityManager manager = pool.getSecurityManager();
            final Account lockOwner = doc.getUserLock();
            if(lockOwner != null && (!lockOwner.equals(user)) && (!manager.hasAdminPrivileges(user)))
                {throw new PermissionDeniedException("Resource is already locked by user " +
                        lockOwner.getName());}
            transaction = transact.beginTransaction();
            doc.setUserLock(null);
// TODO check XML/Binary resource
//            broker.storeDocument(transaction, doc);
            broker.storeXMLResource(transaction, doc);
            transact.commit(transaction);
            return;
        } catch (final Exception ex){
            transact.abort(transaction);
            throw new RemoteException(ex.getMessage());
        } finally {
            transact.close(transaction);
            if(doc != null)
                {doc.getUpdateLock().release(Lock.WRITE_LOCK);}
            pool.release(broker);
        }
    }
View Full Code Here

    }
    public java.lang.String hasUserLock(java.lang.String sessionId, XmldbURI path) throws java.rmi.RemoteException {
        DBBroker broker = null;
        final Session session = getSession(sessionId);
        final Subject user = session.getUser();
        DocumentImpl doc = null;
        try {
            broker = pool.get(user);
// TODO check XML/Binary resource
//            doc = (DocumentImpl) broker.openDocument(path, Lock.READ_LOCK);
            doc = broker.getXMLResource(path, Lock.READ_LOCK);
            if (doc == null)
                {throw new EXistException("Resource "
                        + path + " not found");}
            if(!doc.getPermissions().validate(user, Permission.READ))
                {throw new PermissionDeniedException("Insufficient privileges to read resource");}
            final Account u = doc.getUserLock();
            return u == null ? "" : u.getName();
        } catch (final Exception ex) {
            throw new RemoteException(ex.getMessage());
        } finally {
            if(doc != null)
                {doc.getUpdateLock().release(Lock.READ_LOCK);}
            pool.release(broker);
        }
    }
View Full Code Here

              collection = broker.openCollection(resource, Lock.READ_LOCK);
              Permission perm = null;
              if (collection == null) {
          // TODO check XML/Binary resource
          // DocumentImpl doc = (DocumentImpl) broker.openDocument(resource, Lock.READ_LOCK);
                DocumentImpl doc = null;
                try {
                    doc = broker.getXMLResource(resource, Lock.READ_LOCK);
                    if (doc == null)
                        {throw new EXistException("document or collection " + resource + " not found");}
                    perm = doc.getPermissions();
                } finally {
                  if (doc != null)
                    {doc.getUpdateLock().release(Lock.READ_LOCK);}
                }
              } else {
                  perm = collection.getPermissionsNoLock();
              }
              final Permissions p = new Permissions();
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.