Search in sources :

Example 81 with Text

use of org.w3c.dom.Text in project nutch by apache.

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() && 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)

Example 82 with Text

use of org.w3c.dom.Text in project nutch by apache.

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() && 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)

Example 83 with Text

use of org.w3c.dom.Text in project load-balancer by RestComm.

the class BalancerConf method getNodeValue.

private static String getNodeValue(Node node) {
    if (node == null)
        return null;
    NodeList nodeList = node.getChildNodes();
    if (nodeList == null)
        return null;
    Node child = nodeList.item(0);
    if (child == null)
        return null;
    if ((child.getNodeType() == Node.TEXT_NODE)) {
        String value = ((Text) child).getData();
        return value.trim();
    }
    return null;
}
Also used : NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Text(org.w3c.dom.Text)

Example 84 with Text

use of org.w3c.dom.Text in project cxf by apache.

the class DOMUtils method getRawContent.

/**
 * Get the raw text content of a node or null if there is no text
 */
public static String getRawContent(Node n) {
    if (n == null) {
        return null;
    }
    StringBuilder b = null;
    String s = null;
    Node n1 = n.getFirstChild();
    while (n1 != null) {
        if (n1.getNodeType() == Node.TEXT_NODE || n1.getNodeType() == Node.CDATA_SECTION_NODE) {
            if (b != null) {
                b.append(((Text) n1).getNodeValue());
            } else if (s == null) {
                s = ((Text) n1).getNodeValue();
            } else {
                b = new StringBuilder(s).append(((Text) n1).getNodeValue());
                s = null;
            }
        }
        n1 = n1.getNextSibling();
    }
    if (b != null) {
        return b.toString();
    }
    return s;
}
Also used : Node(org.w3c.dom.Node) Text(org.w3c.dom.Text)

Example 85 with Text

use of org.w3c.dom.Text in project knime-core by knime.

the class BrandingInjector method injectLink.

/**
 * Adds the provided link to the "Where to go from here"-section.
 *
 * @param doc
 * @param xpath
 * @param wtgfhNode
 * @throws XPathExpressionException
 */
private void injectLink(final Document doc, final XPath xpath) throws XPathExpressionException {
    Element wtgfhNode = (Element) xpath.evaluate("//div[@id='links']", doc.getDocumentElement(), XPathConstants.NODE);
    Element linkWrapper = doc.createElement("div");
    linkWrapper.setAttribute("class", "floating-link");
    Element newLink = doc.createElement("a");
    newLink.setAttribute("href", m_brandingInfo.get("WhereToGoFromHereLink"));
    newLink.setAttribute("class", "useful-links");
    Element iconSpanNode = doc.createElement("span");
    iconSpanNode.setAttribute("class", "icon-angle-circled-right");
    Text linkText = doc.createTextNode(m_brandingInfo.get("WhereToGoFromHereText"));
    Element textSpanNode = doc.createElement("span");
    textSpanNode.appendChild(linkText);
    newLink.appendChild(iconSpanNode);
    newLink.appendChild(textSpanNode);
    linkWrapper.appendChild(newLink);
    wtgfhNode.appendChild(linkWrapper);
    // Adjust the boxes to the right size
    wtgfhNode.setAttribute("style", "height:200px");
    ((Element) xpath.evaluate("//div[@id='mru']", doc.getDocumentElement(), XPathConstants.NODE)).setAttribute("style", "height:200px");
}
Also used : Element(org.w3c.dom.Element) Text(org.w3c.dom.Text)

Aggregations

Text (org.w3c.dom.Text)166 Element (org.w3c.dom.Element)93 Document (org.w3c.dom.Document)64 Node (org.w3c.dom.Node)58 NodeList (org.w3c.dom.NodeList)35 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)23 DocumentBuilder (javax.xml.parsers.DocumentBuilder)22 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)17 IOException (java.io.IOException)14 Attr (org.w3c.dom.Attr)14 InputSource (org.xml.sax.InputSource)11 StringReader (java.io.StringReader)10 SAXException (org.xml.sax.SAXException)8 ArrayList (java.util.ArrayList)7 DOMException (org.w3c.dom.DOMException)7 Test (org.junit.Test)6 DOMSource (javax.xml.transform.dom.DOMSource)5 NamedNodeMap (org.w3c.dom.NamedNodeMap)5 HashMap (java.util.HashMap)4 DocumentFragment (org.w3c.dom.DocumentFragment)4