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