KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > teamkonzept > lib > templates > TKWhileTag


1 /*
2  * $Header: /cvsroot/webman-cms/source/webman/com/teamkonzept/lib/templates/TKWhileTag.java,v 1.11 2001/06/11 09:14:09 alex Exp $
3  *
4  */

5 package com.teamkonzept.lib.templates;
6
7 import java.io.*;
8
9 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 {
16     private static final Category cat = Category.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(
26         TKTemplateSyntax parent,
27         String JavaDoc def,
28         PatternMatcherInput matcherInput,
29         boolean hasSubTags
30     ) throws TKTemplateSyntaxException
31     {
32         super( parent, def, hasSubTags );
33         try {
34             listText = parent.newChild( matcherInput, parent.getSource() );
35         }
36         catch (ArrayIndexOutOfBoundsException JavaDoc e) { //thrown by TKTemplateSyntax.newTag()
37
throw new TKTemplateSyntaxException(parent.getSource(),"NOEND","WHILE", def);
38         }
39         checkError(listText,"WHILE", def);
40     }
41
42
43     /*******************************************************************
44     /**
45      *
46      */

47     public String JavaDoc apply( TKTemplateData td ) throws TKTemplateSyntaxException
48     {
49         StringBuffer JavaDoc result = new StringBuffer JavaDoc();
50         Eval ev = new Eval();
51         try {
52             do {
53                 String JavaDoc expression = getLabel( td );
54                 if( Math.abs( ev.eval( expression )) > 0.00001 ) {
55                     result.append( listText.apply( td ) );
56                 }
57                 else {
58                     break;
59                 }
60             } while( true );
61         }
62         catch( Exception JavaDoc e ) {
63             cat.error( "error in while-tag: ",e);
64         }
65         return result.toString();
66     }
67
68
69     public void apply(TKTemplateData td, Writer writer)
70         throws TKTemplateSyntaxException, IOException
71     {
72         StringBuffer JavaDoc result = new StringBuffer JavaDoc();
73         Eval ev = new Eval();
74         try {
75             do {
76                 String JavaDoc expression = getLabel( td );
77                 if( Math.abs( ev.eval( expression )) > 0.00001 ) {
78                     result.append( listText.apply( td ) );
79                 }
80                 else {
81                     break;
82                 }
83             } while( true );
84         }
85         catch( Exception JavaDoc e ) {
86             cat.error( "error in while-tag: ", e );
87         }
88         writer.write(result.toString());
89     }
90
91 }
92
93
Popular Tags