001
014
015 package com.liferay.portlet.expando.model.impl;
016
017 import com.liferay.portal.kernel.language.LanguageUtil;
018 import com.liferay.portal.kernel.log.Log;
019 import com.liferay.portal.kernel.log.LogFactoryUtil;
020 import com.liferay.portal.kernel.util.TextFormatter;
021 import com.liferay.portal.kernel.util.UnicodeProperties;
022 import com.liferay.portlet.expando.model.ExpandoColumnConstants;
023 import com.liferay.portlet.expando.model.ExpandoValue;
024
025 import java.io.IOException;
026 import java.io.Serializable;
027
028 import java.util.Locale;
029
030
034 public class ExpandoColumnImpl extends ExpandoColumnBaseImpl {
035
036 public ExpandoColumnImpl() {
037 }
038
039 public Serializable getDefaultValue() {
040 try {
041 ExpandoValue value = new ExpandoValueImpl();
042
043 value.setColumnId(getColumnId());
044 value.setData(getDefaultData());
045
046 int type = getType();
047
048 if (type == ExpandoColumnConstants.BOOLEAN) {
049 return value.getBoolean();
050 }
051 else if (type == ExpandoColumnConstants.BOOLEAN_ARRAY) {
052 return value.getBooleanArray();
053 }
054 else if (type == ExpandoColumnConstants.DATE) {
055 return value.getDate();
056 }
057 else if (type == ExpandoColumnConstants.DATE_ARRAY) {
058 return value.getDateArray();
059 }
060 else if (type == ExpandoColumnConstants.DOUBLE) {
061 return value.getDouble();
062 }
063 else if (type == ExpandoColumnConstants.DOUBLE_ARRAY) {
064 return value.getDoubleArray();
065 }
066 else if (type == ExpandoColumnConstants.FLOAT) {
067 return value.getFloat();
068 }
069 else if (type == ExpandoColumnConstants.FLOAT_ARRAY) {
070 return value.getFloatArray();
071 }
072 else if (type == ExpandoColumnConstants.INTEGER) {
073 return value.getInteger();
074 }
075 else if (type == ExpandoColumnConstants.INTEGER_ARRAY) {
076 return value.getIntegerArray();
077 }
078 else if (type == ExpandoColumnConstants.LONG) {
079 return value.getLong();
080 }
081 else if (type == ExpandoColumnConstants.LONG_ARRAY) {
082 return value.getLongArray();
083 }
084 else if (type == ExpandoColumnConstants.NUMBER) {
085 return value.getNumber();
086 }
087 else if (type == ExpandoColumnConstants.NUMBER_ARRAY) {
088 return value.getNumberArray();
089 }
090 else if (type == ExpandoColumnConstants.SHORT) {
091 return value.getShort();
092 }
093 else if (type == ExpandoColumnConstants.SHORT_ARRAY) {
094 return value.getShortArray();
095 }
096 else if (type == ExpandoColumnConstants.STRING_ARRAY) {
097 return value.getStringArray();
098 }
099 else if (type == ExpandoColumnConstants.STRING_ARRAY_LOCALIZED) {
100 return (Serializable)value.getStringArrayMap();
101 }
102 else if (type == ExpandoColumnConstants.STRING_LOCALIZED) {
103 return (Serializable)value.getStringMap();
104 }
105 else {
106 return value.getString();
107 }
108 }
109 catch (Exception e) {
110 return null;
111 }
112 }
113
114 public String getDisplayName(Locale locale) {
115 String name = getName();
116
117 String displayName = LanguageUtil.get(locale, name);
118
119 if (name.equals(displayName)) {
120 displayName = TextFormatter.format(name, TextFormatter.J);
121 }
122
123 return displayName;
124 }
125
126 @Override
127 public String getTypeSettings() {
128 if (_typeSettingsProperties == null) {
129 return super.getTypeSettings();
130 }
131 else {
132 return _typeSettingsProperties.toString();
133 }
134 }
135
136 public UnicodeProperties getTypeSettingsProperties() {
137 if (_typeSettingsProperties == null) {
138 _typeSettingsProperties = new UnicodeProperties(true);
139
140 try {
141 _typeSettingsProperties.load(super.getTypeSettings());
142 }
143 catch (IOException ioe) {
144 _log.error(ioe, ioe);
145 }
146 }
147
148 return _typeSettingsProperties;
149 }
150
151 @Override
152 public void setTypeSettings(String typeSettings) {
153 _typeSettingsProperties = null;
154
155 super.setTypeSettings(typeSettings);
156 }
157
158 public void setTypeSettingsProperties(
159 UnicodeProperties typeSettingsProperties) {
160
161 _typeSettingsProperties = typeSettingsProperties;
162
163 super.setTypeSettings(_typeSettingsProperties.toString());
164 }
165
166 private static Log _log = LogFactoryUtil.getLog(ExpandoColumnImpl.class);
167
168 private UnicodeProperties _typeSettingsProperties;
169
170 }