001: /*
002: * $Header: /cvsroot/webman-cms/source/webman/com/teamkonzept/publishing/markups/TKMarkup.java,v 1.8 2001/11/26 15:14:26 sebastian Exp $
003: *
004: */
005: package com.teamkonzept.publishing.markups;
006:
007: import java.util.*;
008:
009: import com.teamkonzept.lib.*;
010:
011: public class TKMarkup {
012:
013: public String name;
014: public int pos;
015: public boolean backsl;// wurde das Markup mit einem / abgeschlossen ?
016:
017: public TKHashtable params;
018:
019: public TKMarkup(String name, TKHashtable params, int pos) {
020:
021: this (name, params, pos, false);
022: }
023:
024: public TKMarkup(String name, TKHashtable params, int pos,
025: boolean backsl) {
026:
027: this .name = name.toUpperCase();
028: this .pos = pos;
029: this .params = params;
030: this .backsl = backsl;
031: }
032:
033: public TKMarkup(TKMarkup markup) {
034:
035: this .name = markup.name;
036: this .pos = markup.pos;
037: this .params = markup.params;
038: }
039:
040: public String toDisplay() {
041:
042: StringBuffer buf = new StringBuffer();
043: buf.append(name);
044:
045: Enumeration e = params == null ? null : params.elements();
046: while ((e != null) && (e.hasMoreElements())) {
047:
048: TKMarkupParam param = (TKMarkupParam) e.nextElement();
049: if ((param != null) && (param.value() != null))
050: buf.append(' ').append(param);
051: }
052:
053: return new String(buf);
054: }
055:
056: public String toId() {
057:
058: return toDisplay();
059: }
060:
061: public String toString() {
062:
063: StringBuffer buf = new StringBuffer();
064: if (backsl)
065: buf.append('<').append(toId()).append("/>");
066: else
067: buf.append('<').append(toId()).append('>');
068:
069: return new String(buf);
070: }
071:
072: public String expand() {
073:
074: StringBuffer buf = new StringBuffer();
075:
076: if (backsl)
077: buf.append('<').append(toDisplay()).append("/>");
078: else
079: buf.append('<').append(toDisplay()).append('>');
080:
081: return new String(buf);
082: }
083:
084: public String convert2Tmpl() {
085:
086: StringBuffer buf = new StringBuffer();
087:
088: buf.append('<').append(name);
089:
090: boolean first = true;
091: Enumeration e = params == null ? null : params.elements();
092: while ((e != null) && (e.hasMoreElements())) {
093:
094: TKMarkupParam param = (TKMarkupParam) e.nextElement();
095: if ((param == null) || (param.value() == null))
096: continue;
097:
098: if (first)
099: buf.append(':');
100: else
101: buf.append(';');
102: buf.append(param.convert2Tmpl());
103:
104: first = false;
105: }
106:
107: buf.append('>');
108:
109: return new String(buf);
110: }
111:
112: public String convert2Xml() {
113:
114: StringBuffer buf = new StringBuffer();
115:
116: buf.append('<').append(name);
117:
118: boolean first = true;
119: Enumeration e = params == null ? null : params.elements();
120: while ((e != null) && (e.hasMoreElements())) {
121:
122: TKMarkupParam param = (TKMarkupParam) e.nextElement();
123: if ((param == null) || (param.value() == null))
124: continue;
125:
126: buf.append(' ').append(param.convert2Xml());
127:
128: first = false;
129: }
130:
131: buf.append("/>");
132:
133: return new String(buf);
134: }
135: }
|