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