1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.service.http;
24  
25  import com.liferay.portal.kernel.json.JSONArray;
26  import com.liferay.portal.kernel.json.JSONFactoryUtil;
27  import com.liferay.portal.kernel.json.JSONObject;
28  import com.liferay.portal.kernel.util.StringPool;
29  import com.liferay.portal.model.Website;
30  
31  import java.util.Date;
32  import java.util.List;
33  
34  /**
35   * <a href="WebsiteJSONSerializer.java.html"><b><i>View Source</i></b></a>
36   *
37   * <p>
38   * ServiceBuilder generated this class. Modifications in this class will be
39   * overwritten the next time is generated.
40   * </p>
41   *
42   * <p>
43   * This class is used by {@link WebsiteServiceJSON} to translate objects.
44   * </p>
45   *
46   * @author    Brian Wing Shun Chan
47   * @see       com.liferay.portal.service.http.WebsiteServiceJSON
48   * @generated
49   */
50  public class WebsiteJSONSerializer {
51      public static JSONObject toJSONObject(Website model) {
52          JSONObject jsonObj = JSONFactoryUtil.createJSONObject();
53  
54          jsonObj.put("websiteId", model.getWebsiteId());
55          jsonObj.put("companyId", model.getCompanyId());
56          jsonObj.put("userId", model.getUserId());
57          jsonObj.put("userName", model.getUserName());
58  
59          Date createDate = model.getCreateDate();
60  
61          String createDateJSON = StringPool.BLANK;
62  
63          if (createDate != null) {
64              createDateJSON = String.valueOf(createDate.getTime());
65          }
66  
67          jsonObj.put("createDate", createDateJSON);
68  
69          Date modifiedDate = model.getModifiedDate();
70  
71          String modifiedDateJSON = StringPool.BLANK;
72  
73          if (modifiedDate != null) {
74              modifiedDateJSON = String.valueOf(modifiedDate.getTime());
75          }
76  
77          jsonObj.put("modifiedDate", modifiedDateJSON);
78          jsonObj.put("classNameId", model.getClassNameId());
79          jsonObj.put("classPK", model.getClassPK());
80          jsonObj.put("url", model.getUrl());
81          jsonObj.put("typeId", model.getTypeId());
82          jsonObj.put("primary", model.getPrimary());
83  
84          return jsonObj;
85      }
86  
87      public static JSONArray toJSONArray(
88          com.liferay.portal.model.Website[] models) {
89          JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
90  
91          for (Website model : models) {
92              jsonArray.put(toJSONObject(model));
93          }
94  
95          return jsonArray;
96      }
97  
98      public static JSONArray toJSONArray(
99          com.liferay.portal.model.Website[][] models) {
100         JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
101 
102         for (Website[] model : models) {
103             jsonArray.put(toJSONArray(model));
104         }
105 
106         return jsonArray;
107     }
108 
109     public static JSONArray toJSONArray(
110         List<com.liferay.portal.model.Website> models) {
111         JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
112 
113         for (Website model : models) {
114             jsonArray.put(toJSONObject(model));
115         }
116 
117         return jsonArray;
118     }
119 }