1 5 package com.teamkonzept.publishing.markups; 6 7 import java.util.*; 8 9 import com.teamkonzept.lib.*; 10 11 public class TKDefinedMarkup extends TKMarkup { 12 13 public String info; 14 public boolean isAtom; 15 public TKMarkupDefinition definition; 16 17 public TKDefinedMarkup (String name, TKHashtable params, int pos) throws Exception { 18 19 super (name,params,pos); 20 21 TKMarkupDefinition definition = TKMarkupDefinition.lookup(name); 22 if (definition == null) 23 throw new Exception ("Fehler beim Erzeugen des Markups "+name+ 24 ": Markup nicht definiert"); 25 26 this.definition = definition; 27 this.info = definition.info; 28 this.isAtom = definition.isAtom; 29 } 30 31 public TKDefinedMarkup (String name, TKHashtable params, int pos,boolean backsl) throws Exception { 32 33 super (name,params,pos,backsl); 34 35 TKMarkupDefinition definition = TKMarkupDefinition.lookup(name); 36 if (definition == null) 37 throw new Exception ("Fehler beim Erzeugen des Markups "+name+ 38 ": Markup nicht definiert"); 39 else 40 { 41 if (definition.isAtom) 42 this.backsl = true; 43 else 44 { 45 if (backsl) 46 throw new Exception ("Fehler beim Erzeugen des Markups "+name+ 47 ": nicht atomares Markup darf nicht mit '/' abgeschlossen werden"); 48 } 49 } 50 51 this.definition = definition; 52 this.info = definition.info; 53 this.isAtom = definition.isAtom; 54 } 55 56 public TKDefinedMarkup (TKDefinedMarkup markup) { 57 58 super ((TKMarkup) markup); 59 60 this.definition = markup.definition; 61 this.info = definition.info; 62 this.isAtom = definition.isAtom; 63 } 64 65 public TKDefinedMarkup (TKMarkup markup, TKMarkupDefinition definition) { 66 67 super ((TKMarkup) markup); 68 69 this.definition = definition; 70 this.info = definition.info; 71 this.isAtom = definition.isAtom; 72 } 73 74 public void complete () throws Exception { 75 76 this.info = definition.info; 77 this.isAtom = definition.isAtom; 78 79 if (params == null) params = new TKHashtable (); 80 81 StringBuffer diags = null; 82 83 Enumeration e = definition.allParams(); 84 while ((e != null) && (e.hasMoreElements())) { 85 86 TKMarkupParamCall paramDef = (TKMarkupParamCall) e.nextElement(); 87 if ((paramDef == null) || (paramDef.name == null)) continue; 88 89 Object currentParam = params.get(paramDef.name); 90 91 try { 92 if (currentParam == null) { 93 94 TKDefinedMarkupParam param = new TKDefinedMarkupParam (paramDef); 95 params.put (param.name,param); 96 param.complete(); 97 98 } else if (currentParam instanceof TKDefinedMarkupParam) { 99 100 TKDefinedMarkupParam param = (TKDefinedMarkupParam) currentParam; 101 param.complete(); 102 } 103 104 } catch (Exception ex) { 105 106 if (diags == null) diags = new StringBuffer (); 107 else diags.append ("; "); 108 109 diags.append (TKMarkupParserException.demandMsg(ex)); 110 } 111 } 112 113 if (diags != null) throw new Exception (diags.toString()); 114 } 115 116 public String convert2Tmpl () { 117 118 StringBuffer buf = new StringBuffer (); 119 120 if (isAtom) buf.append("<TK_ATAG:").append(name); 121 else buf.append("<TK_TAG:").append(name); 122 123 boolean first = true; 124 Enumeration e = params == null ? null : params.elements(); 125 while ((e != null) && (e.hasMoreElements())) { 126 127 TKMarkupParam param = (TKMarkupParam) e.nextElement(); 128 if ((param == null) || (param.value() == null)) continue; 129 130 if (first) buf.append(':'); else buf.append(';'); 131 buf.append(param.convert2Tmpl()); 132 133 first=false; 134 } 135 136 buf.append('>'); 137 138 return new String (buf); 139 } 140 141 public String convert2Xml () { 142 143 StringBuffer buf = new StringBuffer (); 144 145 buf.append("<").append(name); 146 147 Enumeration e = params == null ? null : params.elements(); 148 while ((e != null) && (e.hasMoreElements())) { 149 150 TKMarkupParam param = (TKMarkupParam) e.nextElement(); 151 152 if ((param != null) && (param.value() != null)) 153 buf.append(' ').append(param.convert2Xml()); 154 } 155 156 if (isAtom) buf.append("/>"); 157 else buf.append('>'); 158 159 return new String (buf); 160 } 161 } 164 165 | Popular Tags |