1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package com.germinus.easyconf.taglib;
17
18 import com.germinus.easyconf.EasyConf;
19 import javax.servlet.jsp.tagext.BodyTagSupport;
20 import javax.servlet.jsp.JspException;
21 import org.apache.struts.util.RequestUtils;
22
23
24
25 /***
26 * Read a configuration property and expose it as a page variable and attribute
27 * Examples of use:
28 *
29 * >%@ taglib uri="/WEB-INF/tld/easyconf.tld" prefix="easyconf" %>
30 *
31 * >easyconf:configurationObject id="dbConf"
32 * component="test_module"
33 * type="com.germinus.easyconf.example.DatabaseConf"/>
34 * >bean:write name="dbConf" property="tables"/>
35 *
36 * @jsp.tag name="configurationObject" body-content="empty"
37 * tei-class="com.germinus.easyconf.taglib.ConfigurationObjectTei"
38 */
39 public class ConfigurationObjectTag extends BodyTagSupport {
40
41 protected String id = null;
42 protected String component = null;
43 protected String type = "java.lang.Object";
44
45 /***
46 * @jsp.attribute required="true" rtexprvalue="true"
47 */
48 public String getId() {
49 return (this.id);
50 }
51
52 public void setId(String id) {
53 this.id = id;
54 }
55
56 /***
57 * @jsp.attribute required="true" rtexprvalue="true"
58 */
59 public String getComponent() {
60 return component;
61 }
62
63 public void setComponent(String component) {
64 this.component = component;
65 }
66
67 /***
68 * @jsp.attribute required="false" rtexprvalue="true"
69 */
70 public String getType() {
71 return (this.type);
72 }
73
74 public void setType(String type) {
75 this.type = type;
76 }
77
78 /***
79 * Check if we need to evaluate the body of the tag
80 *
81 * @exception javax.servlet.jsp.JspException if a JSP exception has occurred
82 */
83 public int doStartTag() throws JspException {
84 return (EVAL_BODY_BUFFERED);
85
86 }
87
88
89 /***
90 * Save the body content of this tag (if any), or throw a JspException
91 * if the value was already defined.
92 *
93 * @exception JspException if value was defined by an attribute
94 */
95 public int doAfterBody() throws JspException {
96 return (SKIP_BODY);
97
98 }
99
100
101 /***
102 * Retrieve the required property and expose it as a scripting variable.
103 *
104 * @exception JspException if a JSP exception has occurred
105 */
106 public int doEndTag() throws JspException {
107 Object confObj = EasyConf.getConfiguration(component).
108 getConfigurationObject();
109
110 if (confObj == null) {
111 JspException e = new JspException("The value of the configuration object is null. " +
112 "Check the configuration files");
113 RequestUtils.saveException(pageContext, e);
114 throw e;
115 }
116 pageContext.setAttribute(id, confObj);
117 return (EVAL_PAGE);
118 }
119
120 public void release() {
121 super.release();
122 id = null;
123 component = null;
124 type = null;
125 }
126
127
128 }