001
014
015 package com.liferay.portlet.social.model.impl;
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.util.LocaleUtil;
021 import com.liferay.portal.kernel.util.LocalizationUtil;
022 import com.liferay.portal.kernel.util.Validator;
023 import com.liferay.portlet.asset.model.AssetEntry;
024 import com.liferay.portlet.asset.service.AssetEntryLocalServiceUtil;
025
026 import java.util.Locale;
027
028
032 public class SocialActivityImpl extends SocialActivityBaseImpl {
033
034 @Override
035 public AssetEntry getAssetEntry() {
036 if ((_assetEntry == null) && Validator.isNotNull(getClassName()) &&
037 (getClassPK() > 0)) {
038
039 _assetEntry = AssetEntryLocalServiceUtil.fetchEntry(
040 getClassName(), getClassPK());
041 }
042
043 return _assetEntry;
044 }
045
046 @Override
047 public String getExtraDataValue(String key) throws JSONException {
048 JSONObject extraDataJSONObject = getExtraDataJSONObject();
049
050 return extraDataJSONObject.getString(key);
051 }
052
053 @Override
054 public String getExtraDataValue(String key, Locale locale)
055 throws JSONException {
056
057 JSONObject extraDataJSONObject = getExtraDataJSONObject();
058
059 return LocalizationUtil.getLocalization(
060 extraDataJSONObject.getString(key),
061 LocaleUtil.toLanguageId(locale));
062 }
063
064 @Override
065 public boolean isClassName(String className) {
066 if (className == null) {
067 return false;
068 }
069
070 return className.equals(getClassName());
071 }
072
073 @Override
074 public void setAssetEntry(AssetEntry assetEntry) {
075 _assetEntry = assetEntry;
076 }
077
078 @Override
079 public void setExtraData(String extraData) {
080 _extraDataJSONObject = null;
081
082 super.setExtraData(extraData);
083 }
084
085 @Override
086 public void setExtraDataValue(String key, String value)
087 throws JSONException {
088
089 JSONObject extraDataJSONObject = getExtraDataJSONObject();
090
091 extraDataJSONObject.put(key, value);
092
093 super.setExtraData(extraDataJSONObject.toString());
094 }
095
096 protected JSONObject getExtraDataJSONObject() throws JSONException {
097 if (_extraDataJSONObject != null) {
098 return _extraDataJSONObject;
099 }
100
101 _extraDataJSONObject = JSONFactoryUtil.createJSONObject(getExtraData());
102
103 return _extraDataJSONObject;
104 }
105
106 private AssetEntry _assetEntry;
107 private JSONObject _extraDataJSONObject;
108
109 }