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);
}
}
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);
}
}
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;
}
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;
}
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");
}
Aggregations