Package org.apache.xindice.core.meta

Examples of org.apache.xindice.core.meta.MetaData


        String deleteCustom = req.getParameter("deleteCustom");

        //  add attribute
        if (attrName.length() > 0 && col.isMetaEnabled() && updateAttr == null) {
            try {
                MetaData newMeta = col.getCollectionMeta();
                newMeta.setAttribute(attrName, attrValue);
                col.setCollectionMeta(newMeta);
                attrName = "";
                attrValue = "";
            } catch (DBException e1) {
                log.error(e1);
                printError("Cannot add Attribute " + attrName + ": " + e1.getMessage(), output);
            }
        } else if (updateAttr != null && updateAttr.length() > 0 && col.isMetaEnabled()) {
            attrName = updateAttr;
            try {
                attrValue = (String) col.getCollectionMeta().getAttribute(attrName);
            } catch (DBException e) {
                log.error(e);
                attrValue = "";
            }
        } else if (deleteAttr != null && deleteAttr.length() > 0 && col.isMetaEnabled()) {
            try {
                MetaData delMeta = col.getCollectionMeta();
                delMeta.removeAttribute(deleteAttr);
                col.setCollectionMeta(delMeta);
            } catch (DBException e) {
                log.error(e);
                printError("Cannot delete Attribute " + deleteAttr + ": " + e.getMessage(), output);
            }
        } else if (custom != null && custom.length() > 0 && col.isMetaEnabled()) {
            try {
                MetaData customMeta = col.getCollectionMeta();
                Document customDoc = DOMParser.toDocument(custom);
                customMeta.setCustomDocument(customDoc);
                col.setCollectionMeta(customMeta);
            } catch (DBException e) {
                log.error(e);
                printError("Cannot add/update Custom: " + e.getMessage(), output);
            } catch (XindiceException e) {
                log.error(e);
                printError("Cannot add/update Custom: " + e.getMessage(), output);
            }
        } else if (deleteCustom != null && deleteCustom.length() > 0 && col.isMetaEnabled()) {
            try {
                MetaData customMeta = col.getCollectionMeta();
                if (customMeta != null) {
                    customMeta.setCustomDocument(null);
                    col.setCollectionMeta(customMeta);
                }
            } catch (DBException e) {
                log.error(e);
                printError("Cannot delete Custom: " + e.getMessage(), output);
            }
        } else if (req.getMethod().equalsIgnoreCase("POST")) {
            byte[] content = new byte[0];
            try {
                //  Create a new file upload handler
                ServletFileUpload upload = new ServletFileUpload();
                // Set upload parameters
                upload.setSizeMax(-1);
                upload.setFileItemFactory(new DiskFileItemFactory());

                // Process the uploaded fields
                Iterator i = upload.parseRequest(req).iterator();
                while (i.hasNext()) {
                    FileItem item = (FileItem) i.next();
                    if (!item.isFormField()) {
                        if (item.getFieldName().equals("customfile")) {
                            content = item.get();
                        }
                    }
                    item.delete();
                }
            } catch (FileUploadException e) {
                log.error(e);
            }

            if (content.length > 0) {
                Document customDoc;
                try {
                    customDoc = DOMParser.toDocument(content);
                } catch (XindiceException e1) { // document fragment ?
                    log.error(e1);
                    StringBuffer newContent = new StringBuffer();
                    newContent.append("<custom>").append(new String(content)).append("</custom>");
                    try {
                        customDoc = DOMParser.toDocument(newContent.toString());
                    } catch (XindiceException e2) { // no xml content
                        log.error(e2);
                        printError("Cannot parse Custom: " + e2.getMessage(), output);
                        customDoc = null;
                    }
                }
                if (customDoc != null) {
                    if (!customDoc.getDocumentElement().getNodeName().equals("custom")) {
                        Document newCustomDoc = new DocumentImpl();
                        Element customEle = newCustomDoc.createElement("custom");
                        customEle.appendChild(customDoc.getDocumentElement());
                        newCustomDoc.appendChild(customEle);
                        customDoc = newCustomDoc;
                    }
                    try {
                        MetaData customMeta = col.getCollectionMeta();
                        customMeta.setCustomDocument(customDoc);
                        col.setCollectionMeta(customMeta);
                    } catch (DBException e2) {
                        log.error(e2);
                        printError("Cannot create Custom: " + e2.getMessage(), output);
                    }
                }
            }
        }

        printStartTable("Add/Update Metadata Attribute", output);
        printStartSingleTableBox(output);
        output.print(META_ATTR_UPDATE_FORM_START);
        output.print(attrName);
        output.print(META_ATTR_UPDATE_FORM_MIDDLE);
        output.print(attrValue);
        output.print(META_ATTR_UPDATE_FORM_END);
        printEndSingleTableBox(output);
        printEndTable(output);
        output.println("<br />\n");

        if (col.isMetaEnabled()) {
            MetaData metaData;
            try {
                metaData = col.getCollectionMeta();
            } catch (DBException e) {
                log.error(e);
                metaData = null;
View Full Code Here


        String custom = req.getParameter("custom");
        String deleteCustom = req.getParameter("deleteCustom");

        if (custom != null && custom.length() > 0 && col.isMetaEnabled()) {
            try {
                MetaData customMeta = col.getDocumentMeta(name);
                Document customDoc = DOMParser.toDocument(custom);
                customMeta.setCustomDocument(customDoc);
                col.setDocumentMeta(name, customMeta);
            } catch (DBException e) {
                log.error(e);
                printError("Cannot add/update Custom: " + e.getMessage(), output);
            } catch (XindiceException e) {
                log.error(e);
                printError("Cannot add/update Custom: " + e.getMessage(), output);
            }
        } else if (deleteCustom != null && deleteCustom.length() > 0 && col.isMetaEnabled()) {
            try {
                MetaData customMeta = col.getDocumentMeta(name);
                if (customMeta != null) {
                    customMeta.setCustomDocument(null);
                    col.setDocumentMeta(name, customMeta);
                }
            } catch (DBException e) {
                log.error(e);
                printError("Cannot delete Custom: " + e.getMessage(), output);
            }
        } else if (req.getMethod().equalsIgnoreCase("POST")) {
            byte[] content = new byte[0];
            try {
                //  Create a new file upload handler
                ServletFileUpload upload = new ServletFileUpload();
                // Set upload parameters
                upload.setSizeMax(-1);
                upload.setFileItemFactory(new DiskFileItemFactory());

                // Process the uploaded fields
                Iterator i = upload.parseRequest(req).iterator();
                while (i.hasNext()) {
                    FileItem item = (FileItem) i.next();
                    if (!item.isFormField()) {
                        if (item.getFieldName().equals("customfile")) {
                            content = item.get();
                        }
                    }
                    item.delete();
                }
            } catch (FileUploadException e) {
                log.error(e);
            }
           
            if (content.length > 0) {
                Document customDoc;
                try {
                    customDoc = DOMParser.toDocument(content);
                } catch (XindiceException e1) { // document fragment ?
                    log.error(e1);
                    StringBuffer newContent = new StringBuffer();
                    newContent.append("<custom>").append(new String(content)).append("</custom>");
                    try {
                        customDoc = DOMParser.toDocument(newContent.toString());
                    } catch (XindiceException e2) { // no xml content
                        log.error(e2);
                        printError("Cannot parse Custom: " + e2.getMessage(), output);
                        customDoc = null;
                    }
                }
                if (customDoc != null) {
                    if (!customDoc.getDocumentElement().getNodeName().equals("custom")) {
                        Document newCustomDoc = new DocumentImpl();
                        Element customEle = newCustomDoc.createElement("custom");
                        customEle.appendChild(customDoc.getDocumentElement());
                        newCustomDoc.appendChild(customEle);
                        customDoc = newCustomDoc;
                    }
                    try {
                        MetaData customMeta = col.getDocumentMeta(name);
                        customMeta.setCustomDocument(customDoc);
                        col.setDocumentMeta(name, customMeta);
                    } catch (DBException e2) {
                        log.error(e2);
                        printError("Cannot create Custom: " + e2.getMessage(), output);
                    }
                }
            }
        }

        if (col.isMetaEnabled()) {
            MetaData metaData;
            try {
                metaData = col.getDocumentMeta(name);
            } catch (DBException e) {
                log.error(e);
                metaData = null;
View Full Code Here

            }
            return null;
        }

        MetaSystemCollection metacol = getMetaSystemCollection();
        MetaData meta = metacol.getCollectionMeta(this);
        if (null == meta) {
            long now = System.currentTimeMillis();
            meta = new MetaData(MetaData.COLLECTION, getCanonicalName(), now, now);
            metacol.setCollectionMeta(this, meta);
        }

        return meta;
    }
View Full Code Here

                throw new DBException(FaultCodes.GEN_UNKNOWN,
                                      "Mismatch type of meta data for collection " + getCanonicalName());
            }

            MetaSystemCollection metacol = getMetaSystemCollection();
            MetaData current = metacol.getCollectionMeta(this);
            current.copyDataFrom(meta);
            metacol.setCollectionMeta(this, current);
        }
    }
