1 5 14 package com.teamkonzept.lib.templates; 15 16 import java.io.*; 17 18 import com.oroinc.text.regex.*; 19 20 import com.teamkonzept.lib.*; 21 22 28 public class TKScopeTag extends TKLabelTag { 29 public static final int TAG_TYPE = TKSwitchTag.TAG_TYPE+1; ; 30 public TKTemplateSyntax scopeText; 31 32 40 public TKScopeTag( TKTemplateSyntax parent, String def, PatternMatcherInput matcherInput, boolean hasSubTags ) throws TKTemplateSyntaxException 41 { 42 super( parent, def, hasSubTags ); 43 try { 44 scopeText = parent.newChild( matcherInput, parent.getSource() ); 45 } 46 catch (ArrayIndexOutOfBoundsException e) { throw new TKTemplateSyntaxException(parent.getSource(),"NOEND","SCOPE", def); 48 } 49 checkError(scopeText,"SCOPE", def); 50 } 51 52 59 public String apply( TKTemplateData td ) throws TKTemplateSyntaxException 60 { 61 String label = getLabel(td); 62 Object oldScope = td.getVariable("SCOPE"); 63 td.setLocalVariable( "SCOPE", label ); 64 String result = scopeText.apply( td ); 65 if( oldScope == null ) { 66 td.removeVariable( "SCOPE" ); 67 } 68 else { 69 td.setLocalVariable( "SCOPE", oldScope ); 70 } 71 return result; 72 } 73 74 82 public void apply(TKTemplateData td, Writer writer) 83 throws TKTemplateSyntaxException, IOException 84 { 85 String label = getLabel(td); 86 Object oldScope = td.getVariable("SCOPE"); 87 td.setLocalVariable( "SCOPE", label ); 88 scopeText.apply( td, writer ); 89 if( oldScope == null ) { 90 td.removeVariable( "SCOPE" ); 91 } 92 else { 93 td.setLocalVariable( "SCOPE", oldScope ); 94 } 95 } 96 97 } 98 99 | Popular Tags |