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 {
100 return value.getString();
101 }
102 }
103 catch (Exception e) {
104 return null;
105 }
106 }
107
108 public String getDisplayName(Locale locale) {
109 String name = getName();
110
111 String displayName = LanguageUtil.get(locale, name);
112
113 if (name.equals(displayName)) {
114 displayName = TextFormatter.format(name, TextFormatter.J);
115 }
116
117 return displayName;
118 }
119
120 @Override
121 public String getTypeSettings() {
122 if (_typeSettingsProperties == null) {
123 return super.getTypeSettings();
124 }
125 else {
126 return _typeSettingsProperties.toString();
127 }
128 }
129
130 public UnicodeProperties getTypeSettingsProperties() {
131 if (_typeSettingsProperties == null) {
132 _typeSettingsProperties = new UnicodeProperties(true);
133
134 try {
135 _typeSettingsProperties.load(super.getTypeSettings());
136 }
137 catch (IOException ioe) {
138 _log.error(ioe, ioe);
139 }
140 }
141
142 return _typeSettingsProperties;
143 }
144
145 @Override
146 public void setTypeSettings(String typeSettings) {
147 _typeSettingsProperties = null;
148
149 super.setTypeSettings(typeSettings);
150 }
151
152 public void setTypeSettingsProperties(
153 UnicodeProperties typeSettingsProperties) {
154
155 _typeSettingsProperties = typeSettingsProperties;
156
157 super.setTypeSettings(_typeSettingsProperties.toString());
158 }
159
160 private static Log _log = LogFactoryUtil.getLog(ExpandoColumnImpl.class);
161
162 private UnicodeProperties _typeSettingsProperties;
163
164 }