use of org.w3c.dom.Text in project jabref by JabRef.
the class OpenDocumentRepresentation method addTableCell.
private void addTableCell(Document doc, Element parent, String content) {
Element cell = doc.createElement("table:table-cell");
Element text = doc.createElement("text:p");
Text textNode = doc.createTextNode(content);
text.appendChild(textNode);
//text.setTextContent(content);
cell.appendChild(text);
parent.appendChild(cell);
}
use of org.w3c.dom.Text in project JMRI by JMRI.
the class XMLUtil method normalize.
/**
* Try to normalize a document by removing nonsignificant whitespace.
*
* @see "#62006"
*/
private static Document normalize(Document orig) throws IOException {
DocumentBuilder builder = null;
DocumentBuilderFactory factory = getFactory(false, false);
try {
builder = factory.newDocumentBuilder();
} catch (ParserConfigurationException e) {
//NOI18N
throw new IOException("Cannot create parser satisfying configuration parameters: " + e, e);
}
DocumentType doctype = null;
NodeList nl = orig.getChildNodes();
for (int i = 0; i < nl.getLength(); i++) {
if (nl.item(i) instanceof DocumentType) {
// We cannot import DocumentType's, so we need to manually copy it.
doctype = (DocumentType) nl.item(i);
}
}
Document doc;
if (doctype != null) {
doc = builder.getDOMImplementation().createDocument(orig.getDocumentElement().getNamespaceURI(), orig.getDocumentElement().getTagName(), builder.getDOMImplementation().createDocumentType(orig.getDoctype().getName(), orig.getDoctype().getPublicId(), orig.getDoctype().getSystemId()));
// XXX what about entity decls inside the DOCTYPE?
doc.removeChild(doc.getDocumentElement());
} else {
doc = builder.newDocument();
}
for (int i = 0; i < nl.getLength(); i++) {
Node node = nl.item(i);
if (!(node instanceof DocumentType)) {
try {
doc.appendChild(doc.importNode(node, true));
} catch (DOMException x) {
// Thrown in NB-Core-Build #2896 & 2898 inside GeneratedFilesHelper.applyBuildExtensions
throw new IOException("Could not import or append " + node + " of " + node.getClass(), x);
}
}
}
doc.normalize();
// NOI18N
nl = doc.getElementsByTagName("*");
for (int i = 0; i < nl.getLength(); i++) {
Element e = (Element) nl.item(i);
removeXmlBase(e);
NodeList nl2 = e.getChildNodes();
for (int j = 0; j < nl2.getLength(); j++) {
Node n = nl2.item(j);
if (n instanceof Text && ((Text) n).getNodeValue().trim().length() == 0) {
e.removeChild(n);
// since list is dynamic
j--;
}
}
}
return doc;
}
use of org.w3c.dom.Text in project jdk8u_jdk by JetBrains.
the class XMLUtils method selectNodeText.
/**
* @param sibling
* @param uri
* @param nodeName
* @param number
* @return nodes with the constrain
*/
public static Text selectNodeText(Node sibling, String uri, String nodeName, int number) {
Node n = selectNode(sibling, uri, nodeName, number);
if (n == null) {
return null;
}
n = n.getFirstChild();
while (n != null && n.getNodeType() != Node.TEXT_NODE) {
n = n.getNextSibling();
}
return (Text) n;
}
use of org.w3c.dom.Text in project jdk8u_jdk by JetBrains.
the class ElementProxy method addText.
/**
* Method addText
*
* @param text
*/
public void addText(String text) {
if (text != null) {
Text t = this.doc.createTextNode(text);
this.constructionElement.appendChild(t);
}
}
use of org.w3c.dom.Text in project jdk8u_jdk by JetBrains.
the class Base64 method encodeToElement.
/**
* Method encodeToElement
*
* @param doc
* @param localName
* @param bytes
* @return an Element with the base64 encoded in the text.
*
*/
public static final Element encodeToElement(Document doc, String localName, byte[] bytes) {
Element el = XMLUtils.createElementInSignatureSpace(doc, localName);
Text text = doc.createTextNode(encode(bytes));
el.appendChild(text);
return el;
}
Aggregations