1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portal.service.http;
16  
17  import com.liferay.portal.kernel.json.JSONArray;
18  import com.liferay.portal.kernel.json.JSONFactoryUtil;
19  import com.liferay.portal.kernel.json.JSONObject;
20  import com.liferay.portal.kernel.util.StringPool;
21  import com.liferay.portal.model.Image;
22  
23  import java.util.Date;
24  import java.util.List;
25  
26  /**
27   * <a href="ImageJSONSerializer.java.html"><b><i>View Source</i></b></a>
28   *
29   * <p>
30   * ServiceBuilder generated this class. Modifications in this class will be
31   * overwritten the next time is generated.
32   * </p>
33   *
34   * <p>
35   * This class is used by {@link ImageServiceJSON} to translate objects.
36   * </p>
37   *
38   * @author    Brian Wing Shun Chan
39   * @see       com.liferay.portal.service.http.ImageServiceJSON
40   * @generated
41   */
42  public class ImageJSONSerializer {
43      public static JSONObject toJSONObject(Image model) {
44          JSONObject jsonObj = JSONFactoryUtil.createJSONObject();
45  
46          jsonObj.put("imageId", model.getImageId());
47  
48          Date modifiedDate = model.getModifiedDate();
49  
50          String modifiedDateJSON = StringPool.BLANK;
51  
52          if (modifiedDate != null) {
53              modifiedDateJSON = String.valueOf(modifiedDate.getTime());
54          }
55  
56          jsonObj.put("modifiedDate", modifiedDateJSON);
57          jsonObj.put("text", model.getText());
58          jsonObj.put("type", model.getType());
59          jsonObj.put("height", model.getHeight());
60          jsonObj.put("width", model.getWidth());
61          jsonObj.put("size", model.getSize());
62  
63          return jsonObj;
64      }
65  
66      public static JSONArray toJSONArray(com.liferay.portal.model.Image[] models) {
67          JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
68  
69          for (Image model : models) {
70              jsonArray.put(toJSONObject(model));
71          }
72  
73          return jsonArray;
74      }
75  
76      public static JSONArray toJSONArray(
77          com.liferay.portal.model.Image[][] models) {
78          JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
79  
80          for (Image[] model : models) {
81              jsonArray.put(toJSONArray(model));
82          }
83  
84          return jsonArray;
85      }
86  
87      public static JSONArray toJSONArray(
88          List<com.liferay.portal.model.Image> models) {
89          JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
90  
91          for (Image model : models) {
92              jsonArray.put(toJSONObject(model));
93          }
94  
95          return jsonArray;
96      }
97  }