Package org.exist.xmldb

Examples of org.exist.xmldb.XmldbURI


        return ""; //UNDERSTAND: is it ok?
    }

    //Please, keep in sync with org.exist.memtree.ElementImpl
    protected XmldbURI calculateBaseURI() {
        XmldbURI baseURI = null;
        final String nodeBaseURI = _getAttributeNS(Namespaces.XML_NS, "base");
        if (nodeBaseURI != null) {
            baseURI = XmldbURI.create(nodeBaseURI, false);
            if (baseURI.isAbsolute())
                {return baseURI;}
        }
        final StoredNode parent = getParentStoredNode();
        if (parent != null) {
            if (nodeBaseURI == null) {
                baseURI = parent.calculateBaseURI();
            } else {
                XmldbURI parentsBaseURI = parent.calculateBaseURI();
                if (nodeBaseURI.isEmpty())
                    {baseURI = parentsBaseURI;}
                else {
                    baseURI = parentsBaseURI.append(baseURI);
                }
            }
        } else {
            if (nodeBaseURI == null)
                {return XmldbURI.create(getDocument().getBaseURI(), false);}
View Full Code Here


            if (path != null && path.length() > 0) {
                runQuery(null, packageDir, path, true);
                return null;
            } else {
                // otherwise copy all child directories to the target collection
                XmldbURI targetCollection = null;
                if (userTarget != null) {
                    try {
                        targetCollection = XmldbURI.create(userTarget);
                    } catch (final Exception e) {
                        throw new PackageException("Bad collection URI: " + userTarget, e);
                    }
                } else {
                    final ElementImpl target = findElement(repoXML, TARGET_COLL_ELEMENT);
                    if (target != null) {
                        final String targetPath = target.getStringValue();
                        if (targetPath.length() > 0) {
                            // determine target collection
                            try {
                                targetCollection = XmldbURI.create(getTargetCollection(targetPath));
                            } catch (final Exception e) {
                                throw new PackageException("Bad collection URI for <target> element: " + target.getStringValue(), e);
                            }
                        }
                    }
                }
                if (targetCollection == null) {
                    // no target means: package does not need to be deployed into database
                    // however, we need to preserve a copy for backup purposes
                    final Package pkg = getPackage(pkgName, repo);
                    final String pkgColl = pkg.getAbbrev() + "-" + pkg.getVersion();
                    targetCollection = XmldbURI.SYSTEM.append("repo/" + pkgColl);
                }
                final ElementImpl permissions = findElement(repoXML, PERMISSIONS_ELEMENT);
                if (permissions != null) {
                    // get user, group and default permissions
                    user = permissions.getAttribute("user");
                    group = permissions.getAttribute("group");
                    password = permissions.getAttribute("password");
                    String mode = permissions.getAttribute("mode");
                    try {
                        perms = Integer.parseInt(mode, 8);
                    } catch (final NumberFormatException e) {
                        permsStr = mode;
                        if (!permsStr.matches("^[rwx-]{9}"))
                            {throw new PackageException("Bad format for mode attribute in <permissions>: " + mode);}
                    }
                }

                // run the pre-setup query if present
                final ElementImpl preSetup = findElement(repoXML, PRE_SETUP_ELEMENT);
                if (preSetup != null) {
                    path = preSetup.getStringValue();
                    if (path.length() > 0)
                        {runQuery(targetCollection, packageDir, path, true);}
                }

                // any required users and group should have been created by the pre-setup query.
                // check for invalid users now.
                checkUserSettings();

                // install
                scanDirectory(packageDir, targetCollection, true);

                // run the post-setup query if present
                final ElementImpl postSetup = findElement(repoXML, POST_SETUP_ELEMENT);
                if (postSetup != null) {
                    path = postSetup.getStringValue();
                    if (path.length() > 0)
                        {runQuery(targetCollection, packageDir, path, false);}
                }

                storeRepoXML(repoXML, targetCollection);

                // TODO: it should be save to clean up the file system after a package
                // has been deployed. Might be enabled after 2.0
                //cleanup(pkgName, repo);

                return targetCollection.getCollectionPath();
            }
        } catch (final XPathException e) {
            throw new PackageException("Error found while processing repo.xml: " + e.getMessage(), e);
        }
    }
