KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Header: /cvsroot/webman-cms/source/webman/com/teamkonzept/lib/templates/TKScopeTag.java,v 1.13 2001/08/23 10:40:05 alex Exp $
3  *
4  */

5 /**
6  *
7  *
8  * Aufbau: name="TK_CLASSNAME[par_name;class_name:class_value;...]" value="..."
9  * ------------ ----------
10  * primaere Klasse Sekundaere Klasse
11  *
12  * Bsp: name="TK_EV[THE_EVENT;QOR:0.8_0.5]" value="..."
13  */

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 /**
23  * SwitchTag:
24  * <TK_SWITCH:name:[alt=]tmpl;...>
25  * @author $Author: alex $
26  * @version $Revision: 1.13 $
27  */

28 public class TKScopeTag extends TKLabelTag {
29     public static final int TAG_TYPE = TKSwitchTag.TAG_TYPE+1; ;
30     public TKTemplateSyntax scopeText;
31
32     /*******************************************************************
33     /**
34      * Konstruktor 1
35      * Ein Syntaxbaum fuer ein Template wird erzeugt.
36      *
37      * @param String def, Name des Tags
38      * @param boolean hasSubTags
39      */

40     public TKScopeTag( TKTemplateSyntax parent, String JavaDoc 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 JavaDoc e) { //thrown by TKTemplateSyntax.newTag()
47
throw new TKTemplateSyntaxException(parent.getSource(),"NOEND","SCOPE", def);
48         }
49         checkError(scopeText,"SCOPE", def);
50     }
51
52     /*******************************************************************
53     /**
54      * Die apply-Methode von TKSyntax wird aufgerufen und das entsprechende
55      * Template wird included.
56      *
57      * @param TKTemplateData td
58      */

59     public String JavaDoc apply( TKTemplateData td ) throws TKTemplateSyntaxException
60     {
61         String JavaDoc label = getLabel(td);
62         Object JavaDoc oldScope = td.getVariable("SCOPE");
63         td.setLocalVariable( "SCOPE", label );
64         String JavaDoc 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     /*******************************************************************
75     /**
76      * Die apply-Methode von TKSyntax wird aufgerufen und das entsprechende
77      * Template wird included.
78      *
79      * @param td TKTemplateData
80      * @param writer Writer in den der Part geschrieben wird.
81      */

82     public void apply(TKTemplateData td, Writer writer)
83         throws TKTemplateSyntaxException, IOException
84     {
85         String JavaDoc label = getLabel(td);
86         Object JavaDoc 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