001: /*
002: * $Header: /cvsroot/webman-cms/source/webman/com/teamkonzept/publishing/markups/TKDefinedMarkup.java,v 1.7 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 TKDefinedMarkup extends TKMarkup {
012:
013: public String info;
014: public boolean isAtom;
015: public TKMarkupDefinition definition;
016:
017: public TKDefinedMarkup(String name, TKHashtable params, int pos)
018: throws Exception {
019:
020: super (name, params, pos);
021:
022: TKMarkupDefinition definition = TKMarkupDefinition.lookup(name);
023: if (definition == null)
024: throw new Exception("Fehler beim Erzeugen des Markups "
025: + name + ": Markup nicht definiert");
026:
027: this .definition = definition;
028: this .info = definition.info;
029: this .isAtom = definition.isAtom;
030: }
031:
032: public TKDefinedMarkup(String name, TKHashtable params, int pos,
033: boolean backsl) throws Exception {
034:
035: super (name, params, pos, backsl);
036:
037: TKMarkupDefinition definition = TKMarkupDefinition.lookup(name);
038: if (definition == null)
039: throw new Exception("Fehler beim Erzeugen des Markups "
040: + name + ": Markup nicht definiert");
041: else {
042: if (definition.isAtom)
043: this .backsl = true;
044: else {
045: if (backsl)
046: throw new Exception(
047: "Fehler beim Erzeugen des Markups "
048: + name
049: + ": nicht atomares Markup darf nicht mit '/' abgeschlossen werden");
050: }
051: }
052:
053: this .definition = definition;
054: this .info = definition.info;
055: this .isAtom = definition.isAtom;
056: }
057:
058: public TKDefinedMarkup(TKDefinedMarkup markup) {
059:
060: super ((TKMarkup) markup);
061:
062: this .definition = markup.definition;
063: this .info = definition.info;
064: this .isAtom = definition.isAtom;
065: }
066:
067: public TKDefinedMarkup(TKMarkup markup,
068: TKMarkupDefinition definition) {
069:
070: super ((TKMarkup) markup);
071:
072: this .definition = definition;
073: this .info = definition.info;
074: this .isAtom = definition.isAtom;
075: }
076:
077: public void complete() throws Exception {
078:
079: this .info = definition.info;
080: this .isAtom = definition.isAtom;
081:
082: if (params == null)
083: params = new TKHashtable();
084:
085: StringBuffer diags = null;
086:
087: Enumeration e = definition.allParams();
088: while ((e != null) && (e.hasMoreElements())) {
089:
090: TKMarkupParamCall paramDef = (TKMarkupParamCall) e
091: .nextElement();
092: if ((paramDef == null) || (paramDef.name == null))
093: continue;
094:
095: Object currentParam = params.get(paramDef.name);
096:
097: try {
098: if (currentParam == null) {
099:
100: TKDefinedMarkupParam param = new TKDefinedMarkupParam(
101: paramDef);
102: params.put(param.name, param);
103: param.complete();
104:
105: } else if (currentParam instanceof TKDefinedMarkupParam) {
106:
107: TKDefinedMarkupParam param = (TKDefinedMarkupParam) currentParam;
108: param.complete();
109: }
110:
111: } catch (Exception ex) {
112:
113: if (diags == null)
114: diags = new StringBuffer();
115: else
116: diags.append("; ");
117:
118: diags.append(TKMarkupParserException.demandMsg(ex));
119: }
120: }
121:
122: if (diags != null)
123: throw new Exception(diags.toString());
124: }
125:
126: public String convert2Tmpl() {
127:
128: StringBuffer buf = new StringBuffer();
129:
130: if (isAtom)
131: buf.append("<TK_ATAG:").append(name);
132: else
133: buf.append("<TK_TAG:").append(name);
134:
135: boolean first = true;
136: Enumeration e = params == null ? null : params.elements();
137: while ((e != null) && (e.hasMoreElements())) {
138:
139: TKMarkupParam param = (TKMarkupParam) e.nextElement();
140: if ((param == null) || (param.value() == null))
141: continue;
142:
143: if (first)
144: buf.append(':');
145: else
146: buf.append(';');
147: buf.append(param.convert2Tmpl());
148:
149: first = false;
150: }
151:
152: buf.append('>');
153:
154: return new String(buf);
155: }
156:
157: public String convert2Xml() {
158:
159: StringBuffer buf = new StringBuffer();
160:
161: buf.append("<").append(name);
162:
163: Enumeration e = params == null ? null : params.elements();
164: while ((e != null) && (e.hasMoreElements())) {
165:
166: TKMarkupParam param = (TKMarkupParam) e.nextElement();
167:
168: if ((param != null) && (param.value() != null))
169: buf.append(' ').append(param.convert2Xml());
170: }
171:
172: if (isAtom)
173: buf.append("/>");
174: else
175: buf.append('>');
176:
177: return new String(buf);
178: }
179: //{{DECLARE_CONTROLS
180: //}}
181: }
|