Search in sources :

Example 11 with EntityReference

use of org.w3c.dom.EntityReference in project webservices-axiom by apache.

the class TestCreateEntityReference method runTest.

protected void runTest() throws Throwable {
    Document document = dbf.newDocumentBuilder().newDocument();
    EntityReference entref = document.createEntityReference("myentity");
    assertEquals(Node.ENTITY_REFERENCE_NODE, entref.getNodeType());
    assertEquals("myentity", entref.getNodeName());
    assertNull(entref.getNodeValue());
    assertSame(document, entref.getOwnerDocument());
}
Also used : EntityReference(org.w3c.dom.EntityReference) Document(org.w3c.dom.Document)

Example 12 with EntityReference

use of org.w3c.dom.EntityReference in project webtools.sourceediting by eclipse.

the class CMDocumentFactoryTLD method getContainedText.

protected String getContainedText(Node parent) {
    NodeList children = parent.getChildNodes();
    if (children.getLength() == 1) {
        return getValue(children.item(0));
    }
    StringBuffer s = new StringBuffer();
    Node child = parent.getFirstChild();
    while (child != null) {
        if (child.getNodeType() == Node.ENTITY_REFERENCE_NODE) {
            String reference = ((EntityReference) child).getNodeValue();
            if (reference == null && child.getNodeName() != null) {
                // $NON-NLS-1$ //$NON-NLS-2$
                reference = "&" + child.getNodeName() + ";";
            }
            if (reference != null) {
                s.append(reference.trim());
            }
        } else {
            s.append(getValue(child));
        }
        child = child.getNextSibling();
    }
    return s.toString().trim();
}
Also used : NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) EntityReference(org.w3c.dom.EntityReference)

Example 13 with EntityReference

use of org.w3c.dom.EntityReference in project webtools.sourceediting by eclipse.

the class ProjectDescription method getTextContents.

private String getTextContents(Node parent) {
    NodeList children = parent.getChildNodes();
    if (children.getLength() == 1) {
        Node child = children.item(0);
        if (child.getNodeValue() != null)
            return child.getNodeValue().trim();
    }
    StringBuffer s = new StringBuffer();
    Node child = parent.getFirstChild();
    while (child != null) {
        if (child.getNodeType() == Node.ENTITY_REFERENCE_NODE) {
            String reference = ((EntityReference) child).getNodeValue();
            if (reference == null && child.getNodeName() != null) {
                // $NON-NLS-1$ //$NON-NLS-2$
                reference = "&" + child.getNodeName() + ";";
            }
            if (reference != null) {
                s.append(reference.trim());
            }
        } else if (child.getNodeValue() != null) {
            s.append(child.getNodeValue().trim());
        }
        child = child.getNextSibling();
    }
    return s.toString().trim();
}
Also used : NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) EntityReference(org.w3c.dom.EntityReference)

Example 14 with EntityReference

use of org.w3c.dom.EntityReference in project j2objc by google.

the class TreeWalker method endNode.

/**
 * End processing of given node
 *
 * @param node Node we just finished processing
 *
 * @throws org.xml.sax.SAXException
 */
protected void endNode(Node node) throws org.xml.sax.SAXException {
    switch(node.getNodeType()) {
        case Node.DOCUMENT_NODE:
            break;
        case Node.ELEMENT_NODE:
            String ns = m_dh.getNamespaceOfNode(node);
            if (null == ns)
                ns = "";
            this.m_contentHandler.endElement(ns, m_dh.getLocalNameOfNode(node), node.getNodeName());
            NamedNodeMap atts = ((Element) node).getAttributes();
            int nAttrs = atts.getLength();
            for (int i = 0; i < nAttrs; i++) {
                Node attr = atts.item(i);
                String attrName = attr.getNodeName();
                if (attrName.equals("xmlns") || attrName.startsWith("xmlns:")) {
                    int index;
                    // Use "" instead of null, as Xerces likes "" for the
                    // name of the default namespace.  Fix attributed
                    // to "Steven Murray" <smurray@ebt.com>.
                    String prefix = (index = attrName.indexOf(":")) < 0 ? "" : attrName.substring(index + 1);
                    this.m_contentHandler.endPrefixMapping(prefix);
                }
            }
            break;
        case Node.CDATA_SECTION_NODE:
            break;
        case Node.ENTITY_REFERENCE_NODE:
            {
                EntityReference eref = (EntityReference) node;
                if (m_contentHandler instanceof LexicalHandler) {
                    LexicalHandler lh = ((LexicalHandler) this.m_contentHandler);
                    lh.endEntity(eref.getNodeName());
                }
            }
            break;
        default:
    }
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) LexicalHandler(org.xml.sax.ext.LexicalHandler) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) EntityReference(org.w3c.dom.EntityReference)

