Search in sources :

Example 1 with NodeConsumer

use of org.apache.xml.utils.NodeConsumer in project robovm by robovm.

the class DTMTreeWalker method startNode.

/**
   * Start processing given node
   *
   *
   * @param node Node to process
   *
   * @throws org.xml.sax.SAXException
   */
protected void startNode(int node) throws org.xml.sax.SAXException {
    if (m_contentHandler instanceof NodeConsumer) {
    // %TBD%
    //      ((NodeConsumer) m_contentHandler).setOriginatingNode(node);
    }
    switch(m_dtm.getNodeType(node)) {
        case DTM.COMMENT_NODE:
            {
                XMLString data = m_dtm.getStringValue(node);
                if (m_contentHandler instanceof LexicalHandler) {
                    LexicalHandler lh = ((LexicalHandler) this.m_contentHandler);
                    data.dispatchAsComment(lh);
                }
            }
            break;
        case DTM.DOCUMENT_FRAGMENT_NODE:
            // ??;
            break;
        case DTM.DOCUMENT_NODE:
            this.m_contentHandler.startDocument();
            break;
        case DTM.ELEMENT_NODE:
            DTM dtm = m_dtm;
            for (int nsn = dtm.getFirstNamespaceNode(node, true); DTM.NULL != nsn; nsn = dtm.getNextNamespaceNode(node, nsn, true)) {
                // String prefix = dtm.getPrefix(nsn);
                String prefix = dtm.getNodeNameX(nsn);
                this.m_contentHandler.startPrefixMapping(prefix, dtm.getNodeValue(nsn));
            }
            // System.out.println("m_dh.getNamespaceOfNode(node): "+m_dh.getNamespaceOfNode(node));
            // System.out.println("m_dh.getLocalNameOfNode(node): "+m_dh.getLocalNameOfNode(node));
            String ns = dtm.getNamespaceURI(node);
            if (null == ns)
                ns = "";
            // %OPT% !!
            org.xml.sax.helpers.AttributesImpl attrs = new org.xml.sax.helpers.AttributesImpl();
            for (int i = dtm.getFirstAttribute(node); i != DTM.NULL; i = dtm.getNextAttribute(i)) {
                attrs.addAttribute(dtm.getNamespaceURI(i), dtm.getLocalName(i), dtm.getNodeName(i), "CDATA", dtm.getNodeValue(i));
            }
            this.m_contentHandler.startElement(ns, m_dtm.getLocalName(node), m_dtm.getNodeName(node), attrs);
            break;
        case DTM.PROCESSING_INSTRUCTION_NODE:
            {
                String name = m_dtm.getNodeName(node);
                // String data = pi.getData();
                if (name.equals("xslt-next-is-raw")) {
                    nextIsRaw = true;
                } else {
                    this.m_contentHandler.processingInstruction(name, m_dtm.getNodeValue(node));
                }
            }
            break;
        case DTM.CDATA_SECTION_NODE:
            {
                boolean isLexH = (m_contentHandler instanceof LexicalHandler);
                LexicalHandler lh = isLexH ? ((LexicalHandler) this.m_contentHandler) : null;
                if (isLexH) {
                    lh.startCDATA();
                }
                dispatachChars(node);
                {
                    if (isLexH) {
                        lh.endCDATA();
                    }
                }
            }
            break;
        case DTM.TEXT_NODE:
            {
                if (nextIsRaw) {
                    nextIsRaw = false;
                    m_contentHandler.processingInstruction(javax.xml.transform.Result.PI_DISABLE_OUTPUT_ESCAPING, "");
                    dispatachChars(node);
                    m_contentHandler.processingInstruction(javax.xml.transform.Result.PI_ENABLE_OUTPUT_ESCAPING, "");
                } else {
                    dispatachChars(node);
                }
            }
            break;
        case DTM.ENTITY_REFERENCE_NODE:
            {
                if (m_contentHandler instanceof LexicalHandler) {
                    ((LexicalHandler) this.m_contentHandler).startEntity(m_dtm.getNodeName(node));
                } else {
                // warning("Can not output entity to a pure SAX ContentHandler");
                }
            }
            break;
        default:
    }
}
Also used : NodeConsumer(org.apache.xml.utils.NodeConsumer) LexicalHandler(org.xml.sax.ext.LexicalHandler) XMLString(org.apache.xml.utils.XMLString) XMLString(org.apache.xml.utils.XMLString) DTM(org.apache.xml.dtm.DTM)

Example 2 with NodeConsumer

use of org.apache.xml.utils.NodeConsumer in project j2objc by google.

