001: /*
002: * $Header: /cvsroot/webman-cms/source/webman/com/teamkonzept/publishing/markups/TKXmlTree.java,v 1.6 2001/06/11 09:14:10 alex Exp $
003: *
004: */
005: package com.teamkonzept.publishing.markups;
006:
007: import java.util.*;
008:
009: import com.teamkonzept.lib.*;
010:
011: public class TKXmlTree extends TKMarkupTree {
012:
013: public String doCrControl(String text) {
014:
015: return text;
016: }
017:
018: public Object getSingleSub() {
019:
020: for (int i = 0; i < size(); i++) {
021:
022: Object obj = get(i);
023: if (obj == null)
024: continue;
025:
026: if (obj instanceof String) {
027:
028: String normalized = ((String) obj).replace('\n', ' ')
029: .replace('\r', ' ').replace('\t', ' ').trim();
030:
031: if (normalized.length() != 0)
032: ;
033:
034: continue;
035:
036: }
037:
038: return obj;
039: }
040:
041: return null;
042: }
043:
044: public String getSingleText() {
045:
046: for (int i = 0; i < size(); i++) {
047:
048: Object obj = get(i);
049: if (obj == null)
050: continue;
051:
052: if (obj instanceof String)
053: return TKMarkupParser.doEscapes(((String) obj).replace(
054: '\n', ' ').replace('\r', ' ')
055: .replace('\t', ' ').trim());
056:
057: continue;
058: }
059:
060: return null;
061: }
062:
063: public Object getSub(int index) {
064:
065: Object obj = get(index);
066: if (obj == null)
067: return null;
068:
069: if (obj instanceof String) {
070:
071: String normalized = ((String) obj).replace('\n', ' ')
072: .replace('\r', ' ').replace('\t', ' ').trim();
073:
074: if (normalized.length() != 0)
075: ;
076:
077: return null;
078: }
079:
080: return obj;
081: }
082:
083: public String convert2Markup() {
084:
085: StringBuffer buffer = new StringBuffer();
086:
087: Enumeration e = elements();
088: while (e.hasMoreElements()) {
089:
090: Object elem = e.nextElement();
091: if (elem == null)
092: continue;
093:
094: if (elem instanceof String) {
095:
096: buffer.append(elem);
097:
098: } else if (elem instanceof TKMarkupNode) {
099:
100: TKMarkupNode node = (TKMarkupNode) elem;
101: if (node.markup == null)
102: continue;
103:
104: if (node.markup instanceof TKXmlMarkup) {
105:
106: TKXmlMarkup markup = (TKXmlMarkup) node.markup;
107: buffer.append(markup.toMarkup());
108: if (node.tree != null)
109: buffer.append(node.tree.convert2Xml());
110:
111: if (!markup.isAtom)
112: buffer.append("</").append(markup.name).append(
113: '>');
114:
115: } else
116: buffer.append(node.markup);
117:
118: } else if (elem instanceof TKXmlTree) {
119:
120: buffer.append(((TKXmlTree) elem).convert2Markup());
121:
122: } else if (elem instanceof TKMarkup) {
123:
124: if (elem instanceof TKXmlMarkup) {
125:
126: TKXmlMarkup markup = (TKXmlMarkup) elem;
127: buffer.append(markup.toMarkup());
128:
129: if (!markup.isAtom)
130: buffer.append("</").append(markup.name).append(
131: '>');
132:
133: } else
134: buffer.append(elem);
135: }
136: }
137:
138: return new String(buffer);
139: }
140: }
|