KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > xdoclet > modules > apache > bsf > BsfEngineTagHandler


1 /*
2  * Copyright (c) 2001, 2002 The XDoclet team
3  * All rights reserved.
4  */

5 package xdoclet.modules.apache.bsf;
6
7 import java.util.Properties JavaDoc;
8
9 import org.apache.commons.logging.Log;
10 import xdoclet.XDocletException;
11 import xdoclet.modules.apache.ScriptEngineTagHandler;
12
13 import xdoclet.template.TemplateException;
14 import xdoclet.util.LogUtil;
15
16 /**
17  * This is a tag handler able to execute BSF engine on a block!
18  *
19  * @author zluspai
20  * @created July 16, 2003
21  * @xdoclet.taghandler namespace="Bsf"
22  */

23 public class BsfEngineTagHandler extends ScriptEngineTagHandler
24 {
25     private BsfSubTemplateEngine bsfEngine;
26
27     /**
28      * Get a value of a BSF variable
29      *
30      * @param attributes
31      * @return
32      * @exception XDocletException
33      * @doc.tag type="content"
34      */

35     public String JavaDoc getVariable(Properties JavaDoc attributes) throws XDocletException
36     {
37         return getSubTemplateVariable(getBsfEngine(), attributes);
38     }
39
40     /**
41      * Evaluates the body block with the BSF script If the silent="yes" attribute is set then the Generator will not
42      * produce any output, but the template will run. If the disable="yes" attribute is set then the Velocity template
43      * will not run at all.
44      *
45      * @param template The body of the block tag
46      * @param attributes The attributes of the template tag
47      * @exception TemplateException
48      * @doc.tag type="block"
49      */

50     public void generator(String JavaDoc template, Properties JavaDoc attributes) throws TemplateException
51     {
52         Log log = LogUtil.getLog(BsfEngineTagHandler.class, "generator");
53
54         log.debug("generator() called.");
55         generate(getBsfEngine(), template, attributes);
56     }
57
58     /**
59      * Clear all BSF variables
60      *
61      * @doc.tag type="content"
62      * @throws XDocletException
63      */

64     public void clearVariables() throws XDocletException
65     {
66         getBsfEngine().clearVariables();
67     }
68
69     private BsfSubTemplateEngine getBsfEngine()
70     {
71         if (bsfEngine == null) {
72             bsfEngine = new BsfSubTemplateEngine();
73         }
74         return bsfEngine;
75     }
76 }
77
78
Popular Tags