1 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 25 public TKWhileTag( 26 TKTemplateSyntax parent, 27 String 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 e) { throw new TKTemplateSyntaxException(parent.getSource(),"NOEND","WHILE", def); 38 } 39 checkError(listText,"WHILE", def); 40 } 41 42 43 47 public String apply( TKTemplateData td ) throws TKTemplateSyntaxException 48 { 49 StringBuffer result = new StringBuffer (); 50 Eval ev = new Eval(); 51 try { 52 do { 53 String 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 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 result = new StringBuffer (); 73 Eval ev = new Eval(); 74 try { 75 do { 76 String 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 e ) { 86 cat.error( "error in while-tag: ", e ); 87 } 88 writer.write(result.toString()); 89 } 90 91 } 92 93 | Popular Tags |