View Full Code Here

                throw new DBException(FaultCodes.COL_DOCUMENT_NOT_FOUND,
                                      "Resource '" + id + "' does not exist in '" + getCanonicalName() + "'");
            }

            MetaSystemCollection metacol = getMetaSystemCollection();
            MetaData meta = metacol.getDocumentMeta(this, id);

            /*
            FIXME It is more efficient to store (and retrieve) created/modified timestamps
                  from the Record itself instead of storing them in the separate MetaData
                  object. Storing in the Record avoids writing two documents on each update
                  (Document itself and its MetaData).
                  Retrieval of the timestamps from Record can be implemented via TimeRecord.

            TimeRecord rec = null;
            if( null == meta || !meta.hasContext() )
               rec = getDatabase().getTime(path);

            long created = (null != rec) ? rec.getCreatedTime() : System.currentTimeMillis();
            long modified = (null != rec) ? rec.getModifiedTime() : System.currentTimeMillis();
            */

            // this is wrong.. but it should work for now...
            long now = System.currentTimeMillis();
            if (meta == null) {
                meta = new MetaData(MetaData.DOCUMENT, getCanonicalDocumentName(id), now, now);
                metacol.setDocumentMeta(this, id, meta);
            } else if (!meta.hasContext()) {
                meta.setContext(now, now);
            }

            return meta;
        }
    }
