1   /**
2    * Copyright (c) 2000-2010 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   *
12   *
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.CharPool;
20  import com.liferay.portal.kernel.util.PropertiesUtil;
21  import com.liferay.portal.kernel.util.SafeProperties;
22  import com.liferay.portal.kernel.util.StringPool;
23  import com.liferay.portal.kernel.util.StringUtil;
24  import com.liferay.portal.kernel.util.Validator;
25  import com.liferay.portal.model.ColorScheme;
26  import com.liferay.portal.util.PropsValues;
27  
28  import java.io.IOException;
29  
30  import java.util.Properties;
31  
32  /**
33   * <a href="ColorSchemeImpl.java.html"><b><i>View Source</i></b></a>
34   *
35   * @author Brian Wing Shun Chan
36   */
37  public class ColorSchemeImpl implements ColorScheme {
38  
39      public static String getDefaultRegularColorSchemeId() {
40          return PropsValues.DEFAULT_REGULAR_COLOR_SCHEME_ID;
41      }
42  
43      public static String getDefaultWapColorSchemeId() {
44          return PropsValues.DEFAULT_WAP_COLOR_SCHEME_ID;
45      }
46  
47      public static ColorScheme getNullColorScheme() {
48          return new ColorSchemeImpl(
49              getDefaultRegularColorSchemeId(), StringPool.BLANK,
50              StringPool.BLANK);
51      }
52  
53      public ColorSchemeImpl() {
54      }
55  
56      public ColorSchemeImpl(String colorSchemeId) {
57          _colorSchemeId = colorSchemeId;
58      }
59  
60      public ColorSchemeImpl(String colorSchemeId, String name, String cssClass) {
61          _colorSchemeId = colorSchemeId;
62          _name = name;
63          _cssClass = cssClass;
64      }
65  
66      public String getColorSchemeId() {
67          return _colorSchemeId;
68      }
69  
70      public String getName() {
71          if (Validator.isNull(_name)) {
72              return _colorSchemeId;
73          }
74          else {
75              return _name;
76          }
77      }
78  
79      public void setName(String name) {
80          _name = name;
81      }
82  
83      public boolean getDefaultCs() {
84          return _defaultCs;
85      }
86  
87      public boolean isDefaultCs() {
88          return _defaultCs;
89      }
90  
91      public void setDefaultCs(boolean defaultCs) {
92          _defaultCs = defaultCs;
93      }
94  
95      public String getCssClass() {
96          return _cssClass;
97      }
98  
99      public void setCssClass(String cssClass) {
100         _cssClass = cssClass;
101     }
102 
103     public String getColorSchemeImagesPath() {
104         return _colorSchemeImagesPath;
105     }
106 
107     public String getColorSchemeThumbnailPath() {
108 
109         // LEP-5270
110 
111         if (Validator.isNotNull(_cssClass) &&
112             Validator.isNotNull(_colorSchemeImagesPath)) {
113 
114             int pos = _cssClass.indexOf(CharPool.SPACE);
115 
116             if (pos > 0) {
117                 if (_colorSchemeImagesPath.endsWith(
118                         _cssClass.substring(0, pos))) {
119 
120                     String subclassPath = StringUtil.replace(
121                         _cssClass, CharPool.SPACE, CharPool.SLASH);
122 
123                     return _colorSchemeImagesPath + subclassPath.substring(pos);
124                 }
125             }
126         }
127 
128         return _colorSchemeImagesPath;
129     }
130 
131     public void setColorSchemeImagesPath(String colorSchemeImagesPath) {
132         _colorSchemeImagesPath = colorSchemeImagesPath;
133     }
134 
135     public String getSettings() {
136         return PropertiesUtil.toString(_settingsProperties);
137     }
138 
139     public void setSettings(String settings) {
140         _settingsProperties.clear();
141 
142         try {
143             PropertiesUtil.load(_settingsProperties, settings);
144             PropertiesUtil.trimKeys(_settingsProperties);
145         }
146         catch (IOException ioe) {
147             _log.error(ioe);
148         }
149     }
150 
151     public Properties getSettingsProperties() {
152         return _settingsProperties;
153     }
154 
155     public void setSettingsProperties(Properties settingsProperties) {
156         _settingsProperties = settingsProperties;
157     }
158 
159     public String getSetting(String key) {
160         //return _settingsProperties.getProperty(key);
161 
162         // FIX ME
163 
164         if (key.endsWith("-bg")) {
165             return "#FFFFFF";
166         }
167         else {
168             return "#000000";
169         }
170     }
171 
172     public int compareTo(ColorScheme colorScheme) {
173         return getName().compareTo(colorScheme.getName());
174     }
175 
176     public boolean equals(Object obj) {
177         if (obj == null) {
178             return false;
179         }
180 
181         ColorScheme colorScheme = null;
182 
183         try {
184             colorScheme = (ColorScheme)obj;
185         }
186         catch (ClassCastException cce) {
187             return false;
188         }
189 
190         String colorSchemeId = colorScheme.getColorSchemeId();
191 
192         if (getColorSchemeId().equals(colorSchemeId)) {
193             return true;
194         }
195         else {
196             return false;
197         }
198     }
199 
200     public int hashCode() {
201         return _colorSchemeId.hashCode();
202     }
203 
204     private static Log _log = LogFactoryUtil.getLog(ColorScheme.class);
205 
206     private String _colorSchemeId;
207     private String _name;
208     private String _cssClass;
209     private String _colorSchemeImagesPath =
210         "${images-path}/color_schemes/${css-class}";
211     private boolean _defaultCs;
212     private Properties _settingsProperties = new SafeProperties();
213 
214 }