use of org.w3c.dom.Text in project robovm by robovm.
the class NodeNormalize method testNormalize.
/**
* Runs the test case.
*
* @throws Throwable
* Any uncaught exception causes test to fail
*/
public void testNormalize() throws Throwable {
Document doc;
Document newDoc;
DOMImplementation domImpl;
DocumentType docTypeNull = null;
Element documentElement;
Element element1;
Element element2;
Element element3;
Element element4;
Element element5;
Element element6;
Element element7;
Text text1;
Text text2;
Text text3;
ProcessingInstruction pi;
CDATASection cData;
Comment comment;
EntityReference entRef;
NodeList elementList;
doc = (Document) load("staffNS", builder);
domImpl = doc.getImplementation();
newDoc = domImpl.createDocument("http://www.w3.org/DOM/Test", "dom:root", docTypeNull);
element1 = newDoc.createElement("element1");
element2 = newDoc.createElement("element2");
element3 = newDoc.createElement("element3");
element4 = newDoc.createElement("element4");
element5 = newDoc.createElement("element5");
element6 = newDoc.createElement("element6");
element7 = newDoc.createElement("element7");
text1 = newDoc.createTextNode("text1");
text2 = newDoc.createTextNode("text2");
text3 = newDoc.createTextNode("text3");
cData = newDoc.createCDATASection("Cdata");
comment = newDoc.createComment("comment");
pi = newDoc.createProcessingInstruction("PITarget", "PIData");
entRef = newDoc.createEntityReference("EntRef");
assertNotNull("createdEntRefNotNull", entRef);
documentElement = newDoc.getDocumentElement();
documentElement.appendChild(element1);
element2.appendChild(text1);
element2.appendChild(text2);
element2.appendChild(text3);
element1.appendChild(element2);
text1 = (Text) text1.cloneNode(false);
text2 = (Text) text2.cloneNode(false);
element3.appendChild(entRef);
element3.appendChild(text1);
element3.appendChild(text2);
element1.appendChild(element3);
text1 = (Text) text1.cloneNode(false);
text2 = (Text) text2.cloneNode(false);
element4.appendChild(cData);
element4.appendChild(text1);
element4.appendChild(text2);
element1.appendChild(element4);
text2 = (Text) text2.cloneNode(false);
text3 = (Text) text3.cloneNode(false);
element5.appendChild(comment);
element5.appendChild(text2);
element5.appendChild(text3);
element1.appendChild(element5);
text2 = (Text) text2.cloneNode(false);
text3 = (Text) text3.cloneNode(false);
element6.appendChild(pi);
element6.appendChild(text2);
element6.appendChild(text3);
element1.appendChild(element6);
entRef = (EntityReference) entRef.cloneNode(false);
text1 = (Text) text1.cloneNode(false);
text2 = (Text) text2.cloneNode(false);
text3 = (Text) text3.cloneNode(false);
element7.appendChild(entRef);
element7.appendChild(text1);
element7.appendChild(text2);
element7.appendChild(text3);
element1.appendChild(element7);
elementList = element1.getChildNodes();
assertEquals("nodeNormalize01_1Bef", 6, elementList.getLength());
elementList = element2.getChildNodes();
assertEquals("nodeNormalize01_2Bef", 3, elementList.getLength());
elementList = element3.getChildNodes();
assertEquals("nodeNormalize01_3Bef", 3, elementList.getLength());
elementList = element4.getChildNodes();
assertEquals("nodeNormalize01_4Bef", 3, elementList.getLength());
elementList = element5.getChildNodes();
assertEquals("nodeNormalize01_5Bef", 3, elementList.getLength());
elementList = element6.getChildNodes();
assertEquals("nodeNormalize01_6Bef", 3, elementList.getLength());
elementList = element7.getChildNodes();
assertEquals("nodeNormalize01_7Bef", 4, elementList.getLength());
newDoc.normalize();
elementList = element1.getChildNodes();
assertEquals("nodeNormalize01_1Aft", 6, elementList.getLength());
elementList = element2.getChildNodes();
assertEquals("nodeNormalize01_2Aft", 1, elementList.getLength());
elementList = element3.getChildNodes();
assertEquals("nodeNormalize01_3Aft", 2, elementList.getLength());
elementList = element4.getChildNodes();
assertEquals("nodeNormalize01_4Aft", 2, elementList.getLength());
elementList = element5.getChildNodes();
assertEquals("nodeNormalize01_5Aft", 2, elementList.getLength());
elementList = element6.getChildNodes();
assertEquals("nodeNormalize01_6Aft", 2, elementList.getLength());
elementList = element7.getChildNodes();
assertEquals("nodeNormalize01_7Aft", 2, elementList.getLength());
}
use of org.w3c.dom.Text in project robovm by robovm.
the class ImportNode method _testImportNode1.
/**
* Runs the test case.
*
* @throws Throwable
* Any uncaught exception causes test to fail
*/
public void _testImportNode1() throws Throwable {
Document doc;
Document aNewDoc;
Attr newAttr;
Text importedChild;
Node aNode;
Document ownerDocument;
Element attrOwnerElement;
DocumentType docType;
String system;
boolean specified;
NodeList childList;
String nodeName;
Node child;
String childValue;
List<String> expectedResult = new ArrayList<String>();
expectedResult.add("elem:attr1");
expectedResult.add("importedText");
doc = (Document) load("staffNS", builder);
aNewDoc = (Document) load("staffNS", builder);
newAttr = aNewDoc.createAttribute("elem:attr1");
importedChild = aNewDoc.createTextNode("importedText");
aNode = newAttr.appendChild(importedChild);
aNode = doc.importNode(newAttr, false);
ownerDocument = aNode.getOwnerDocument();
docType = ownerDocument.getDoctype();
system = docType.getSystemId();
assertNotNull("aNode", aNode);
assertURIEquals("systemId", null, null, null, "staffNS.dtd", null, null, null, null, system);
attrOwnerElement = ((Attr) /* Node */
aNode).getOwnerElement();
assertNull("ownerElement", attrOwnerElement);
specified = ((Attr) /* Node */
aNode).getSpecified();
assertTrue("specified", specified);
childList = aNode.getChildNodes();
assertEquals("childList", 1, childList.getLength());
nodeName = aNode.getNodeName();
assertEquals("nodeName", "elem:attr1", nodeName);
child = aNode.getFirstChild();
childValue = child.getNodeValue();
assertEquals("childValue", "importedText", childValue);
}
use of org.w3c.dom.Text in project robovm by robovm.
the class TextImpl method splitText.
public final Text splitText(int offset) throws DOMException {
Text newText = document.createTextNode(substringData(offset, getLength() - offset));
deleteData(0, offset);
Node refNode = getNextSibling();
if (refNode == null) {
getParentNode().appendChild(newText);
} else {
getParentNode().insertBefore(newText, refNode);
}
return this;
}
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);
}
}
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;
}
Aggregations