001
014
015 package com.liferay.portlet.dynamicdatamapping.storage;
016
017 import com.liferay.portal.kernel.util.FastDateFormatFactoryUtil;
018 import com.liferay.portal.kernel.util.StringPool;
019 import com.liferay.portal.kernel.util.StringUtil;
020 import com.liferay.portal.kernel.util.Validator;
021
022 import java.io.Serializable;
023
024 import java.text.Format;
025
026 import java.util.ArrayList;
027 import java.util.List;
028 import java.util.Locale;
029
030
034 public class DateFieldRenderer extends BaseFieldRenderer {
035
036 @Override
037 protected String doRender(Field field, Locale locale) throws Exception {
038 Format format = FastDateFormatFactoryUtil.getDate(locale);
039
040 List<String> values = new ArrayList<String>();
041
042 for (Serializable value : field.getValues(locale)) {
043 if (Validator.isNull(value)) {
044 continue;
045 }
046
047 values.add(format.format(value));
048 }
049
050 return StringUtil.merge(values, StringPool.COMMA_AND_SPACE);
051 }
052
053 @Override
054 protected String doRender(Field field, Locale locale, int valueIndex) {
055 Serializable value = field.getValue(locale, valueIndex);
056
057 if (Validator.isNull(value)) {
058 return StringPool.BLANK;
059 }
060
061 Format format = FastDateFormatFactoryUtil.getDate(locale);
062
063 return format.format(value);
064 }
065
066 }