1
14
15 package com.liferay.portlet.expando.model.impl;
16
17 import com.liferay.portal.kernel.language.LanguageUtil;
18 import com.liferay.portal.kernel.log.Log;
19 import com.liferay.portal.kernel.log.LogFactoryUtil;
20 import com.liferay.portal.kernel.util.UnicodeProperties;
21 import com.liferay.portlet.expando.model.ExpandoColumn;
22 import com.liferay.portlet.expando.model.ExpandoColumnConstants;
23 import com.liferay.portlet.expando.model.ExpandoValue;
24 import com.liferay.util.TextFormatter;
25
26 import java.io.IOException;
27 import java.io.Serializable;
28
29 import java.util.Locale;
30
31
37 public class ExpandoColumnImpl
38 extends ExpandoColumnModelImpl implements ExpandoColumn {
39
40 public ExpandoColumnImpl() {
41 }
42
43 public Serializable getDefaultValue() {
44 try {
45 ExpandoValue value = new ExpandoValueImpl();
46
47 value.setColumnId(getColumnId());
48 value.setData(getDefaultData());
49
50 int type = getType();
51
52 if (type == ExpandoColumnConstants.BOOLEAN) {
53 return value.getBoolean();
54 }
55 else if (type == ExpandoColumnConstants.BOOLEAN_ARRAY) {
56 return value.getBooleanArray();
57 }
58 else if (type == ExpandoColumnConstants.DATE) {
59 return value.getDate();
60 }
61 else if (type == ExpandoColumnConstants.DATE_ARRAY) {
62 return value.getDateArray();
63 }
64 else if (type == ExpandoColumnConstants.DOUBLE) {
65 return value.getDouble();
66 }
67 else if (type == ExpandoColumnConstants.DOUBLE_ARRAY) {
68 return value.getDoubleArray();
69 }
70 else if (type == ExpandoColumnConstants.FLOAT) {
71 return value.getFloat();
72 }
73 else if (type == ExpandoColumnConstants.FLOAT_ARRAY) {
74 return value.getFloatArray();
75 }
76 else if (type == ExpandoColumnConstants.INTEGER) {
77 return value.getInteger();
78 }
79 else if (type == ExpandoColumnConstants.INTEGER_ARRAY) {
80 return value.getIntegerArray();
81 }
82 else if (type == ExpandoColumnConstants.LONG) {
83 return value.getLong();
84 }
85 else if (type == ExpandoColumnConstants.LONG_ARRAY) {
86 return value.getLongArray();
87 }
88 else if (type == ExpandoColumnConstants.SHORT) {
89 return value.getShort();
90 }
91 else if (type == ExpandoColumnConstants.SHORT_ARRAY) {
92 return value.getShortArray();
93 }
94 else if (type == ExpandoColumnConstants.STRING_ARRAY) {
95 return value.getStringArray();
96 }
97 else {
98 return value.getString();
99 }
100 }
101 catch (Exception e) {
102 return null;
103 }
104 }
105
106 public String getDisplayName(Locale locale) {
107 String name = getName();
108
109 String displayName = LanguageUtil.get(locale, name);
110
111 if (name.equals(displayName)) {
112 displayName = TextFormatter.format(name, TextFormatter.J);
113 }
114
115 return displayName;
116 }
117
118 public String getTypeSettings() {
119 if (_typeSettingsProperties == null) {
120 return super.getTypeSettings();
121 }
122 else {
123 return _typeSettingsProperties.toString();
124 }
125 }
126
127 public UnicodeProperties getTypeSettingsProperties() {
128 if (_typeSettingsProperties == null) {
129 _typeSettingsProperties = new UnicodeProperties(true);
130
131 try {
132 _typeSettingsProperties.load(super.getTypeSettings());
133 }
134 catch (IOException ioe) {
135 _log.error(ioe, ioe);
136 }
137 }
138
139 return _typeSettingsProperties;
140 }
141
142 public void setTypeSettings(String typeSettings) {
143 _typeSettingsProperties = null;
144
145 super.setTypeSettings(typeSettings);
146 }
147
148 public void setTypeSettingsProperties(
149 UnicodeProperties typeSettingsProperties) {
150
151 _typeSettingsProperties = typeSettingsProperties;
152
153 super.setTypeSettings(_typeSettingsProperties.toString());
154 }
155
156 private static Log _log = LogFactoryUtil.getLog(ExpandoColumnImpl.class);
157
158 private UnicodeProperties _typeSettingsProperties = null;
159
160 }