View Full Code Here

                if (log.isInfoEnabled()) {
                    log.info(debugHeader() + "Set document meta " + id);
                }
                MetaSystemCollection metacol = getMetaSystemCollection();
                MetaData current = metacol.getDocumentMeta(this, id);
                current.copyDataFrom(meta);
                metacol.setDocumentMeta(this, id, current);
            }
        }
    }
View Full Code Here

     */
    protected void updateCollectionMeta() {
        // update the meta data if necessary
        if (isMetaEnabled()) {
            MetaSystemCollection metacol = getMetaSystemCollection();
            MetaData meta;
            try {
                meta = metacol.getCollectionMeta(this);
            } catch (DBException e) {
                // something strange has happened.. can't get the
                // meta data for this collection
                if (log.isWarnEnabled()) {
                    log.warn("Error fetching meta for collection '" + getCanonicalName() + "'", e);
                }
                return;
            }

            if (log.isTraceEnabled()) {
                log.trace(debugHeader() + "Updating modified time for collection");
            }
            long now = System.currentTimeMillis();
            if (null == meta) {
                meta = new MetaData(MetaData.COLLECTION, getCanonicalName(), now, now);
            } else if (!meta.hasContext()) {
                // Newly created meta. Update its created and modified time.
                meta.setContext(now, now);
            } else {
                // This collection already has a meta. So update its modified time.
                meta.setContext(0, now);
            }

            try {
                metacol.setCollectionMeta(this, meta);
            } catch (DBException e) {
View Full Code Here

            return;
        }

        MetaSystemCollection metacol = getMetaSystemCollection();
        String id = record.getKey().toString();
        MetaData meta = metacol.getDocumentMeta(this, id);
        String path = getCanonicalDocumentName(id);

        if (log.isTraceEnabled()) {
            log.trace(debugHeader() + "Updating modified time for document '" + id + "'");
        }

        long now = System.currentTimeMillis();
        // Creation and modification time are not necessary will be available.
        // Some filers may not have that information, in which case current time is used
        Long time = (Long) record.getMetaData(Record.CREATED);
        long created = time != null ? time.longValue() : now;

        time = (Long) record.getMetaData(Record.MODIFIED);
        long modified = time != null ? time.longValue() : now;

        if (null == meta) {
            meta = new MetaData(MetaData.DOCUMENT, path, created, modified);
        } else if (!meta.hasContext()) {
            meta.setContext(created, modified);
        } else {
            meta.setContext(0, modified);
        }

        metacol.setDocumentMeta(this, id, meta);
    }
View Full Code Here

            // 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));
        return result;
    }
View Full Code Here

            // 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));
        return result;
    }
View Full Code Here

TOP

Related Classes of org.apache.xindice.core.meta.MetaData

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.