Package org.exist.xmldb

Examples of org.exist.xmldb.XmldbURI


     */
    @Override
    public DocumentImpl getResource(XmldbURI fileName, final int accessType) throws PermissionDeniedException {
        fileName = prepend(fileName.toCollectionPathURI());
        //TODO : resolve URIs !!!
        final XmldbURI collUri = fileName.removeLastSegment();
        final XmldbURI docUri = fileName.lastSegment();
        final Collection collection = getCollection(collUri);
        if(collection == null) {
            LOG.debug("collection '" + collUri + "' not found!");
            return null;
        }
View Full Code Here


        if(fileName == null) {
            return null;
        }
        fileName = prepend(fileName.toCollectionPathURI());
        //TODO : resolve URIs !
        final XmldbURI collUri = fileName.removeLastSegment();
        final XmldbURI docUri = fileName.lastSegment();
        final Collection collection = openCollection(collUri, lockMode);
        if(collection == null) {
            LOG.debug("collection '" + collUri + "' not found!");
            return null;
        }
View Full Code Here

   
    private QueryResponseCollection[] collectQueryInfo(TreeMap collections) {
        final QueryResponseCollection c[] = new QueryResponseCollection[collections.size()];
        QueryResponseDocument doc;
        QueryResponseDocument docs[];
        XmldbURI docId;
        int k = 0;
        int l;
        TreeMap documents;
        for (final Iterator i = collections.entrySet().iterator(); i.hasNext(); k++) {
            final Map.Entry entry = (Map.Entry) i.next();
            c[k] = new QueryResponseCollection();
            c[k].setCollectionName(((XmldbURI) entry.getKey()).toString());
            documents = (TreeMap) entry.getValue();
            docs = new QueryResponseDocument[documents.size()];
            c[k].setDocuments(new QueryResponseDocuments(docs));
            l = 0;
            for (final Iterator j = documents.entrySet().iterator(); j.hasNext(); l++) {
                final Map.Entry docEntry = (Map.Entry) j.next();
                doc = new QueryResponseDocument();
                docId = (XmldbURI) docEntry.getKey();
                //TODO: Unnecessary?
                docId = docId.lastSegment();
                doc.setDocumentName(docId.toString());
                doc.setHitCount(((Integer) docEntry.getValue()).intValue());
                docs[l] = doc;
            }
        }
        return c;
View Full Code Here

                    throw new EXistException(
                        "The collection '" + destination.getURI() + "' already has a sub-collection named '" + newName.lastSegment() + "', you cannot create a Document with the same name as an existing collection."
                    );
                }

                final XmldbURI newURI = destination.getURI().append(newName);
                final XmldbURI oldUri = doc.getURI();

                final DocumentTrigger trigger = new DocumentTriggers(this, collection);

                if(oldDoc == null) {
                    if(!destination.getPermissionsNoLock().validate(getSubject(), Permission.WRITE)) {
View Full Code Here

                childCollections[j] = ((XmldbURI) i.next()).toString();
           
            // Resources
            final String[] resources = new String[collection.getDocumentCount(broker)];
            j = 0;
            XmldbURI resource;
            for (final Iterator i = collection.iterator(broker); i.hasNext(); j++) {
                resource = ((DocumentImpl) i.next()).getFileURI();
                resources[j] = resource.lastSegment().toString();
            }
            c.setResources(new StringArray(resources));
            c.setCollections(new StringArray(childCollections));
            return c;
        } catch (final EXistException e) {
View Full Code Here

       
        /* Copy reference to original document */
        final File fsOriginalDocument = getCollectionFile(fsDir, doc.getURI(), true);


        final XmldbURI oldName = doc.getFileURI();
        if(newName == null) {
            newName = oldName;
        }

        try {
            if(destination.hasChildCollection(this, newName.lastSegment())) {
                throw new PermissionDeniedException(
                    "The collection '" + destination.getURI() + "' have collection '" + newName.lastSegment() + "'. " +
                        "Document with same name can't be created."
                );
            }

            final DocumentTrigger trigger = new DocumentTriggers(this, collection);

            // check if the move would overwrite a collection
            //TODO : resolve URIs : destination.getURI().resolve(newName)
            final DocumentImpl oldDoc = destination.getDocument(this, newName);
            if(oldDoc != null) {

                if(doc.getDocId() == oldDoc.getDocId()) {
                    throw new PermissionDeniedException("Cannot move resource to itself '" + doc.getURI() + "'.");
                }

                // GNU mv command would prompt for Confirmation here, you can say yes or pass the '-f' flag. As we cant prompt for confirmation we assume OK
                /* if(!oldDoc.getPermissions().validate(getSubject(), Permission.WRITE)) {
                    throw new PermissionDeniedException("Resource with same name exists in target collection and write is denied");
                }
                */

                trigger.beforeDeleteDocument(this, transaction, oldDoc);
                trigger.afterDeleteDocument(this, transaction, oldDoc.getURI());
            }

            boolean renameOnly = collection.getId() == destination.getId();

            final XmldbURI oldURI = doc.getURI();
            final XmldbURI newURI = destination.getURI().append(newName);

            trigger.beforeMoveDocument(this, transaction, doc, newURI);

            collection.unlinkDocument(this, doc);
            removeResourceMetadata(transaction, doc);
View Full Code Here

                    ;
                }
            }

            if (staticDocs.size() > 0) {
                XmldbURI contextDocs[] = new XmldbURI[staticDocs.size()];
                int i = 0;
                for (String path : staticDocs) {
                    contextDocs[i++] = XmldbURI.createInternal(path);
                }
                context.setStaticallyKnownDocuments(contextDocs);
View Full Code Here

        Collection collection = null;
        try {
            collection = broker.openCollection(collUri, Lock.READ_LOCK);
            if (collection == null)
                {throw new EXistException("collection " + collUri + " not found!");}
            XmldbURI id;
            final Random rand = new Random();
            boolean ok;
            do {
                ok = true;
                id = XmldbURI.create(Integer.toHexString(rand.nextInt()) + ".xml");
                // check if this id does already exist
                if (collection.hasDocument(broker, id))
                    {ok = false;}
               
                if (collection.hasSubcollection(broker, id))
                    {ok = false;}
               
            } while (!ok);
            return id.toString();
        } finally {
            if(collection != null)
                {collection.release(Lock.READ_LOCK);}
            factory.getBrokerPool().release(broker);
        }
View Full Code Here

        final Object[] staticDocuments = (Object[])parameters.get(RpcAPI.STATIC_DOCUMENTS);
        if(staticDocuments != null) {
          try {
            final XmldbURI[] d = new XmldbURI[staticDocuments.length];
            for (int i = 0; i < staticDocuments.length; i++) {
                XmldbURI next = XmldbURI.xmldbUriFor((String) staticDocuments[i]);
                d[i] = next;
            }
            context.setStaticallyKnownDocuments(d);
          } catch(final URISyntaxException e) {
            throw new XPathException(e);
View Full Code Here

      Collection collection = null;
      DocumentImpl doc = null;
      DBBroker broker = null;
      try {
            broker = factory.getBrokerPool().get(user);
            final XmldbURI docURI = XmldbURI.xmldbUriFor(docName)
            collection = broker.openCollection(docURI.removeLastSegment(), Lock.READ_LOCK);
            if (collection == null) {
                LOG.debug("collection " + docURI.removeLastSegment() + " not found!");
                throw new EXistException("Collection " + docURI.removeLastSegment() + " not found!");
            }
            //if(!collection.getPermissions().validate(user, Permission.READ)) {
            //  throw new PermissionDeniedException("Insufficient privileges to read resource");
            //}
            doc = collection.getDocumentWithLock(broker, docURI.lastSegment(), Lock.READ_LOCK);
            if (doc == null) {
                LOG.debug("document " + docURI + " not found!");
                throw new EXistException("document "+docURI+" not found");
            }
View Full Code Here

TOP

Related Classes of org.exist.xmldb.XmldbURI

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.