001
014
015 package com.liferay.portal.model.impl;
016
017 import com.liferay.portal.kernel.log.Log;
018 import com.liferay.portal.kernel.log.LogFactoryUtil;
019 import com.liferay.portal.kernel.util.CharPool;
020 import com.liferay.portal.kernel.util.PropertiesUtil;
021 import com.liferay.portal.kernel.util.SafeProperties;
022 import com.liferay.portal.kernel.util.StringPool;
023 import com.liferay.portal.kernel.util.StringUtil;
024 import com.liferay.portal.kernel.util.Validator;
025 import com.liferay.portal.model.ColorScheme;
026 import com.liferay.portal.util.PropsValues;
027
028 import java.io.IOException;
029
030 import java.util.Properties;
031
032
035 public class ColorSchemeImpl implements ColorScheme {
036
037 public static String getDefaultRegularColorSchemeId() {
038 return PropsValues.DEFAULT_REGULAR_COLOR_SCHEME_ID;
039 }
040
041 public static String getDefaultWapColorSchemeId() {
042 return PropsValues.DEFAULT_WAP_COLOR_SCHEME_ID;
043 }
044
045 public static ColorScheme getNullColorScheme() {
046 return new ColorSchemeImpl(
047 getDefaultRegularColorSchemeId(), StringPool.BLANK,
048 StringPool.BLANK);
049 }
050
051 public ColorSchemeImpl() {
052 }
053
054 public ColorSchemeImpl(String colorSchemeId) {
055 _colorSchemeId = colorSchemeId;
056 }
057
058 public ColorSchemeImpl(String colorSchemeId, String name, String cssClass) {
059 _colorSchemeId = colorSchemeId;
060 _name = name;
061 _cssClass = cssClass;
062 }
063
064 @Override
065 public int compareTo(ColorScheme colorScheme) {
066 return getName().compareTo(colorScheme.getName());
067 }
068
069 @Override
070 public boolean equals(Object obj) {
071 if (this == obj) {
072 return true;
073 }
074
075 if (!(obj instanceof ColorScheme)) {
076 return false;
077 }
078
079 ColorScheme colorScheme = (ColorScheme)obj;
080
081 String colorSchemeId = colorScheme.getColorSchemeId();
082
083 if (getColorSchemeId().equals(colorSchemeId)) {
084 return true;
085 }
086 else {
087 return false;
088 }
089 }
090
091 @Override
092 public String getColorSchemeId() {
093 return _colorSchemeId;
094 }
095
096 @Override
097 public String getColorSchemeImagesPath() {
098 return _colorSchemeImagesPath;
099 }
100
101 @Override
102 public String getColorSchemeThumbnailPath() {
103
104
105
106 if (Validator.isNotNull(_cssClass) &&
107 Validator.isNotNull(_colorSchemeImagesPath)) {
108
109 int pos = _cssClass.indexOf(CharPool.SPACE);
110
111 if (pos > 0) {
112 if (_colorSchemeImagesPath.endsWith(
113 _cssClass.substring(0, pos))) {
114
115 String subclassPath = StringUtil.replace(
116 _cssClass, CharPool.SPACE, CharPool.SLASH);
117
118 return _colorSchemeImagesPath + subclassPath.substring(pos);
119 }
120 }
121 }
122
123 return _colorSchemeImagesPath;
124 }
125
126 @Override
127 public String getCssClass() {
128 return _cssClass;
129 }
130
131 @Override
132 public boolean getDefaultCs() {
133 return _defaultCs;
134 }
135
136 @Override
137 public String getName() {
138 if (Validator.isNull(_name)) {
139 return _colorSchemeId;
140 }
141 else {
142 return _name;
143 }
144 }
145
146 @Override
147 public String getSetting(String key) {
148
149
150
151
152 if (key.endsWith("-bg")) {
153 return "#FFFFFF";
154 }
155 else {
156 return "#000000";
157 }
158 }
159
160 @Override
161 public String getSettings() {
162 return PropertiesUtil.toString(_settingsProperties);
163 }
164
165 @Override
166 public Properties getSettingsProperties() {
167 return _settingsProperties;
168 }
169
170 @Override
171 public int hashCode() {
172 return _colorSchemeId.hashCode();
173 }
174
175 @Override
176 public boolean isDefaultCs() {
177 return _defaultCs;
178 }
179
180 @Override
181 public void setColorSchemeImagesPath(String colorSchemeImagesPath) {
182 _colorSchemeImagesPath = colorSchemeImagesPath;
183 }
184
185 @Override
186 public void setCssClass(String cssClass) {
187 _cssClass = cssClass;
188 }
189
190 @Override
191 public void setDefaultCs(boolean defaultCs) {
192 _defaultCs = defaultCs;
193 }
194
195 @Override
196 public void setName(String name) {
197 _name = name;
198 }
199
200 @Override
201 public void setSettings(String settings) {
202 _settingsProperties.clear();
203
204 try {
205 PropertiesUtil.load(_settingsProperties, settings);
206 PropertiesUtil.trimKeys(_settingsProperties);
207 }
208 catch (IOException ioe) {
209 _log.error(ioe);
210 }
211 }
212
213 @Override
214 public void setSettingsProperties(Properties settingsProperties) {
215 _settingsProperties = settingsProperties;
216 }
217
218 private static Log _log = LogFactoryUtil.getLog(ColorSchemeImpl.class);
219
220 private String _colorSchemeId;
221 private String _colorSchemeImagesPath =
222 "${images-path}/color_schemes/${css-class}";
223 private String _cssClass;
224 private boolean _defaultCs;
225 private String _name;
226 private Properties _settingsProperties = new SafeProperties();
227
228 }