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.EventsProcessor;
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             else {
527                 LayoutServiceUtil.addLayout(
528                     groupId, privateLayout, parentLayoutId, localeNamesMap,
529                     localeTitlesMap, description, type, hidden, friendlyURL);
530             }
531         }
532         else {
533 
534             // Update layout
535 
536             Layout layout = LayoutLocalServiceUtil.getLayout(
537                 groupId, privateLayout, layoutId);
538 
539             layout = LayoutServiceUtil.updateLayout(
540                 groupId, privateLayout, layoutId, layout.getParentLayoutId(),
541                 localeNamesMap, localeTitlesMap, description, type, hidden,
542                 friendlyURL, Boolean.valueOf(iconImage), iconBytes);
543 
544             UnicodeProperties formTypeSettingsProperties =
545                 getTypeSettingsProperties(actionRequest);
546 
547             if (type.equals(LayoutConstants.TYPE_PORTLET)) {
548                 if ((copyLayoutId > 0) &&
549                     (copyLayoutId != layout.getLayoutId())) {
550 
551                     try {
552                         Layout copyLayout = LayoutLocalServiceUtil.getLayout(
553                             groupId, privateLayout, copyLayoutId);
554 
555                         if (copyLayout.getType().equals(
556                                 LayoutConstants.TYPE_PORTLET)) {
557 
558                             LayoutServiceUtil.updateLayout(
559                                 groupId, privateLayout, layoutId,
560                                 copyLayout.getTypeSettings());
561 
562                             copyPreferences(actionRequest, layout, copyLayout);
563                         }
564                     }
565                     catch (NoSuchLayoutException nsle) {
566                     }
567                 }
568                 else {
569                     UnicodeProperties layoutTypeSettingsProperties =
570                         layout.getTypeSettingsProperties();
571 
572                     for (String property: formTypeSettingsProperties.keySet()) {
573                         layoutTypeSettingsProperties.setProperty(
574                             property,
575                             formTypeSettingsProperties.getProperty(property));
576                     }
577 
578                     LayoutServiceUtil.updateLayout(
579                         groupId, privateLayout, layoutId,
580                         layout.getTypeSettings());
581                 }
582             }
583             else {
584                 layout.setTypeSettingsProperties(formTypeSettingsProperties);
585 
586                 LayoutServiceUtil.updateLayout(
587                     groupId, privateLayout, layoutId, layout.getTypeSettings());
588             }
589 
590             HttpServletResponse response = PortalUtil.getHttpServletResponse(
591                 actionResponse);
592 
593             String[] eventClasses = StringUtil.split(
594                 PropsUtil.get(
595                     PropsKeys.LAYOUT_CONFIGURATION_ACTION_UPDATE,
596                     new Filter(type)));
597 
598             EventsProcessor.process(
599                 PropsKeys.LAYOUT_CONFIGURATION_ACTION_UPDATE, eventClasses,
600                 uploadRequest, response);
601         }
602     }
603 
604     protected void updateLogo(ActionRequest actionRequest) throws Exception {
605         UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(
606             actionRequest);
607 
608         long liveGroupId = ParamUtil.getLong(actionRequest, "liveGroupId");
609         long stagingGroupId = ParamUtil.getLong(
610             actionRequest, "stagingGroupId");
611 
612         boolean privateLayout = ParamUtil.getBoolean(
613             actionRequest, "privateLayout");
614         boolean logo = ParamUtil.getBoolean(actionRequest, "logo");
615 
616         File file = uploadRequest.getFile("logoFileName");
617         byte[] bytes = FileUtil.getBytes(file);
618 
619         if (logo && ((bytes == null) || (bytes.length == 0))) {
620             throw new UploadException();
621         }
622 
623         LayoutSetServiceUtil.updateLogo(liveGroupId, privateLayout, logo, file);
624 
625         if (stagingGroupId > 0) {
626             LayoutSetServiceUtil.updateLogo(
627                 stagingGroupId, privateLayout, logo, file);
628         }
629     }
630 
631     protected void updateLookAndFeel(ActionRequest actionRequest)
632         throws Exception {
633 
634         ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(
635             WebKeys.THEME_DISPLAY);
636 
637         long companyId = themeDisplay.getCompanyId();
638 
639         long liveGroupId = ParamUtil.getLong(actionRequest, "liveGroupId");
640         long stagingGroupId = ParamUtil.getLong(
641             actionRequest, "stagingGroupId");
642 
643         boolean privateLayout = ParamUtil.getBoolean(
644             actionRequest, "privateLayout");
645         long layoutId = ParamUtil.getLong(actionRequest, "layoutId");
646         String themeId = ParamUtil.getString(actionRequest, "themeId");
647         String colorSchemeId = ParamUtil.getString(
648             actionRequest, "colorSchemeId");
649         String css = ParamUtil.getString(actionRequest, "css");
650         boolean wapTheme = ParamUtil.getBoolean(actionRequest, "wapTheme");
651 
652         if (stagingGroupId > 0) {
653             updateLookAndFeel(
654                 companyId, stagingGroupId, privateLayout, layoutId, themeId,
655                 colorSchemeId, css, wapTheme);
656         }
657         else {
658             updateLookAndFeel(
659                 companyId, liveGroupId, privateLayout, layoutId, themeId,
660                 colorSchemeId, css, wapTheme);
661         }
662     }
663 
664     protected void updateLookAndFeel(
665             long companyId, long groupId, boolean privateLayout, long layoutId,
666             String themeId, String colorSchemeId, String css, boolean wapTheme)
667         throws Exception {
668 
669         if (Validator.isNotNull(themeId) && Validator.isNull(colorSchemeId)) {
670             ColorScheme colorScheme = ThemeLocalServiceUtil.getColorScheme(
671                 companyId, themeId, colorSchemeId, wapTheme);
672 
673             colorSchemeId = colorScheme.getColorSchemeId();
674         }
675 
676         if (layoutId <= 0) {
677             LayoutSetServiceUtil.updateLookAndFeel(
678                 groupId, privateLayout, themeId, colorSchemeId, css, wapTheme);
679         }
680         else {
681             LayoutServiceUtil.updateLookAndFeel(
682                 groupId, privateLayout, layoutId, themeId, colorSchemeId, css,
683                 wapTheme);
684         }
685     }
686 
687     protected void updateMergePages(ActionRequest actionRequest)
688         throws Exception {
689 
690         long liveGroupId = ParamUtil.getLong(actionRequest, "liveGroupId");
691 
692         boolean mergeGuestPublicPages = ParamUtil.getBoolean(
693             actionRequest, "mergeGuestPublicPages");
694 
695         Group liveGroup = GroupLocalServiceUtil.getGroup(liveGroupId);
696 
697         UnicodeProperties props = liveGroup.getTypeSettingsProperties();
698 
699         props.setProperty(
700             "mergeGuestPublicPages", String.valueOf(mergeGuestPublicPages));
701 
702         GroupServiceUtil.updateGroup(liveGroupId, liveGroup.getTypeSettings());
703     }
704 
705     protected void updateMonitoring(ActionRequest actionRequest)
706         throws Exception {
707 
708         long liveGroupId = ParamUtil.getLong(actionRequest, "liveGroupId");
709 
710         String googleAnalyticsId = ParamUtil.getString(
711             actionRequest, "googleAnalyticsId");
712 
713         Group liveGroup = GroupLocalServiceUtil.getGroup(liveGroupId);
714 
715         UnicodeProperties props = liveGroup.getTypeSettingsProperties();
716 
717         props.setProperty("googleAnalyticsId", googleAnalyticsId);
718 
719         GroupServiceUtil.updateGroup(liveGroupId, liveGroup.getTypeSettings());
720     }
721 
722     protected void updateVirtualHost(ActionRequest actionRequest)
723         throws Exception {
724 
725         long liveGroupId = ParamUtil.getLong(actionRequest, "liveGroupId");
726 
727         String publicVirtualHost = ParamUtil.getString(
728             actionRequest, "publicVirtualHost");
729         String privateVirtualHost = ParamUtil.getString(
730             actionRequest, "privateVirtualHost");
731         String friendlyURL = ParamUtil.getString(actionRequest, "friendlyURL");
732 
733         LayoutSetServiceUtil.updateVirtualHost(
734             liveGroupId, false, publicVirtualHost);
735 
736         LayoutSetServiceUtil.updateVirtualHost(
737             liveGroupId, true, privateVirtualHost);
738 
739         GroupServiceUtil.updateFriendlyURL(liveGroupId, friendlyURL);
740 
741         Group liveGroup = GroupServiceUtil.getGroup(liveGroupId);
742 
743         if (liveGroup.hasStagingGroup()) {
744             Group stagingGroup = liveGroup.getStagingGroup();
745 
746             publicVirtualHost = ParamUtil.getString(
747                 actionRequest, "stagingPublicVirtualHost");
748             privateVirtualHost = ParamUtil.getString(
749                 actionRequest, "stagingPrivateVirtualHost");
750             friendlyURL = ParamUtil.getString(
751                 actionRequest, "stagingFriendlyURL");
752 
753             LayoutSetServiceUtil.updateVirtualHost(
754                 stagingGroup.getGroupId(), false, publicVirtualHost);
755 
756             LayoutSetServiceUtil.updateVirtualHost(
757                 stagingGroup.getGroupId(), true, privateVirtualHost);
758 
759             GroupServiceUtil.updateFriendlyURL(
760                 stagingGroup.getGroupId(), friendlyURL);
761         }
762     }
763 
764     protected void updateWorkflow(ActionRequest actionRequest)
765         throws Exception {
766 
767         long liveGroupId = ParamUtil.getLong(actionRequest, "liveGroupId");
768 
769         boolean workflowEnabled = ParamUtil.getBoolean(
770             actionRequest, "workflowEnabled");
771         int workflowStages = ParamUtil.getInteger(
772             actionRequest, "workflowStages");
773 
774         StringBuilder sb = new StringBuilder();
775 
776         for (int i = 1; i <= workflowStages; i++) {
777             String workflowRoleName = ParamUtil.getString(
778                 actionRequest, "workflowRoleName_" + i);
779 
780             sb.append(workflowRoleName);
781 
782             if ((i + 1) <= workflowStages) {
783                 sb.append(",");
784             }
785         }
786 
787         String workflowRoleNames = sb.toString();
788 
789         GroupServiceUtil.updateWorkflow(
790             liveGroupId, workflowEnabled, workflowStages, workflowRoleNames);
791     }
792 
793 }