Search in sources :

Example 6 with Text

use of org.w3c.dom.Text in project openblocks by mikaelhg.

the class Comment method getSaveNode.

/**
     * Returns the node for this comment.
     * @return
     */
public Node getSaveNode(Document document) {
    Element commentElement = document.createElement("Comment");
    // Text
    Element textElement = document.createElement("Text");
    Text text = document.createTextNode(this.getText().replaceAll("`", "'"));
    textElement.appendChild(text);
    commentElement.appendChild(textElement);
    // Location
    Element locationElement = document.createElement("Location");
    Element xElement = document.createElement("X");
    xElement.appendChild(document.createTextNode(String.valueOf(descale(getLocation().getX()))));
    locationElement.appendChild(xElement);
    Element yElement = document.createElement("Y");
    yElement.appendChild(document.createTextNode(String.valueOf(descale(getLocation().getY()))));
    locationElement.appendChild(yElement);
    commentElement.appendChild(locationElement);
    // Box size
    Element boxSizeElement = document.createElement("BoxSize");
    Element widthElement = document.createElement("Width");
    widthElement.appendChild(document.createTextNode(String.valueOf(descale(getWidth()))));
    boxSizeElement.appendChild(widthElement);
    Element heightElement = document.createElement("Height");
    heightElement.appendChild(document.createTextNode(String.valueOf(descale(getHeight()))));
    boxSizeElement.appendChild(heightElement);
    commentElement.appendChild(boxSizeElement);
    // Collapse
    if (!commentLabel.isActive()) {
        Element collapsedElement = document.createElement("Collapsed");
        commentElement.appendChild(collapsedElement);
    }
    return commentElement;
}
Also used : Element(org.w3c.dom.Element) Text(org.w3c.dom.Text)

Example 7 with Text

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

the class InfoPList method replacePropertyRefs.

static void replacePropertyRefs(Node node, Properties props) {
    if (node instanceof Text) {
        Text el = (Text) node;
        String value = el.getNodeValue();
        if (value != null && value.trim().length() > 0) {
            Matcher matcher = VARIABLE_PATTERN.matcher(value);
            StringBuilder sb = new StringBuilder();
            int pos = 0;
            while (matcher.find()) {
                if (pos < matcher.start()) {
                    sb.append(value.substring(pos, matcher.start()));
                }
                String key = matcher.group(1);
                sb.append(props.getProperty(key, matcher.group()));
                pos = matcher.end();
            }
            if (pos < value.length()) {
                sb.append(value.substring(pos));
            }
            el.setNodeValue(sb.toString());
        }
    }
    NodeList children = node.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
        replacePropertyRefs(children.item(i), props);
    }
}
Also used : Matcher(java.util.regex.Matcher) NodeList(org.w3c.dom.NodeList) Text(org.w3c.dom.Text)

Example 8 with Text

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

the class SimpleBuilderTest method getTextContent.

private String getTextContent(Node node) {
    String result = (node instanceof Text ? ((Text) node).getData() : "");
    Node child = node.getFirstChild();
    while (child != null) {
        result = result + getTextContent(child);
        child = child.getNextSibling();
    }
    return result;
}
Also used : Node(org.w3c.dom.Node) Text(org.w3c.dom.Text)

Example 9 with Text

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

the class NormalizeTest method testInvalidCharactersText.

public void testInvalidCharactersText() throws Exception {
    ErrorRecorder errorRecorder = new ErrorRecorder();
    domConfiguration.setParameter("error-handler", errorRecorder);
    domConfiguration.setParameter("namespaces", false);
    Element root = document.createElement("foo");
    document.appendChild(root);
    Text text = document.createTextNode("");
    root.appendChild(text);
    for (int c = 0; c <= Character.MAX_VALUE; c++) {
        text.setData(new String(new char[] { 'A', 'B', (char) c }));
        document.normalizeDocument();
        if (isValid((char) c)) {
            assertEquals(Collections.<DOMError>emptyList(), errorRecorder.errors);
        } else {
            errorRecorder.assertAllErrors("For character " + c, DOMError.SEVERITY_ERROR, "wf-invalid-character");
        }
    }
}
Also used : Element(org.w3c.dom.Element) Text(org.w3c.dom.Text)

Example 10 with Text

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

the class DOMBuilder method characters.

/**
   * Receive notification of character data.
   *
   * <p>The Parser will call this method to report each chunk of
   * character data.  SAX parsers may return all contiguous character
   * data in a single chunk, or they may split it into several
   * chunks; however, all of the characters in any single event
   * must come from the same external entity, so that the Locator
   * provides useful information.</p>
   *
   * <p>The application must not attempt to read from the array
   * outside of the specified range.</p>
   *
   * <p>Note that some parsers will report whitespace using the
   * ignorableWhitespace() method rather than this one (validating
   * parsers must do so).</p>
   *
   * @param ch The characters from the XML document.
   * @param start The start position in the array.
   * @param length The number of characters to read from the array.
   * @see #ignorableWhitespace
   * @see org.xml.sax.Locator
   */
public void characters(char[] ch, int start, int length) throws org.xml.sax.SAXException {
    if (isOutsideDocElem() && org.apache.xml.utils.XMLCharacterRecognizer.isWhiteSpace(ch, start, length))
        // avoid DOM006 Hierarchy request error
        return;
    if (m_inCData) {
        cdata(ch, start, length);
        return;
    }
    String s = new String(ch, start, length);
    Node childNode;
    childNode = m_currentNode != null ? m_currentNode.getLastChild() : null;
    if (childNode != null && childNode.getNodeType() == Node.TEXT_NODE) {
        ((Text) childNode).appendData(s);
    } else {
        Text text = m_doc.createTextNode(s);
        append(text);
    }
}
Also used : Node(org.w3c.dom.Node) Text(org.w3c.dom.Text)

Aggregations

Text (org.w3c.dom.Text)144 Element (org.w3c.dom.Element)82 Document (org.w3c.dom.Document)51 Node (org.w3c.dom.Node)48 NodeList (org.w3c.dom.NodeList)27 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)20 DocumentBuilder (javax.xml.parsers.DocumentBuilder)19 Attr (org.w3c.dom.Attr)12 StringReader (java.io.StringReader)10 InputSource (org.xml.sax.InputSource)10 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)9 DOMException (org.w3c.dom.DOMException)7 IOException (java.io.IOException)6 Test (org.junit.Test)6 HashMap (java.util.HashMap)4 DOMSource (javax.xml.transform.dom.DOMSource)4 DocumentFragment (org.w3c.dom.DocumentFragment)4 NamedNodeMap (org.w3c.dom.NamedNodeMap)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3