1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.portal.model.impl;
21  
22  import com.liferay.portal.kernel.log.Log;
23  import com.liferay.portal.kernel.log.LogFactoryUtil;
24  import com.liferay.portal.kernel.util.PropertiesUtil;
25  import com.liferay.portal.kernel.util.SafeProperties;
26  import com.liferay.portal.kernel.util.StringPool;
27  import com.liferay.portal.kernel.util.StringUtil;
28  import com.liferay.portal.kernel.util.Validator;
29  import com.liferay.portal.model.ColorScheme;
30  import com.liferay.portal.util.PropsValues;
31  
32  import java.io.IOException;
33  
34  import java.util.Properties;
35  
36  /**
37   * <a href="ColorSchemeImpl.java.html"><b><i>View Source</i></b></a>
38   *
39   * @author Brian Wing Shun Chan
40   *
41   */
42  public class ColorSchemeImpl implements ColorScheme {
43  
44      public static String getDefaultRegularColorSchemeId() {
45          return PropsValues.DEFAULT_REGULAR_COLOR_SCHEME_ID;
46      }
47  
48      public static String getDefaultWapColorSchemeId() {
49          return PropsValues.DEFAULT_WAP_COLOR_SCHEME_ID;
50      }
51  
52      public static ColorScheme getNullColorScheme() {
53          return new ColorSchemeImpl(
54              getDefaultRegularColorSchemeId(), StringPool.BLANK,
55              StringPool.BLANK);
56      }
57  
58      public ColorSchemeImpl() {
59      }
60  
61      public ColorSchemeImpl(String colorSchemeId) {
62          _colorSchemeId = colorSchemeId;
63      }
64  
65      public ColorSchemeImpl(String colorSchemeId, String name, String cssClass) {
66          _colorSchemeId = colorSchemeId;
67          _name = name;
68          _cssClass = cssClass;
69      }
70  
71      public String getColorSchemeId() {
72          return _colorSchemeId;
73      }
74  
75      public String getName() {
76          if (Validator.isNull(_name)) {
77              return _colorSchemeId;
78          }
79          else {
80              return _name;
81          }
82      }
83  
84      public void setName(String name) {
85          _name = name;
86      }
87  
88      public boolean getDefaultCs() {
89          return _defaultCs;
90      }
91  
92      public boolean isDefaultCs() {
93          return _defaultCs;
94      }
95  
96      public void setDefaultCs(boolean defaultCs) {
97          _defaultCs = defaultCs;
98      }
99  
100     public String getCssClass() {
101         return _cssClass;
102     }
103 
104     public void setCssClass(String cssClass) {
105         _cssClass = cssClass;
106     }
107 
108     public String getColorSchemeImagesPath() {
109         return _colorSchemeImagesPath;
110     }
111 
112     public String getColorSchemeThumbnailPath() {
113 
114         // LEP-5270
115 
116         if (Validator.isNotNull(_cssClass) &&
117             Validator.isNotNull(_colorSchemeImagesPath)) {
118 
119             int pos = _cssClass.indexOf(StringPool.SPACE);
120 
121             if (pos > 0) {
122                 if (_colorSchemeImagesPath.endsWith(
123                         _cssClass.substring(0, pos))) {
124 
125                     String subclassPath = StringUtil.replace(
126                         _cssClass, StringPool.SPACE, StringPool.SLASH);
127 
128                     return _colorSchemeImagesPath + subclassPath.substring(pos);
129                 }
130             }
131         }
132 
133         return _colorSchemeImagesPath;
134     }
135 
136     public void setColorSchemeImagesPath(String colorSchemeImagesPath) {
137         _colorSchemeImagesPath = colorSchemeImagesPath;
138     }
139 
140     public String getSettings() {
141         return PropertiesUtil.toString(_settingsProperties);
142     }
143 
144     public void setSettings(String settings) {
145         _settingsProperties.clear();
146 
147         try {
148             PropertiesUtil.load(_settingsProperties, settings);
149             PropertiesUtil.trimKeys(_settingsProperties);
150         }
151         catch (IOException ioe) {
152             _log.error(ioe);
153         }
154     }
155 
156     public Properties getSettingsProperties() {
157         return _settingsProperties;
158     }
159 
160     public void setSettingsProperties(Properties settingsProperties) {
161         _settingsProperties = settingsProperties;
162     }
163 
164     public String getSetting(String key) {
165         //return _settingsProperties.getProperty(key);
166 
167         // FIX ME
168 
169         if (key.endsWith("-bg")) {
170             return "#FFFFFF";
171         }
172         else {
173             return "#000000";
174         }
175     }
176 
177     public int compareTo(ColorScheme colorScheme) {
178         return getName().compareTo(colorScheme.getName());
179     }
180 
181     public boolean equals(Object obj) {
182         if (obj == null) {
183             return false;
184         }
185 
186         ColorScheme colorScheme = null;
187 
188         try {
189             colorScheme = (ColorScheme)obj;
190         }
191         catch (ClassCastException cce) {
192             return false;
193         }
194 
195         String colorSchemeId = colorScheme.getColorSchemeId();
196 
197         if (getColorSchemeId().equals(colorSchemeId)) {
198             return true;
199         }
200         else {
201             return false;
202         }
203     }
204 
205     private static Log _log = LogFactoryUtil.getLog(ColorScheme.class);
206 
207     private String _colorSchemeId;
208     private String _name;
209     private String _cssClass;
210     private String _colorSchemeImagesPath =
211         "${images-path}/color_schemes/${css-class}";
212     private boolean _defaultCs;
213     private Properties _settingsProperties = new SafeProperties();
214 
215 }