Package org.apache.xindice.xml.dom

Examples of org.apache.xindice.xml.dom.DocumentImpl


                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());
View Full Code Here


    /* see superclass for documentation */
    public org.xmldb.api.base.Collection createCollection(String name) throws XMLDBException {

        checkOpen();
        try {
            Document doc = new DocumentImpl();

            Element colEle = doc.createElement("collection");
            colEle.setAttribute("compressed", "true");
            colEle.setAttribute("name", name);
            doc.appendChild(colEle);

            Element filEle = doc.createElement("filer");
            filEle.setAttribute("class", "org.apache.xindice.core.filer.BTreeFiler");
            colEle.appendChild(filEle);

            return createCollection(name, doc);
        } catch (Exception e) {
View Full Code Here

        if (!message.containsKey(NAME)) {
            throw new Exception(MISSING_NAME_PARAM);
        }
        String docname = (String) message.get(NAME);
        MetaData meta = col.getDocumentMeta(docname);
        Document 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

                        break;

                    case XObject.CLASS_BOOLEAN:
                        ni = EMPTY_NODE_ITERATOR;

                        node = new DocumentImpl().createTextNode(String.valueOf(xobject.bool()));
                        if (n instanceof DBNode) {
                            ((TextImpl) node).setSource(((DBNode) n).getSource());
                        }
                        break;

                    case XObject.CLASS_STRING:
                        ni = EMPTY_NODE_ITERATOR;

                        node = new DocumentImpl().createTextNode(xobject.str());
                        if (n instanceof DBNode) {
                            ((TextImpl) node).setSource(((DBNode) n).getSource());
                        }
                        break;

                    case XObject.CLASS_NUMBER:
                        ni = EMPTY_NODE_ITERATOR;

                        node = new DocumentImpl().createTextNode(Double.toString(xobject.num()));
                        if (n instanceof DBNode) {
                            ((TextImpl) node).setSource(((DBNode) n).getSource());
                        }
                        break;
                }
View Full Code Here

     * Adds additional meta data to the query results,
     * and turns it into a DOM document.
     * @param expandSource if true, source meta attributes will be added
     */
    public static Document queryResultsToDOM(NodeSet nodeSet, boolean expandSource) {
        DocumentImpl doc = new DocumentImpl();

        Element root = doc.createElement("result");
        doc.appendChild(root);
        int count = 0;
        while (nodeSet != null && nodeSet.hasMoreNodes()) {
            final Object element = nodeSet.getNextNode();
            if (element instanceof Attr) {
                Attr n = (Attr) element;

                Element holder = doc.createElementNS(XindiceCollection.QUERY_NS, "xq:result");
                holder.setAttribute(NodeImpl.XMLNS_PREFIX + ":xq", XindiceCollection.QUERY_NS);
                holder.setAttributeNode((Attr) doc.importNode(n, true));

                if (expandSource && n instanceof DBNode) {
                    ((DBNode) holder).setSource(((DBNode) n).getSource());
                    ((DBNode) holder).expandSource();
                }

                root.appendChild(holder);
            } else if (element instanceof Text || element instanceof Comment) {
                Node n = (Node) element;

                Element holder = doc.createElementNS(XindiceCollection.QUERY_NS, "xq:result");
                holder.setAttribute(NodeImpl.XMLNS_PREFIX + ":xq", XindiceCollection.QUERY_NS);
                holder.appendChild(doc.importNode(n, true));

                if (expandSource && n instanceof DBNode) {
                    ((DBNode) holder).setSource(((DBNode) n).getSource());
                    ((DBNode) holder).expandSource();
                }

                root.appendChild(holder);
            } else if (element instanceof ProcessingInstruction) {
                if (log.isWarnEnabled()) {
                    log.warn("XPath query with ProcessingInstruction result is not supported");
                }
            } else if (element instanceof Node) {
                Node n = (Node) element;

                if (n.getNodeType() == Node.DOCUMENT_NODE) {
                    n = ((Document) n).getDocumentElement();
                }

                if (expandSource && n instanceof DBNode) {
                    ((DBNode) n).expandSource();
                }

                root.appendChild(doc.importNode(n, true));
            } else {
                throw new XindiceRuntimeException("Unknown result type (" + element.getClass().getName() + ") in nodeset");
            }

            count++;
View Full Code Here

                if (colName.equals("")) {
                    System.out.println("Cannot create a NULL collection");
                    return false;
                }

                Document doc = new DocumentImpl();

                Element colEle = doc.createElement("collection");
                colEle.setAttribute("name", colName);
                // FIXME Make this configurable
                colEle.setAttribute("compressed", "true");
                colEle.setAttribute("inline-metadata", "true");

                doc.appendChild(colEle);

                Element filEle = doc.createElement("filer");
                String filerClass = "org.apache.xindice.core.filer.BTreeFiler";
                // see if user specified filer type
                if (table.containsKey(XMLTools.FILER)) {
                    String filer = (String) table.get(XMLTools.FILER);
                    if ("HashFiler".equals(filer)) {
View Full Code Here

                // Create a collection manager instance for the collection
                CollectionManager colman = (CollectionManager) col.getService("CollectionManager", XMLDBAPIVERSION);

                if (table.get(XMLTools.NAME_OF) != null && table.get(XMLTools.PATTERN) != null) {

                    Document doc = new DocumentImpl();

                    // Create the index element to hold attributes
                    Element idxEle = doc.createElement("index");
                    idxEle.setAttribute("class", XINDICE_VAL_INDEXER);
                    idxEle.setAttribute("name", (String) table.get(XMLTools.NAME_OF));
                    idxEle.setAttribute("pattern", (String) table.get(XMLTools.PATTERN));


                    // Setup optional index attributes
                    if (table.containsKey(XMLTools.TYPE)) {
                        String t = (String) table.get(XMLTools.TYPE);
                        if (t.equalsIgnoreCase("name")) {
                            idxEle.setAttribute("class", XINDICE_NAME_INDEXER);
                        } else {
                            idxEle.setAttribute("type", (String) table.get(XMLTools.TYPE));
                        }
                    }

                    if (table.containsKey(XMLTools.PAGE_SIZE)) {
                        idxEle.setAttribute(XMLTools.PAGE_SIZE, (String) table.get(XMLTools.PAGE_SIZE));
                    }
                    if (table.containsKey(XMLTools.MAX_KEY_SIZE)) {
                        idxEle.setAttribute(XMLTools.MAX_KEY_SIZE, (String) table.get(XMLTools.MAX_KEY_SIZE));
                    }
                    if (table.containsKey(XMLTools.PAGE_COUNT)) {
                      idxEle.setAttribute(XMLTools.PAGE_COUNT, (String) table.get(XMLTools.PAGE_COUNT));
                    }


                    // Add Element to the document
                    doc.appendChild(idxEle);

                    // If in verbose mode, show....
                    if ("true".equals(table.get(XMLTools.VERBOSE))) {
                        String indexstr = TextWriter.toString(doc);
                        System.out.println("Index node element = ");
View Full Code Here

        }
    }

    public Node getContextNode() {
        if (elem == null) {
            Document d = new DocumentImpl();
            elem = d.createElement("nsmap");
            d.appendChild(elem);
            Iterator i = entrySet().iterator();
            while (i.hasNext()) {
                Map.Entry entry = (Map.Entry) i.next();
                String pfx = (String) entry.getKey();
                String uri = (String) entry.getValue();
View Full Code Here

     * @return A new Hashtable
     */
    public Hashtable getSymBuffer() {
        long lm = syms.getLastModified();
        if (lm > lastMod) {
            DocumentImpl doc = new DocumentImpl();
            doc.setSymbols(hcSyms);

            synchronized (syms) {
                Element elem = syms.streamToXML(doc);
                doc.appendChild(elem);

                symBytes = DOMCompressor.compress(doc, hcSyms);
                lastMod = lm;
            }
        }
View Full Code Here

                           SymbolTable symbols, byte[] bytes) throws XMLDBException {
        this.collection = collection;
        this.symbols = symbols;
        this.bytes = bytes;

        initResources(new DocumentImpl(bytes, symbols, null));
    }
View Full Code Here

TOP

Related Classes of org.apache.xindice.xml.dom.DocumentImpl

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.