1 5 package com.teamkonzept.publishing.markups; 6 7 import java.util.*; 8 9 import com.teamkonzept.lib.*; 10 11 public class TKXmlTree extends TKMarkupTree { 12 13 public String doCrControl (String text) { 14 15 return text; 16 } 17 18 public Object getSingleSub () { 19 20 for (int i = 0; i < size(); i++) { 21 22 Object obj = get(i); 23 if (obj == null) continue; 24 25 if (obj instanceof String ) { 26 27 String normalized = 28 ((String ) obj).replace ('\n',' ').replace ('\r',' ').replace('\t',' ').trim(); 29 30 if (normalized.length() != 0) 31 ; 32 33 continue; 34 35 } 36 37 return obj; 38 } 39 40 return null; 41 } 42 43 public String getSingleText () { 44 45 for (int i = 0; i < size(); i++) { 46 47 Object obj = get(i); 48 if (obj == null) continue; 49 50 if (obj instanceof String ) 51 return TKMarkupParser.doEscapes 52 (((String ) obj).replace ('\n',' ').replace ('\r',' ').replace('\t',' ').trim()); 53 54 continue; 55 } 56 57 return null; 58 } 59 60 public Object getSub (int index) { 61 62 Object obj = get(index); 63 if (obj == null) return null; 64 65 if (obj instanceof String ) { 66 67 String normalized = 68 ((String ) obj).replace ('\n',' ').replace ('\r',' ').replace('\t',' ').trim(); 69 70 if (normalized.length() != 0) 71 ; 72 73 return null; 74 } 75 76 return obj; 77 } 78 79 public String convert2Markup() { 80 81 StringBuffer buffer = new StringBuffer (); 82 83 Enumeration e = elements(); 84 while (e.hasMoreElements()) { 85 86 Object elem = e.nextElement(); 87 if (elem == null) continue; 88 89 if (elem instanceof String ) { 90 91 buffer.append(elem); 92 93 } else if (elem instanceof TKMarkupNode) { 94 95 TKMarkupNode node = (TKMarkupNode) elem; 96 if (node.markup == null) continue; 97 98 if (node.markup instanceof TKXmlMarkup) { 99 100 TKXmlMarkup markup = (TKXmlMarkup) node.markup; 101 buffer.append (markup.toMarkup()); 102 if (node.tree != null) buffer.append (node.tree.convert2Xml()); 103 104 if (!markup.isAtom) buffer.append ("</").append(markup.name).append('>'); 105 106 } else buffer.append (node.markup); 107 108 } else if (elem instanceof TKXmlTree) { 109 110 buffer.append (((TKXmlTree) elem).convert2Markup()); 111 112 } else if (elem instanceof TKMarkup) { 113 114 if (elem instanceof TKXmlMarkup) { 115 116 TKXmlMarkup markup = (TKXmlMarkup) elem; 117 buffer.append (markup.toMarkup()); 118 119 if (!markup.isAtom) buffer.append ("</").append(markup.name).append('>'); 120 121 } else buffer.append (elem); 122 } 123 } 124 125 return new String (buffer); 126 } 127 } 128 129 | Popular Tags |