View Full Code Here

     * @throws PackageException
     */
    private void uninstall(Package pkg, ElementImpl target)
            throws PackageException {
        // determine target collection
        XmldbURI targetCollection;
        if (target == null || target.getStringValue().length() == 0) {
            final String pkgColl = pkg.getAbbrev() + "-" + pkg.getVersion();
            targetCollection = XmldbURI.SYSTEM.append("repo/" + pkgColl);
        } else {
            final String targetPath = target.getStringValue();
            try {
                targetCollection = XmldbURI.create(getTargetCollection(targetPath));
            } catch (final Exception e) {
                throw new PackageException("Bad collection URI for <target> element: " + targetPath);
            }
        }
        final TransactionManager mgr = broker.getBrokerPool().getTransactionManager();
        final Txn txn = mgr.beginTransaction();
        try {
            Collection collection = broker.getOrCreateCollection(txn, targetCollection);
            if (collection != null)
                {broker.removeCollection(txn, collection);}
            if (target != null) {
                final XmldbURI configCollection = XmldbURI.CONFIG_COLLECTION_URI.append(targetCollection);
                collection = broker.getOrCreateCollection(txn, configCollection);
                if (collection != null)
                    {broker.removeCollection(txn, collection);}
            }
            mgr.commit(txn);
View Full Code Here

        final TransactionManager mgr = broker.getBrokerPool().getTransactionManager();
        final Txn txn = mgr.beginTransaction();
        try {
            final Collection collection = broker.getOrCreateCollection(txn, targetCollection);
            final XmldbURI name = XmldbURI.createInternal("repo.xml");
            final IndexInfo info = collection.validateXMLResource(txn, broker, name, updatedXML);
            final Permission permission = info.getDocument().getPermissions();
            setPermissions(false, MimeType.XML_TYPE, permission);

            collection.store(txn, broker, info, updatedXML, false);
View Full Code Here

                {continue;}
            if (!file.isDirectory()) {
                MimeType mime = mimeTab.getContentTypeFor(file.getName());
                if (mime == null)
                    {mime = MimeType.BINARY_TYPE;}
                final XmldbURI name = XmldbURI.create(file.getName());

                final Txn txn = mgr.beginTransaction();
                try {
                    if (mime.isXMLType()) {
                        final InputSource is = new InputSource(file.toURI().toASCIIString());
View Full Code Here

    }


    private void checkCollection( Collection collection, List<ErrorReport> errors, ProgressCallback callback ) throws TerminatedException
    {
        final XmldbURI uri = collection.getURI();
        if (callback != null)
          {callback.startCollection( uri.toString() );}

        checkPermissions(collection, errors);
        try {
            for(final Iterator<XmldbURI> i = collection.collectionIteratorNoLock(broker); i.hasNext(); ) {
                final XmldbURI childUri = i.next();

                try {
                    final Collection child = broker.getCollection( uri.append( childUri ) );

                    if( child == null ) {
View Full Code Here

            }
        }
       
        try {
            listener.createCollection(name);
            XmldbURI collUri;

            if(version >= STRICT_URI_VERSION) {
                collUri = XmldbURI.create(name);
            } else {
                try {
View Full Code Here

            } catch(final XPathException xpe) {
                listener.warn("Illegal modification date. Ignoring date...");
            }
        }

        final XmldbURI docUri;

        if(version >= STRICT_URI_VERSION) {
            docUri = XmldbURI.create(name);
        } else {
            try {
View Full Code Here

      }

        } else if("resource".equals(type)) {

          try {
            final XmldbURI uri = XmldbURI.create(name);
            final DocumentImpl doc = currentCollection.getDocument(broker, uri);
           
            if (doc != null) {
              final TransactionManager txnManager = broker.getDatabase().getTransactionManager();
              final Txn txn = txnManager.beginTransaction();
View Full Code Here

        return (DocumentImpl) get(docId);
    }

    @Override
    public XmldbURI[] getNames() {
        final XmldbURI result[] = new XmldbURI[size()];
        DocumentImpl d;
        int j = 0;
        for (final Iterator<DocumentImpl> i = getDocumentIterator(); i.hasNext(); j++) {
            d = i.next();
            result[j] = d.getFileURI();
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.