001: // @@
002: // @@
003: /*
004: * Wi.Ser Framework
005: *
006: * Version: 1.8.1, 20-September-2007
007: * Copyright (C) 2005 Dirk von der Weiden <dvdw@imail.de>
008: *
009: * This library is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU Lesser General Public
011: * License as published by the Free Software Foundation; either
012: * version 2 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: * Lesser General Public License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library located in LGPL.txt in the
021: * license directory; if not, write to the
022: * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
023: * Boston, MA 02111-1307, USA.
024: *
025: * If this agreement does not cover your requirements, please contact us
026: * via email to get detailed information about the commercial license
027: * or our service offerings!
028: *
029: */
030: // @@
031: package de.ug2t.channel.markup.generic;
032:
033: import java.io.*;
034: import java.util.*;
035:
036: import de.ug2t.connector.*;
037: import de.ug2t.kernel.*;
038:
039: /**
040: * @author Dirk
041: *
042: * date: 11.12.2003 project: JmcFrame_all
043: *
044: * <p>
045: * This class reads a MARKUP template and stores variable and fixed parts in a
046: * list
047: * </p>
048: */
049: public final class MuGenericTemplate implements Serializable {
050: // @@
051:
052: public static void pcmf_clearCache() {
053: // @@
054: }
055:
056: public static MuGenericTemplate pcmf_getMarkupTpl(String xTplName,
057: ACoDataGetter xDg) throws Exception {
058: MuGenericTemplate l_ret = null;
059: // @@
060:
061: l_ret = MuGenericTemplate.pcmf_createNewTpl(xTplName, xDg);
062:
063: // @@
064:
065: return (l_ret);
066: }
067:
068: public static MuGenericTemplate pcmf_createNewTpl(String xTplName,
069: ACoDataGetter xDg) throws Exception {
070: return (new MuGenericTemplate(xTplName, xDg));
071: }
072:
073: private transient HashMap pem_segments = null;
074: private String pem_string = null;
075: private ACoDataGetter pem_dg = null;
076: private Object pem_tplName = null;
077:
078: // @@
079: /**
080: *
081: */
082: public MuGenericTemplate(String xTplName, ACoDataGetter xDg) {
083: try {
084: this .pemf_construct(xDg.pcmf_getString(xTplName));
085: this .pem_tplName = xTplName;
086: this .pem_dg = xDg;
087: } catch (Exception e) {
088: KeLog.pcmf_logException("ug2t", this , e);
089: }
090: }
091:
092: public MuGenericTemplate(String xTpl) throws Exception {
093: this .pemf_construct(xTpl);
094: this .pem_string = xTpl;
095: }
096:
097: private void pemf_construct(String xTpl) {
098: try {
099: pem_segments = new HashMap();
100:
101: String l_sep = "#";
102: xTpl = xTpl.trim();
103: if (xTpl.charAt(0) != '#') {
104: l_sep = xTpl.substring(0, 1);
105: xTpl = xTpl.substring(1, xTpl.length());
106: }
107:
108: StringTokenizer l_tok = new StringTokenizer(xTpl, l_sep,
109: true);
110: String l_var = null;
111: String l_val = null;
112: char l_stok = ' ';
113: while (l_tok.hasMoreTokens()) {
114: l_val = l_tok.nextToken();
115: if (l_var != null) {
116: this .pem_segments.put(l_var, l_val);
117: if (l_tok.hasMoreTokens())
118: l_val = l_tok.nextToken();
119: else
120: break;
121: }
122: if (l_val.length() == 1) {
123: l_stok = l_val.charAt(0);
124: if (l_stok == l_sep.charAt(0)) {
125: l_var = l_tok.nextToken();
126: l_tok.nextToken();
127: }
128: }
129: }
130: } catch (Exception e) {
131: KeLog.pcmf_log("ug2t",
132: "error tokenizing template: " + xTpl, this ,
133: KeLog.ERROR);
134: }
135: }
136:
137: public String pcmf_getRawString(String xSegment) {
138: String l_ret = (String) this .pem_segments.get(xSegment);
139: return (l_ret);
140: };
141:
142: public KeStringTemplate pcmf_getMarkupString(String xSegment) {
143: String l_ret = (String) this .pem_segments.get(xSegment);
144: KeStringTemplate l_tpl = null;
145: if (l_ret != null)
146: l_tpl = new KeStringTemplate(l_ret);
147:
148: return (l_tpl);
149: }
150:
151: public void pcmf_setMarkupString(String xSegment, String xMString) {
152: this .pem_segments.put(xSegment, xMString);
153: }
154:
155: public ArrayList pcmf_getAllMarkupKeys() {
156: return new ArrayList(this.pem_segments.keySet());
157: }
158: }
|