1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.commons.jelly.tags.bsf;
17
18 import org.apache.commons.jelly.JellyException;
19 import org.apache.commons.jelly.Tag;
20 import org.apache.commons.jelly.expression.ExpressionFactory;
21 import org.apache.commons.jelly.impl.TagFactory;
22 import org.apache.commons.jelly.tags.core.CoreTagLibrary;
23 import org.xml.sax.Attributes;
24
25 import org.apache.bsf.BSFEngine;
26 import org.apache.bsf.BSFException;
27
28
29 /*** Describes the Taglib. This class could be generated by XDoclet
30 *
31 * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
32 * @version $Revision: 155420 $
33 */
34 public class BSFTagLibrary extends CoreTagLibrary {
35
36 private BSFExpressionFactory expressionFactory = new BSFExpressionFactory();
37
38 public BSFTagLibrary() {
39 registerTagFactory(
40 "script",
41 new TagFactory() {
42 public Tag createTag(String name, Attributes attributes)
43 throws JellyException {
44 return createScriptTag(name, attributes);
45 }
46 }
47 );
48 }
49
50 public BSFTagLibrary(String language) {
51 this();
52 setLanguage(language);
53 }
54
55 public void setLanguage(String language) {
56 expressionFactory.setLanguage(language);
57 }
58
59 /*** Allows derived tag libraries to use their own factory */
60 protected ExpressionFactory getExpressionFactory() {
61 return expressionFactory;
62 }
63
64 protected BSFEngine getBSFEngine() throws BSFException {
65 return expressionFactory.getBSFEngine();
66 }
67
68 /***
69 * Factory method to create a new ScriptTag with a BSFEngine
70 *
71 * @param name is the name of the tag (typically 'script')
72 * @param attributes the attributes of the tag
73 * @return Tag
74 */
75 protected Tag createScriptTag(String name, Attributes attributes) throws JellyException {
76 try {
77 return new ScriptTag( expressionFactory.getBSFEngine(),
78 expressionFactory.getBSFManager());
79 }
80 catch (BSFException e) {
81 throw new JellyException("Failed to create BSFEngine: " + e, e);
82 }
83 }
84 }