001
014
015 package com.liferay.portlet.expando.model;
016
017 import com.liferay.portal.kernel.log.Log;
018 import com.liferay.portal.kernel.log.LogFactoryUtil;
019 import com.liferay.portal.kernel.util.DateFormatFactoryUtil;
020 import com.liferay.portal.kernel.util.GetterUtil;
021 import com.liferay.portal.kernel.util.LocaleUtil;
022
023 import java.io.Serializable;
024
025 import java.text.DateFormat;
026
027 import java.util.Date;
028
029
034 public class ExpandoColumnConstants {
035
036 public static final int BOOLEAN = 1;
037
038 public static final int BOOLEAN_ARRAY = 2;
039
040 public static final String BOOLEAN_ARRAY_LABEL =
041 "custom.field.boolean.array";
042
043 public static final String BOOLEAN_LABEL = "custom.field.boolean";
044
045 public static final int DATE = 3;
046
047 public static final int DATE_ARRAY = 4;
048
049 public static final String DATE_ARRAY_LABEL =
050 "custom.field.java.util.Date.array";
051
052 public static final String DATE_LABEL = "custom.field.java.util.Date";
053
054 public static final int DOUBLE = 5;
055
056 public static final int DOUBLE_ARRAY = 6;
057
058 public static final String DOUBLE_ARRAY_LABEL = "custom.field.double.array";
059
060 public static final String DOUBLE_LABEL = "custom.field.double";
061
062 public static final int FLOAT = 7;
063
064 public static final int FLOAT_ARRAY = 8;
065
066 public static final String FLOAT_ARRAY_LABEL = "custom.field.float.array";
067
068 public static final String FLOAT_LABEL = "custom.field.float";
069
070 public static final String INDEX_TYPE = "index-type";
071
072 public static final int INDEX_TYPE_KEYWORD = 2;
073
074 public static final int INDEX_TYPE_NONE = 0;
075
076 public static final int INDEX_TYPE_TEXT = 1;
077
078 public static final int INTEGER = 9;
079
080 public static final int INTEGER_ARRAY = 10;
081
082 public static final String INTEGER_ARRAY_LABEL = "custom.field.int.array";
083
084 public static final String INTEGER_LABEL = "custom.field.int";
085
086 public static final int LONG = 11;
087
088 public static final int LONG_ARRAY = 12;
089
090 public static final String LONG_ARRAY_LABEL = "custom.field.long.array";
091
092 public static final String LONG_LABEL = "custom.field.long";
093
094 public static final int NUMBER = 17;
095
096 public static final int NUMBER_ARRAY = 18;
097
098 public static final String NUMBER_ARRAY_LABEL = "custom.field.number.array";
099
100 public static final String NUMBER_LABEL = "custom.field.number";
101
102 public static final String PROPERTY_DISPLAY_TYPE = "display-type";
103
104 public static final String PROPERTY_DISPLAY_TYPE_CHECKBOX = "checkbox";
105
106 public static final String PROPERTY_DISPLAY_TYPE_RADIO = "radio";
107
108 public static final String PROPERTY_DISPLAY_TYPE_SELECTION_LIST =
109 "selection-list";
110
111 public static final String PROPERTY_DISPLAY_TYPE_TEXT_BOX = "text-box";
112
113 public static final String PROPERTY_HEIGHT = "height";
114
115 public static final String PROPERTY_HIDDEN = "hidden";
116
117 public static final String PROPERTY_SECRET = "secret";
118
119 public static final String PROPERTY_VISIBLE_WITH_UPDATE_PERMISSION =
120 "visible-with-update-permission";
121
122 public static final String PROPERTY_WIDTH = "width";
123
124 public static final int SHORT = 13;
125
126 public static final int SHORT_ARRAY = 14;
127
128 public static final String SHORT_ARRAY_LABEL = "custom.field.short.array";
129
130 public static final String SHORT_LABEL = "custom.field.short";
131
132 public static final int STRING = 15;
133
134 public static final int STRING_ARRAY = 16;
135
136 public static final String STRING_ARRAY_LABEL =
137 "custom.field.java.lang.String.array";
138
139 public static final int STRING_ARRAY_LOCALIZED = 19;
140
141 public static final String STRING_ARRAY_LOCALIZED_LABEL =
142 "custom.field.java.lang.String.array.localized";
143
144 public static final String STRING_LABEL = "custom.field.java.lang.String";
145
146 public static final int STRING_LOCALIZED = 20;
147
148 public static final String STRING_LOCALIZED_LABEL =
149 "custom.field.java.lang.String.localized";
150
151 public static final int[] TYPES = new int[] {
152 BOOLEAN, BOOLEAN_ARRAY, DATE, DATE_ARRAY, DOUBLE, DOUBLE_ARRAY, FLOAT,
153 FLOAT_ARRAY, INTEGER, INTEGER_ARRAY, LONG, LONG_ARRAY, NUMBER,
154 NUMBER_ARRAY, SHORT, SHORT_ARRAY, STRING, STRING_ARRAY,
155 STRING_ARRAY_LOCALIZED, STRING_LOCALIZED
156 };
157
158 public static final String UNKNOWN_LABEL = "Unknown";
159
160 public static final Serializable getSerializable(int type, String value) {
161 if (type == BOOLEAN) {
162 return GetterUtil.getBoolean(value);
163 }
164 else if (type == BOOLEAN_ARRAY) {
165 return new Boolean[] {GetterUtil.getBoolean(value)};
166 }
167 else if (type == DATE) {
168 try {
169 DateFormat dateFormat = DateFormatFactoryUtil.getDateTime(
170 LocaleUtil.getDefault());
171
172 return dateFormat.parse(value);
173 }
174 catch (Exception e) {
175 if (_log.isWarnEnabled()) {
176 _log.warn("Unable to parse date " + value, e);
177 }
178 }
179 }
180 else if (type == DATE_ARRAY) {
181 Serializable dateSerializable = getSerializable(DATE, value);
182
183 if (dateSerializable instanceof Date) {
184 return new Date[] {(Date)dateSerializable};
185 }
186 }
187 else if (type == DOUBLE) {
188 return GetterUtil.getDouble(value);
189 }
190 else if (type == DOUBLE_ARRAY) {
191 return new double[] {GetterUtil.getDouble(value)};
192 }
193 else if (type == FLOAT) {
194 return GetterUtil.getFloat(value);
195 }
196 else if (type == FLOAT_ARRAY) {
197 return new float[] {GetterUtil.getFloat(value)};
198 }
199 else if (type == INTEGER) {
200 return GetterUtil.getInteger(value);
201 }
202 else if (type == INTEGER_ARRAY) {
203 return new int[] {GetterUtil.getInteger(value)};
204 }
205 else if (type == LONG) {
206 return GetterUtil.getLong(value);
207 }
208 else if (type == LONG_ARRAY) {
209 return new long[] {GetterUtil.getLong(value)};
210 }
211 else if (type == NUMBER) {
212 return GetterUtil.getNumber(value);
213 }
214 else if (type == NUMBER_ARRAY) {
215 return new Number[] {GetterUtil.getNumber(value)};
216 }
217 else if (type == SHORT) {
218 return GetterUtil.getShort(value);
219 }
220 else if (type == SHORT_ARRAY) {
221 return new short[] {GetterUtil.getShort(value)};
222 }
223 else if (type == STRING_ARRAY) {
224 return new String[] {value};
225 }
226
227 return value;
228 }
229
230 public static final String getTypeLabel(int type) {
231 if (type == BOOLEAN) {
232 return BOOLEAN_LABEL;
233 }
234 else if (type == BOOLEAN_ARRAY) {
235 return BOOLEAN_ARRAY_LABEL;
236 }
237 else if (type == DATE) {
238 return DATE_LABEL;
239 }
240 else if (type == DATE_ARRAY) {
241 return DATE_ARRAY_LABEL;
242 }
243 else if (type == DOUBLE) {
244 return DOUBLE_LABEL;
245 }
246 else if (type == DOUBLE_ARRAY) {
247 return DOUBLE_ARRAY_LABEL;
248 }
249 else if (type == FLOAT) {
250 return FLOAT_LABEL;
251 }
252 else if (type == FLOAT_ARRAY) {
253 return FLOAT_ARRAY_LABEL;
254 }
255 else if (type == INTEGER) {
256 return INTEGER_LABEL;
257 }
258 else if (type == INTEGER_ARRAY) {
259 return INTEGER_ARRAY_LABEL;
260 }
261 else if (type == LONG) {
262 return LONG_LABEL;
263 }
264 else if (type == LONG_ARRAY) {
265 return LONG_ARRAY_LABEL;
266 }
267 else if (type == NUMBER) {
268 return NUMBER_LABEL;
269 }
270 else if (type == NUMBER_ARRAY) {
271 return NUMBER_ARRAY_LABEL;
272 }
273 else if (type == SHORT) {
274 return SHORT_LABEL;
275 }
276 else if (type == SHORT_ARRAY) {
277 return SHORT_ARRAY_LABEL;
278 }
279 else if (type == STRING) {
280 return STRING_LABEL;
281 }
282 else if (type == STRING_ARRAY) {
283 return STRING_ARRAY_LABEL;
284 }
285 else if (type == STRING_ARRAY_LOCALIZED) {
286 return STRING_ARRAY_LOCALIZED_LABEL;
287 }
288 else if (type == STRING_LOCALIZED) {
289 return STRING_LOCALIZED_LABEL;
290 }
291
292 return UNKNOWN_LABEL;
293 }
294
295 private static Log _log = LogFactoryUtil.getLog(
296 ExpandoColumnConstants.class);
297
298 }