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");
}
}
}
use of org.w3c.dom.Text in project cdap by caskdata.
the class Configuration method loadResource.
private void loadResource(Properties properties, Object name, boolean quiet) {
try {
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
//ignore all comments inside the xml file
docBuilderFactory.setIgnoringComments(true);
//allow includes in the xml file
docBuilderFactory.setNamespaceAware(true);
try {
docBuilderFactory.setXIncludeAware(true);
} catch (UnsupportedOperationException e) {
LOG.error("Failed to set setXIncludeAware(true) for parser " + docBuilderFactory + ":" + e, e);
}
DocumentBuilder builder = docBuilderFactory.newDocumentBuilder();
Document doc = null;
Element root = null;
if (name instanceof URL) {
// an URL resource
URL url = (URL) name;
if (url != null) {
if (!quiet) {
LOG.info("parsing " + url);
}
doc = builder.parse(url.toString());
}
} else if (name instanceof String) {
// a CLASSPATH resource
URL url = getResource((String) name);
if (url != null) {
if (!quiet) {
LOG.info("parsing " + url);
}
doc = builder.parse(url.toString());
}
} else if (name instanceof InputStream) {
try {
doc = builder.parse((InputStream) name);
} finally {
((InputStream) name).close();
}
} else if (name instanceof Element) {
root = (Element) name;
}
if (doc == null && root == null) {
if (quiet) {
return;
}
throw new RuntimeException(name + " not found");
}
if (root == null) {
root = doc.getDocumentElement();
}
if (!"configuration".equals(root.getTagName())) {
LOG.error("bad conf file: top-level element not <configuration>");
}
NodeList props = root.getChildNodes();
for (int i = 0; i < props.getLength(); i++) {
Node propNode = props.item(i);
if (!(propNode instanceof Element)) {
continue;
}
Element prop = (Element) propNode;
if ("configuration".equals(prop.getTagName())) {
loadResource(properties, prop, quiet);
continue;
}
if (!"property".equals(prop.getTagName())) {
LOG.warn("bad conf file: element not <property>");
}
NodeList fields = prop.getChildNodes();
String attr = null;
String value = null;
boolean finalParameter = false;
for (int j = 0; j < fields.getLength(); j++) {
Node fieldNode = fields.item(j);
if (!(fieldNode instanceof Element)) {
continue;
}
Element field = (Element) fieldNode;
if ("name".equals(field.getTagName()) && field.hasChildNodes()) {
attr = ((Text) field.getFirstChild()).getData().trim();
}
if ("value".equals(field.getTagName()) && field.hasChildNodes()) {
value = ((Text) field.getFirstChild()).getData();
}
if ("final".equals(field.getTagName()) && field.hasChildNodes()) {
finalParameter = "true".equals(((Text) field.getFirstChild()).getData());
}
}
// Ignore this parameter if it has already been marked as 'final'
if (attr != null) {
if (deprecatedKeyMap.containsKey(attr)) {
DeprecatedKeyInfo keyInfo = deprecatedKeyMap.get(attr);
keyInfo.accessed = false;
warnOnceIfDeprecated(attr);
for (String key : keyInfo.newKeys) {
// update new keys with deprecated key's value
loadProperty(properties, name, key, value, finalParameter);
}
} else {
loadProperty(properties, name, attr, value, finalParameter);
}
}
}
} catch (IOException e) {
LOG.error("error parsing conf file.", e);
throw new RuntimeException(e);
} catch (DOMException e) {
LOG.error("error parsing conf file.", e);
throw new RuntimeException(e);
} catch (SAXException e) {
LOG.error("error parsing conf file.", e);
throw new RuntimeException(e);
} catch (ParserConfigurationException e) {
LOG.error("error parsing conf file.", e);
throw new RuntimeException(e);
}
}
use of org.w3c.dom.Text in project jdk8u_jdk by JetBrains.
the class XMLSignature method setSignatureValueElement.
/**
* Base64 encodes and sets the bytes as the content of the SignatureValue
* Node.
*
* @param bytes bytes to be used by SignatureValue before Base64 encoding
*/
private void setSignatureValueElement(byte[] bytes) {
while (signatureValueElement.hasChildNodes()) {
signatureValueElement.removeChild(signatureValueElement.getFirstChild());
}
String base64codedValue = Base64.encode(bytes);
if (base64codedValue.length() > 76 && !XMLUtils.ignoreLineBreaks()) {
base64codedValue = "\n" + base64codedValue + "\n";
}
Text t = this.doc.createTextNode(base64codedValue);
signatureValueElement.appendChild(t);
}
use of org.w3c.dom.Text in project jdk8u_jdk by JetBrains.
the class Reference method setDigestValueElement.
/**
* Method setDigestValueElement
*
* @param digestValue
*/
private void setDigestValueElement(byte[] digestValue) {
Node n = digestValueElement.getFirstChild();
while (n != null) {
digestValueElement.removeChild(n);
n = n.getNextSibling();
}
String base64codedValue = Base64.encode(digestValue);
Text t = this.doc.createTextNode(base64codedValue);
digestValueElement.appendChild(t);
}
use of org.w3c.dom.Text in project jabref by JabRef.
the class OOCalcDatabase method addTableCell.
private static 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);
}
Aggregations