1 37 38 package org.htmlcleaner; 39 40 import java.io.IOException ; 41 import java.io.Writer ; 42 import java.util.*; 43 44 50 public class SimpleXmlSerializer extends XmlSerializer { 51 52 protected SimpleXmlSerializer(Writer writer, HtmlCleaner htmlCleaner) { 53 super(writer, htmlCleaner); 54 } 55 56 private void serialize(List nodes, TagNode tagNode) throws IOException { 57 if ( nodes != null && !nodes.isEmpty() ) { 58 Iterator childrenIt = nodes.iterator(); 59 while ( childrenIt.hasNext() ) { 60 Object item = childrenIt.next(); 61 if (item != null) { 62 if (item instanceof List) { 63 serialize((List)item, tagNode); 64 } else if ( item instanceof ContentToken ) { 65 ContentToken contentToken = (ContentToken) item; 66 String content = contentToken.getContent().toString(); 67 if ( !dontEscape(tagNode) ) { 68 content = escapeXml(content).toString(); 69 } else { 70 content = content.replaceAll("]]>", "]]&"); 71 } 72 writer.write(content); 73 } else { 74 ((BaseToken)item).serialize(this); 75 } 76 } 77 } 78 } 79 } 80 81 protected void serialize(TagNode tagNode) throws IOException { 82 serializeOpenTag(tagNode); 83 84 List tagChildren = tagNode.getChildren(); 85 if ( !tagChildren.isEmpty() ) { 86 serialize(tagChildren, tagNode); 87 serializeEndTag(tagNode); 88 } 89 } 90 91 } | Popular Tags |