Package org.exist.collections

Examples of org.exist.collections.Collection$DocumentEntry


            txn = txnManager.beginTransaction();
            assertNotNull(txn);
           
            System.out.println("Transaction started ...");

            Collection root = broker.getOrCreateCollection(txn, col1uri);
            assertNotNull(root);
            broker.saveCollection(txn, root);

            Collection test2 = broker.getOrCreateCollection(txn, col2uri);
            assertNotNull(test2);
            broker.saveCollection(txn, test2);

            CollectionConfigurationManager mgr = pool.getConfigurationManager();
            mgr.addConfiguration(txn, broker, root, COLLECTION_CONFIG);
View Full Code Here


            assertNotNull(txnManager);
            txn = txnManager.beginTransaction();
            assertNotNull(txn);
            System.out.println("Transaction started ...");

            Collection col = broker.getOrCreateCollection(txn, col1uri);
            assertNotNull(col);
          broker.removeCollection(txn, col);

//            col = broker.getOrCreateCollection(txn, col2uri);
//            assertNotNull(col);
View Full Code Here

      }
    }
    public org.exist.soap.CollectionDesc getCollectionDesc(java.lang.String sessionId, XmldbURI collectionName) throws java.rmi.RemoteException {
        DBBroker broker = null;
        final Session session = getSession(sessionId);
        Collection collection = null;
        try {
            broker = pool.get(session.getUser());
            if (collectionName == null)
                {collectionName = XmldbURI.ROOT_COLLECTION_URI;}
           
            collection = broker.openCollection(collectionName, Lock.READ_LOCK);
            if (collection == null)
                {throw new EXistException("collection " + collectionName
                        + " 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();) {
                    collections.add(i.next().toString());
                }
            }
            Permission perms = collection.getPermissionsNoLock();
            desc.setCollections(new Strings(collections.toArray(new String[collections.size()])));
            desc.setDocuments(new DocumentDescs(docs.toArray(new DocumentDesc[docs.size()])));
            desc.setName(collection.getURI().toString());
            desc.setCreated(collection.getCreationTime());
            desc.setOwner(perms.getOwner().getName());
            desc.setGroup(perms.getGroup().getName());
            desc.setPermissions(perms.getMode());
            return desc;
        } catch (final Exception ex){
            throw new RemoteException(ex.getMessage());
        } finally {
            if(collection != null)
                {collection.release(Lock.READ_LOCK);}
            pool.release(broker);
        }
    }
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;
            }
