Package org.exist.stax

Examples of org.exist.stax.EmbeddedXMLStreamReader$ElementEvent


        }
    }

    private void addChildren(NodeProxy contextNode, NodeSet result) {
        try {
            final EmbeddedXMLStreamReader reader = broker.getXMLStreamReader(contextNode, true);
            int status = reader.next();
            int level = 0;
            if (status == XMLStreamConstants.START_ELEMENT) {
                while (reader.hasNext()) {
                    status = reader.next();
                    if (axis == Constants.ATTRIBUTE_AXIS && status != XMLStreamConstants.ATTRIBUTE)
                        {break;}
                    switch (status) {
                    case XMLStreamConstants.END_ELEMENT:
                        if (--level < 0)
                            {return;}
                        break;
                    case XMLStreamConstants.ATTRIBUTE:
                        if ((axis == Constants.ATTRIBUTE_AXIS && level == 0) ||
                            axis == Constants.DESCENDANT_ATTRIBUTE_AXIS) {
                            final AttrImpl attr = (AttrImpl) reader.getNode();
                            if (test.matches(attr)) {
                                final NodeProxy p = new NodeProxy(attr);
                                p.deepCopyContext(contextNode);
                                if (useSelfAsContext && inPredicate) {
                                    p.addContextNode(contextId, p);
                                } else if (inPredicate) {
                                    p.addContextNode(contextId, contextNode);
                                }
                                result.add(p);
                            }
                        }
                        break;
                    default:
                        if (((axis == Constants.CHILD_AXIS && level == 0) ||
                            axis == Constants.DESCENDANT_AXIS ||
                            axis == Constants.DESCENDANT_SELF_AXIS) &&
                            test.matches(reader)) {
                            final NodeId nodeId = (NodeId) reader.getProperty(ExtendedXMLStreamReader.PROPERTY_NODE_ID);
                            final NodeProxy p = new NodeProxy(contextNode.getDocument(), nodeId,
                                reader.getNodeType(), reader.getCurrentPosition());
                            p.deepCopyContext(contextNode);
                            if (useSelfAsContext && inPredicate) {
                                p.addContextNode(contextId, p);
                            } else if (inPredicate) {
                                p.addContextNode(contextId, contextNode);
View Full Code Here


     * @param  receiver  the output handler
     */
    private void writeXML( DocumentImpl doc, Receiver receiver )
    {
        try {
            EmbeddedXMLStreamReader   reader;
            char[]                    ch;
            int                       nsdecls;
            final NamespaceSupport          nsSupport = new NamespaceSupport();
            final NodeList                  children  = doc.getChildNodes();
           
      final DocumentType docType = doc.getDoctype();
            if (docType != null)
          {receiver.documentType(docType.getName(), docType.getPublicId(), docType.getSystemId());}

            for( int i = 0; i < children.getLength(); i++ ) {
                final StoredNode child = (StoredNode)children.item( i );
                reader = broker.getXMLStreamReader( child, false );

                while( reader.hasNext() ) {
                    final int status = reader.next();

                    switch( status ) {

                        case XMLStreamReader.START_DOCUMENT:
                        case XMLStreamReader.END_DOCUMENT: {
                            break;
                        }

                        case XMLStreamReader.START_ELEMENT: {
                            nsdecls = reader.getNamespaceCount();
                            for( int ni = 0; ni < nsdecls; ni++ ) {
                                receiver.startPrefixMapping( reader.getNamespacePrefix( ni ), reader.getNamespaceURI( ni ) );
                            }

                            final AttrList attribs = new AttrList();
                            for( int j = 0; j < reader.getAttributeCount(); j++ ) {
                                final QName qn = new QName( reader.getAttributeLocalName( j ), reader.getAttributeNamespace( j ), reader.getAttributePrefix( j ) );
                                attribs.addAttribute( qn, reader.getAttributeValue( j ) );
                            }
                            receiver.startElement( new QName( reader.getLocalName(), reader.getNamespaceURI(), reader.getPrefix() ), attribs );
                            break;
                        }

                        case XMLStreamReader.END_ELEMENT: {
                            receiver.endElement( new QName( reader.getLocalName(), reader.getNamespaceURI(), reader.getPrefix() ) );
                            nsdecls = reader.getNamespaceCount();
                            for( int ni = 0; ni < nsdecls; ni++ ) {
                                receiver.endPrefixMapping( reader.getNamespacePrefix( ni ) );
                            }
                            break;
                        }

                        case XMLStreamReader.CHARACTERS: {
                            receiver.characters( reader.getText() );
                            break;
                        }

                        case XMLStreamReader.CDATA: {
                            ch = reader.getTextCharacters();
                            receiver.cdataSection( ch, 0, ch.length );
                            break;
                        }

                        case XMLStreamReader.COMMENT: {
                            ch = reader.getTextCharacters();
                            receiver.comment( ch, 0, ch.length );
                            break;
                        }

                        case XMLStreamReader.PROCESSING_INSTRUCTION: {
                            receiver.processingInstruction( reader.getPITarget(), reader.getPIData() );
                            break;
                        }
                    }

                    if( ( child.getNodeType() == Node.COMMENT_NODE ) || ( child.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE ) ) {
View Full Code Here

        if (parent == null) {return null;}
        if (parent.isDirty()) {
            DBBroker broker = null;
            try {
                broker = ownerDocument.getBrokerPool().get(null);
                final EmbeddedXMLStreamReader reader = broker.getXMLStreamReader(parent, true);
                final int level = nodeId.getTreeLevel();
                StoredNode last = null;
                while (reader.hasNext()) {
                    final int status = reader.next();
                    final NodeId currentId = (NodeId) reader.getProperty(ExtendedXMLStreamReader.PROPERTY_NODE_ID);
                    if (status != XMLStreamConstants.END_ELEMENT && currentId.getTreeLevel() == level) {
                        if (currentId.equals(nodeId))
                            {return last;}
                        last = reader.getNode();
                    }
                }
            } catch (final IOException e) {
                LOG.error("Internal error while reading child nodes: " + e.getMessage(), e);
                //TODO : throw exception -pb
View Full Code Here

        if (parent == null) {return null;}
        if (parent.isDirty()) {
            DBBroker broker = null;
            try {
                broker = ownerDocument.getBrokerPool().get(null);
                final EmbeddedXMLStreamReader reader = broker.getXMLStreamReader(parent, true);
                final int level = nodeId.getTreeLevel();
                while (reader.hasNext()) {
                    final int status = reader.next();
                    final NodeId currentId = (NodeId) reader.getProperty(ExtendedXMLStreamReader.PROPERTY_NODE_ID);
                    if (status != XMLStreamConstants.END_ELEMENT && currentId.getTreeLevel() == level) {
                        if (currentId.compareTo(nodeId) > 0)
                            {return reader.getNode();}
                    }
                }
            } catch (final IOException e) {
                LOG.error("Internal error while reading child nodes: " + e.getMessage(), e);
                //TODO : throw exception -pb
View Full Code Here

        if (!node.hasChildNodes())
            {return node;}
        DBBroker broker = null;
        try {
            broker = ownerDocument.getBrokerPool().get(null);
            final EmbeddedXMLStreamReader reader = broker.getXMLStreamReader(node, true);
            while (reader.hasNext()) {
                reader.next();
            }
            return reader.getPreviousNode();
        } catch (final IOException e) {
            LOG.error("Internal error while reading child nodes: " + e.getMessage(), e);
          //TODO : throw exception -pb
        } catch (final XMLStreamException e) {
            LOG.error("Internal error while reading child nodes: " + e.getMessage(), e);
View Full Code Here

    @Override
    public EmbeddedXMLStreamReader getXMLStreamReader(final NodeHandle node, final boolean reportAttributes)
        throws IOException, XMLStreamException {
        if(streamReader == null) {
            final RawNodeIterator iterator = new RawNodeIterator(this, domDb, node);
            streamReader = new EmbeddedXMLStreamReader(this, (DocumentImpl) node.getOwnerDocument(), iterator, node, reportAttributes);
        } else {
            streamReader.reposition(this, node, reportAttributes);
        }
        return streamReader;
    }
View Full Code Here

    @Override
    public EmbeddedXMLStreamReader newXMLStreamReader(final NodeHandle node, final boolean reportAttributes)
        throws IOException, XMLStreamException {
        final RawNodeIterator iterator = new RawNodeIterator(this, domDb, node);
        return new EmbeddedXMLStreamReader(this, (DocumentImpl) node.getOwnerDocument(), iterator, null, reportAttributes);
    }
View Full Code Here

    String actualNodeId = "-2";
    boolean getFragmentMode = false;
    try {
      brokerPool = docImpl.getBrokerPool();
      dbBroker = brokerPool.get(null);
      EmbeddedXMLStreamReader reader = null;
      final NodeList children = docImpl.getChildNodes();
      for (int i = 0; i < children.getLength(); i++) {
        final StoredNode docChildStoredNode = (StoredNode) children.item(i);
        final int docChildStoredNodeType = docChildStoredNode.getNodeType();
        reader = dbBroker.getXMLStreamReader(docChildStoredNode, false);
        while (reader.hasNext() && ! node2NodeId.equals(actualNodeId) && docChildStoredNodeType != Node.PROCESSING_INSTRUCTION_NODE && docChildStoredNodeType != Node.COMMENT_NODE) {
          final int status = reader.next();
          switch (status) {
            case XMLStreamReader.START_DOCUMENT:
            case XMLStreamReader.END_DOCUMENT:
              break;
            case XMLStreamReader.START_ELEMENT :
              actualNodeId = reader.getNode().getNodeId().toString();
              if (actualNodeId.equals(node1NodeId))
                {getFragmentMode = true;}
              if (actualNodeId.equals(node2NodeId))
                {getFragmentMode = false;}
              if (getFragmentMode) {
View Full Code Here

        final ElementImpl root = (ElementImpl) doc.getDocumentElement();
        try {
            final NodePath path = new NodePath();
            final Stack<NodeStats> stack = new Stack<NodeStats>();
            QName qname;
            final EmbeddedXMLStreamReader reader = broker.getXMLStreamReader(root, false);
            while (reader.hasNext()) {
                final int status = reader.next();
                switch (status) {
                    case XMLStreamReader.START_ELEMENT:
                        for (int i = 0; i < stack.size(); i++) {
                            final NodeStats next = stack.elementAt(i);
                            next.incDepth();
                        }
                        qname = reader.getQName();
                        path.addComponent(qname);
                        final NodeStats nodeStats = perDocGuide.add(path);
                        stack.push(nodeStats);
                        break;
                    case XMLStreamReader.END_ELEMENT:
View Full Code Here

TOP

Related Classes of org.exist.stax.EmbeddedXMLStreamReader$ElementEvent

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.