001
014
015 package com.liferay.portlet.journal.service.http;
016
017 import com.liferay.portal.kernel.json.JSONArray;
018 import com.liferay.portal.kernel.json.JSONFactoryUtil;
019 import com.liferay.portal.kernel.json.JSONObject;
020 import com.liferay.portal.kernel.util.StringPool;
021
022 import com.liferay.portlet.journal.model.JournalTemplate;
023
024 import java.util.Date;
025 import java.util.List;
026
027
031 public class JournalTemplateJSONSerializer {
032 public static JSONObject toJSONObject(JournalTemplate model) {
033 JSONObject jsonObj = JSONFactoryUtil.createJSONObject();
034
035 jsonObj.put("uuid", model.getUuid());
036 jsonObj.put("id", model.getId());
037 jsonObj.put("groupId", model.getGroupId());
038 jsonObj.put("companyId", model.getCompanyId());
039 jsonObj.put("userId", model.getUserId());
040 jsonObj.put("userName", model.getUserName());
041
042 Date createDate = model.getCreateDate();
043
044 String createDateJSON = StringPool.BLANK;
045
046 if (createDate != null) {
047 createDateJSON = String.valueOf(createDate.getTime());
048 }
049
050 jsonObj.put("createDate", createDateJSON);
051
052 Date modifiedDate = model.getModifiedDate();
053
054 String modifiedDateJSON = StringPool.BLANK;
055
056 if (modifiedDate != null) {
057 modifiedDateJSON = String.valueOf(modifiedDate.getTime());
058 }
059
060 jsonObj.put("modifiedDate", modifiedDateJSON);
061 jsonObj.put("templateId", model.getTemplateId());
062 jsonObj.put("structureId", model.getStructureId());
063 jsonObj.put("name", model.getName());
064 jsonObj.put("description", model.getDescription());
065 jsonObj.put("xsl", model.getXsl());
066 jsonObj.put("langType", model.getLangType());
067 jsonObj.put("cacheable", model.getCacheable());
068 jsonObj.put("smallImage", model.getSmallImage());
069 jsonObj.put("smallImageId", model.getSmallImageId());
070 jsonObj.put("smallImageURL", model.getSmallImageURL());
071
072 return jsonObj;
073 }
074
075 public static JSONArray toJSONArray(
076 com.liferay.portlet.journal.model.JournalTemplate[] models) {
077 JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
078
079 for (JournalTemplate model : models) {
080 jsonArray.put(toJSONObject(model));
081 }
082
083 return jsonArray;
084 }
085
086 public static JSONArray toJSONArray(
087 com.liferay.portlet.journal.model.JournalTemplate[][] models) {
088 JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
089
090 for (JournalTemplate[] model : models) {
091 jsonArray.put(toJSONArray(model));
092 }
093
094 return jsonArray;
095 }
096
097 public static JSONArray toJSONArray(
098 List<com.liferay.portlet.journal.model.JournalTemplate> models) {
099 JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
100
101 for (JournalTemplate model : models) {
102 jsonArray.put(toJSONObject(model));
103 }
104
105 return jsonArray;
106 }
107 }