Package org.apache.xindice.core.data

Examples of org.apache.xindice.core.data.Entry


     */
    public Resource getResource(String id) throws XMLDBException {

        checkOpen();
        try {
            Entry entry = col.getEntry(id);
            if (entry == null) {
                return null;
            }

            switch (entry.getEntryType()) {
                case Entry.DOCUMENT:
                    DocumentImpl doc = (DocumentImpl) entry.getValue();

                    // This should probably just pass the document.
                    if (doc.getDataBytes() == null) {
                        return new XMLResourceImpl(id, id, this, TextWriter.toString(doc));
                    } else {
                        return new XMLResourceImpl(id, id, this, doc.getSymbols(), doc.getDataBytes());
                    }

                case Entry.BINARY:
                    return new BinaryResourceImpl(id, this, (byte[]) entry.getValue());

                default:
                    throw new XMLDBException(ErrorCodes.UNKNOWN_RESOURCE_TYPE,
                                             "Internal error: Unexpected resource type " + entry.getEntryType());
            }

        } catch (Exception e) {
            throw FaultCodes.createXMLDBException("Resource not available: " + id, e);
        }
View Full Code Here


            res.setStatus(HttpServletResponse.SC_NOT_FOUND);
            return;
        }

        try {
            Entry resource = col.getEntry(name);

            if (resource != null) {

                byte[] resultBytes;
                if (resource.getEntryType() == Entry.DOCUMENT) {
                    resultBytes = TextWriter.toString((Document) resource.getValue()).getBytes();
                    res.setContentType(MimeTable.XML_MIME_TYPE);
                } else {
                    resultBytes = (byte[]) resource.getValue();
                    res.setContentType(MimeTable.getMimeType(name));
                }

                if (resource.getModificationTime() != 0) {
                    res.addDateHeader("Last-Modified", resource.getModificationTime());
                }
                res.setContentLength(resultBytes.length);
            } else {
                res.setStatus(HttpServletResponse.SC_NOT_FOUND);
            }
View Full Code Here

        } 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

        HashMap result = new HashMap();

        // copy resources
        String[] resList = srcCol.listDocuments();
        for (int i = 0; i < resList.length; i++) {
            Entry object = srcCol.getEntry(resList[i]);
            if (object.getEntryType() == Entry.DOCUMENT) {
                destCol.setDocument(resList[i], (Document) object.getValue());
            } else {
                destCol.setBinary(resList[i], (byte[]) object.getValue());
            }
        }

        // copy child collections content collections
        /* From the specification:
View Full Code Here

            private void prepareNextNode() throws DBException {
                nextNode = null;

                while (nextNode == null && keyPos < keyLen) {
                    Entry entry = context.getEntry(keySet[keyPos++]);
                    if (entry == null || entry.getEntryType() != Entry.DOCUMENT) {
                        continue;
                    }

                    DBDocument d = (DBDocument) entry.getValue();
                    if (d != null) {
                        nextNode = d.getDocumentElement();
                    }
                }
            }
View Full Code Here

            case DocumentCache.COMPRESSED:
                {          
                    SymbolTable s = col.getSymbols();
                    NodeSource ns = new NodeSource(col, key);
                    Document doc =  new DocumentImpl(e.getValue().getData(), s, ns);
                    return new Entry(key, doc, e.getMeta());
                }

            case DocumentCache.UNCOMPRESSED:
                try {
                    Document doc = DOMParser.toDocument(e.getValue());
                    ((DBDocument) doc).setSource(new NodeSource(col, key));
                    return new Entry(key, doc, e.getMeta());
                } catch (Exception ex) {
                    if (log.isWarnEnabled()) {
                        log.warn("ignored exception", ex);
                    }
                }
                break;

            case DocumentCache.BINARY:
                return new Entry(Entry.BINARY, key, e.getValue().getData(), e.getMeta());

            default:
                throw new IllegalStateException("Invalid cache entry type: <" + e.getType() + ">");
        }
View Full Code Here

        }
        if (e == null) {
            return null;
        }

        return new Entry(key, e.getMeta());
    }
View Full Code Here

        if (!message.containsKey(NAME)) {
            throw new Exception(MISSING_NAME_PARAM);
        }

        Collection col = getCollection((String) message.get(COLLECTION));
        Entry obj = col.getEntry(message.get(NAME));

        Map result = new HashMap(3);
        if (obj == null) {
            // Return empty result

        } else if (obj.getEntryType() == Entry.BINARY) {
            // Binary resource
            result.put(RESULT, obj.getValue());

        } else if (message.containsKey(COMPRESSED)) {
            // Compressed XML resource
            SymbolSerializer symbolSerializer = new SymbolSerializer(col.getSymbols());

            long timestamp = 1;
            /* TODO: Timestamp optimization.
               Longs are causing problems with XML-RPC
               so we'll try to get everything working without them.
            if (!message.containsKey(TIMESTAMP)) {
                throw new Exception(MISSING_TIMESTAMP_PARAM);
            }
            int timestamp = ((Integer) message.get("timestamp")).intValue();
            */

            // Document might be compressed (with bytes) or not. In a latter case, convert to string.
            Document doc = (Document) obj.getValue();
            if (/*( timestamp != -1) &&*/ ((CompressedDocument) doc).getDataBytes() != null) {
                result.put(RESULT, symbolSerializer.convertFromDocument(doc, timestamp));
            } else {
                result.put(RESULT, TextWriter.toString(doc));
            }

        } else {
            // XML resource
            Document doc = (Document) obj.getValue();
            result.put(RESULT, TextWriter.toString(doc));
        }

        return result;
    }
View Full Code Here

            node = null;

      while (keyPos < keySet.length) {
                final Key key = keySet[keyPos++];

                Entry entry = context.getEntry(key);
                if (entry.getEntryType() != Entry.DOCUMENT) {
                    continue;
                }

                DBDocument d = (DBDocument) entry.getValue();

                final Node n = d.getDocumentElement();
                if (n == null) {
                    if (log.isInfoEnabled()) {
                        log.info("Document " + context.getCanonicalDocumentName(key+ " is empty, skipping.");
View Full Code Here

            if (depth != 0) {
                processChildren(res, contextPath, col, requestedProps, type, depth);
            }

        } else {
            Entry entry = col.getEntry(name);
            if (entry == null) {
                res.setStatus(HttpServletResponse.SC_NOT_FOUND);
            } else {
                HashMap values = getProperties(col, entry, requestedProps, type);
                addPropfindResponse(res, getLocation(contextPath, col, name), values);
View Full Code Here

TOP

Related Classes of org.apache.xindice.core.data.Entry

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.