View Javadoc

1   /**
2    * Copyright (C) 2005-2009 Alfresco Software Limited.
3    *
4    * This file is part of the Spring Surf Extension project.
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  
19  package org.springframework.extensions.surf.studio;
20  
21  import java.io.Serializable;
22  import java.util.HashMap;
23  import java.util.Map;
24  
25  import org.apache.commons.logging.Log;
26  import org.apache.commons.logging.LogFactory;
27  
28  /**
29   * Implementation class for a Web Studio applet.
30   * 
31   * @author muzquiano
32   */
33  public class BrowserStateBean implements Serializable
34  {
35      private static Log logger = LogFactory.getLog(BrowserStateBean.class);
36  
37      private String id = null;
38  
39      private String title = null;
40      private String description = null;
41  
42      private String className = null;
43  
44      private Map<String, String> jsFiles = null;
45      private Map<String, String> cssFiles = null;
46      private Map<String, String> domFiles = null;
47  
48      private Map<String, String> properties = null;
49  
50      /**
51       * Instantiates a new applet state bean.
52       * 
53       * @param id the id
54       */
55      public BrowserStateBean(String id)
56      {
57          this.id = id;
58  
59          this.jsFiles = new HashMap<String, String>(16, 1.0f);
60          this.cssFiles = new HashMap<String, String>(16, 1.0f);
61          this.domFiles = new HashMap<String, String>(16, 1.0f);
62  
63          this.properties = new HashMap<String, String>(16, 1.0f);
64  
65          // enable by default
66          put("enabled", "true");
67      }
68  
69      /**
70       * Gets the id.
71       * 
72       * @return the id
73       */
74      public String getId()
75      {
76          return this.id;
77      }
78  
79      /**
80       * Gets the title.
81       * 
82       * @return the title
83       */
84      public String getTitle()
85      {
86          return this.title;
87      }
88  
89      /**
90       * Sets the title.
91       * 
92       * @param title the new title
93       */
94      public void setTitle(String title)
95      {
96          this.title = title;
97      }
98  
99      /**
100      * Gets the description.
101      * 
102      * @return the description
103      */
104     public String getDescription()
105     {
106         return this.description;
107     }
108 
109     /**
110      * Sets the description.
111      * 
112      * @param description the new description
113      */
114     public void setDescription(String description)
115     {
116         this.description = description;
117     }
118 
119     /**
120      * Gets the js files.
121      * 
122      * @return the js files
123      */
124     public String[] getJsFiles()
125     {
126         return jsFiles.values().toArray(new String[jsFiles.size()]);
127     }
128 
129     /**
130      * Adds the js file.
131      * 
132      * @param file the file
133      */
134     public void addJsFile(String file)
135     {
136         jsFiles.put(file, file);
137     }
138 
139     /**
140      * Gets the css files.
141      * 
142      * @return the css files
143      */
144     public String[] getCssFiles()
145     {
146         return cssFiles.values().toArray(new String[cssFiles.size()]);
147     }
148 
149     /**
150      * Adds the css file.
151      * 
152      * @param file the file
153      */
154     public void addCssFile(String file)
155     {
156         cssFiles.put(file, file);
157     }
158 
159     /**
160      * Gets the dom files.
161      * 
162      * @return the dom files
163      */
164     public String[] getDomFiles()
165     {
166         return domFiles.values().toArray(new String[domFiles.size()]);
167     }
168 
169     /**
170      * Adds the dom file.
171      * 
172      * @param file the file
173      */
174     public void addDomFile(String file)
175     {
176         domFiles.put(file, file);
177     }
178 
179     /**
180      * Gets the classname.
181      * 
182      * @return the classname
183      */
184     public String getClassname()
185     {
186         return this.className;
187     }
188 
189     /**
190      * Sets the classname.
191      * 
192      * @param className the new classname
193      */
194     public void setClassname(String className)
195     {
196         this.className = className;
197     }
198 
199 
200     /**
201      * Stores a property onto this element
202      * 
203      * @param key the key
204      * @param value the value
205      */
206     public void put(String key, String value)
207     {
208         this.properties.put(key, value);
209     }
210 
211     /**
212      * Retrieves a property from this element
213      * 
214      * @param key the key
215      */
216     public String get(String key)
217     {
218         return this.properties.get(key);
219     }
220 
221     /**
222      * Returns the map of all properties
223      * 
224      * @return properties
225      */
226     public Map<String, String> getProperties()
227     {
228         return this.properties;
229     }
230 
231     /**
232      * Removes a property from this element
233      * 
234      * @param key
235      */
236     public void remove(String key)
237     {
238         this.properties.remove(key);
239     }
240 
241     /**
242      * Removes all properties
243      */
244     public void removeProperties()
245     {
246         this.properties = new HashMap<String, String>(16, 1.0f);
247     }
248 
249     /**
250      * Enables this browser component
251      */
252     public void enable()
253     {
254         put("enabled", "true");
255     }
256 
257     /**
258      * Disables this browser component
259      */
260     public void disable()
261     {
262         remove("enabled");
263     }
264 
265     /**
266      * Returns whether this browser component is enabled
267      * 
268      * @return enabled or not
269      */
270     public boolean isEnabled()
271     {
272         return "true".equals(get("enabled"));
273     }
274 
275     /**
276      * Clears all file dependencies
277      */
278     public void clearDependencies()
279     {
280         this.jsFiles = new HashMap<String, String>(16, 1.0f);
281         this.cssFiles = new HashMap<String, String>(16, 1.0f);
282         this.domFiles = new HashMap<String, String>(16, 1.0f);
283     }
284 }