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 java.io.Serializable;
23  
24  
25  /**
26   * Dojo configuration holder helper
27   * this is a helper class to generate
28   * a dojo configuration
29   * if a null value is set the toString
30   * ignores the djconfig
31   *
32   * the toString method generates a full djconfig
33   *
34   * Warning if you adjust the dojo config params
35   * do it before rendering
36   * because this stuff is shared in the request
37   * as a singleton value in normal circumstances!
38   *
39   * (unless you want to influence the dojo config
40   * seriously afterwards please, follow this guideline
41   * use the decode phase or something similar if not available)
42   *
43   * @author Werner Punz (latest modification by $Author: grantsmith $)
44   * @version $Revision: 472638 $ $Date: 2006-11-08 15:54:13 -0500 (Wed, 08 Nov 2006) $
45   */
46  public class DojoConfig implements Serializable {
47  
48      /**
49       *
50       */
51      private static final long   serialVersionUID      = 1L;
52      private static final String CONFIG_FOOTER         = "}; \n";
53      private static final String CONFIG_HEADER         = "var djConfig = { \n";
54      public static String        ATTR_DOJO_TYPE        = "dojoType";
55      Boolean                     _allowQueryConfig     = null;
56      String                      _baseScriptUri        = null;
57      String                      _bindEncoding         = null;
58      Boolean                     _debug                = null;
59      Boolean                     _debugAtAllCosts      = null;
60      String                      _debugContainerId     = null;
61      Boolean                     _ignoreClassNames     = null;
62      String                      _ioSendTransport      = null;
63      Boolean                     _parseWidgets         = null;
64      Boolean                     _preventBackButtonFix = null;
65      String                      _searchIds            = null;
66      Boolean                     _development           = null;
67      
68      //getters and setters for the djconfig
69      public Boolean getAllowQueryConfig() {
70          return _allowQueryConfig;
71      }
72  
73      public String getBaseScriptUri() {
74          return _baseScriptUri;
75      }
76  
77      public String getBindEncoding() {
78          return _bindEncoding;
79      }
80  
81      public Boolean getDebug() {
82          return _debug;
83      }
84  
85      public Boolean getDebugAtAllCosts() {
86          return _debugAtAllCosts;
87      }
88  
89      public String getDebugContainerId() {
90          return _debugContainerId;
91      }
92  
93      public Boolean getIgnoreClassNames() {
94          return _ignoreClassNames;
95      }
96  
97      public String getIoSendTransport() {
98          return _ioSendTransport;
99      }
100 
101     public Boolean getParseWidgets() {
102         return _parseWidgets;
103     }
104 
105     public Boolean getPreventBackButtonFix() {
106         return _preventBackButtonFix;
107     }
108 
109     public String getSearchIds() {
110         return _searchIds;
111     }
112 
113     public void setAllowQueryConfig(Boolean allowQueryConfig) {
114         this._allowQueryConfig = allowQueryConfig;
115     }
116 
117     public void setBaseScriptUri(String baseScriptUri) {
118         this._baseScriptUri = baseScriptUri;
119     }
120 
121     public void setBindEncoding(String bindEncoding) {
122         this._bindEncoding = bindEncoding;
123     }
124 
125     public void setDebug(Boolean debug) {
126         this._debug = debug;
127     }
128 
129     public void setDebugAtAllCosts(Boolean debugAtAllCosts) {
130         this._debugAtAllCosts = debugAtAllCosts;
131     }
132 
133     public void setDebugContainerId(String debugContainerId) {
134         this._debugContainerId = debugContainerId;
135     }
136 
137     public void setIgnoreClassNames(Boolean ignoreClassNames) {
138         this._ignoreClassNames = ignoreClassNames;
139     }
140 
141     public void setIoSendTransport(String ioSendTransport) {
142         this._ioSendTransport = ioSendTransport;
143     }
144 
145     public void setParseWidgets(Boolean parseWidgets) {
146         this._parseWidgets = parseWidgets;
147     }
148 
149     public void setPreventBackButtonFix(Boolean preventBackButtonFix) {
150         this._preventBackButtonFix = preventBackButtonFix;
151     }
152 
153     public void setSearchIds(String searchIds) {
154         this._searchIds = searchIds;
155     }
156 
157     /**
158      * returns a valid djconfig string
159      */
160     public String toString() {
161 
162         StringBuffer configBuilder = new StringBuffer(128);
163         configBuilder.append(CONFIG_HEADER);
164 
165         createConfigEntry(configBuilder, "ioSendTransport", _ioSendTransport);
166         createConfigEntry(configBuilder, "isDebug", _debug);
167         createConfigEntry(configBuilder, "baseScriptUri", _baseScriptUri);
168         createConfigEntry(configBuilder, "allowQueryConfig", _allowQueryConfig);
169         createConfigEntry(configBuilder, "debugContainerId", _debugContainerId);
170         createConfigEntry(configBuilder, "searchIds", _searchIds);
171         createConfigEntry(configBuilder, "parseWidgets", _parseWidgets);
172         createConfigEntry(configBuilder, "bindEncoding", _bindEncoding);
173         createConfigEntry(configBuilder, "ignoreClassNames", _ignoreClassNames);
174         createConfigEntry(configBuilder, "preventBackButtonFix", _preventBackButtonFix);
175         createConfigEntry(configBuilder, "debugAtAllCosts", _debugAtAllCosts);
176 
177         configBuilder.append("\n");
178         configBuilder.append(CONFIG_FOOTER);
179 
180         return configBuilder.toString();
181     }
182 
183     /**
184      * helper to create a new config entry in the expected djConfig syntax
185      * @param target    the target stringbuffer which gets all the values
186      * @param configKey      the name of the entry
187      * @param configValue     the value of the entry
188      */
189     private final void createConfigEntry(StringBuffer target, String configKey, Object configValue) {
190 
191         if (configValue == null)
192             return;
193 
194         if (target.indexOf(":") != -1)
195             target.append(",\n");
196 
197         target.append(configKey);
198         target.append(":");
199         //strings have to be handled separately because we have to have them in quotes
200         boolean isStringValue = (configValue instanceof String);
201         if(isStringValue)
202             target.append("'");
203         target.append(configValue);
204         if(isStringValue)
205             target.append("'");
206 
207     }
208 
209     public Boolean getDevelopment() {
210         return _development;
211     }
212 
213     public void setDevelopment(Boolean development) {
214         this._development = development;
215     }
216 
217 }