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