1   /**
2    * Copyright (c) 2000-2007 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.model.impl;
24  
25  import com.liferay.portal.kernel.util.NullSafeProperties;
26  import com.liferay.portal.kernel.util.PropertiesUtil;
27  import com.liferay.portal.kernel.util.StringPool;
28  import com.liferay.portal.kernel.util.Validator;
29  import com.liferay.portal.model.ColorScheme;
30  import com.liferay.portal.util.PropsUtil;
31  
32  import java.io.IOException;
33  
34  import java.util.Properties;
35  
36  import org.apache.commons.logging.Log;
37  import org.apache.commons.logging.LogFactory;
38  
39  /**
40   * <a href="ColorSchemeImpl.java.html"><b><i>View Source</i></b></a>
41   *
42   * @author Brian Wing Shun Chan
43   *
44   */
45  public class ColorSchemeImpl implements ColorScheme {
46  
47      public static final String BODY_BG = "body-bg";
48  
49      public static final String LAYOUT_BG = "layout-bg";
50  
51      public static final String LAYOUT_TEXT = "layout-text";
52  
53      public static final String LAYOUT_TAB_BG = "layout-tab-bg";
54  
55      public static final String LAYOUT_TAB_TEXT = "layout-tab-text";
56  
57      public static final String LAYOUT_TAB_SELECTED_BG =
58          "layout-tab-selected-bg";
59  
60      public static final String LAYOUT_TAB_SELECTED_TEXT =
61          "layout-tab-selected-text";
62  
63      public static final String PORTLET_TITLE_BG = "portlet-title-bg";
64  
65      public static final String PORTLET_TITLE_TEXT = "portlet-title-text";
66  
67      public static final String PORTLET_MENU_BG = "portlet-menu-bg";
68  
69      public static final String PORTLET_MENU_TEXT = "portlet-menu-text";
70  
71      public static final String PORTLET_BG = "portlet-bg";
72  
73      public static final String PORTLET_FONT = "portlet-font";
74  
75      public static final String PORTLET_FONT_DIM = "portlet-font-dim";
76  
77      public static final String PORTLET_MSG_STATUS = "portlet-msg-status";
78  
79      public static final String PORTLET_MSG_INFO = "portlet-msg-info";
80  
81      public static final String PORTLET_MSG_ERROR = "portlet-msg-error";
82  
83      public static final String PORTLET_MSG_ALERT = "portlet-msg-alert";
84  
85      public static final String PORTLET_MSG_SUCCESS = "portlet-msg-success";
86  
87      public static final String PORTLET_SECTION_HEADER =
88          "portlet-section-header";
89  
90      public static final String PORTLET_SECTION_HEADER_BG =
91          "portlet-section-header-bg";
92  
93      public static final String PORTLET_SECTION_SUBHEADER =
94          "portlet-section-subheader";
95  
96      public static final String PORTLET_SECTION_SUBHEADER_BG =
97          "portlet-section-subheader-bg";
98  
99      public static final String PORTLET_SECTION_BODY = "portlet-section-body";
100 
101     public static final String PORTLET_SECTION_BODY_BG =
102         "portlet-section-body-bg";
103 
104     public static final String PORTLET_SECTION_BODY_HOVER =
105         "portlet-section-body-hover";
106 
107     public static final String PORTLET_SECTION_BODY_HOVER_BG =
108         "portlet-section-body-hover-bg";
109 
110     public static final String PORTLET_SECTION_ALTERNATE =
111         "portlet-section-alternate";
112 
113     public static final String PORTLET_SECTION_ALTERNATE_BG =
114         "portlet-section-alternate-bg";
115 
116     public static final String PORTLET_SECTION_ALTERNATE_HOVER =
117         "portlet-section-alternate-hover";
118 
119     public static final String PORTLET_SECTION_ALTERNATE_HOVER_BG =
120         "portlet-section-alternate-hover-bg";
121 
122     public static final String PORTLET_SECTION_SELECTED =
123         "portlet-section-selected";
124 
125     public static final String PORTLET_SECTION_SELECTED_BG =
126         "portlet-section-selected-bg";
127 
128     public static final String PORTLET_SECTION_SELECTED_HOVER =
129         "portlet-section-selected-hover";
130 
131     public static final String PORTLET_SECTION_SELECTED_HOVER_BG =
132         "portlet-section-selected-hover-bg";
133 
134     public static String getDefaultRegularColorSchemeId() {
135         return PropsUtil.get(PropsUtil.DEFAULT_REGULAR_COLOR_SCHEME_ID);
136     }
137 
138     public static String getDefaultWapColorSchemeId() {
139         return PropsUtil.get(PropsUtil.DEFAULT_WAP_COLOR_SCHEME_ID);
140     }
141 
142     public static ColorScheme getNullColorScheme() {
143         return new ColorSchemeImpl(
144             getDefaultRegularColorSchemeId(), StringPool.BLANK,
145             StringPool.BLANK);
146     }
147 
148     public ColorSchemeImpl() {
149     }
150 
151     public ColorSchemeImpl(String colorSchemeId) {
152         _colorSchemeId = colorSchemeId;
153     }
154 
155     public ColorSchemeImpl(String colorSchemeId, String name, String cssClass) {
156         _colorSchemeId = colorSchemeId;
157         _name = name;
158         _cssClass = cssClass;
159     }
160 
161     public String getColorSchemeId() {
162         return _colorSchemeId;
163     }
164 
165     public String getName() {
166         if (Validator.isNull(_name)) {
167             return _colorSchemeId;
168         }
169         else {
170             return _name;
171         }
172     }
173 
174     public void setName(String name) {
175         _name = name;
176     }
177 
178     public boolean getDefaultCs() {
179         return _defaultCs;
180     }
181 
182     public boolean isDefaultCs() {
183         return _defaultCs;
184     }
185 
186     public void setDefaultCs(boolean defaultCs) {
187         _defaultCs = defaultCs;
188     }
189 
190     public String getCssClass() {
191         return _cssClass;
192     }
193 
194     public void setCssClass(String cssClass) {
195         _cssClass = cssClass;
196     }
197 
198     public String getColorSchemeImagesPath() {
199         return _colorSchemeImagesPath;
200     }
201 
202     public void setColorSchemeImagesPath(String colorSchemeImagesPath) {
203         _colorSchemeImagesPath = colorSchemeImagesPath;
204     }
205 
206     public String getSettings() {
207         return PropertiesUtil.toString(_settingsProperties);
208     }
209 
210     public void setSettings(String settings) {
211         _settingsProperties.clear();
212 
213         try {
214             PropertiesUtil.load(_settingsProperties, settings);
215             PropertiesUtil.trimKeys(_settingsProperties);
216         }
217         catch (IOException ioe) {
218             _log.error(ioe);
219         }
220     }
221 
222     public Properties getSettingsProperties() {
223         return _settingsProperties;
224     }
225 
226     public void setSettingsProperties(Properties settingsProperties) {
227         _settingsProperties = settingsProperties;
228     }
229 
230     public String getSetting(String key) {
231         //return _settingsProperties.getProperty(key);
232 
233         // FIX ME
234 
235         if (key.endsWith("-bg")) {
236             return "#FFFFFF";
237         }
238         else {
239             return "#000000";
240         }
241     }
242 
243     public String getBodyBg() {
244         return getSetting(BODY_BG);
245     }
246 
247     public String getLayoutBg() {
248         return getSetting(LAYOUT_BG);
249     }
250 
251     public String getLayoutText() {
252         return getSetting(LAYOUT_TEXT);
253     }
254 
255     public String getLayoutTabBg() {
256         return getSetting(LAYOUT_TAB_BG);
257     }
258 
259     public String getLayoutTabText() {
260         return getSetting(LAYOUT_TAB_TEXT);
261     }
262 
263     public String getLayoutTabSelectedBg() {
264         return getSetting(LAYOUT_TAB_SELECTED_BG);
265     }
266 
267     public String getLayoutTabSelectedText() {
268         return getSetting(LAYOUT_TAB_SELECTED_TEXT);
269     }
270 
271     public String getPortletTitleBg() {
272         return getSetting(PORTLET_TITLE_BG);
273     }
274 
275     public String getPortletTitleText() {
276         return getSetting(PORTLET_TITLE_TEXT);
277     }
278 
279     public String getPortletMenuBg() {
280         return getSetting(PORTLET_MENU_BG);
281     }
282 
283     public String getPortletMenuText() {
284         return getSetting(PORTLET_MENU_TEXT);
285     }
286 
287     public String getPortletBg() {
288         return getSetting(PORTLET_BG);
289     }
290 
291     public String getPortletFont() {
292         return getSetting(PORTLET_FONT);
293     }
294 
295     public String getPortletFontDim() {
296         return getSetting(PORTLET_FONT_DIM);
297     }
298 
299     public String getPortletMsgStatus() {
300         return getSetting(PORTLET_MSG_STATUS);
301     }
302 
303     public String getPortletMsgInfo() {
304         return getSetting(PORTLET_MSG_INFO);
305     }
306 
307     public String getPortletMsgError() {
308         return getSetting(PORTLET_MSG_ERROR);
309     }
310 
311     public String getPortletMsgAlert() {
312         return getSetting(PORTLET_MSG_ALERT);
313     }
314 
315     public String getPortletMsgSuccess() {
316         return getSetting(PORTLET_MSG_SUCCESS);
317     }
318 
319     public String getPortletSectionHeader() {
320         return getSetting(PORTLET_SECTION_HEADER);
321     }
322 
323     public String getPortletSectionHeaderBg() {
324         return getSetting(PORTLET_SECTION_HEADER_BG);
325     }
326 
327     public String getPortletSectionSubheader() {
328         return getSetting(PORTLET_SECTION_SUBHEADER);
329     }
330 
331     public String getPortletSectionSubheaderBg() {
332         return getSetting(PORTLET_SECTION_SUBHEADER_BG);
333     }
334 
335     public String getPortletSectionBody() {
336         return getSetting(PORTLET_SECTION_BODY);
337     }
338 
339     public String getPortletSectionBodyBg() {
340         return getSetting(PORTLET_SECTION_BODY_BG);
341     }
342 
343     public String getPortletSectionBodyHover() {
344         return getSetting(PORTLET_SECTION_BODY_HOVER);
345     }
346 
347     public String getPortletSectionBodyHoverBg() {
348         return getSetting(PORTLET_SECTION_BODY_HOVER_BG);
349     }
350 
351     public String getPortletSectionAlternate() {
352         return getSetting(PORTLET_SECTION_ALTERNATE);
353     }
354 
355     public String getPortletSectionAlternateBg() {
356         return getSetting(PORTLET_SECTION_ALTERNATE_BG);
357     }
358 
359     public String getPortletSectionAlternateHover() {
360         return getSetting(PORTLET_SECTION_ALTERNATE_HOVER);
361     }
362 
363     public String getPortletSectionAlternateHoverBg() {
364         return getSetting(PORTLET_SECTION_ALTERNATE_HOVER_BG);
365     }
366 
367     public String getPortletSectionSelected() {
368         return getSetting(PORTLET_SECTION_SELECTED);
369     }
370 
371     public String getPortletSectionSelectedBg() {
372         return getSetting(PORTLET_SECTION_SELECTED_BG);
373     }
374 
375     public String getPortletSectionSelectedHover() {
376         return getSetting(PORTLET_SECTION_SELECTED_HOVER);
377     }
378 
379     public String getPortletSectionSelectedHoverBg() {
380         return getSetting(PORTLET_SECTION_SELECTED_HOVER_BG);
381     }
382 
383     public int compareTo(Object obj) {
384         if (obj == null) {
385             return -1;
386         }
387 
388         ColorScheme colorScheme = (ColorScheme) obj;
389 
390         return getName().compareTo(colorScheme.getName());
391     }
392 
393     public boolean equals(Object obj) {
394         if (obj == null) {
395             return false;
396         }
397 
398         ColorScheme colorScheme = null;
399 
400         try {
401             colorScheme = (ColorScheme)obj;
402         }
403         catch (ClassCastException cce) {
404             return false;
405         }
406 
407         String colorSchemeId = colorScheme.getColorSchemeId();
408 
409         if (getColorSchemeId().equals(colorSchemeId)) {
410             return true;
411         }
412         else {
413             return false;
414         }
415     }
416 
417     private static Log _log = LogFactory.getLog(ColorScheme.class);
418 
419     private String _colorSchemeId;
420     private String _name;
421     private String _cssClass;
422     private String _colorSchemeImagesPath =
423         "${images-path}/color_schemes/${css-class}";
424     private boolean _defaultCs;
425     private Properties _settingsProperties = new NullSafeProperties();
426 
427 }