1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.model.impl;
16  
17  import com.liferay.portal.kernel.log.Log;
18  import com.liferay.portal.kernel.log.LogFactoryUtil;
19  import com.liferay.portal.kernel.util.PropertiesUtil;
20  import com.liferay.portal.kernel.util.SafeProperties;
21  import com.liferay.portal.kernel.util.StringPool;
22  import com.liferay.portal.kernel.util.StringUtil;
23  import com.liferay.portal.kernel.util.Validator;
24  import com.liferay.portal.model.ColorScheme;
25  import com.liferay.portal.util.PropsValues;
26  
27  import java.io.IOException;
28  
29  import java.util.Properties;
30  
31  /**
32   * <a href="ColorSchemeImpl.java.html"><b><i>View Source</i></b></a>
33   *
34   * @author Brian Wing Shun Chan
35   */
36  public class ColorSchemeImpl implements ColorScheme {
37  
38      public static String getDefaultRegularColorSchemeId() {
39          return PropsValues.DEFAULT_REGULAR_COLOR_SCHEME_ID;
40      }
41  
42      public static String getDefaultWapColorSchemeId() {
43          return PropsValues.DEFAULT_WAP_COLOR_SCHEME_ID;
44      }
45  
46      public static ColorScheme getNullColorScheme() {
47          return new ColorSchemeImpl(
48              getDefaultRegularColorSchemeId(), StringPool.BLANK,
49              StringPool.BLANK);
50      }
51  
52      public ColorSchemeImpl() {
53      }
54  
55      public ColorSchemeImpl(String colorSchemeId) {
56          _colorSchemeId = colorSchemeId;
57      }
58  
59      public ColorSchemeImpl(String colorSchemeId, String name, String cssClass) {
60          _colorSchemeId = colorSchemeId;
61          _name = name;
62          _cssClass = cssClass;
63      }
64  
65      public String getColorSchemeId() {
66          return _colorSchemeId;
67      }
68  
69      public String getName() {
70          if (Validator.isNull(_name)) {
71              return _colorSchemeId;
72          }
73          else {
74              return _name;
75          }
76      }
77  
78      public void setName(String name) {
79          _name = name;
80      }
81  
82      public boolean getDefaultCs() {
83          return _defaultCs;
84      }
85  
86      public boolean isDefaultCs() {
87          return _defaultCs;
88      }
89  
90      public void setDefaultCs(boolean defaultCs) {
91          _defaultCs = defaultCs;
92      }
93  
94      public String getCssClass() {
95          return _cssClass;
96      }
97  
98      public void setCssClass(String cssClass) {
99          _cssClass = cssClass;
100     }
101 
102     public String getColorSchemeImagesPath() {
103         return _colorSchemeImagesPath;
104     }
105 
106     public String getColorSchemeThumbnailPath() {
107 
108         // LEP-5270
109 
110         if (Validator.isNotNull(_cssClass) &&
111             Validator.isNotNull(_colorSchemeImagesPath)) {
112 
113             int pos = _cssClass.indexOf(StringPool.SPACE);
114 
115             if (pos > 0) {
116                 if (_colorSchemeImagesPath.endsWith(
117                         _cssClass.substring(0, pos))) {
118 
119                     String subclassPath = StringUtil.replace(
120                         _cssClass, StringPool.SPACE, StringPool.SLASH);
121 
122                     return _colorSchemeImagesPath + subclassPath.substring(pos);
123                 }
124             }
125         }
126 
127         return _colorSchemeImagesPath;
128     }
129 
130     public void setColorSchemeImagesPath(String colorSchemeImagesPath) {
131         _colorSchemeImagesPath = colorSchemeImagesPath;
132     }
133 
134     public String getSettings() {
135         return PropertiesUtil.toString(_settingsProperties);
136     }
137 
138     public void setSettings(String settings) {
139         _settingsProperties.clear();
140 
141         try {
142             PropertiesUtil.load(_settingsProperties, settings);
143             PropertiesUtil.trimKeys(_settingsProperties);
144         }
145         catch (IOException ioe) {
146             _log.error(ioe);
147         }
148     }
149 
150     public Properties getSettingsProperties() {
151         return _settingsProperties;
152     }
153 
154     public void setSettingsProperties(Properties settingsProperties) {
155         _settingsProperties = settingsProperties;
156     }
157 
158     public String getSetting(String key) {
159         //return _settingsProperties.getProperty(key);
160 
161         // FIX ME
162 
163         if (key.endsWith("-bg")) {
164             return "#FFFFFF";
165         }
166         else {
167             return "#000000";
168         }
169     }
170 
171     public int compareTo(ColorScheme colorScheme) {
172         return getName().compareTo(colorScheme.getName());
173     }
174 
175     public boolean equals(Object obj) {
176         if (obj == null) {
177             return false;
178         }
179 
180         ColorScheme colorScheme = null;
181 
182         try {
183             colorScheme = (ColorScheme)obj;
184         }
185         catch (ClassCastException cce) {
186             return false;
187         }
188 
189         String colorSchemeId = colorScheme.getColorSchemeId();
190 
191         if (getColorSchemeId().equals(colorSchemeId)) {
192             return true;
193         }
194         else {
195             return false;
196         }
197     }
198 
199     private static Log _log = LogFactoryUtil.getLog(ColorScheme.class);
200 
201     private String _colorSchemeId;
202     private String _name;
203     private String _cssClass;
204     private String _colorSchemeImagesPath =
205         "${images-path}/color_schemes/${css-class}";
206     private boolean _defaultCs;
207     private Properties _settingsProperties = new SafeProperties();
208 
209 }