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