1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions 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.portlet.communities.action;
24  
25  import com.liferay.portal.LayoutFriendlyURLException;
26  import com.liferay.portal.LayoutHiddenException;
27  import com.liferay.portal.LayoutNameException;
28  import com.liferay.portal.LayoutParentLayoutIdException;
29  import com.liferay.portal.LayoutSetVirtualHostException;
30  import com.liferay.portal.LayoutTypeException;
31  import com.liferay.portal.NoSuchGroupException;
32  import com.liferay.portal.NoSuchLayoutException;
33  import com.liferay.portal.RemoteExportException;
34  import com.liferay.portal.RequiredLayoutException;
35  import com.liferay.portal.events.EventsProcessorUtil;
36  import com.liferay.portal.kernel.configuration.Filter;
37  import com.liferay.portal.kernel.servlet.SessionErrors;
38  import com.liferay.portal.kernel.upload.UploadPortletRequest;
39  import com.liferay.portal.kernel.util.Constants;
40  import com.liferay.portal.kernel.util.FileUtil;
41  import com.liferay.portal.kernel.util.GetterUtil;
42  import com.liferay.portal.kernel.util.ParamUtil;
43  import com.liferay.portal.kernel.util.PropertiesParamUtil;
44  import com.liferay.portal.kernel.util.StringUtil;
45  import com.liferay.portal.kernel.util.UnicodeProperties;
46  import com.liferay.portal.kernel.util.Validator;
47  import com.liferay.portal.model.ColorScheme;
48  import com.liferay.portal.model.Group;
49  import com.liferay.portal.model.Layout;
50  import com.liferay.portal.model.LayoutConstants;
51  import com.liferay.portal.model.LayoutTypePortlet;
52  import com.liferay.portal.model.PortletPreferencesIds;
53  import com.liferay.portal.model.User;
54  import com.liferay.portal.security.auth.PrincipalException;
55  import com.liferay.portal.security.permission.ActionKeys;
56  import com.liferay.portal.security.permission.PermissionChecker;
57  import com.liferay.portal.service.GroupLocalServiceUtil;
58  import com.liferay.portal.service.GroupServiceUtil;
59  import com.liferay.portal.service.LayoutLocalServiceUtil;
60  import com.liferay.portal.service.LayoutServiceUtil;
61  import com.liferay.portal.service.LayoutSetServiceUtil;
62  import com.liferay.portal.service.PortletPreferencesLocalServiceUtil;
63  import com.liferay.portal.service.ThemeLocalServiceUtil;
64  import com.liferay.portal.service.UserLocalServiceUtil;
65  import com.liferay.portal.service.permission.GroupPermissionUtil;
66  import com.liferay.portal.service.permission.LayoutPermissionUtil;
67  import com.liferay.portal.service.permission.OrganizationPermissionUtil;
68  import com.liferay.portal.service.permission.UserPermissionUtil;
69  import com.liferay.portal.struts.PortletAction;
70  import com.liferay.portal.theme.ThemeDisplay;
71  import com.liferay.portal.util.PortalUtil;
72  import com.liferay.portal.util.PortletKeys;
73  import com.liferay.portal.util.PropsKeys;
74  import com.liferay.portal.util.PropsUtil;
75  import com.liferay.portal.util.PropsValues;
76  import com.liferay.portal.util.WebKeys;
77  import com.liferay.portlet.PortletPreferencesFactoryUtil;
78  import com.liferay.portlet.communities.util.CommunitiesUtil;
79  import com.liferay.portlet.communities.util.StagingUtil;
80  import com.liferay.portlet.tasks.NoSuchProposalException;
81  import com.liferay.util.LocalizationUtil;
82  import com.liferay.util.servlet.UploadException;
83  
84  import java.io.File;
85  
86  import java.util.List;
87  import java.util.Locale;
88  import java.util.Map;
89  
90  import javax.portlet.ActionRequest;
91  import javax.portlet.ActionResponse;
92  import javax.portlet.PortletConfig;
93  import javax.portlet.PortletPreferences;
94  import javax.portlet.PortletRequest;
95  import javax.portlet.PortletRequestDispatcher;
96  import javax.portlet.RenderRequest;
97  import javax.portlet.RenderResponse;
98  import javax.portlet.ResourceRequest;
99  import javax.portlet.ResourceResponse;
100 
101 import javax.servlet.http.HttpServletRequest;
102 import javax.servlet.http.HttpServletResponse;
103 
104 import org.apache.struts.action.ActionForm;
105 import org.apache.struts.action.ActionForward;
106 import org.apache.struts.action.ActionMapping;
107 
108 /**
109  * <a href="EditPagesAction.java.html"><b><i>View Source</i></b></a>
110  *
111  * @author Brian Wing Shun Chan
112  *
113  */
114 public class EditPagesAction extends PortletAction {
115 
116     public void processAction(
117             ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
118             ActionRequest actionRequest, ActionResponse actionResponse)
119         throws Exception {
120 
121         try {
122             checkPermissions(actionRequest);
123         }
124         catch (PrincipalException pe) {
125             return;
126         }
127 
128         String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
129 
130         try {
131             if (cmd.equals(Constants.ADD) || cmd.equals(Constants.UPDATE)) {
132                 updateLayout(actionRequest, actionResponse);
133             }
134             else if (cmd.equals(Constants.DELETE)) {
135                 CommunitiesUtil.deleteLayout(actionRequest, actionResponse);
136             }
137             else if (cmd.equals("copy_from_live")) {
138                 StagingUtil.copyFromLive(actionRequest);
139             }
140             else if (cmd.equals("display_order")) {
141                 updateDisplayOrder(actionRequest);
142             }
143             else if (cmd.equals("logo")) {
144                 updateLogo(actionRequest);
145             }
146             else if (cmd.equals("look_and_feel")) {
147                 updateLookAndFeel(actionRequest);
148             }
149             else if (cmd.equals("merge_pages")) {
150                 updateMergePages(actionRequest);
151             }
152             else if (cmd.equals("monitoring")) {
153                 updateMonitoring(actionRequest);
154             }
155             else if (cmd.equals("publish_to_live")) {
156                 StagingUtil.publishToLive(actionRequest);
157             }
158             else if (cmd.equals("publish_to_remote")) {
159                 StagingUtil.publishToRemote(actionRequest);
160             }
161             else if (cmd.equals("schedule_copy_from_live")) {
162                 StagingUtil.scheduleCopyFromLive(actionRequest);
163             }
164             else if (cmd.equals("schedule_publish_to_live")) {
165                 StagingUtil.schedulePublishToLive(actionRequest);
166             }
167             else if (cmd.equals("schedule_publish_to_remote")) {
168                 StagingUtil.schedulePublishToRemote(actionRequest);
169             }
170             else if (cmd.equals("staging")) {
171                 StagingUtil.updateStaging(actionRequest);
172             }
173             else if (cmd.equals("unschedule_copy_from_live")) {
174                 StagingUtil.unscheduleCopyFromLive(actionRequest);
175             }
176             else if (cmd.equals("unschedule_publish_to_live")) {
177                 StagingUtil.unschedulePublishToLive(actionRequest);
178             }
179             else if (cmd.equals("unschedule_publish_to_remote")) {
180                 StagingUtil.unschedulePublishToRemote(actionRequest);
181             }
182             else if (cmd.equals("virtual_host")) {
183                 updateVirtualHost(actionRequest);
184             }
185             else if (cmd.equals("workflow")) {
186                 updateWorkflow(actionRequest);
187             }
188 
189             String redirect = ParamUtil.getString(
190                 actionRequest, "pagesRedirect");
191 
192             sendRedirect(actionRequest, actionResponse, redirect);
193         }
194         catch (Exception e) {
195             if (e instanceof NoSuchLayoutException ||
196                 e instanceof NoSuchProposalException ||
197                 e instanceof PrincipalException) {
198 
199                 SessionErrors.add(actionRequest, e.getClass().getName());
200 
201                 setForward(actionRequest, "portlet.communities.error");
202             }
203             else if (e instanceof RemoteExportException) {
204                 SessionErrors.add(actionRequest, e.getClass().getName(), e);
205 
206                 String redirect = ParamUtil.getString(
207                     actionRequest, "pagesRedirect");
208 
209                 sendRedirect(actionRequest, actionResponse, redirect);
210             }
211             else if (e instanceof LayoutFriendlyURLException ||
212                      e instanceof LayoutHiddenException ||
213                      e instanceof LayoutNameException ||
214                      e instanceof LayoutParentLayoutIdException ||
215                      e instanceof LayoutSetVirtualHostException ||
216                      e instanceof LayoutTypeException ||
217                      e instanceof RequiredLayoutException ||
218                      e instanceof UploadException) {
219 
220                 if (e instanceof LayoutFriendlyURLException) {
221                     SessionErrors.add(
222                         actionRequest,
223                         LayoutFriendlyURLException.class.getName(), e);
224                 }
225                 else {
226                     SessionErrors.add(actionRequest, e.getClass().getName(), e);
227                 }
228             }
229             else {
230                 throw e;
231             }
232         }
233     }
234 
235     public ActionForward render(
236             ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
237             RenderRequest renderRequest, RenderResponse renderResponse)
238         throws Exception {
239 
240         try {
241             checkPermissions(renderRequest);
242         }
243         catch (PrincipalException pe) {
244             SessionErrors.add(
245                 renderRequest, PrincipalException.class.getName());
246 
247             return mapping.findForward("portlet.communities.error");
248         }
249 
250         try {
251             ActionUtil.getGroup(renderRequest);
252         }
253         catch (Exception e) {
254             if (e instanceof NoSuchGroupException ||
255                 e instanceof PrincipalException) {
256 
257                 SessionErrors.add(renderRequest, e.getClass().getName());
258 
259                 return mapping.findForward("portlet.communities.error");
260             }
261             else {
262                 throw e;
263             }
264         }
265 
266         return mapping.findForward(
267             getForward(renderRequest, "portlet.communities.edit_pages"));
268     }
269 
270     public void serveResource(
271             ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
272             ResourceRequest resourceRequest, ResourceResponse resourceResponse)
273         throws Exception {
274 
275         String resourceId = GetterUtil.getString(
276             resourceRequest.getResourceID());
277 
278         if (resourceId.equals("/html/portlet/communities/tree_js_node.jsp")) {
279             long groupId = ParamUtil.getLong(resourceRequest, "groupId");
280             boolean privateLayout = ParamUtil.getBoolean(
281                 resourceRequest, "privateLayout");
282             long parentLayoutId = ParamUtil.getLong(
283                 resourceRequest, "parentLayoutId");
284             long nodeId = ParamUtil.getLong(resourceRequest, "nodeId");
285             long[] openNodes = StringUtil.split(
286                 ParamUtil.getString(resourceRequest, "openNodes"), 0L);
287             boolean selectableTree = ParamUtil.getBoolean(
288                 resourceRequest, "selectableTree");
289             long[] selectedNodes = StringUtil.split(
290                 ParamUtil.getString(resourceRequest, "selectedNodes"), 0L);
291             String portletURL = ParamUtil.getString(
292                 resourceRequest, "portletURL");
293 
294             resourceRequest.setAttribute(WebKeys.TREE_GROUP_ID, groupId);
295             resourceRequest.setAttribute(
296                 WebKeys.TREE_PRIVATE_LAYOUT, privateLayout);
297             resourceRequest.setAttribute(
298                 WebKeys.TREE_PARENT_LAYOUT_ID, parentLayoutId);
299             resourceRequest.setAttribute(WebKeys.TREE_NODE_ID, nodeId);
300             resourceRequest.setAttribute(WebKeys.TREE_OPEN_NODES, openNodes);
301             resourceRequest.setAttribute(
302                 WebKeys.TREE_SELECTABLE_TREE, selectableTree);
303             resourceRequest.setAttribute(
304                 WebKeys.TREE_SELECTED_NODES, selectedNodes);
305             resourceRequest.setAttribute(WebKeys.TREE_PORTLET_URL, portletURL);
306             resourceRequest.setAttribute(
307                 WebKeys.TREE_RENDER_CHILDREN_ONLY, true);
308         }
309         else {
310             resourceId =
311                 "/html/portlet/communities/scheduled_publishing_events.jsp";
312         }
313 
314         PortletRequestDispatcher portletRequestDispatcher =
315             portletConfig.getPortletContext().getRequestDispatcher(resourceId);
316 
317         portletRequestDispatcher.include(resourceRequest, resourceResponse);
318     }
319 
320     protected void checkPermissions(PortletRequest portletRequest)
321         throws Exception {
322 
323         // LEP-850
324 
325         ThemeDisplay themeDisplay = (ThemeDisplay)portletRequest.getAttribute(
326             WebKeys.THEME_DISPLAY);
327 
328         PermissionChecker permissionChecker =
329             themeDisplay.getPermissionChecker();
330 
331         String tabs1 = ParamUtil.getString(portletRequest, "tabs1");
332 
333         long groupId = ParamUtil.getLong(portletRequest, "groupId");
334         boolean privateLayout = tabs1.equals("private-pages");
335 
336         Group group = GroupLocalServiceUtil.getGroup(groupId);
337 
338         Layout layout = themeDisplay.getLayout();
339 
340         boolean hasUpdateLayoutPermission = false;
341 
342         if (layout != null) {
343             hasUpdateLayoutPermission = LayoutPermissionUtil.contains(
344                 permissionChecker, layout.getGroupId(),
345                 layout.isPrivateLayout(), layout.getLayoutId(),
346                 ActionKeys.UPDATE);
347         }
348 
349         if (group.isCommunity()) {
350             if (!GroupPermissionUtil.contains(
351                     permissionChecker, group.getGroupId(),
352                     ActionKeys.APPROVE_PROPOSAL) &&
353                 !GroupPermissionUtil.contains(
354                     permissionChecker, group.getGroupId(),
355                     ActionKeys.MANAGE_LAYOUTS) &&
356                 !hasUpdateLayoutPermission) {
357 
358                 throw new PrincipalException();
359             }
360         }
361         else if (group.isOrganization()) {
362             long organizationId = group.getClassPK();
363 
364             if (!OrganizationPermissionUtil.contains(
365                     permissionChecker, organizationId,
366                     ActionKeys.APPROVE_PROPOSAL) &&
367                 !OrganizationPermissionUtil.contains(
368                     permissionChecker, organizationId,
369                     ActionKeys.MANAGE_LAYOUTS) &&
370                 !hasUpdateLayoutPermission) {
371 
372                 throw new PrincipalException();
373             }
374         }
375         else if (group.isUser()) {
376             long groupUserId = group.getClassPK();
377 
378             User groupUser = UserLocalServiceUtil.getUserById(groupUserId);
379 
380             long[] organizationIds = groupUser.getOrganizationIds();
381 
382             UserPermissionUtil.check(
383                 permissionChecker, groupUserId, organizationIds,
384                 ActionKeys.UPDATE);
385 
386             if ((privateLayout &&
387                  !PropsValues.LAYOUT_USER_PRIVATE_LAYOUTS_MODIFIABLE) ||
388                 (!privateLayout &&
389                  !PropsValues.LAYOUT_USER_PUBLIC_LAYOUTS_MODIFIABLE)) {
390 
391                 throw new PrincipalException();
392             }
393         }
394     }
395 
396     protected void copyPreferences(
397             ActionRequest actionRequest, Layout layout, Layout copyLayout)
398         throws Exception {
399 
400         long companyId = layout.getCompanyId();
401 
402         LayoutTypePortlet copyLayoutTypePortlet =
403             (LayoutTypePortlet)copyLayout.getLayoutType();
404 
405         List<String> copyPortletIds = copyLayoutTypePortlet.getPortletIds();
406 
407         for (String copyPortletId : copyPortletIds) {
408             HttpServletRequest request = PortalUtil.getHttpServletRequest(
409                 actionRequest);
410 
411             // Copy preference
412 
413             PortletPreferencesIds portletPreferencesIds =
414                 PortletPreferencesFactoryUtil.getPortletPreferencesIds(
415                     request, layout, copyPortletId);
416 
417             PortletPreferencesLocalServiceUtil.getPreferences(
418                 portletPreferencesIds);
419 
420             PortletPreferencesIds copyPortletPreferencesIds =
421                 PortletPreferencesFactoryUtil.getPortletPreferencesIds(
422                     request, copyLayout, copyPortletId);
423 
424             PortletPreferences copyPrefs =
425                 PortletPreferencesLocalServiceUtil.getPreferences(
426                     copyPortletPreferencesIds);
427 
428             PortletPreferencesLocalServiceUtil.updatePreferences(
429                 portletPreferencesIds.getOwnerId(),
430                 portletPreferencesIds.getOwnerType(),
431                 portletPreferencesIds.getPlid(),
432                 portletPreferencesIds.getPortletId(), copyPrefs);
433 
434             // Copy portlet setup
435 
436             PortletPreferencesLocalServiceUtil.getPreferences(
437                 companyId, PortletKeys.PREFS_OWNER_ID_DEFAULT,
438                 PortletKeys.PREFS_OWNER_TYPE_LAYOUT, layout.getPlid(),
439                 copyPortletId);
440 
441             copyPrefs =
442                 PortletPreferencesLocalServiceUtil.getPreferences(
443                     companyId, PortletKeys.PREFS_OWNER_ID_DEFAULT,
444                     PortletKeys.PREFS_OWNER_TYPE_LAYOUT, copyLayout.getPlid(),
445                     copyPortletId);
446 
447             PortletPreferencesLocalServiceUtil.updatePreferences(
448                 PortletKeys.PREFS_OWNER_ID_DEFAULT,
449                 PortletKeys.PREFS_OWNER_TYPE_LAYOUT, layout.getPlid(),
450                 copyPortletId, copyPrefs);
451         }
452     }
453 
454     protected UnicodeProperties getTypeSettingsProperties(
455         ActionRequest actionRequest) {
456 
457         return PropertiesParamUtil.getProperties(
458             actionRequest, "TypeSettingsProperties(");
459     }
460 
461     protected void updateDisplayOrder(ActionRequest actionRequest)
462         throws Exception {
463 
464         long groupId = ParamUtil.getLong(actionRequest, "groupId");
465         boolean privateLayout = ParamUtil.getBoolean(
466             actionRequest, "privateLayout");
467         long parentLayoutId = ParamUtil.getLong(
468             actionRequest, "parentLayoutId");
469         long[] layoutIds = StringUtil.split(
470             ParamUtil.getString(actionRequest, "layoutIds"), 0L);
471 
472         LayoutServiceUtil.setLayouts(
473             groupId, privateLayout, parentLayoutId, layoutIds);
474     }
475 
476     protected void updateLayout(
477             ActionRequest actionRequest, ActionResponse actionResponse)
478         throws Exception {
479 
480         UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(
481             actionRequest);
482 
483         String cmd = ParamUtil.getString(uploadRequest, Constants.CMD);
484 
485         long groupId = ParamUtil.getLong(actionRequest, "groupId");
486         boolean privateLayout = ParamUtil.getBoolean(
487             actionRequest, "privateLayout");
488         long layoutId = ParamUtil.getLong(actionRequest, "layoutId");
489         long parentLayoutId = ParamUtil.getLong(
490             uploadRequest, "parentLayoutId");
491         String description = ParamUtil.getString(uploadRequest, "description");
492         String type = ParamUtil.getString(uploadRequest, "type");
493         boolean hidden = ParamUtil.getBoolean(uploadRequest, "hidden");
494         String friendlyURL = ParamUtil.getString(uploadRequest, "friendlyURL");
495         boolean iconImage = ParamUtil.getBoolean(uploadRequest, "iconImage");
496         byte[] iconBytes = FileUtil.getBytes(
497             uploadRequest.getFile("iconFileName"));
498 
499         boolean inheritFromParentLayoutId = ParamUtil.getBoolean(
500             uploadRequest, "inheritFromParentLayoutId");
501 
502         long copyLayoutId = ParamUtil.getLong(uploadRequest, "copyLayoutId");
503 
504         Map<Locale, String> localeNamesMap =
505             LocalizationUtil.getLocalizedParameter(actionRequest, "name");
506         Map<Locale, String> localeTitlesMap =
507             LocalizationUtil.getLocalizedParameter(actionRequest, "title");
508 
509         if (cmd.equals(Constants.ADD)) {
510 
511             // Add layout
512 
513             if (inheritFromParentLayoutId && (parentLayoutId > 0)) {
514                 Layout parentLayout = LayoutLocalServiceUtil.getLayout(
515                     groupId, privateLayout, parentLayoutId);
516 
517                 Layout layout = LayoutServiceUtil.addLayout(
518                     groupId, privateLayout, parentLayoutId, localeNamesMap,
519                     localeTitlesMap, description, parentLayout.getType(),
520                     parentLayout.isHidden(), friendlyURL);
521 
522                 LayoutServiceUtil.updateLayout(
523                     layout.getGroupId(), layout.isPrivateLayout(),
524                     layout.getLayoutId(), parentLayout.getTypeSettings());
525 
526                 if (parentLayout.getType().equals(
527                         LayoutConstants.TYPE_PORTLET)) {
528 
529                     copyPreferences(actionRequest, layout, parentLayout);
530                 }
531             }
532             else {
533                 LayoutServiceUtil.addLayout(
534                     groupId, privateLayout, parentLayoutId, localeNamesMap,
535                     localeTitlesMap, description, type, hidden, friendlyURL);
536             }
537         }
538         else {
539 
540             // Update layout
541 
542             Layout layout = LayoutLocalServiceUtil.getLayout(
543                 groupId, privateLayout, layoutId);
544 
545             layout = LayoutServiceUtil.updateLayout(
546                 groupId, privateLayout, layoutId, layout.getParentLayoutId(),
547                 localeNamesMap, localeTitlesMap, description, type, hidden,
548                 friendlyURL, Boolean.valueOf(iconImage), iconBytes);
549 
550             UnicodeProperties formTypeSettingsProperties =
551                 getTypeSettingsProperties(actionRequest);
552 
553             if (type.equals(LayoutConstants.TYPE_PORTLET)) {
554                 if ((copyLayoutId > 0) &&
555                     (copyLayoutId != layout.getLayoutId())) {
556 
557                     try {
558                         Layout copyLayout = LayoutLocalServiceUtil.getLayout(
559                             groupId, privateLayout, copyLayoutId);
560 
561                         if (copyLayout.getType().equals(
562                                 LayoutConstants.TYPE_PORTLET)) {
563 
564                             LayoutServiceUtil.updateLayout(
565                                 groupId, privateLayout, layoutId,
566                                 copyLayout.getTypeSettings());
567 
568                             copyPreferences(actionRequest, layout, copyLayout);
569                         }
570                     }
571                     catch (NoSuchLayoutException nsle) {
572                     }
573                 }
574                 else {
575                     UnicodeProperties layoutTypeSettingsProperties =
576                         layout.getTypeSettingsProperties();
577 
578                     for (String property: formTypeSettingsProperties.keySet()) {
579                         layoutTypeSettingsProperties.setProperty(
580                             property,
581                             formTypeSettingsProperties.getProperty(property));
582                     }
583 
584                     LayoutServiceUtil.updateLayout(
585                         groupId, privateLayout, layoutId,
586                         layout.getTypeSettings());
587                 }
588             }
589             else {
590                 layout.setTypeSettingsProperties(formTypeSettingsProperties);
591 
592                 LayoutServiceUtil.updateLayout(
593                     groupId, privateLayout, layoutId, layout.getTypeSettings());
594             }
595 
596             HttpServletResponse response = PortalUtil.getHttpServletResponse(
597                 actionResponse);
598 
599             String[] eventClasses = StringUtil.split(
600                 PropsUtil.get(
601                     PropsKeys.LAYOUT_CONFIGURATION_ACTION_UPDATE,
602                     new Filter(type)));
603 
604             EventsProcessorUtil.process(
605                 PropsKeys.LAYOUT_CONFIGURATION_ACTION_UPDATE, eventClasses,
606                 uploadRequest, response);
607         }
608     }
609 
610     protected void updateLogo(ActionRequest actionRequest) throws Exception {
611         UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(
612             actionRequest);
613 
614         long liveGroupId = ParamUtil.getLong(actionRequest, "liveGroupId");
615         long stagingGroupId = ParamUtil.getLong(
616             actionRequest, "stagingGroupId");
617 
618         boolean privateLayout = ParamUtil.getBoolean(
619             actionRequest, "privateLayout");
620         boolean logo = ParamUtil.getBoolean(actionRequest, "logo");
621 
622         File file = uploadRequest.getFile("logoFileName");
623         byte[] bytes = FileUtil.getBytes(file);
624 
625         if (logo && ((bytes == null) || (bytes.length == 0))) {
626             throw new UploadException();
627         }
628 
629         LayoutSetServiceUtil.updateLogo(liveGroupId, privateLayout, logo, file);
630 
631         if (stagingGroupId > 0) {
632             LayoutSetServiceUtil.updateLogo(
633                 stagingGroupId, privateLayout, logo, file);
634         }
635     }
636 
637     protected void updateLookAndFeel(ActionRequest actionRequest)
638         throws Exception {
639 
640         ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(
641             WebKeys.THEME_DISPLAY);
642 
643         long companyId = themeDisplay.getCompanyId();
644 
645         long liveGroupId = ParamUtil.getLong(actionRequest, "liveGroupId");
646         long stagingGroupId = ParamUtil.getLong(
647             actionRequest, "stagingGroupId");
648 
649         boolean privateLayout = ParamUtil.getBoolean(
650             actionRequest, "privateLayout");
651         long layoutId = ParamUtil.getLong(actionRequest, "layoutId");
652         String themeId = ParamUtil.getString(actionRequest, "themeId");
653         String colorSchemeId = ParamUtil.getString(
654             actionRequest, "colorSchemeId");
655         String css = ParamUtil.getString(actionRequest, "css");
656         boolean wapTheme = ParamUtil.getBoolean(actionRequest, "wapTheme");
657 
658         if (stagingGroupId > 0) {
659             updateLookAndFeel(
660                 companyId, stagingGroupId, privateLayout, layoutId, themeId,
661                 colorSchemeId, css, wapTheme);
662         }
663         else {
664             updateLookAndFeel(
665                 companyId, liveGroupId, privateLayout, layoutId, themeId,
666                 colorSchemeId, css, wapTheme);
667         }
668     }
669 
670     protected void updateLookAndFeel(
671             long companyId, long groupId, boolean privateLayout, long layoutId,
672             String themeId, String colorSchemeId, String css, boolean wapTheme)
673         throws Exception {
674 
675         if (Validator.isNotNull(themeId) && Validator.isNull(colorSchemeId)) {
676             ColorScheme colorScheme = ThemeLocalServiceUtil.getColorScheme(
677                 companyId, themeId, colorSchemeId, wapTheme);
678 
679             colorSchemeId = colorScheme.getColorSchemeId();
680         }
681 
682         if (layoutId <= 0) {
683             LayoutSetServiceUtil.updateLookAndFeel(
684                 groupId, privateLayout, themeId, colorSchemeId, css, wapTheme);
685         }
686         else {
687             LayoutServiceUtil.updateLookAndFeel(
688                 groupId, privateLayout, layoutId, themeId, colorSchemeId, css,
689                 wapTheme);
690         }
691     }
692 
693     protected void updateMergePages(ActionRequest actionRequest)
694         throws Exception {
695 
696         long liveGroupId = ParamUtil.getLong(actionRequest, "liveGroupId");
697 
698         boolean mergeGuestPublicPages = ParamUtil.getBoolean(
699             actionRequest, "mergeGuestPublicPages");
700 
701         Group liveGroup = GroupLocalServiceUtil.getGroup(liveGroupId);
702 
703         UnicodeProperties props = liveGroup.getTypeSettingsProperties();
704 
705         props.setProperty(
706             "mergeGuestPublicPages", String.valueOf(mergeGuestPublicPages));
707 
708         GroupServiceUtil.updateGroup(liveGroupId, liveGroup.getTypeSettings());
709     }
710 
711     protected void updateMonitoring(ActionRequest actionRequest)
712         throws Exception {
713 
714         long liveGroupId = ParamUtil.getLong(actionRequest, "liveGroupId");
715 
716         String googleAnalyticsId = ParamUtil.getString(
717             actionRequest, "googleAnalyticsId");
718 
719         Group liveGroup = GroupLocalServiceUtil.getGroup(liveGroupId);
720 
721         UnicodeProperties props = liveGroup.getTypeSettingsProperties();
722 
723         props.setProperty("googleAnalyticsId", googleAnalyticsId);
724 
725         GroupServiceUtil.updateGroup(liveGroupId, liveGroup.getTypeSettings());
726     }
727 
728     protected void updateVirtualHost(ActionRequest actionRequest)
729         throws Exception {
730 
731         long liveGroupId = ParamUtil.getLong(actionRequest, "liveGroupId");
732 
733         String publicVirtualHost = ParamUtil.getString(
734             actionRequest, "publicVirtualHost");
735         String privateVirtualHost = ParamUtil.getString(
736             actionRequest, "privateVirtualHost");
737         String friendlyURL = ParamUtil.getString(actionRequest, "friendlyURL");
738 
739         LayoutSetServiceUtil.updateVirtualHost(
740             liveGroupId, false, publicVirtualHost);
741 
742         LayoutSetServiceUtil.updateVirtualHost(
743             liveGroupId, true, privateVirtualHost);
744 
745         GroupServiceUtil.updateFriendlyURL(liveGroupId, friendlyURL);
746 
747         Group liveGroup = GroupServiceUtil.getGroup(liveGroupId);
748 
749         if (liveGroup.hasStagingGroup()) {
750             Group stagingGroup = liveGroup.getStagingGroup();
751 
752             publicVirtualHost = ParamUtil.getString(
753                 actionRequest, "stagingPublicVirtualHost");
754             privateVirtualHost = ParamUtil.getString(
755                 actionRequest, "stagingPrivateVirtualHost");
756             friendlyURL = ParamUtil.getString(
757                 actionRequest, "stagingFriendlyURL");
758 
759             LayoutSetServiceUtil.updateVirtualHost(
760                 stagingGroup.getGroupId(), false, publicVirtualHost);
761 
762             LayoutSetServiceUtil.updateVirtualHost(
763                 stagingGroup.getGroupId(), true, privateVirtualHost);
764 
765             GroupServiceUtil.updateFriendlyURL(
766                 stagingGroup.getGroupId(), friendlyURL);
767         }
768     }
769 
770     protected void updateWorkflow(ActionRequest actionRequest)
771         throws Exception {
772 
773         long liveGroupId = ParamUtil.getLong(actionRequest, "liveGroupId");
774 
775         boolean workflowEnabled = ParamUtil.getBoolean(
776             actionRequest, "workflowEnabled");
777         int workflowStages = ParamUtil.getInteger(
778             actionRequest, "workflowStages");
779 
780         StringBuilder sb = new StringBuilder();
781 
782         for (int i = 1; i <= workflowStages; i++) {
783             String workflowRoleName = ParamUtil.getString(
784                 actionRequest, "workflowRoleName_" + i);
785 
786             sb.append(workflowRoleName);
787 
788             if ((i + 1) <= workflowStages) {
789                 sb.append(",");
790             }
791         }
792 
793         String workflowRoleNames = sb.toString();
794 
795         GroupServiceUtil.updateWorkflow(
796             liveGroupId, workflowEnabled, workflowStages, workflowRoleNames);
797     }
798 
799 }