Example 15 with EntityReference

use of org.w3c.dom.EntityReference in project j2objc by google.

the class TreeWalker method endNode.

/**
 * End processing of given node
 *
 * @param node Node we just finished processing
 *
 * @throws org.xml.sax.SAXException
 */
protected void endNode(Node node) throws org.xml.sax.SAXException {
    switch(node.getNodeType()) {
        case Node.DOCUMENT_NODE:
            break;
        case Node.ELEMENT_NODE:
            String ns = m_dh.getNamespaceOfNode(node);
            if (null == ns)
                ns = "";
            this.m_contentHandler.endElement(ns, m_dh.getLocalNameOfNode(node), node.getNodeName());
            if (m_Serializer == null) {
                // Don't bother with endPrefixMapping calls if the ContentHandler is a
                // SerializationHandler because SerializationHandler's ignore the
                // endPrefixMapping() calls anyways. . . .  This is an optimization.
                Element elem_node = (Element) node;
                NamedNodeMap atts = elem_node.getAttributes();
                int nAttrs = atts.getLength();
                // of the startPrefixMapping calls
                for (int i = (nAttrs - 1); 0 <= i; i--) {
                    final Node attr = atts.item(i);
                    final String attrName = attr.getNodeName();
                    final int colon = attrName.indexOf(':');
                    final String prefix;
                    if (attrName.equals("xmlns") || attrName.startsWith("xmlns:")) {
                        // to "Steven Murray" <smurray@ebt.com>.
                        if (colon < 0)
                            prefix = "";
                        else
                            prefix = attrName.substring(colon + 1);
                        this.m_contentHandler.endPrefixMapping(prefix);
                    } else if (colon > 0) {
                        prefix = attrName.substring(0, colon);
                        this.m_contentHandler.endPrefixMapping(prefix);
                    }
                }
                {
                    String uri = elem_node.getNamespaceURI();
                    if (uri != null) {
                        String prefix = elem_node.getPrefix();
                        if (prefix == null)
                            prefix = "";
                        this.m_contentHandler.endPrefixMapping(prefix);
                    }
                }
            }
            break;
        case Node.CDATA_SECTION_NODE:
            break;
        case Node.ENTITY_REFERENCE_NODE:
            {
                EntityReference eref = (EntityReference) node;
                if (m_contentHandler instanceof LexicalHandler) {
                    LexicalHandler lh = ((LexicalHandler) this.m_contentHandler);
                    lh.endEntity(eref.getNodeName());
                }
            }
            break;
        default:
    }
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) LexicalHandler(org.xml.sax.ext.LexicalHandler) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) EntityReference(org.w3c.dom.EntityReference)

Aggregations

EntityReference (org.w3c.dom.EntityReference)32 Node (org.w3c.dom.Node)24 NodeList (org.w3c.dom.NodeList)17 Element (org.w3c.dom.Element)14 Comment (org.w3c.dom.Comment)12 CharacterData (org.w3c.dom.CharacterData)10 NamedNodeMap (org.w3c.dom.NamedNodeMap)8 LexicalHandler (org.xml.sax.ext.LexicalHandler)8 Document (org.w3c.dom.Document)7 ProcessingInstruction (org.w3c.dom.ProcessingInstruction)7 Locator (org.xml.sax.Locator)4 Text (org.w3c.dom.Text)3 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)2 AttList (org.apache.xml.serializer.utils.AttList)2 DOMException (org.w3c.dom.DOMException)2 DocumentType (org.w3c.dom.DocumentType)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 StringReader (java.io.StringReader)1 ArrayDeque (java.util.ArrayDeque)1