KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > uitags > tag > search > SearchTag


1 /**
2  * Nov 23, 2006
3  *
4  * Copyright 2004 uitags
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package net.sf.uitags.tag.search;
19
20 import javax.servlet.jsp.JspException JavaDoc;
21
22 import net.sf.uitags.tag.AbstractUiTag;
23 import net.sf.uitags.tagutil.TaglibProperties;
24 import net.sf.uitags.tagutil.validation.RuntimeValidator;
25 import net.sf.uitags.util.StringUtils;
26 import net.sf.uitags.util.Template;
27
28 /**
29  * Generates JS code to turn an element into a search trigger.
30  *
31  * @author hgani
32  * @version $Id$
33  */

34 public class SearchTag extends AbstractUiTag {
35
36   ///////////////////////////////
37
////////// Constants //////////
38
///////////////////////////////
39

40   /**
41    * Serial Version UID.
42    */

43   private static final long serialVersionUID = 100L;
44
45
46
47   ///////////////////////////////////////////////
48
////////// Property keys (constants) //////////
49
///////////////////////////////////////////////
50

51   private static final String JavaDoc PROP_EVENT = "search.on";
52   private static final String JavaDoc PROP_INIT = "search.searchInitially";
53
54
55
56   ////////////////////////////
57
////////// Fields //////////
58
////////////////////////////
59

60   /**
61    * The "injectTo" tag attribute
62    */

63   private String JavaDoc injectTo;
64   /**
65    * The "injectToName" tag attribute
66    */

67   private String JavaDoc injectToName;
68   /**
69    * The "on" tag attribute
70    */

71   private String JavaDoc eventName;
72   /**
73    * The "searchStrategy" tag attribute
74    */

75   private String JavaDoc searchStrategy;
76   /**
77    * The "targetPopulator" tag attribute
78    */

79   private String JavaDoc targetPopulator;
80   /**
81    * The "listener" tag attribute
82    */

83   private String JavaDoc listener;
84   /**
85    * The "searchInitially" tag attribute
86    */

87   private Boolean JavaDoc searchInitially;
88
89
90
91   //////////////////////////////////
92
////////// Constructors //////////
93
//////////////////////////////////
94

95   /**
96    * Default constructor.
97    */

98   public SearchTag() {
99     super();
100   }
101
102
103
104   ///////////////////////////////////////////
105
////////// Tag attribute setters //////////
106
///////////////////////////////////////////
107

108   /**
109    * Tag attribute setter.
110    *
111    * @param val value of the tag attribute
112    */

113   public void setInjectTo(String JavaDoc val) {
114     this.injectTo = val;
115   }
116
117   /**
118    * Tag attribute setter.
119    *
120    * @param val value of the tag attribute
121    */

122   public void setInjectToName(String JavaDoc val) {
123     this.injectToName = val;
124   }
125
126   /**
127    * Tag attribute setter.
128    *
129    * @param val value of the tag attribute
130    */

131   public void setOn(String JavaDoc val) {
132     this.eventName = val;
133   }
134
135   /**
136    * Tag attribute setter.
137    *
138    * @param val value of the tag attribute
139    */

140   public void setSearchStrategy(String JavaDoc val) {
141     this.searchStrategy = val;
142   }
143
144   /**
145    * Tag attribute setter.
146    *
147    * @param val value of the tag attribute
148    */

149   public void setTargetPopulator(String JavaDoc val) {
150     this.targetPopulator = val;
151   }
152
153   /**
154    * Tag attribute setter.
155    *
156    * @param val value of the tag attribute
157    */

158   public void setListener(String JavaDoc val) {
159     this.listener = val;
160   }
161
162   /**
163    * Tag attribute setter.
164    *
165    * @param val value of the tag attribute
166    */

167   public void setSearchInitially(Boolean JavaDoc val) {
168     this.searchInitially = val;
169   }
170
171
172
173   ///////////////////////////////
174
////////// Tag logic //////////
175
///////////////////////////////
176

177   /**
178    * Instructs web container to evaluate the tag's body.
179    *
180    * @see javax.servlet.jsp.tagext.Tag#doStartTag()
181    * @return <code>EVAL_BODY_INCLUDE</code>
182    * @throws JspException to communicate error
183    */

184   public int doStartTag() throws JspException JavaDoc {
185     return EVAL_BODY_INCLUDE;
186   }
187
188   /**
189    * Prints out HTML code to construct the button.
190    *
191    * @return <code>EVAL_PAGE</code>
192    * @throws JspException to communicate error
193    */

194   public int doEndTag() throws JspException JavaDoc {
195     RuntimeValidator.assertAttributeExclusive(
196         "injectTo", this.injectTo, "injectToName", this.injectToName);
197     RuntimeValidator.assertEitherSpecified(
198         "injectTo", this.injectTo, "injectToName", this.injectToName);
199
200     TaglibProperties props = TaglibProperties.getInstance();
201     props.setRuntimeProperty(PROP_EVENT, this.eventName);
202     props.setRuntimeProperty(PROP_INIT, StringUtils.toStringOrNull(this.searchInitially));
203
204     Template tpl = Template.forName(Template.SEARCH);
205     tpl.map("injectTo", this.injectTo);
206     tpl.map("injectToName", this.injectToName);
207     tpl.map("triggerEvent", props.get(PROP_EVENT));
208     tpl.map("searchStrategy", this.searchStrategy);
209     tpl.map("targetPopulator", this.targetPopulator);
210     tpl.map("listener", this.listener);
211     tpl.map("searchInitially", Boolean.valueOf(props.get(PROP_INIT)));
212     println(tpl.evalToString());
213
214     return EVAL_PAGE;
215   }
216 }
217
Popular Tags