Package org.exist.xmldb

Examples of org.exist.xmldb.XmldbURI


        super(context, signature);
    }

    @Override
    public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {
        XmldbURI uri = ((AnyURIValue)args[0].itemAt(0)).toXmldbURI();
        String entryName = args[1].itemAt(0).getStringValue();

        ZipFileSource zipFileSource =  new ZipFileFromDb(uri);
        ZipInputStream zis = null;
View Full Code Here


    return buf.toString();
  }
 
  protected boolean existsInContext(String proposedName) {
    if (proposedName == null || proposedName.length() == 0) throw new IllegalArgumentException("name null or empty");
    XmldbURI proposedUri = XmldbURI.create(proposedName);
               
                DBBroker _broker = null;
                try {
                    _broker = db.acquireBroker();
                    return context.hasDocument(_broker, proposedUri) || context.hasSubcollection(_broker, proposedUri);
View Full Code Here

      release();
    }
  }
 
  DocumentImpl moveOrCopyDocument(DocumentImpl doc, Name name, boolean copy) {
    XmldbURI uri;
    transact(Lock.WRITE_LOCK);
    try {
      name.setContext(handle);
      uri = XmldbURI.create(name.get());
      if (copy) {
View Full Code Here

            if (broker == null) {
                LOG.error("Unable to retrieve DBBroker for " + principal.getMetadataValue(AXSchemaType.ALIAS_USERNAME));
                return false;
            }

            XmldbURI pathUri = XmldbURI.create(xqueryResourcePath);


            resource = broker.getXMLResource(pathUri, Lock.READ_LOCK);

            if(resource != null) {
View Full Code Here

    @Override
    public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {

        Sequence result = Sequence.EMPTY_SEQUENCE;
        if (isCalledAs(FILE_ENTRIES)) {
            XmldbURI uri = ((AnyURIValue) args[0].itemAt(0)).toXmldbURI();
            result = extractEntries(uri);
        }
        else if (isCalledAs(ZIP_FILE)) {
            Element zipEntry = (Element)args[0].itemAt(0);
            result = createZip(zipEntry);
        } else if (isCalledAs(UPDATE_ENTRIES)) {
            XmldbURI uri = ((AnyURIValue)args[0].itemAt(0)).toXmldbURI();
            String[] paths = getPaths(args[1]);
            BinaryValue[] newData = getBinaryData(args[2]);
            result = updateZip(uri, paths, newData);
        }
View Full Code Here

    public XmldbURI createCollection(String name) throws PermissionDeniedException, CollectionExistsException, EXistException {

        if(LOG.isDebugEnabled())
            LOG.debug(String.format("Create  '%s' in '%s'", name, xmldbUri));

        XmldbURI newCollection = xmldbUri.append(name);


        DBBroker broker = null;
        Collection collection = null;
View Full Code Here

            throws IOException, PermissionDeniedException, CollectionDoesNotExistException {

        if(LOG.isDebugEnabled())
            LOG.debug(String.format("Create '%s' in '%s'", newName, xmldbUri));

        XmldbURI newNameUri = XmldbURI.create(newName);

        // Get mime, or NULL when not available
        MimeType mime = MimeTable.getInstance().getContentTypeFor(newName);
        if (mime == null) {
            mime = MimeType.BINARY_TYPE;
        }

        // References to the database
        DBBroker broker = null;
        Collection collection = null;

        // create temp file and store. Existdb needs to read twice from a stream.
        BufferedInputStream bis = new BufferedInputStream(is);

        VirtualTempFile vtf = new VirtualTempFile();

        BufferedOutputStream bos = new BufferedOutputStream(vtf);

        // Perform actual copy
        IOUtils.copy(bis, bos);
        bis.close();
        bos.close();
        vtf.close();

        // To support LockNullResource, a 0-byte XML document can received. Since 0-byte
        // XML documents are not supported a small file will be created.
        if (mime.isXMLType() && vtf.length() == 0L) {

            if(LOG.isDebugEnabled())
                LOG.debug(String.format("Creating dummy XML file for null resource lock '%s'", newNameUri));

            vtf = new VirtualTempFile();
            IOUtils.write("<null_resource/>", vtf);
            vtf.close();
        }

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

        try {
            broker = brokerPool.get(subject);

            // Check if collection exists. not likely to happen since availability is checked
            // by ResourceFactory
            collection = broker.openCollection(xmldbUri, Lock.WRITE_LOCK);
            if (collection == null) {
                LOG.debug(String.format("Collection %s does not exist", xmldbUri));
                txnManager.abort(txn);
                throw new CollectionDoesNotExistException(xmldbUri + "");
            }


            if (mime.isXMLType()) {

                if(LOG.isDebugEnabled())
                    LOG.debug(String.format("Inserting XML document '%s'", mime.getName()));

                // Stream into database
                VirtualTempFileInputSource vtfis = new VirtualTempFileInputSource(vtf);
                IndexInfo info = collection.validateXMLResource(txn, broker, newNameUri, vtfis);
                DocumentImpl doc = info.getDocument();
                doc.getMetadata().setMimeType(mime.getName());
                collection.store(txn, broker, info, vtfis, false);

            } else {

                if(LOG.isDebugEnabled())
                    LOG.debug(String.format("Inserting BINARY document '%s'", mime.getName()));

                // Stream into database
                InputStream fis = vtf.getByteStream();
                bis = new BufferedInputStream(fis);
                collection.addBinaryResource(txn, broker, newNameUri, bis, mime.getName(), length);
                bis.close();
            }

            // Commit change
            txnManager.commit(txn);

            if (LOG.isDebugEnabled()) {
                LOG.debug("Document created sucessfully");
            }


        } catch (EXistException | SAXException e) {
            LOG.error(e);
            txnManager.abort(txn);
            throw new IOException(e);

        } catch (LockException e) {
            LOG.error(e);
            txnManager.abort(txn);
            throw new PermissionDeniedException(xmldbUri + "");

        } catch (IOException | PermissionDeniedException e) {
            LOG.error(e);
            txnManager.abort(txn);
            throw e;

        } finally {

            if (vtf != null) {
                vtf.delete();
            }

            // TODO: check if can be done earlier
            if (collection != null) {
                collection.release(Lock.WRITE_LOCK);
            }
            txnManager.close(txn);
            brokerPool.release(broker);

            if(LOG.isDebugEnabled())
                LOG.debug("Finished creation");
        }

        // Send the result back to the client
        XmldbURI newResource = xmldbUri.append(newName);

        return newResource;
    }
View Full Code Here

    void resourceCopyMove(XmldbURI destCollectionUri, String newName, Mode mode) throws EXistException {

        if(LOG.isDebugEnabled())
            LOG.debug(String.format("%s '%s' to '%s' named '%s'", mode, xmldbUri, destCollectionUri, newName));

        XmldbURI newNameUri = null;
        try {
            newNameUri = XmldbURI.xmldbUriFor(newName);
           
        } catch (URISyntaxException ex) {
            LOG.error(ex);
            throw new EXistException(ex.getMessage());
        }

        DBBroker broker = null;
        Collection srcCollection = null;
        Collection destCollection = null;


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

        try {
            broker = brokerPool.get(subject);

            // This class contains already the URI of the resource that shall be moved/copied
            XmldbURI srcCollectionUri = xmldbUri;

            // Open collection if possible, else abort
            srcCollection = broker.openCollection(srcCollectionUri, Lock.WRITE_LOCK);
            if (srcCollection == null) {
                txnManager.abort(txn);
View Full Code Here

            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 " +
View Full Code Here

      if (!special && date != null) {
        currentFile.setLastModified(SVNDate.parseDate(date).getTime());
      }

      XmldbURI fileName = XmldbURI.create(path).lastSegment();

      MimeType mimeType = MimeTable.getInstance().getContentTypeFor(
          fileName);
      // unknown mime type, here preferred is to do nothing
      if (mimeType == null) {
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.