View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  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,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.myfaces.custom.dojo;
21  
22  import javax.faces.component.UIOutput;
23  import javax.faces.context.FacesContext;
24  
25  
26  /**
27   * Default component for the dojo intializer
28   * <br/>
29   * This component is purely non visual, and serves for
30   * quick hacking, and prototyping the dojo toolkit within
31   * verbatimed html.
32   * <br/>
33   * Dojo initializer helper tag for debugging and communication flags. 
34   * This tag encapsules the Dojo DjConfig meta configuration and also 
35   * adds the needed dojo required functionality.
36   *
37   * @JSFComponent
38   *   name = "t:dojoInitializer"
39   *   tagClass = "org.apache.myfaces.custom.dojo.DojoInitializerTag"
40   *
41   * @JSFJspProperty name = "converter" tagExcluded = "true"
42   * @JSFJspProperty name = "value" tagExcluded = "true"
43   * @author Werner Punz (latest modification by $Author: lu4242 $)
44   * @version $Revision: 672986 $ $Date: 2008-06-30 23:13:55 -0500 (Mon, 30 Jun 2008) $
45   */
46  public class DojoInitializer extends UIOutput {
47  
48      public static final String COMPONENT_TYPE        = "org.apache.myfaces.DojoInitializer";
49      public static final String DEFAULT_RENDERER_TYPE = "org.apache.myfaces.DojoInitializerRenderer";
50      public static final String COMPONENT_FAMILY      = "javax.faces.Output";
51      Boolean                    _debugConsole         = null;
52      DojoConfig                 _dojoConfig           = new DojoConfig();
53      Boolean                    _expanded             = null;
54      String                     _provide              = null;
55      String                     _require              = null;
56      Boolean                    _development          = null;
57      
58      //we handle that specifically to speed things up (we do not want an NxN runtime complexity via enforced
59      //reflection in the utils
60      boolean dojoConfigParamSet = false;
61  
62      public DojoInitializer() {
63          super();
64          setRendererType(DEFAULT_RENDERER_TYPE);
65      }
66  
67      /**
68       * Triggers a standard dojo allowQueryConfig as defined
69       * by the <a href="http://dojotoolkit.org/">Dojo Toolkit</a>.
70       * If someone has additional infos about this tag,
71       * please fill in here.
72       * 
73       * @JSFProperty
74       */
75      public Boolean getAllowQueryConfig() {
76          return _dojoConfig.getAllowQueryConfig();
77      }
78  
79      /**
80       * Triggers a standard dojo baseScriptUri as defined by the
81       * <a href="http://dojotoolkit.org/">Dojo Toolkit</a>
82       * <br />
83       * <br />
84       * Allows the alteration of the dojo loading root path
85       * used by require.
86       * 
87       * @JSFProperty
88       */
89      public String getBaseScriptUri() {
90          return _dojoConfig.getBaseScriptUri();
91      }
92  
93      /**
94       * Triggers a standard dojo bindEncoding as defined by the
95       * <a href="http://dojotoolkit.org/">Dojo Toolkit</a>
96       * 
97       * Although this control most of the times is not
98       * needed one usage in plain jsf applications can be
99       * thought of. The changing of the bind encodings, if
100      * you check the parameter list of the control
101      * <b>ioSendTransport</b>
102      * can be used to change this encoding to any encoding
103      * parameter needed. This can be used to change the
104      * internal ajax request encodings of various controls
105      * in a global manner.
106      * 
107      * @JSFProperty
108      */
109     public String getBindEncoding() {
110         return _dojoConfig.getBindEncoding();
111     }
112 
113     public String getComponentType() {
114         return COMPONENT_TYPE;
115     }
116 
117     /**
118      * Triggers a standard dojo debug as defined by the
119      * <a href="http://dojotoolkit.org/">Dojo Toolkit</a>
120      * <br />
121      * <br />
122      * Enables the dojo debugging framework. The usage of
123      * dojo.debug causes output to be displayed in either
124      * the current container or a target container, if one
125      * is set.
126      * 
127      * @JSFProperty
128      */
129     public Boolean getDebug() {
130         return _dojoConfig.getDebug();
131     }
132 
133     /**
134      * Triggers a standard dojo debugAtAllCosts as defined by the
135      * <a href="http://dojotoolkit.org/">Dojo Toolkit</a>
136      * <br />
137      * Tries to enforce debugging even if the browser
138      * version does not allow it to work properlys
139      * 
140      * @JSFProperty
141      */
142     public Boolean getDebugAtAllCosts() {
143         return _dojoConfig.getDebugAtAllCosts();
144     }
145 
146     /**
147      * Triggers a standard dojo debugConsole as defined by the
148      * <a href="http://dojotoolkit.org/">Dojo Toolkit</a>
149      * <br />
150      * <br />
151      * This flag pops up a separate in frame floating
152      * window which receives the debugging output.
153      * <br />
154      * <br />
155      * Note: This flag only works if debugging is enabled
156      * generally via the debug="true" flag set
157      * 
158      * @JSFProperty
159      */
160     public Boolean getDebugConsole() {
161         return _debugConsole;
162     }
163 
164     /**
165      * Triggers a standard dojo debugContainerId as defined by the
166      * <a href="http://dojotoolkit.org/">Dojo Toolkit</a>
167      * <br />
168      * <br />
169      * This flag notifies the Dojo toolkit about the id
170      * which should receive the debug output. Dojo has a
171      * full debugging framework in it which allows to turn
172      * on debug output via a logging mechanism @see
173      * dojo.debug() for further references.
174      * <br />
175      * <br />
176      * The debugging output is not limited to the current
177      * container triggering the debugging statement any
178      * container can receive the debugging output this flag
179      * is the flag which has to be set for setting a
180      * different target id for the debugging output.
181      * 
182      * @JSFProperty
183      */
184     public String getDebugContainerId() {
185         return _dojoConfig.getDebugContainerId();
186     }
187 
188     public DojoConfig getDojoConfig() {
189         return _dojoConfig;
190     }
191 
192     /**
193      * Triggers a standard dojo development as defined by the
194      * <a href="http://dojotoolkit.org/">Dojo Toolkit</a>
195      * If you can find additional info about this attribute
196      * please fill in here
197      * 
198      * @JSFProperty
199      */
200     public Boolean getExpanded() {
201         return _expanded;
202     }
203 
204     public String getFamily() {
205         return COMPONENT_FAMILY;
206     }
207 
208     /**
209      * Triggers a standard dojo ignoreClassNames as defined
210      * by the
211      * <a href="http://dojotoolkit.org/">Dojo Toolkit</a>
212      * <br />
213      * <br />
214      * This attribute turns on the case insensitive
215      * handling of classnames by require and other Dojo
216      * class loader mechanisms.
217      * <br />
218      * <br />
219      * Case sensitivity is by default turned
220      * <b>on</b>.
221      * 
222      * @JSFProperty
223      */
224     public Boolean getIgnoreClassNames() {
225         return _dojoConfig.getIgnoreClassNames();
226     }
227 
228     /**
229      * Dojo in its underlying architecture allows various
230      * options of server-client side communication. This
231      * setting allows the alteration of the communication
232      * layer to a different protocol. Currently only in
233      * usage is xmlhttprequest, hence setting this encoding
234      * will not change too much. But different encodings
235      * like iframe are planned for the future.
236      * 
237      * @JSFProperty
238      */
239     public String getIoSendTransport() {
240         return _dojoConfig.getIoSendTransport();
241     }
242 
243     /**
244      * Triggers a standard dojo parseWidgets as defined by the
245      * <a href="http://dojotoolkit.org/">Dojo Toolkit</a>
246      * 
247      * This parameter is used to turn on or off the dojo
248      * widgeting parsing. The parsing is not used by
249      * MyFaces for various reasons, but can be used by your
250      * own html code.
251      * <br />
252      * <br />
253      * For addititional information regarding the Dojo
254      * Toolkit widget parsing, visit the
255      * <br />
256      * <a href="http://dojotoolkit.org/">Dojo Toolkit Homepage</a>
257      * 
258      * @JSFProperty
259      */
260     public Boolean getParseWidgets() {
261         return _dojoConfig.getParseWidgets();
262     }
263 
264     /**
265      * Dojo uses internally back button blockers to avoid
266      * problems with ajax requests causing the back button,
267      * to move out of the back page navigation order.
268      * Sometimes this behavior is not wanted and can be
269      * turned off with this on a global scale;
270      * 
271      * @JSFProperty
272      */
273     public Boolean getPreventBackButtonFix() {
274         return _dojoConfig.getPreventBackButtonFix();
275     }
276 
277     /**
278      * Triggers a standard dojo provide as defined by the
279      * <a href="http://dojotoolkit.org/">Dojo Toolkit</a>
280      * 
281      * @JSFProperty
282      */
283     public String getProvide() {
284         return _provide;
285     }
286 
287     public String getRendererType() {
288         return DojoInitializerRenderer.RENDERER_TYPE;
289     }
290 
291     /**
292      * Triggers a standard dojo provide as defined by the
293      * <a href="http://dojotoolkit.org/">Dojo Toolkit</a>
294      * 
295      * @JSFProperty
296      */
297     public String getRequire() {
298         return _require;
299     }
300 
301     /**
302      * Triggers a standard dojo development as defined by the
303      * <a href="http://dojotoolkit.org/">Dojo Toolkit</a>
304      * If you can find additional info about this attribute
305      * please fill in here
306      * 
307      * @JSFProperty
308      */
309     public String getSearchIds() {
310         return _dojoConfig.getSearchIds();
311     }
312     
313     /**
314      * Triggers a standard dojo development as defined by the
315      * <a href="http://dojotoolkit.org/">Dojo Toolkit</a>
316      * If this parameter is set to true. The expanded
317      * debuggable version of dojo is included
318      * if set to false the compressed one is included.
319      * 
320      * @JSFProperty
321      */
322     public Boolean getDevelopment() {
323         return _dojoConfig.getDevelopment();
324     }
325 
326     public Object getValue() {
327         return "DojoInitializers";
328     }
329 
330     public boolean isDojoConfigParamSet() {
331         return dojoConfigParamSet;
332     }
333 
334     public void restoreState(FacesContext context, Object state) {
335         Object[] values = (Object[]) state;
336         super.restoreState(context, values[0]);
337         setAllowQueryConfig((Boolean) values[1]);
338         setBaseScriptUri((String) values[2]);
339         setBindEncoding((String) values[3]);
340         setDebug((Boolean) values[4]);
341         setDebugContainerId((String) values[5]);
342         setIgnoreClassNames((Boolean) values[6]);
343         setIoSendTransport((String) values[7]);
344         setParseWidgets((Boolean) values[8]);
345         setPreventBackButtonFix((Boolean) values[9]);
346         setSearchIds((String) values[10]);
347         _require      = (String) values[11];
348         _provide      = (String) values[12];
349         _debugConsole = (Boolean) values[13];
350         setDebugAtAllCosts((Boolean) values[14]);
351         _expanded = (Boolean) values[15];
352         _development = (Boolean) values[16];
353     }
354 
355     public Object saveState(FacesContext context) {
356         Object[] values = new Object[17];
357         values[0]  = super.saveState(context);
358         values[1]  = _dojoConfig.getAllowQueryConfig();
359         values[2]  = _dojoConfig.getBaseScriptUri();
360         values[3]  = _dojoConfig.getBindEncoding();
361         values[4]  = _dojoConfig.getDebug();
362         values[5]  = _dojoConfig.getDebugContainerId();
363         values[6]  = _dojoConfig.getIgnoreClassNames();
364         values[7]  = _dojoConfig.getIoSendTransport();
365         values[8]  = _dojoConfig.getParseWidgets();
366         values[9]  = _dojoConfig.getPreventBackButtonFix();
367         values[10] = _dojoConfig.getSearchIds();
368         values[11] = _require;
369         values[12] = _provide;
370         values[13] = _debugConsole;
371         values[14] = _dojoConfig.getDebugAtAllCosts();
372         values[15] = _expanded;
373         values[16] = _development;
374         
375         return values;
376     }
377 
378     public void setAllowQueryConfig(Boolean allowQueryConfig) {
379 
380         if (allowQueryConfig != null) {
381             dojoConfigParamSet = true;
382             DojoUtils.getDjConfigInstance(FacesContext.getCurrentInstance()).setAllowQueryConfig(allowQueryConfig);
383         }
384 
385         _dojoConfig.setAllowQueryConfig(allowQueryConfig);
386 
387     }
388 
389     public void setBaseScriptUri(String baseScriptUri) {
390 
391         if (baseScriptUri != null) {
392             dojoConfigParamSet = true;
393             DojoUtils.getDjConfigInstance(FacesContext.getCurrentInstance()).setBaseScriptUri(baseScriptUri);
394         }
395 
396         _dojoConfig.setBaseScriptUri(baseScriptUri);
397     }
398 
399     public void setBindEncoding(String bindEncoding) {
400 
401         if (bindEncoding != null) {
402             dojoConfigParamSet = true;
403             DojoUtils.getDjConfigInstance(FacesContext.getCurrentInstance()).setBindEncoding(bindEncoding);
404         }
405 
406         _dojoConfig.setBindEncoding(bindEncoding);
407     }
408 
409     public void setDebug(Boolean debug) {
410 
411         if (debug != null) {
412             dojoConfigParamSet = true;
413             DojoUtils.getDjConfigInstance(FacesContext.getCurrentInstance()).setDebug(debug);
414         }
415 
416         _dojoConfig.setDebug(debug);
417 
418     }
419 
420     public void setDebugAtAllCosts(Boolean debugAtAllCosts) {
421 
422         if (debugAtAllCosts != null) {
423             dojoConfigParamSet = true;
424             DojoUtils.getDjConfigInstance(FacesContext.getCurrentInstance()).setDebugAtAllCosts(debugAtAllCosts);
425         }
426 
427         _dojoConfig.setDebugAtAllCosts(debugAtAllCosts);
428     }
429 
430     public void setDebugConsole(Boolean debugConsole) {
431         this._debugConsole = debugConsole;
432     }
433 
434     public void setDebugContainerId(String debugContainerId) {
435 
436         if (debugContainerId != null) {
437             dojoConfigParamSet = true;
438             DojoUtils.getDjConfigInstance(FacesContext.getCurrentInstance()).setDebugContainerId(debugContainerId);
439         }
440 
441         _dojoConfig.setDebugContainerId(debugContainerId);
442     }
443 
444     public void setDojoConfigParamSet(boolean dojoConfigParamSet) {
445         this.dojoConfigParamSet = dojoConfigParamSet;
446     }
447 
448     public void setExpanded(Boolean expanded) {
449 
450         //we have a logical or over all expanded tags
451         if (expanded != null) {
452             dojoConfigParamSet = true;
453             DojoUtils.setExpanded(FacesContext.getCurrentInstance(), expanded);
454         }
455 
456         _expanded = expanded;
457     }
458 
459     public void setIgnoreClassNames(Boolean ignoreClassNames) {
460 
461         if (ignoreClassNames != null) {
462             dojoConfigParamSet = true;
463             DojoUtils.getDjConfigInstance(FacesContext.getCurrentInstance()).setIgnoreClassNames(ignoreClassNames);
464         }
465 
466         _dojoConfig.setIgnoreClassNames(ignoreClassNames);
467     }
468 
469     public void setIoSendTransport(String ioSendTransport) {
470 
471         if (ioSendTransport != null) {
472             dojoConfigParamSet = true;
473             DojoUtils.getDjConfigInstance(FacesContext.getCurrentInstance()).setIoSendTransport(ioSendTransport);
474         }
475 
476         _dojoConfig.setIoSendTransport(ioSendTransport);
477 
478     }
479 
480     public void setParseWidgets(Boolean parseWidgets) {
481 
482         if (parseWidgets != null) {
483             dojoConfigParamSet = true;
484             DojoUtils.getDjConfigInstance(FacesContext.getCurrentInstance()).setParseWidgets(parseWidgets);
485         }
486 
487         _dojoConfig.setParseWidgets(parseWidgets);
488     }
489 
490     public void setPreventBackButtonFix(Boolean preventBackButtonFix) {
491 
492         if (preventBackButtonFix != null) {
493             dojoConfigParamSet = true;
494             DojoUtils.getDjConfigInstance(FacesContext.getCurrentInstance()).setPreventBackButtonFix(preventBackButtonFix);
495         }
496 
497         _dojoConfig.setPreventBackButtonFix(preventBackButtonFix);
498     }
499 
500     public void setProvide(String provide) {
501         this._provide = provide;
502     }
503 
504     public void setRequire(String required) {
505         this._require = required;
506     }
507 
508     public void setSearchIds(String searchIds) {
509 
510         if (searchIds != null) {
511             dojoConfigParamSet = true;
512             DojoUtils.getDjConfigInstance(FacesContext.getCurrentInstance()).setSearchIds(searchIds);
513         }
514 
515         _dojoConfig.setSearchIds(searchIds);
516     }
517 
518  
519      public void setDevelopment(Boolean development)
520     {
521          if (development != null) {
522              dojoConfigParamSet = true;
523              DojoUtils.getDjConfigInstance(FacesContext.getCurrentInstance()).setDevelopment(development);
524          }
525          _development = development;
526     }
527 
528  
529 }