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 _log.warn("Unable to parse date " + value, e);
176 }
177 }
178 else if (type == DATE_ARRAY) {
179 Serializable dateSerializable = getSerializable(DATE, value);
180
181 if (dateSerializable instanceof Date) {
182 return new Date[] {(Date)dateSerializable};
183 }
184 }
185 else if (type == DOUBLE) {
186 return GetterUtil.getDouble(value);
187 }
188 else if (type == DOUBLE_ARRAY) {
189 return new double[] {GetterUtil.getDouble(value)};
190 }
191 else if (type == FLOAT) {
192 return GetterUtil.getFloat(value);
193 }
194 else if (type == FLOAT_ARRAY) {
195 return new float[] {GetterUtil.getFloat(value)};
196 }
197 else if (type == INTEGER) {
198 return GetterUtil.getInteger(value);
199 }
200 else if (type == INTEGER_ARRAY) {
201 return new int[] {GetterUtil.getInteger(value)};
202 }
203 else if (type == LONG) {
204 return GetterUtil.getLong(value);
205 }
206 else if (type == LONG_ARRAY) {
207 return new long[] {GetterUtil.getLong(value)};
208 }
209 else if (type == NUMBER) {
210 return GetterUtil.getNumber(value);
211 }
212 else if (type == NUMBER_ARRAY) {
213 return new Number[] {GetterUtil.getNumber(value)};
214 }
215 else if (type == SHORT) {
216 return GetterUtil.getShort(value);
217 }
218 else if (type == SHORT_ARRAY) {
219 return new short[] {GetterUtil.getShort(value)};
220 }
221 else if (type == STRING_ARRAY) {
222 return new String[] {value};
223 }
224
225 return value;
226 }
227
228 public static final String getTypeLabel(int type) {
229 if (type == BOOLEAN) {
230 return BOOLEAN_LABEL;
231 }
232 else if (type == BOOLEAN_ARRAY) {
233 return BOOLEAN_ARRAY_LABEL;
234 }
235 else if (type == DATE) {
236 return DATE_LABEL;
237 }
238 else if (type == DATE_ARRAY) {
239 return DATE_ARRAY_LABEL;
240 }
241 else if (type == DOUBLE) {
242 return DOUBLE_LABEL;
243 }
244 else if (type == DOUBLE_ARRAY) {
245 return DOUBLE_ARRAY_LABEL;
246 }
247 else if (type == FLOAT) {
248 return FLOAT_LABEL;
249 }
250 else if (type == FLOAT_ARRAY) {
251 return FLOAT_ARRAY_LABEL;
252 }
253 else if (type == INTEGER) {
254 return INTEGER_LABEL;
255 }
256 else if (type == INTEGER_ARRAY) {
257 return INTEGER_ARRAY_LABEL;
258 }
259 else if (type == LONG) {
260 return LONG_LABEL;
261 }
262 else if (type == LONG_ARRAY) {
263 return LONG_ARRAY_LABEL;
264 }
265 else if (type == NUMBER) {
266 return NUMBER_LABEL;
267 }
268 else if (type == NUMBER_ARRAY) {
269 return NUMBER_ARRAY_LABEL;
270 }
271 else if (type == SHORT) {
272 return SHORT_LABEL;
273 }
274 else if (type == SHORT_ARRAY) {
275 return SHORT_ARRAY_LABEL;
276 }
277 else if (type == STRING) {
278 return STRING_LABEL;
279 }
280 else if (type == STRING_ARRAY) {
281 return STRING_ARRAY_LABEL;
282 }
283 else if (type == STRING_ARRAY_LOCALIZED) {
284 return STRING_ARRAY_LOCALIZED_LABEL;
285 }
286 else if (type == STRING_LOCALIZED) {
287 return STRING_LOCALIZED_LABEL;
288 }
289
290 return UNKNOWN_LABEL;
291 }
292
293 private static Log _log = LogFactoryUtil.getLog(
294 ExpandoColumnConstants.class);
295
296 }