KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jresearch > gossip > tags > ConfiguratorTag


1 /*
2  * $$Id$$
3  *
4  * ***** BEGIN LICENSE BLOCK *****
5  * The contents of this file are subject to the Mozilla Public License
6  * Version 1.1 (the "License"); you may not use this file except in
7  * compliance with the License. You may obtain a copy of the License
8  * at http://www.mozilla.org/MPL/
9  *
10  * Software distributed under the License is distributed on an "AS IS"
11  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
12  * the License for the specific language governing rights and
13  * limitations under the License.
14  *
15  * The Original Code is JGossip forum code.
16  *
17  * The Initial Developer of the Original Code is the JResearch, Org.
18  * Portions created by the Initial Developer are Copyright (C) 2004
19  * the Initial Developer. All Rights Reserved.
20  *
21  * Contributor(s):
22  * Dmitry Belov <bel@jresearch.org>
23  *
24  * ***** END LICENSE BLOCK ***** */

25 package org.jresearch.gossip.tags;
26
27 import java.io.IOException JavaDoc;
28
29 import javax.servlet.jsp.JspException JavaDoc;
30 import javax.servlet.jsp.JspWriter JavaDoc;
31 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
32
33 import org.jresearch.gossip.configuration.Configurator;
34 import org.jresearch.gossip.exception.ConfiguratorException;
35 import org.jresearch.gossip.util.HtmlCodec;
36
37 /**
38  * DOCUMENT ME!
39  *
40  * @author dbelov
41  */

42 public class ConfiguratorTag extends TagSupport JavaDoc {
43     private static Configurator config;
44
45     protected String JavaDoc key;
46
47     private boolean quote;
48
49     /**
50      * DOCUMENT ME!
51      *
52      * @return DOCUMENT ME!
53      *
54      * @throws JspException
55      * DOCUMENT ME!
56      */

57     public int doStartTag() throws JspException JavaDoc {
58         String JavaDoc param = null;
59
60         try {
61             param = getConfigurator().get(key);
62         } catch (ConfiguratorException e1) {
63             throw new JspException JavaDoc(e1);
64         }
65
66         if (this.quote) {
67             HtmlCodec.encode(param);
68         }
69
70         JspWriter JavaDoc out = pageContext.getOut();
71
72         try {
73             out.print(param);
74         } catch (IOException JavaDoc e) {
75             throw new JspException JavaDoc(e);
76         }
77
78         return (SKIP_BODY);
79     }
80
81     protected static Configurator getConfigurator() {
82         if (config == null) {
83             config = Configurator.getInstance();
84         }
85
86         return config;
87     }
88
89     /**
90      * DOCUMENT ME!
91      *
92      * @return
93      */

94     public String JavaDoc getKey() {
95         return key;
96     }
97
98     /**
99      * DOCUMENT ME!
100      *
101      * @param string
102      */

103     public void setKey(String JavaDoc string) {
104         key = string;
105     }
106
107     /**
108      * DOCUMENT ME!
109      *
110      * @return
111      */

112     public boolean isQuote() {
113         return quote;
114     }
115
116     /**
117      * DOCUMENT ME!
118      *
119      * @param b
120      */

121     public void setQuote(boolean b) {
122         quote = b;
123     }
124 }
125
Popular Tags