01: /*
02: * $Header: /cvsroot/webman-cms/source/webman/com/teamkonzept/lib/templates/TKCaseTag.java,v 1.10 2001/08/14 13:48:49 mischa Exp $
03: *
04: */
05: /**
06: *
07: *
08: * Aufbau: name="TK_CLASSNAME[par_name;class_name:class_value;...]" value="..."
09: * ------------ ----------
10: * primaere Klasse Sekundaere Klasse
11: *
12: * Bsp: name="TK_EV[THE_EVENT;QOR:0.8_0.5]" value="..."
13: */package com.teamkonzept.lib.templates;
14:
15: import java.io.*;
16: import com.oroinc.text.regex.*;
17:
18: import com.teamkonzept.lib.*;
19:
20: /**
21: * Ein TK_CASE wird aus dem Template gefiltert
22: * @author $Author: mischa $
23: * @version $Revision: 1.10 $
24: */
25: public class TKCaseTag extends TKLabelTag {
26:
27: public TKTemplateSyntax caseText;
28: static final int TAG_TYPE = TKTrimTag.TAG_TYPE + 1;
29:
30: /*******************************************************************
31: /**
32: * Konstruktor 1
33: * Ein Syntaxbaum fuer ein Template wird erzeugt.
34: *
35: * @param String def, Name des Tags
36: * @param PatternMatcherInput matcherInput,
37: * @param boolean hasSubTags
38: */
39: public TKCaseTag(TKTemplateSyntax parent, String def,
40: PatternMatcherInput matcherInput, boolean hasSubTags)
41: throws TKTemplateSyntaxException {
42:
43: super (parent, def, hasSubTags);
44: try {
45: caseText = parent
46: .newChild(matcherInput, parent.getSource());
47: } catch (ArrayIndexOutOfBoundsException e) { //thrown by TKTemplateSyntax.newTag()
48: throw new TKTemplateSyntaxException(parent.getSource(),
49: "NOEND", "CASE", def);
50: }
51: checkError(caseText, "CASE", def);
52: }
53:
54: /*******************************************************************
55: /**
56: * Der entsprechende CASE-Part des Templates wird bearbeitet
57: *
58: * @param TKTemplateData td
59: * @return den String, der den bearbeiteten Case-Part enthaelt
60: */
61: public String apply(TKTemplateData td)
62: throws TKTemplateSyntaxException {
63: String value = expandVariable(getLabel(td), td, null);
64:
65: if (value != null && value.length() > 0) {
66: return caseText.apply(td);
67: }
68: return null;
69: }
70:
71: /*******************************************************************
72: /**
73: * Der entsprechende CASE-Part des Templates wird bearbeitet
74: *
75: * @param TKTemplateData td
76: * @param Writer writer
77: */
78: public void apply(TKTemplateData td, Writer writer)
79: throws TKTemplateSyntaxException, IOException {
80: StringWriter tmpWriter = new StringWriter();
81: expandVariable(getLabel(td), td, null, tmpWriter);
82: StringBuffer value = tmpWriter.getBuffer();
83:
84: if (value != null && value.length() > 0) {
85: caseText.apply(td, writer);
86: }
87: }
88:
89: }//end class
|