the class DTMTreeWalker method startNode.

/**
   * Start processing given node
   *
   *
   * @param node Node to process
   *
   * @throws org.xml.sax.SAXException
   */
protected void startNode(int node) throws org.xml.sax.SAXException {
    if (m_contentHandler instanceof NodeConsumer) {
    // %TBD%
    //      ((NodeConsumer) m_contentHandler).setOriginatingNode(node);
    }
    switch(m_dtm.getNodeType(node)) {
        case DTM.COMMENT_NODE:
            {
                XMLString data = m_dtm.getStringValue(node);
                if (m_contentHandler instanceof LexicalHandler) {
                    LexicalHandler lh = ((LexicalHandler) this.m_contentHandler);
                    data.dispatchAsComment(lh);
                }
            }
            break;
        case DTM.DOCUMENT_FRAGMENT_NODE:
            // ??;
            break;
        case DTM.DOCUMENT_NODE:
            this.m_contentHandler.startDocument();
            break;
        case DTM.ELEMENT_NODE:
            DTM dtm = m_dtm;
            for (int nsn = dtm.getFirstNamespaceNode(node, true); DTM.NULL != nsn; nsn = dtm.getNextNamespaceNode(node, nsn, true)) {
                // String prefix = dtm.getPrefix(nsn);
                String prefix = dtm.getNodeNameX(nsn);
                this.m_contentHandler.startPrefixMapping(prefix, dtm.getNodeValue(nsn));
            }
            // System.out.println("m_dh.getNamespaceOfNode(node): "+m_dh.getNamespaceOfNode(node));
            // System.out.println("m_dh.getLocalNameOfNode(node): "+m_dh.getLocalNameOfNode(node));
            String ns = dtm.getNamespaceURI(node);
            if (null == ns)
                ns = "";
            // %OPT% !!
            org.xml.sax.helpers.AttributesImpl attrs = new org.xml.sax.helpers.AttributesImpl();
            for (int i = dtm.getFirstAttribute(node); i != DTM.NULL; i = dtm.getNextAttribute(i)) {
                attrs.addAttribute(dtm.getNamespaceURI(i), dtm.getLocalName(i), dtm.getNodeName(i), "CDATA", dtm.getNodeValue(i));
            }
            this.m_contentHandler.startElement(ns, m_dtm.getLocalName(node), m_dtm.getNodeName(node), attrs);
            break;
        case DTM.PROCESSING_INSTRUCTION_NODE:
            {
                String name = m_dtm.getNodeName(node);
                // String data = pi.getData();
                if (name.equals("xslt-next-is-raw")) {
                    nextIsRaw = true;
                } else {
                    this.m_contentHandler.processingInstruction(name, m_dtm.getNodeValue(node));
                }
            }
            break;
        case DTM.CDATA_SECTION_NODE:
            {
                boolean isLexH = (m_contentHandler instanceof LexicalHandler);
                LexicalHandler lh = isLexH ? ((LexicalHandler) this.m_contentHandler) : null;
                if (isLexH) {
                    lh.startCDATA();
                }
                dispatachChars(node);
                {
                    if (isLexH) {
                        lh.endCDATA();
                    }
                }
            }
            break;
        case DTM.TEXT_NODE:
            {
                if (nextIsRaw) {
                    nextIsRaw = false;
                    m_contentHandler.processingInstruction(javax.xml.transform.Result.PI_DISABLE_OUTPUT_ESCAPING, "");
                    dispatachChars(node);
                    m_contentHandler.processingInstruction(javax.xml.transform.Result.PI_ENABLE_OUTPUT_ESCAPING, "");
                } else {
                    dispatachChars(node);
                }
            }
            break;
        case DTM.ENTITY_REFERENCE_NODE:
            {
                if (m_contentHandler instanceof LexicalHandler) {
                    ((LexicalHandler) this.m_contentHandler).startEntity(m_dtm.getNodeName(node));
                } else {
                // warning("Can not output entity to a pure SAX ContentHandler");
                }
            }
            break;
        default:
    }
}
Also used : NodeConsumer(org.apache.xml.utils.NodeConsumer) LexicalHandler(org.xml.sax.ext.LexicalHandler) XMLString(org.apache.xml.utils.XMLString) XMLString(org.apache.xml.utils.XMLString) DTM(org.apache.xml.dtm.DTM)

Aggregations

DTM (org.apache.xml.dtm.DTM)2 NodeConsumer (org.apache.xml.utils.NodeConsumer)2 XMLString (org.apache.xml.utils.XMLString)2 LexicalHandler (org.xml.sax.ext.LexicalHandler)2