Example usage for com.liferay.portal.kernel.util DateUtil formatDate

List of usage examples for com.liferay.portal.kernel.util DateUtil formatDate

Introduction

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

Prototype

public static String formatDate(String fromPattern, String dateString, Locale locale) throws ParseException 

Source Link

Usage

From source file:com.liferay.dynamic.data.mapping.internal.render.DateDDMFormFieldValueRenderer.java

License:Open Source License

private String _format(Serializable value, Locale locale) {
    try {/*  w w  w .jav a  2 s.  c o m*/
        return DateUtil.formatDate("yyyy-MM-dd", value.toString(), locale);
    } catch (Exception e) {
        if (_log.isWarnEnabled()) {
            _log.warn(e, e);
        }

        return LanguageUtil.format(locale, "is-temporarily-unavailable", "content");
    }
}

From source file:com.liferay.dynamic.data.mapping.internal.util.DDMImpl.java

License:Open Source License

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

    if (type.equals(DDMImpl.TYPE_DDM_DATE)) {
        fieldValue = DateUtil.formatDate("yyyy-MM-dd", fieldValue.toString(), themeDisplay.getLocale());
    } else if (type.equals(DDMImpl.TYPE_CHECKBOX)) {
        Boolean valueBoolean = (Boolean) fieldValue;

        if (valueBoolean) {
            fieldValue = LanguageUtil.get(themeDisplay.getLocale(), "yes");
        } else {/* ww w. ja v  a  2s.  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 = _dlAppLocalService.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 = _layoutLocalService.getLayout(groupId, privateLayout, layoutId);

        fieldValue = _portal.getLayoutFriendlyURL(layout, themeDisplay);
    } else if (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;
}

From source file:com.liferay.dynamic.data.mapping.type.date.internal.DateDDMFormFieldValueRenderer.java

License:Open Source License

protected String render(String valueString, Locale locale) {
    if (Validator.isNotNull(valueString)) {
        try {//from  w  w  w  .j  a va 2 s .co  m
            return DateUtil.formatDate("yyyy-MM-dd", valueString, locale);
        } catch (ParseException pe) {
            _log.error("Unable to parse date", pe);
        }
    }

    return StringPool.BLANK;
}