Package org.exist.dom

Examples of org.exist.dom.ElementImpl


            NodeId skipSubtree = null;
            while (reader.hasNext()) {
                int status = reader.next();
                NodeId nodeId = (NodeId) reader.getProperty(EmbeddedXMLStreamReader.PROPERTY_NODE_ID);
                if (status != XMLStreamReader.END_ELEMENT) {
                    ElementImpl insertedNode = insertedNodes.get(nodeId);
                    if (insertedNode != null) {
                        insertNode(insertedNode, receiver, null);
                    }
                } else {
                    ElementImpl appendedNode = appendedNodes.get(nodeId);
                    if (appendedNode != null) {
                        insertNode(appendedNode, receiver, null);
                    }
                }
                String opt = deletedNodes.get(nodeId);
View Full Code Here


            NodeId skipSubtree = null;
            while (reader.hasNext()) {
                int status = reader.next();
                NodeId nodeId = (NodeId) reader.getProperty(EmbeddedXMLStreamReader.PROPERTY_NODE_ID);
                if (status != XMLStreamReader.END_ELEMENT) {
                    ElementImpl insertedNode = insertedNodes.get(nodeId);
                    if (insertedNode != null) {
                        insertNode(insertedNode, receiver, CHANGE_INSERT);
                    }
                } else {
                    ElementImpl appendedNode = appendedNodes.get(nodeId);
                    if (appendedNode != null) {
                        insertNode(appendedNode, receiver, CHANGE_APPEND);
                    }
                }
                boolean skip = false;
View Full Code Here

            if (!validate) {
                broker.storeNode(transaction, comment, currentPath, indexSpec);
            }
            document.appendChild(comment);
        } else {
            final ElementImpl last = stack.peek();
            if (charBuf != null && charBuf.length() > 0) {
                text.setData(charBuf);
                text.setOwnerDocument(document);
                last.appendChildInternal(prevNode, text);
                if (!validate) {
                    storeText();
                }
                setPrevious(text);
                charBuf.reset();
            }
            last.appendChildInternal(prevNode, comment);
            setPrevious(comment);
            if (!validate) {
                broker.storeNode(transaction, comment, currentPath, indexSpec);
            }
        }
View Full Code Here

        }
    }

    public void endCDATA() {
        if (!stack.isEmpty()) {
            final ElementImpl last = stack.peek();
            if (charBuf != null && charBuf.length() > 0) {
                final CDATASectionImpl cdata = new CDATASectionImpl(charBuf);
                cdata.setOwnerDocument(document);
                last.appendChildInternal(prevNode, cdata);
                if (!validate) {
                    broker.storeNode(transaction, cdata, currentPath, indexSpec);
                    if (indexListener != null) {
                        indexListener.characters(transaction, cdata, currentPath);
                    }
View Full Code Here

        }
        //LOG.debug("elementCnt = " + childCnt.length);
    }

    public void endElement(String namespace, String name, String qname) {
        final ElementImpl last = stack.peek();
        if (last.getNodeName().equals(qname)) {
            if (charBuf != null && charBuf.length() > 0) {
                // remove whitespace if the node has just a single text child,
                // keep whitespace for mixed content.
                final XMLString normalized;
                if ((charBuf.isWhitespaceOnly() && suppressWSmixed) || last.preserveSpace()) {
                    normalized = charBuf;
                } else {
                    normalized = last.getChildCount() == 0 ?
                        charBuf.normalize(normalize) :
                            (charBuf.isWhitespaceOnly() ? null : charBuf);
                }
                if (normalized != null && normalized.length() > 0) {
                    text.setData(normalized);
                    text.setOwnerDocument(document);
                    last.appendChildInternal(prevNode, text);
                    if (!validate)
                        {storeText();}
                    setPrevious(text);
                }
                charBuf.reset();
            }
            stack.pop();
            XMLString elemContent = null;
            if (!validate && RangeIndexSpec.hasQNameOrValueIndex(last.getIndexType())) {
                elemContent = nodeContentStack.pop();
            }
            if (!validate) {
                final String content = elemContent == null ?
                        null : elemContent.toString();
                broker.endElement(last, currentPath, content);
                if (indexListener != null)
                    {indexListener.endElement(transaction, last, currentPath);}
            }
            currentPath.removeLastComponent();
            if (validate) {
                if (childCnt != null)
                    {setChildCount(last);}
            } else {
                document.setOwnerDocument(document);
                if ((childCnt == null && last.getChildCount() > 0)
                    || (childCnt != null && childCnt[last.getPosition()] != last.getChildCount())) {
                    broker.updateNode(transaction, last, false);
                }
            }
            setPrevious(last);
            level--;
View Full Code Here

            if (!validate) {
                broker.storeNode(transaction, pi, currentPath, indexSpec);
            }
            document.appendChild(pi);
        } else {
            final ElementImpl last = stack.peek();
            if (charBuf != null && charBuf.length() > 0) {
                final XMLString normalized = charBuf.normalize(normalize);
                if (normalized.length() > 0) {
                    // TextImpl text =
                    // new TextImpl( normalized );
                    text.setData(normalized);
                    text.setOwnerDocument(document);
                    last.appendChildInternal(prevNode, text);
                    if (!validate) {
                        storeText();
                    }
                    setPrevious(text);
                }
                charBuf.reset();
            }
            last.appendChildInternal(prevNode, pi);
            setPrevious(pi);
            if (!validate) {
                broker.storeNode(transaction, pi, currentPath, indexSpec);
            }
        }
View Full Code Here

//        //}
//    //}

    public void startCDATA() {
        if (!stack.isEmpty()) {
            final ElementImpl last = stack.peek();
            if (charBuf != null && charBuf.length() > 0) {
                text.setData(charBuf);
                text.setOwnerDocument(document);
                last.appendChildInternal(prevNode, text);
                if (!validate)
                    {storeText();}
                setPrevious(text);
                charBuf.reset();
            }
View Full Code Here

            attrQName = attributes.getQName(i);
            if (attrQName.startsWith("xmlns")
                    || attrNS.equals(Namespaces.EXIST_NS))
                {--attrLength;}
        }
        ElementImpl last;
        ElementImpl node;
        int p = qname.indexOf(':');
        final String prefix = (p != Constants.STRING_NOT_FOUND) ?
                qname.substring(0, p) : "";
        final QName qn = broker.getBrokerPool().getSymbols().getQName(
                Node.ELEMENT_NODE, namespace, name, prefix);
        if (!stack.empty()) {
            last = stack.peek();
            if (charBuf != null) {
                if (charBuf.isWhitespaceOnly()) {
                    if (suppressWSmixed) {
                        if (charBuf.length() > 0 && !(last.getChildCount() == 0 && (normalize & XMLString.SUPPRESS_LEADING_WS) != 0)) {
                            text.setData(charBuf);
                            text.setOwnerDocument(document);
                            last.appendChildInternal(prevNode, text);
                            if (!validate)
                                {storeText();}
                            setPrevious(text);
                        }
                    }
                } else if (charBuf.length() > 0) {
                    // mixed element content: don't normalize the text node,
                    // just check
                    // if there is any text at all
                    text.setData(charBuf);
                    text.setOwnerDocument(document);
                    last.appendChildInternal(prevNode, text);
                    if (!validate)
                        {storeText();}
                    setPrevious(text);
                }
                charBuf.reset();
            }
            try {
                if (!usedElements.isEmpty()) {
                    node = usedElements.pop();
                    node.setNodeName(qn, broker.getBrokerPool().getSymbols());
                } else {
                    node = new ElementImpl(qn, broker.getBrokerPool().getSymbols());
                }
            } catch (DOMException e) {
                throw new SAXException(e.getMessage(), e);
            }
            // copy xml:space setting
            node.setPreserveSpace(last.preserveSpace());
            // append the node to its parent
            // (computes the node id and updates the parent's child count)
            last.appendChildInternal(prevNode, node);
            setPrevious(null);
            node.setOwnerDocument(document);
            node.setAttributes((short) attrLength);
            if (nsMappings != null && nsMappings.size() > 0) {
                node.setNamespaceMappings(nsMappings);
                nsMappings.clear();
            }
            stack.push(node);
            currentPath.addComponent(qn);
            node.setPosition(elementCnt++);
            if (!validate) {
                if (childCnt != null) {
                    node.setChildCount(childCnt[node.getPosition()]);
                }
                storeElement(node);
            }
        } else {
            try {
                node = new ElementImpl(qn, broker.getBrokerPool().getSymbols());
            } catch (DOMException e) {
                throw new SAXException(e.getMessage(), e);
            }
            rootNode = node;
            setPrevious(null);
            node.setOwnerDocument(document);
            node.setNodeId(broker.getBrokerPool().getNodeFactory()
                .createInstance(nodeFactoryInstanceCnt++));
            node.setAttributes((short) attrLength);
            if (nsMappings != null && nsMappings.size() > 0) {
                node.setNamespaceMappings(nsMappings);
                nsMappings.clear();
            }
            stack.push(node);
            currentPath.addComponent(qn);
            node.setPosition(elementCnt++);
            if (!validate) {
                if (childCnt != null) {
                    node.setChildCount(childCnt[node.getPosition()]);
                }
                storeElement(node);
            }
            document.appendChild(node);
        }
        level++;

        String attrPrefix;
        String attrLocalName;
        for (int i = 0; i < attributes.getLength(); i++) {
            attrNS = attributes.getURI(i);
            attrLocalName = attributes.getLocalName(i);
            attrQName = attributes.getQName(i);
            // skip xmlns-attributes and attributes in eXist's namespace
            if (attrQName.startsWith("xmlns")
                    || attrNS.equals(Namespaces.EXIST_NS))
                {--attrLength;}
            else {
                p = attrQName.indexOf(':');
                attrPrefix = (p != Constants.STRING_NOT_FOUND) ?
                    attrQName.substring(0, p) : null;
                final AttrImpl attr = (AttrImpl) NodePool.getInstance().borrowNode(Node.ATTRIBUTE_NODE);
                final QName attrQN = broker.getBrokerPool().getSymbols().getQName(Node.ATTRIBUTE_NODE, attrNS, attrLocalName, attrPrefix);
                try {
                    attr.setNodeName(attrQN, broker.getBrokerPool().getSymbols());
                } catch (DOMException e) {
                    throw new SAXException(e.getMessage(), e);
                }
                attr.setValue(attributes.getValue(i));
                attr.setOwnerDocument(document);
                if (attributes.getType(i).equals(ATTR_ID_TYPE)) {
                    attr.setType(AttrImpl.ID);
                } else if (attributes.getType(i).equals(ATTR_IDREF_TYPE)) {
                    attr.setType(AttrImpl.IDREF);
                } else if (attributes.getType(i).equals(ATTR_IDREFS_TYPE)) {
                    attr.setType(AttrImpl.IDREFS);
                } else if (attr.getQName().equalsSimple(Namespaces.XML_ID_QNAME)) {
                    // an xml:id attribute. Normalize the attribute and set its
                    // type to ID
                    attr.setValue(StringValue.trimWhitespace(StringValue
                            .collapseWhitespace(attr.getValue())));
                    if (!XMLChar.isValidNCName(attr.getValue()))
                        {throw new SAXException(
                            "Value of xml:id attribute is not a valid NCName: "
                            + attr.getValue());}
                    attr.setType(AttrImpl.ID);
                } else if (attr.getQName().equalsSimple(Namespaces.XML_SPACE_QNAME)) {
                    node.setPreserveSpace("preserve".equals(attr.getValue()));
                }
                node.appendChildInternal(prevNode, attr);
                setPrevious(attr);
                if (!validate) {
                    broker.storeNode(transaction, attr, currentPath, indexSpec);
                    if (indexListener != null)
                        {indexListener.attribute(transaction, attr, currentPath);}
                }
            }
        }
        if (attrLength > 0)
            {node.setAttributes((short) attrLength);}
        // notify observers about progress every 100 lines
        if (locator != null) {
            currentLine = locator.getLineNumber();
            if (!validate) {
                progress.setValue(currentLine);
View Full Code Here

    /**
     * Store the nodes.
     */
    public void store() {
        //Create a wrapper element as root node
        final ElementImpl elem = new ElementImpl(ROOT_QNAME, broker.getBrokerPool().getSymbols());
        elem.setNodeId(broker.getBrokerPool().getNodeFactory().createInstance());
        elem.setOwnerDocument(targetDoc);
        elem.setChildCount(doc.getChildCount());
        elem.addNamespaceMapping("exist", Namespaces.EXIST_NS);
        final NodePath path = new NodePath();
        path.addComponent(ROOT_QNAME);
        stack.push(elem);
        broker.storeNode(transaction, elem, path, indexSpec);
        targetDoc.appendChild(elem);
        elem.setChildCount(0);
        // store the document nodes
        int top = (doc.size > 1) ? 1 : -1;
        while (top > 0) {
            store(top, path);
            top = doc.getNextSiblingFor(top);
View Full Code Here

     * @param  nodeNr
     * @param  currentPath  DOCUMENT ME!
     */
    private void startNode( int nodeNr, NodePath currentPath )
    {
        ElementImpl last;

        switch( doc.nodeKind[nodeNr] ) {

            case Node.ELEMENT_NODE: {
                final ElementImpl elem = (ElementImpl)NodePool.getInstance().borrowNode( Node.ELEMENT_NODE );
                if( stack.empty() ) {
                    elem.setNodeId( broker.getBrokerPool().getNodeFactory().createInstance() );
                    initElement( nodeNr, elem );
                    stack.push( elem );
                    broker.storeNode( transaction, elem, currentPath, indexSpec );
                    targetDoc.appendChild( elem );
                    elem.setChildCount( 0 );
                } else {
                    last = stack.peek();
                    initElement( nodeNr, elem );
                    last.appendChildInternal( prevNode, elem );
                    stack.push( elem );
                    broker.storeNode( transaction, elem, currentPath, indexSpec );
                    elem.setChildCount( 0 );
                }
                setPrevious( null );
                currentPath.addComponent( elem.getQName() );
                storeAttributes( nodeNr, elem, currentPath );
                break;
            }

            case Node.TEXT_NODE: {
View Full Code Here

TOP

Related Classes of org.exist.dom.ElementImpl

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.