Example usage for com.liferay.portal.kernel.util DateFormatFactoryUtil getDate

List of usage examples for com.liferay.portal.kernel.util DateFormatFactoryUtil getDate

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util DateFormatFactoryUtil getDate.

Prototype

public static DateFormat getDate(TimeZone timeZone) 

Source Link

Usage

From source file:com.liferay.portlet.dynamicdatamapping.util.DDMImpl.java

License:Open Source License

@Override
public Serializable getDisplayFieldValue(ThemeDisplay themeDisplay, Serializable fieldValue, String type)
        throws Exception {

    if (fieldValue instanceof Date) {
        Date valueDate = (Date) fieldValue;

        DateFormat dateFormat = DateFormatFactoryUtil.getDate(themeDisplay.getLocale());

        fieldValue = dateFormat.format(valueDate);
    } else if (type.equals(DDMImpl.TYPE_CHECKBOX)) {
        Boolean valueBoolean = (Boolean) fieldValue;

        if (valueBoolean) {
            fieldValue = LanguageUtil.get(themeDisplay.getLocale(), "yes");
        } else {//from w  w  w.  j av  a2 s. c o  m
            fieldValue = LanguageUtil.get(themeDisplay.getLocale(), "no");
        }
    } else if (type.equals(DDMImpl.TYPE_DDM_DOCUMENTLIBRARY)) {
        if (Validator.isNull(fieldValue)) {
            return StringPool.BLANK;
        }

        String valueString = String.valueOf(fieldValue);

        JSONObject jsonObject = JSONFactoryUtil.createJSONObject(valueString);

        String uuid = jsonObject.getString("uuid");
        long groupId = jsonObject.getLong("groupId");

        FileEntry fileEntry = DLAppLocalServiceUtil.getFileEntryByUuidAndGroupId(uuid, groupId);

        fieldValue = DLUtil.getPreviewURL(fileEntry, fileEntry.getFileVersion(), null, StringPool.BLANK, false,
                true);
    } else if (type.equals(DDMImpl.TYPE_DDM_LINK_TO_PAGE)) {
        if (Validator.isNull(fieldValue)) {
            return StringPool.BLANK;
        }

        String valueString = String.valueOf(fieldValue);

        JSONObject jsonObject = JSONFactoryUtil.createJSONObject(valueString);

        long groupId = jsonObject.getLong("groupId");
        boolean privateLayout = jsonObject.getBoolean("privateLayout");
        long layoutId = jsonObject.getLong("layoutId");

        Layout layout = LayoutLocalServiceUtil.getLayout(groupId, privateLayout, layoutId);

        fieldValue = PortalUtil.getLayoutFriendlyURL(layout, themeDisplay);
    } else if (type.equals(DDMImpl.TYPE_RADIO) || type.equals(DDMImpl.TYPE_SELECT)) {

        String valueString = String.valueOf(fieldValue);

        JSONArray jsonArray = JSONFactoryUtil.createJSONArray(valueString);

        String[] stringArray = ArrayUtil.toStringArray(jsonArray);

        fieldValue = stringArray[0];
    }

    return fieldValue;
}