Search in sources :

Example 21 with EntityReference

use of org.w3c.dom.EntityReference in project robovm by robovm.

the class ElementSetAttributeNodeNS method _testSetAttributeNodeNS6.

public void _testSetAttributeNodeNS6() throws Throwable {
    Document doc;
    Element element;
    Attr attribute;
    Attr attribute2;
    EntityReference entRef;
    NodeList elementList;
    doc = (Document) load("staffNS", builder);
    element = doc.createElementNS("http://www.w3.org/DOM/Test", "elem1");
    attribute = doc.createAttributeNS("http://www.w3.org/DOM/Test", "attr");
    entRef = doc.createEntityReference("ent4");
    attribute.appendChild(entRef);
    element.setAttributeNodeNS(attribute);
    elementList = entRef.getChildNodes();
    element = (Element) elementList.item(0);
    attribute2 = doc.createAttributeNS("http://www.w3.org/DOM/Test", "attr2");
    {
        boolean success = false;
        try {
            element.setAttributeNodeNS(attribute2);
        } catch (DOMException ex) {
            success = (ex.code == DOMException.NO_MODIFICATION_ALLOWED_ERR);
        }
        assertTrue("elementsetattributenodens06", success);
    }
}
Also used : DOMException(org.w3c.dom.DOMException) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) EntityReference(org.w3c.dom.EntityReference) Document(org.w3c.dom.Document) Attr(org.w3c.dom.Attr)

Example 22 with EntityReference

use of org.w3c.dom.EntityReference in project robovm by robovm.

the class TreeWalker method startNode.

/**
   * Start processing given node
   *
   *
   * @param node Node to process
   *
   * @throws org.xml.sax.SAXException
   */
protected void startNode(Node node) throws org.xml.sax.SAXException {
    if (node instanceof Locator) {
        Locator loc = (Locator) node;
        m_locator.setColumnNumber(loc.getColumnNumber());
        m_locator.setLineNumber(loc.getLineNumber());
        m_locator.setPublicId(loc.getPublicId());
        m_locator.setSystemId(loc.getSystemId());
    } else {
        m_locator.setColumnNumber(0);
        m_locator.setLineNumber(0);
    }
    switch(node.getNodeType()) {
        case Node.COMMENT_NODE:
            {
                String data = ((Comment) node).getData();
                if (m_contentHandler instanceof LexicalHandler) {
                    LexicalHandler lh = ((LexicalHandler) this.m_contentHandler);
                    lh.comment(data.toCharArray(), 0, data.length());
                }
            }
            break;
        case Node.DOCUMENT_FRAGMENT_NODE:
            // ??;
            break;
        case Node.DOCUMENT_NODE:
            break;
        case Node.ELEMENT_NODE:
            Element elem_node = (Element) node;
            {
                // Make sure the namespace node
                // for the element itself is declared
                // to the ContentHandler
                String uri = elem_node.getNamespaceURI();
                if (uri != null) {
                    String prefix = elem_node.getPrefix();
                    if (prefix == null)
                        prefix = "";
                    this.m_contentHandler.startPrefixMapping(prefix, uri);
                }
            }
            NamedNodeMap atts = elem_node.getAttributes();
            int nAttrs = atts.getLength();
            // each attribute is declared to the ContentHandler
            for (int i = 0; i < nAttrs; i++) {
                final Node attr = atts.item(i);
                final String attrName = attr.getNodeName();
                final int colon = attrName.indexOf(':');
                final String prefix;
                // System.out.println("TreeWalker#startNode: attr["+i+"] = "+attrName+", "+attr.getNodeValue());
                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.startPrefixMapping(prefix, attr.getNodeValue());
                } else if (colon > 0) {
                    prefix = attrName.substring(0, colon);
                    String uri = attr.getNamespaceURI();
                    if (uri != null)
                        this.m_contentHandler.startPrefixMapping(prefix, uri);
                }
            }
            String ns = m_dh.getNamespaceOfNode(node);
            if (null == ns)
                ns = "";
            this.m_contentHandler.startElement(ns, m_dh.getLocalNameOfNode(node), node.getNodeName(), new AttList(atts, m_dh));
            break;
        case Node.PROCESSING_INSTRUCTION_NODE:
            {
                ProcessingInstruction pi = (ProcessingInstruction) node;
                String name = pi.getNodeName();
                // String data = pi.getData();
                if (name.equals("xslt-next-is-raw")) {
                    nextIsRaw = true;
                } else {
                    this.m_contentHandler.processingInstruction(pi.getNodeName(), pi.getData());
                }
            }
            break;
        case Node.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 Node.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 Node.ENTITY_REFERENCE_NODE:
            {
                EntityReference eref = (EntityReference) node;
                if (m_contentHandler instanceof LexicalHandler) {
                    ((LexicalHandler) this.m_contentHandler).startEntity(eref.getNodeName());
                } else {
                // warning("Can not output entity to a pure SAX ContentHandler");
                }
            }
            break;
        default:
    }
}
Also used : Locator(org.xml.sax.Locator) AttList(org.apache.xml.serializer.utils.AttList) 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) ProcessingInstruction(org.w3c.dom.ProcessingInstruction)

Example 23 with EntityReference

use of org.w3c.dom.EntityReference in project karaf by apache.

the class NamespaceHandler method getTextValue.

private static String getTextValue(Element element) {
    StringBuffer value = new StringBuffer();
    NodeList nl = element.getChildNodes();
    for (int i = 0; i < nl.getLength(); i++) {
        Node item = nl.item(i);
        if ((item instanceof CharacterData && !(item instanceof Comment)) || item instanceof EntityReference) {
            value.append(item.getNodeValue());
        }
    }
    return value.toString();
}
Also used : Comment(org.w3c.dom.Comment) CharacterData(org.w3c.dom.CharacterData) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) EntityReference(org.w3c.dom.EntityReference)

Example 24 with EntityReference

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

the class TaglibHyperlinkDetector method getContainedText.

private static String getContainedText(Node parent) {
    NodeList children = parent.getChildNodes();
    if (children.getLength() == 1) {
        return children.item(0).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 {
            s.append(child.getNodeValue().trim());
        }
        child = child.getNextSibling();
    }
    return s.toString().trim();
}
Also used : NodeList(org.w3c.dom.NodeList) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) Node(org.w3c.dom.Node) EntityReference(org.w3c.dom.EntityReference)

Example 25 with EntityReference

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

the class DeploymentDescriptorPropertyCache method getContainedText.

static String getContainedText(Node parent) {
    NodeList children = parent.getChildNodes();
    if (children.getLength() == 1) {
        return children.item(0).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 {
            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)

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