001
014
015 package com.liferay.portlet.dynamicdatamapping.storage;
016
017 import com.liferay.portal.kernel.json.JSONException;
018 import com.liferay.portal.kernel.json.JSONFactoryUtil;
019 import com.liferay.portal.kernel.json.JSONObject;
020 import com.liferay.portal.kernel.language.LanguageUtil;
021 import com.liferay.portal.kernel.log.Log;
022 import com.liferay.portal.kernel.log.LogFactoryUtil;
023 import com.liferay.portal.kernel.repository.model.FileEntry;
024 import com.liferay.portal.kernel.util.StringPool;
025 import com.liferay.portal.kernel.util.Validator;
026 import com.liferay.portal.security.auth.PrincipalException;
027 import com.liferay.portlet.documentlibrary.NoSuchFileEntryException;
028 import com.liferay.portlet.documentlibrary.service.DLAppServiceUtil;
029
030 import java.io.Serializable;
031
032 import java.util.Locale;
033
034
037 public class DocumentLibraryFieldRenderer extends BaseFieldRenderer {
038
039 @Override
040 protected String doRender(Field field, Locale locale) {
041 Serializable fieldValue = field.getValue();
042
043 if (Validator.isNull(fieldValue) ||
044 fieldValue.equals(JSONFactoryUtil.getNullJSON())) {
045
046 return StringPool.BLANK;
047 }
048
049 JSONObject fieldValueJSONObject = null;
050
051 try {
052 fieldValueJSONObject = JSONFactoryUtil.createJSONObject(
053 String.valueOf(fieldValue));
054 }
055 catch (JSONException jsone) {
056 if (_log.isDebugEnabled()) {
057 _log.debug("Unable to parse JSON", jsone);
058 }
059
060 return StringPool.BLANK;
061 }
062
063 long fileEntryGroupId = fieldValueJSONObject.getLong("groupId");
064 String fileEntryUUID = fieldValueJSONObject.getString("uuid");
065
066 try {
067 FileEntry fileEntry = DLAppServiceUtil.getFileEntryByUuidAndGroupId(
068 fileEntryUUID, fileEntryGroupId);
069
070 return fileEntry.getTitle();
071 }
072 catch (Exception e) {
073 if (e instanceof NoSuchFileEntryException ||
074 e instanceof PrincipalException) {
075
076 return LanguageUtil.format(
077 locale, "is-temporarily-unavailable", "content");
078 }
079 }
080
081 return StringPool.BLANK;
082 }
083
084 private static Log _log = LogFactoryUtil.getLog(
085 DocumentLibraryFieldRenderer.class);
086
087 }