Package org.apache.xindice.core

Examples of org.apache.xindice.core.Collection


     * @throws DBException
     */
    public static Map copy(Collection col, String dest, boolean overwrite, boolean deep) throws DBException {

        Location destLocation = new Location(dest);
        Collection destCollection = destLocation.getCollection();
        String destName = destLocation.getName();
        Map results = new HashMap();

        if (destLocation.isRoot()) {
            results.put(dest, new Integer(WebdavStatus.SC_BAD_REQUEST));
            return results;
        } else if (destCollection == null) {
            // either intermidiate collection does not exist or destination points to
            // the first level collection (database).
            results.put(dest, new Integer(WebdavStatus.SC_CONFLICT));
            return results;
        } else if (deep && destCollection.getCanonicalName().startsWith(col.getCanonicalName())) {
            // destination points to a location inside target collection subtree.
            // deep copy does not make sense in that case
            results.put(dest, new Integer(WebdavStatus.SC_FORBIDDEN));
            return results;
        }

        // FIXME: the operations are not atomic, they can fail because of another
        // thread deleting or creating collections. Introduce locks.
        if (destName != null) { // destination collection does not exist

            results.putAll(copyCollection(col, destCollection, destName, deep));
            if (results.size() == 0) {
                results.put(dest, new Integer(WebdavStatus.SC_CREATED));
            }
        } else { // existing collection

            if (overwrite) {
                // overwrites the collection
                String name = destCollection.getName();
                Collection parent = destCollection.getParentCollection();
                // delete collection
                parent.dropCollection(destCollection);
                results.putAll(copyCollection(col, parent, name, deep));
                if (results.size() == 0) {
                    results.put(dest, new Integer(WebdavStatus.SC_NO_CONTENT));
                }
            } else {
View Full Code Here


     * @throws DBException
     */
    public static int copy(Collection col, String name, String dest, boolean overwrite) throws DBException {

        Location destLocation = new Location(dest);
        Collection destCollection = destLocation.getCollection();
        String destName = destLocation.getName();

        if (destLocation.isRoot()) {
            // resource cannot be added to root directly, database has to be created manually
            return WebdavStatus.SC_FORBIDDEN;
        } else if (destCollection == null) {
            return WebdavStatus.SC_CONFLICT;
        } else if (col == destCollection && name.equals(destName)) {
            return WebdavStatus.SC_FORBIDDEN;
        }

        // get source
        Entry object = col.getEntry(name);
        if (object == null) {
            return WebdavStatus.SC_NOT_FOUND;
        }

        int status;
        try {
            if (object.getEntryType() == Entry.BINARY) { // insert Binary
                if (overwrite) {
                    if (destCollection.setBinary(new Key(destName), (byte[]) object.getValue())) {
                        status = WebdavStatus.SC_CREATED;
                    } else {
                        status = WebdavStatus.SC_NO_CONTENT;
                    }
                } else {
                    destCollection.insertBinary(destName, (byte[]) object.getValue());
                    status = WebdavStatus.SC_CREATED;
                }
            } else if (object.getEntryType() == Entry.DOCUMENT) {
                if (overwrite) {
                    if (destCollection.setDocument(new Key(destName), (Document) object.getValue())) {
                        status = WebdavStatus.SC_CREATED;
                    } else {
                        status = WebdavStatus.SC_NO_CONTENT;
                    }
                } else {
                    destCollection.insertDocument(destName, (Document) object.getValue());
                    status = WebdavStatus.SC_CREATED;
                }
            } else {
                // placeholder, won't get here
                status = WebdavStatus.SC_FORBIDDEN;
View Full Code Here

    private static Map copyCollection(Collection col, Collection parent, String name, boolean deep)
            throws DBException {

        Configuration config = CollectionConfigurationHelper.copyConfiguration(name, col.getConfig());
        Collection newCol = parent.createCollection(name, config);

        if (deep) {
            return copyCollectionContent(col, newCol);
        } else {
            return Collections.EMPTY_MAP;
View Full Code Here

           attempt to copy other subtrees and their members, that are not descendents
           of an error-causing collection).
          */
        String[] colList = srcCol.listCollections();
        for (int i = 0; i < colList.length; i++) {
            Collection srcChild = srcCol.getCollection(colList[i]);
            Collection destChild = destCol.getCollection(colList[i]);
            try {
                result.putAll(copyCollectionContent(srcChild, destChild));
            } catch (DBException e) {
                int code;
                if (e.faultCode == FaultCodes.COL_NO_FILER) {
                    code = WebdavStatus.SC_FORBIDDEN;
                } else if (e.faultCode == FaultCodes.COL_COLLECTION_NOT_FOUND) {
                    code = WebdavStatus.SC_CONFLICT;
                } else if (e.faultCode == FaultCodes.COL_CANNOT_STORE) {
                    if (log.isDebugEnabled()) {
                        log.debug("Collection Inline Metadata is not enabled!");
                    }
                    code = WebdavStatus.SC_FORBIDDEN;
                } else {
                    throw e;
                }

                result.put(destChild.getCanonicalName(), new Integer(code));
            }
        }

        return result;
    }
View Full Code Here

        if (!message.containsKey(DOCUMENT)) {
            throw new Exception(MISSING_DOCUMENT_PARAM);
        }

        Collection col = getCollection((String) message.get(COLLECTION));

        Document doc = DOMParser.toDocument((String) message.get(DOCUMENT));
        if (doc == null) {
            throw new Exception("Unable to parse Document");
        }

        String id = (String) message.get(NAME);
        col.setDocument(id, doc);

        Map result = new HashMap(3);
        result.put(RESULT, id);
        return result;
    }
View Full Code Here

                container = col.getContainer(name);
                document = container.getDocument();
                return DOCUMENT;

            case COLLECTION:
                Collection c = col.getCollection(name);
                if (c != null) {
                    collection = c;
                    String tmp = parseName("/(?");
                    // If we have another name recurse to handle it.
                    if (!tmp.equals("")) {
View Full Code Here

        if (!message.containsKey(COLLECTION)) {
            throw new Exception(MISSING_COLLECTION_PARAM);
        }

        Collection col = getCollection((String) message.get(COLLECTION));

        Map result = new HashMap(3);
        result.put(RESULT, new Integer((int) col.getDocumentCount()));
        return result;
    }
View Full Code Here

        if (!message.containsKey(COLLECTION)) {
            throw new Exception(MISSING_COLLECTION_PARAM);
        }

        Collection col = getCollection((String) message.get(COLLECTION));
        String[] list = col.listDocuments();

        Vector docs = new Vector();
        for (int i = 0; (list != null) && (i < list.length); i++) {
            docs.addElement(list[i]);
        }
View Full Code Here

        if (!message.containsKey(META)) {
            throw new Exception(MISSING_META_PARAM);
        }

        Collection col = getCollection((String) message.get(COLLECTION));
        if (!col.isMetaEnabled()) {
            // meta information is not enabled !
            throw new Exception(MISSING_META_CONFIGURATION);
        }

        // Read and store sent meta data
        MetaData meta = new MetaData();
        Document doc = DOMParser.toDocument((String) message.get(META));
        meta.streamFromXML(doc.getDocumentElement());
        col.setCollectionMeta(meta);

        // Retreive stored meta data and sent back
        meta = col.getCollectionMeta();
        doc = new DocumentImpl();
        doc.appendChild(meta.streamToXML(doc, true));

        Map result = new HashMap(3);
        result.put(RESULT, TextWriter.toString(doc));
View Full Code Here

        }
        if (!message.containsKey(META)) {
            throw new Exception(MISSING_META_PARAM);
        }

        Collection col = getCollection((String) message.get(COLLECTION));
        if (!col.isMetaEnabled()) {
            // meta information is not enabled !
            throw new Exception(MISSING_META_CONFIGURATION);
        }

        // Read and store sent meta data
        MetaData meta = new MetaData();
        Document doc = DOMParser.toDocument((String) message.get(META));
        meta.streamFromXML(doc.getDocumentElement());

        String docname = (String) message.get(NAME);
        col.setDocumentMeta(docname, meta);

        // Retreive stored meta data and sent back
        meta = col.getDocumentMeta(docname);
        doc = new DocumentImpl();
        meta.streamToXML(doc, true);

        Map result = new HashMap(3);
        result.put(RESULT, TextWriter.toString(doc));
View Full Code Here

TOP

Related Classes of org.apache.xindice.core.Collection

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.