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