1 16 17 package org.apache.cocoon.transformation; 18 19 import javax.xml.parsers.DocumentBuilderFactory ; 20 21 import junit.framework.TestCase; 22 23 import org.apache.cocoon.xml.AttributesImpl; 24 import org.apache.cocoon.xml.dom.DOMBuilder; 25 import org.w3c.dom.Document ; 26 import org.w3c.dom.Element ; 27 import org.w3c.dom.NodeList ; 28 import org.xml.sax.Attributes ; 29 30 35 public class XAbstractDOMTransformerTestCase extends TestCase { 36 37 41 public XAbstractDOMTransformerTestCase(String name) { 42 super(name); 43 } 44 45 49 public void testJoiningCharacters() throws Exception { 50 55 AbstractDOMTransformer adt = new AbstractDOMTransformer() { 56 protected Document transform(Document doc) { 57 try { 58 Document newdoc = DocumentBuilderFactory 59 .newInstance().newDocumentBuilder().newDocument(); 60 Element root = newdoc.createElement("out"); 61 newdoc.appendChild(root); 62 NodeList children = doc.getDocumentElement().getChildNodes(); 63 StringBuffer value = new StringBuffer (); 64 for (int i = 0 ; i < children.getLength() ; ++i) { 65 value.append(children.item(i).getNodeValue()); 66 } 67 root.appendChild(newdoc.createTextNode(value.toString())); 68 return newdoc; 69 } catch (Exception e) { 70 e.printStackTrace(); 71 return null; 72 } 73 } 74 }; 75 DOMBuilder builder = new DOMBuilder(); 76 adt.setConsumer(builder); 77 Attributes attrs = new AttributesImpl(); 78 char c1[] = "ABC".toCharArray(); 79 char c2[] = "DEF".toCharArray(); 80 adt.startDocument(); 81 adt.startElement("", "in", "in", attrs); 82 adt.characters(c1, 0, 3); 83 adt.characters(c2, 0, 3); 84 adt.endElement("", "in", "in"); 85 adt.endDocument(); 86 assertEquals("Content of root element not what expected", "ABCDEF", 87 builder.getDocument().getDocumentElement().getFirstChild().getNodeValue()); 88 } 89 } 90 | Popular Tags |