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 public String getColorSchemeId() {
065 return _colorSchemeId;
066 }
067
068 public String getName() {
069 if (Validator.isNull(_name)) {
070 return _colorSchemeId;
071 }
072 else {
073 return _name;
074 }
075 }
076
077 public void setName(String name) {
078 _name = name;
079 }
080
081 public boolean getDefaultCs() {
082 return _defaultCs;
083 }
084
085 public boolean isDefaultCs() {
086 return _defaultCs;
087 }
088
089 public void setDefaultCs(boolean defaultCs) {
090 _defaultCs = defaultCs;
091 }
092
093 public String getCssClass() {
094 return _cssClass;
095 }
096
097 public void setCssClass(String cssClass) {
098 _cssClass = cssClass;
099 }
100
101 public String getColorSchemeImagesPath() {
102 return _colorSchemeImagesPath;
103 }
104
105 public String getColorSchemeThumbnailPath() {
106
107
108
109 if (Validator.isNotNull(_cssClass) &&
110 Validator.isNotNull(_colorSchemeImagesPath)) {
111
112 int pos = _cssClass.indexOf(CharPool.SPACE);
113
114 if (pos > 0) {
115 if (_colorSchemeImagesPath.endsWith(
116 _cssClass.substring(0, pos))) {
117
118 String subclassPath = StringUtil.replace(
119 _cssClass, CharPool.SPACE, CharPool.SLASH);
120
121 return _colorSchemeImagesPath + subclassPath.substring(pos);
122 }
123 }
124 }
125
126 return _colorSchemeImagesPath;
127 }
128
129 public void setColorSchemeImagesPath(String colorSchemeImagesPath) {
130 _colorSchemeImagesPath = colorSchemeImagesPath;
131 }
132
133 public String getSettings() {
134 return PropertiesUtil.toString(_settingsProperties);
135 }
136
137 public void setSettings(String settings) {
138 _settingsProperties.clear();
139
140 try {
141 PropertiesUtil.load(_settingsProperties, settings);
142 PropertiesUtil.trimKeys(_settingsProperties);
143 }
144 catch (IOException ioe) {
145 _log.error(ioe);
146 }
147 }
148
149 public Properties getSettingsProperties() {
150 return _settingsProperties;
151 }
152
153 public void setSettingsProperties(Properties settingsProperties) {
154 _settingsProperties = settingsProperties;
155 }
156
157 public String getSetting(String key) {
158
159
160
161
162 if (key.endsWith("-bg")) {
163 return "#FFFFFF";
164 }
165 else {
166 return "#000000";
167 }
168 }
169
170 public int compareTo(ColorScheme colorScheme) {
171 return getName().compareTo(colorScheme.getName());
172 }
173
174 public boolean equals(Object obj) {
175 if (obj == null) {
176 return false;
177 }
178
179 ColorScheme colorScheme = null;
180
181 try {
182 colorScheme = (ColorScheme)obj;
183 }
184 catch (ClassCastException cce) {
185 return false;
186 }
187
188 String colorSchemeId = colorScheme.getColorSchemeId();
189
190 if (getColorSchemeId().equals(colorSchemeId)) {
191 return true;
192 }
193 else {
194 return false;
195 }
196 }
197
198 public int hashCode() {
199 return _colorSchemeId.hashCode();
200 }
201
202 private static Log _log = LogFactoryUtil.getLog(ColorScheme.class);
203
204 private String _colorSchemeId;
205 private String _name;
206 private String _cssClass;
207 private String _colorSchemeImagesPath =
208 "${images-path}/color_schemes/${css-class}";
209 private boolean _defaultCs;
210 private Properties _settingsProperties = new SafeProperties();
211
212 }