01: /*
02: * $Header: /cvsroot/webman-cms/source/webman/com/teamkonzept/lib/templates/TKWhileTag.java,v 1.11 2001/06/11 09:14:09 alex Exp $
03: *
04: */
05: package com.teamkonzept.lib.templates;
06:
07: import java.io.*;
08:
09: import com.oroinc.text.regex.*;
10: import org.apache.log4j.Category;
11: import com.teamkonzept.lib.*;
12: import com.teamkonzept.lib.math.*;
13:
14: public class TKWhileTag extends TKLabelTag {
15: private static final Category cat = Category
16: .getInstance(TKWhileTag.class);
17:
18: public static final int TAG_TYPE = TKExpressionTag.TAG_TYPE + 1;
19: public TKTemplateSyntax listText;
20:
21: /**
22: * Konstruktor 1
23: * Ein Syntaxbaum fuer ein Template wird erzeugt.
24: */
25: public TKWhileTag(TKTemplateSyntax parent, String def,
26: PatternMatcherInput matcherInput, boolean hasSubTags)
27: throws TKTemplateSyntaxException {
28: super (parent, def, hasSubTags);
29: try {
30: listText = parent
31: .newChild(matcherInput, parent.getSource());
32: } catch (ArrayIndexOutOfBoundsException e) { //thrown by TKTemplateSyntax.newTag()
33: throw new TKTemplateSyntaxException(parent.getSource(),
34: "NOEND", "WHILE", def);
35: }
36: checkError(listText, "WHILE", def);
37: }
38:
39: /*******************************************************************
40: /**
41: *
42: */
43: public String apply(TKTemplateData td)
44: throws TKTemplateSyntaxException {
45: StringBuffer result = new StringBuffer();
46: Eval ev = new Eval();
47: try {
48: do {
49: String expression = getLabel(td);
50: if (Math.abs(ev.eval(expression)) > 0.00001) {
51: result.append(listText.apply(td));
52: } else {
53: break;
54: }
55: } while (true);
56: } catch (Exception e) {
57: cat.error("error in while-tag: ", e);
58: }
59: return result.toString();
60: }
61:
62: public void apply(TKTemplateData td, Writer writer)
63: throws TKTemplateSyntaxException, IOException {
64: StringBuffer result = new StringBuffer();
65: Eval ev = new Eval();
66: try {
67: do {
68: String expression = getLabel(td);
69: if (Math.abs(ev.eval(expression)) > 0.00001) {
70: result.append(listText.apply(td));
71: } else {
72: break;
73: }
74: } while (true);
75: } catch (Exception e) {
76: cat.error("error in while-tag: ", e);
77: }
78: writer.write(result.toString());
79: }
80:
81: }
|