View Full Code Here

            throws RemoteException {
        final TransactionManager transact = pool.getTransactionManager();
        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

            throws EXistException, PermissionDeniedException, RemoteException {
        final TransactionManager transact = pool.getTransactionManager();
        final Txn transaction = transact.beginTransaction();
        DBBroker broker = null;
        final Session session = getSession(sessionId);
        Collection collection = null;
        Collection destination = null;
        try {
            final Subject user = session.getUser();
            broker = pool.get(user);
            // get source document
            collection = broker.openCollection(collectionPath, move ? Lock.WRITE_LOCK : Lock.READ_LOCK);
            if (collection == null) {
                transact.abort(transaction);
                throw new EXistException("Collection " + collectionPath
                        + " not found");
            }
            // get destination collection
            destination = broker.openCollection(destinationPath, Lock.WRITE_LOCK);
            if(destination == null) {
                transact.abort(transaction);
                throw new EXistException("Destination collection " + destinationPath + " not found");
            }
            if(move)
                {broker.moveCollection(transaction, collection, destination, newName);}
            else
                {broker.copyCollection(transaction, collection, destination, newName);}
            transact.commit(transaction);
//            documentCache.clear();
            return true;
        } catch (final IOException e) {
          transact.abort(transaction);
            throw new RemoteException(e.getMessage());           
        } catch (final LockException e) {
          transact.abort(transaction);
            throw new PermissionDeniedException(e.getMessage());
        } catch (final TriggerException e) {
          transact.abort(transaction);
            throw new RemoteException(e.getMessage());           
    } finally {
            transact.close(transaction);
            if(collection != null)
                {collection.release(move ? Lock.WRITE_LOCK : Lock.READ_LOCK);}
            if(destination != null)
                {destination.release(Lock.WRITE_LOCK);}
            pool.release(broker);
        }
    }
View Full Code Here

        DBBroker broker = null;
        final Session session = getSession(sessionId);
        final Subject user = session.getUser();
        try {
            broker = pool.get(user);
            Collection collection = null;
            try {
              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();
              p.setOwner(perm.getOwner().getName());
              p.setGroup(perm.getGroup().getName());
              p.setPermissions(perm.getMode());
              return p;
            } finally {
              if (collection != null)
                {collection.release(Lock.READ_LOCK);}             
            }
        } catch (final Exception ex) {
            throw new RemoteException(ex.getMessage());
        } finally {
            pool.release(broker);
View Full Code Here

    }
    public org.exist.soap.EntityPermissionsList listCollectionPermissions(java.lang.String sessionId, XmldbURI name) throws java.rmi.RemoteException {
        DBBroker broker = null;
        final Session session = getSession(sessionId);
        final Subject user = session.getUser();
        Collection collection = null;
        try {
            broker = pool.get(user);
            collection = broker.openCollection(name, Lock.READ_LOCK);
            if (collection == null)
                {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.getChildCollectionCount(broker)];
            XmldbURI child, path;
            Collection childColl;
            Permission perm;
            int cnt = 0;
            for (final Iterator<XmldbURI> i = collection.collectionIterator(broker); i.hasNext(); ) {
                child = i.next();
                path = name.append(child);
                childColl = broker.getCollection(path);
                perm = childColl.getPermissionsNoLock();
                result[cnt] = new EntityPermissions();
                result[cnt].setName(child.toString());
                result[cnt].setOwner(perm.getOwner().getName());
                result[cnt].setGroup(perm.getGroup().getName());
                result[cnt].setPermissions(perm.getMode());
View Full Code Here

    }
    public org.exist.soap.EntityPermissionsList listDocumentPermissions(java.lang.String sessionId, XmldbURI name) throws java.rmi.RemoteException {
        DBBroker broker = null;
        final Session session = getSession(sessionId);
        final Subject user = session.getUser();
        Collection collection = null;
        try {
            broker = pool.get(user);
            collection = broker.openCollection(name, Lock.READ_LOCK);
            if (collection == null)
                {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++;
            }
            return new EntityPermissionsList(result);
        } catch (final Exception ex) {
            throw new RemoteException(ex.getMessage());
        } finally {
            if(collection != null)
                {collection.release(Lock.READ_LOCK);}
            pool.release(broker);
        }
    }
View Full Code Here

    }
    public org.exist.soap.IndexedElements getIndexedElements(java.lang.String sessionId, XmldbURI collectionName, boolean inclusive) throws java.rmi.RemoteException {
        DBBroker broker = null;
        final Session session = getSession(sessionId);
        final Subject user = session.getUser();
        Collection collection = null;
        try {
            broker = pool.get(user);
            collection = broker.openCollection(collectionName, Lock.READ_LOCK);
            if (collection == null)
                {throw new EXistException("collection " + collectionName
                        + " not found");}
            final Occurrences occurrences[] = broker.getElementIndex().scanIndexedElements(collection,
                    inclusive);
            final IndexedElement[] result = new IndexedElement[occurrences.length];
            for (int i = 0; i < occurrences.length; i++) {
                final QName qname = (QName)occurrences[i].getTerm();
                result[i] = new IndexedElement(qname.getLocalName(),qname.getNamespaceURI(),
                        qname.getPrefix() == null ? "" : qname.getPrefix(),
                        occurrences[i].getOccurrences());
            }
            return new IndexedElements(result);
        } catch (final Exception ex) {
            throw new RemoteException(ex.getMessage());
        } finally {
            if(collection != null)
                {collection.release(Lock.READ_LOCK);}
            pool.release(broker);
        }
    }
View Full Code Here

TOP

Related Classes of org.exist.collections.Collection$DocumentEntry

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.