Example usage for com.liferay.portal.kernel.language LanguageUtil getTimeDescription

List of usage examples for com.liferay.portal.kernel.language LanguageUtil getTimeDescription

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.language LanguageUtil getTimeDescription.

Prototype

public static String getTimeDescription(Locale locale, long milliseconds, boolean approximate) 

Source Link

Usage

From source file:com.liferay.item.selector.taglib.internal.util.ItemSelectorRepositoryEntryBrowserUtil.java

License:Open Source License

public static JSONObject getItemMetadataJSONObject(FileEntry fileEntry, Locale locale) throws PortalException {

    JSONObject itemMetadataJSONObject = JSONFactoryUtil.createJSONObject();

    JSONArray groupsJSONArray = JSONFactoryUtil.createJSONArray();

    JSONObject firstTabJSONObject = JSONFactoryUtil.createJSONObject();

    JSONArray firstTabDataJSONArray = JSONFactoryUtil.createJSONArray();

    FileVersion latestFileVersion = fileEntry.getLatestFileVersion();

    firstTabDataJSONArray.put(_createJSONObject(LanguageUtil.get(locale, "format"),
            HtmlUtil.escape(latestFileVersion.getExtension())));

    firstTabDataJSONArray.put(_createJSONObject(LanguageUtil.get(locale, "size"),
            TextFormatter.formatStorageSize(fileEntry.getSize(), locale)));
    firstTabDataJSONArray.put(_createJSONObject(LanguageUtil.get(locale, "name"),
            HtmlUtil.escape(DLUtil.getTitleWithExtension(fileEntry))));

    Date modifiedDate = fileEntry.getModifiedDate();

    firstTabDataJSONArray.put(_createJSONObject(LanguageUtil.get(locale, "modified"),
            LanguageUtil.format(locale, "x-ago-by-x",
                    new Object[] {
                            LanguageUtil.getTimeDescription(locale,
                                    System.currentTimeMillis() - modifiedDate.getTime(), true),
                            HtmlUtil.escape(fileEntry.getUserName()) })));

    firstTabJSONObject.put("data", firstTabDataJSONArray);

    firstTabJSONObject.put("title", LanguageUtil.get(locale, "file-info"));

    groupsJSONArray.put(firstTabJSONObject);

    JSONObject secondTabJSONObject = JSONFactoryUtil.createJSONObject();

    JSONArray secondTabDataJSONArray = JSONFactoryUtil.createJSONArray();

    secondTabDataJSONArray.put(_createJSONObject(LanguageUtil.get(locale, "version"),
            HtmlUtil.escape(latestFileVersion.getVersion())));
    secondTabDataJSONArray.put(_createJSONObject(LanguageUtil.get(locale, "status"),
            WorkflowConstants.getStatusLabel(latestFileVersion.getStatus())));

    secondTabJSONObject.put("data", secondTabDataJSONArray);

    secondTabJSONObject.put("title", LanguageUtil.get(locale, "version"));

    groupsJSONArray.put(secondTabJSONObject);

    itemMetadataJSONObject.put("groups", groupsJSONArray);

    return itemMetadataJSONObject;
}