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;
16  
17  import com.liferay.portal.SystemException;
18  import com.liferay.portal.kernel.json.JSONObject;
19  import com.liferay.portal.kernel.util.LocaleUtil;
20  import com.liferay.portal.kernel.util.StringUtil;
21  import com.liferay.portal.model.PortletPreferencesIds;
22  
23  import java.util.Locale;
24  
25  import javax.portlet.PortletPreferences;
26  
27  /**
28   * <a href="ServiceContextUtil.java.html"><b><i>View Source</i></b></a>
29   *
30   * @author Raymond Augé
31   * @author Brian Wing Shun Chan
32   * @author Jorge Ferrer
33   */
34  public class ServiceContextUtil {
35  
36      public static Object deserialize(JSONObject jsonObject) {
37          ServiceContext serviceContext = new ServiceContext();
38  
39          // Theme display
40  
41          serviceContext.setCompanyId(jsonObject.getLong("companyId"));
42          serviceContext.setLayoutFullURL(jsonObject.getString("layoutFullURL"));
43          serviceContext.setLayoutURL(jsonObject.getString("layoutURL"));
44          serviceContext.setPathMain(jsonObject.getString("pathMain"));
45          serviceContext.setPlid(jsonObject.getLong("plid"));
46          serviceContext.setPortalURL(jsonObject.getString("portalURL"));
47          serviceContext.setScopeGroupId(jsonObject.getLong("scopeGroupId"));
48          serviceContext.setUserDisplayURL(
49              jsonObject.getString("userDisplayURL"));
50  
51          // Permissions
52  
53          String[] communityPermissions = StringUtil.split(
54              jsonObject.getString("communityPermissions"));
55          String[] guestPermissions = StringUtil.split(
56              jsonObject.getString("guestPermissions"));
57  
58          serviceContext.setAddCommunityPermissions(
59              jsonObject.getBoolean("addCommunityPermissions"));
60          serviceContext.setAddGuestPermissions(
61              jsonObject.getBoolean("addGuestPermissions"));
62          serviceContext.setCommunityPermissions(communityPermissions);
63          serviceContext.setGuestPermissions(guestPermissions);
64  
65          // Tags
66  
67          String[] tagsCategories = StringUtil.split(
68              jsonObject.getString("tagsCategories"));
69          String[] tagsEntries = StringUtil.split(
70              jsonObject.getString("tagsEntries"));
71  
72          serviceContext.setTagsCategories(tagsCategories);
73          serviceContext.setTagsEntries(tagsEntries);
74  
75          return serviceContext;
76      }
77  
78      public static Locale getLocale(ServiceContext serviceContext) {
79          return LocaleUtil.fromLanguageId(serviceContext.getLanguageId());
80      }
81  
82      public static PortletPreferences getPortletPreferences(
83              ServiceContext serviceContext)
84          throws SystemException {
85  
86          if (serviceContext == null) {
87              return null;
88          }
89  
90          PortletPreferencesIds portletPreferencesIds =
91              serviceContext.getPortletPreferencesIds();
92  
93          if (portletPreferencesIds == null) {
94              return null;
95          }
96          else {
97              return PortletPreferencesLocalServiceUtil.getPreferences(
98                  portletPreferencesIds.getCompanyId(),
99                  portletPreferencesIds.getOwnerId(),
100                 portletPreferencesIds.getOwnerType(),
101                 portletPreferencesIds.getPlid(),
102                 portletPreferencesIds.getPortletId());
103         }
104     }
105 
106 }