1   /**
2    * Copyright (c) 2000-2007 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.RequiredLayoutException;
34  import com.liferay.portal.kernel.lar.PortletDataHandlerKeys;
35  import com.liferay.portal.kernel.security.permission.ActionKeys;
36  import com.liferay.portal.kernel.security.permission.PermissionChecker;
37  import com.liferay.portal.kernel.util.Constants;
38  import com.liferay.portal.kernel.util.ParamUtil;
39  import com.liferay.portal.kernel.util.StringUtil;
40  import com.liferay.portal.kernel.util.Validator;
41  import com.liferay.portal.model.ColorScheme;
42  import com.liferay.portal.model.Group;
43  import com.liferay.portal.model.Layout;
44  import com.liferay.portal.model.LayoutTypePortlet;
45  import com.liferay.portal.model.Organization;
46  import com.liferay.portal.model.PortletPreferencesIds;
47  import com.liferay.portal.model.User;
48  import com.liferay.portal.model.impl.GroupImpl;
49  import com.liferay.portal.model.impl.LayoutImpl;
50  import com.liferay.portal.security.auth.PrincipalException;
51  import com.liferay.portal.service.GroupLocalServiceUtil;
52  import com.liferay.portal.service.GroupServiceUtil;
53  import com.liferay.portal.service.LayoutLocalServiceUtil;
54  import com.liferay.portal.service.LayoutServiceUtil;
55  import com.liferay.portal.service.LayoutSetServiceUtil;
56  import com.liferay.portal.service.OrganizationLocalServiceUtil;
57  import com.liferay.portal.service.PortletPreferencesLocalServiceUtil;
58  import com.liferay.portal.service.UserLocalServiceUtil;
59  import com.liferay.portal.service.impl.ThemeLocalUtil;
60  import com.liferay.portal.service.permission.GroupPermissionUtil;
61  import com.liferay.portal.service.permission.LocationPermissionUtil;
62  import com.liferay.portal.service.permission.OrganizationPermissionUtil;
63  import com.liferay.portal.service.permission.UserPermissionUtil;
64  import com.liferay.portal.struts.PortletAction;
65  import com.liferay.portal.theme.ThemeDisplay;
66  import com.liferay.portal.util.PortalUtil;
67  import com.liferay.portal.util.PortletKeys;
68  import com.liferay.portal.util.PropsUtil;
69  import com.liferay.portal.util.WebKeys;
70  import com.liferay.portlet.PortletPreferencesFactoryUtil;
71  import com.liferay.portlet.communities.form.PageForm;
72  import com.liferay.util.FileUtil;
73  import com.liferay.util.servlet.SessionErrors;
74  import com.liferay.util.servlet.UploadException;
75  import com.liferay.util.servlet.UploadPortletRequest;
76  
77  import java.io.ByteArrayInputStream;
78  import java.io.File;
79  
80  import java.util.HashMap;
81  import java.util.List;
82  import java.util.Map;
83  import java.util.Properties;
84  
85  import javax.portlet.ActionRequest;
86  import javax.portlet.ActionResponse;
87  import javax.portlet.PortletConfig;
88  import javax.portlet.PortletPreferences;
89  import javax.portlet.PortletRequest;
90  import javax.portlet.RenderRequest;
91  import javax.portlet.RenderResponse;
92  
93  import javax.servlet.http.HttpServletRequest;
94  
95  import org.apache.commons.logging.Log;
96  import org.apache.commons.logging.LogFactory;
97  import org.apache.struts.action.ActionForm;
98  import org.apache.struts.action.ActionForward;
99  import org.apache.struts.action.ActionMapping;
100 
101 /**
102  * <a href="EditPagesAction.java.html"><b><i>View Source</i></b></a>
103  *
104  * @author Brian Wing Shun Chan
105  *
106  */
107 public class EditPagesAction extends PortletAction {
108 
109     public void processAction(
110             ActionMapping mapping, ActionForm form, PortletConfig config,
111             ActionRequest req, ActionResponse res)
112         throws Exception {
113 
114         try {
115             checkPermissions(req);
116         }
117         catch (PrincipalException pe) {
118             return;
119         }
120 
121         PageForm pageForm = (PageForm)form;
122 
123         String cmd = ParamUtil.getString(req, Constants.CMD);
124 
125         try {
126             if (cmd.equals(Constants.ADD) || cmd.equals(Constants.UPDATE)) {
127                 updateLayout(pageForm, req);
128             }
129             else if (cmd.equals(Constants.DELETE)) {
130                 deleteLayout(req);
131             }
132             else if (cmd.equals("copy_from_live")) {
133                 copyFromLive(req);
134             }
135             else if (cmd.equals("display_order")) {
136                 updateDisplayOrder(req);
137             }
138             else if (cmd.equals("logo")) {
139                 updateLogo(req);
140             }
141             else if (cmd.equals("look_and_feel")) {
142                 updateLookAndFeel(req);
143             }
144             else if (cmd.equals("merge_pages")) {
145                 updateMergePages(req);
146             }
147             else if (cmd.equals("monitoring")) {
148                 updateMonitoring(req);
149             }
150             else if (cmd.equals("publish_to_live")) {
151                 publishToLive(req);
152             }
153             else if (cmd.equals("update_staging_state")) {
154                 updateStagingState(req);
155             }
156             else if (cmd.equals("virtual_host")) {
157                 updateVirtualHost(req);
158             }
159 
160             String redirect = ParamUtil.getString(req, "pagesRedirect");
161 
162             sendRedirect(req, res, redirect);
163         }
164         catch (Exception e) {
165             if (e instanceof NoSuchLayoutException ||
166                 e instanceof PrincipalException) {
167 
168                 SessionErrors.add(req, e.getClass().getName());
169 
170                 setForward(req, "portlet.communities.error");
171             }
172             else if (e instanceof LayoutFriendlyURLException ||
173                      e instanceof LayoutHiddenException ||
174                      e instanceof LayoutNameException ||
175                      e instanceof LayoutParentLayoutIdException ||
176                      e instanceof LayoutSetVirtualHostException ||
177                      e instanceof LayoutTypeException ||
178                      e instanceof RequiredLayoutException ||
179                      e instanceof UploadException) {
180 
181                 if (e instanceof LayoutFriendlyURLException) {
182                     SessionErrors.add(
183                         req, LayoutFriendlyURLException.class.getName(), e);
184                 }
185                 else {
186                     SessionErrors.add(req, e.getClass().getName(), e);
187                 }
188             }
189             else {
190                 throw e;
191             }
192         }
193     }
194 
195     public ActionForward render(
196             ActionMapping mapping, ActionForm form, PortletConfig config,
197             RenderRequest req, RenderResponse res)
198         throws Exception {
199 
200         try {
201             checkPermissions(req);
202         }
203         catch (PrincipalException pe) {
204             SessionErrors.add(req, PrincipalException.class.getName());
205 
206             return mapping.findForward("portlet.communities.error");
207         }
208 
209         try {
210             ActionUtil.getGroup(req);
211         }
212         catch (Exception e) {
213             if (e instanceof NoSuchGroupException ||
214                 e instanceof PrincipalException) {
215 
216                 SessionErrors.add(req, e.getClass().getName());
217 
218                 return mapping.findForward("portlet.communities.error");
219             }
220             else {
221                 throw e;
222             }
223         }
224 
225         return mapping.findForward(
226             getForward(req, "portlet.communities.edit_pages"));
227     }
228 
229     protected void checkPermissions(PortletRequest req) throws Exception {
230 
231         // LEP-850
232 
233         ThemeDisplay themeDisplay =
234             (ThemeDisplay)req.getAttribute(WebKeys.THEME_DISPLAY);
235 
236         PermissionChecker permissionChecker =
237             themeDisplay.getPermissionChecker();
238 
239         long groupId = ParamUtil.getLong(req, "groupId");
240 
241         Group group = GroupLocalServiceUtil.getGroup(groupId);
242 
243         if (group.isCommunity()) {
244             GroupPermissionUtil.check(
245                 permissionChecker, group.getGroupId(),
246                 ActionKeys.MANAGE_LAYOUTS);
247         }
248         else if (group.isOrganization()) {
249             Organization organization =
250                 OrganizationLocalServiceUtil.getOrganization(
251                     group.getClassPK());
252 
253             if (!organization.isLocation()) {
254                 OrganizationPermissionUtil.check(
255                     permissionChecker, organization.getOrganizationId(),
256                     ActionKeys.UPDATE);
257             }
258             else {
259                 LocationPermissionUtil.check(
260                     permissionChecker, organization.getOrganizationId(),
261                     ActionKeys.UPDATE);
262             }
263         }
264         else if (group.isUser()) {
265             long groupUserId = group.getClassPK();
266 
267             User groupUser = UserLocalServiceUtil.getUserById(groupUserId);
268 
269             long organizationId =
270                 groupUser.getOrganization().getOrganizationId();
271             long locationId = groupUser.getLocation().getOrganizationId();
272 
273             UserPermissionUtil.check(
274                 permissionChecker, groupUserId, organizationId, locationId,
275                 ActionKeys.UPDATE);
276 
277             if (!groupUser.isLayoutsRequired()) {
278                 throw new PrincipalException();
279             }
280         }
281     }
282 
283     protected void copyFromLive(ActionRequest req) throws Exception{
284         User user = PortalUtil.getUser(req);
285 
286         String tabs2 = ParamUtil.getString(req, "tabs2");
287 
288         long stagingGroupId = ParamUtil.getLong(req, "stagingGroupId");
289 
290         Group stagingGroup = GroupLocalServiceUtil.getGroup(stagingGroupId);
291 
292         boolean privateLayout = true;
293 
294         if (tabs2.equals("public")) {
295             privateLayout = false;
296         }
297 
298         if (_log.isDebugEnabled()) {
299             _log.debug(
300                 "Copying staging to live for group " +
301                     stagingGroup.getLiveGroupId());
302         }
303 
304         copyLayouts(
305             user.getUserId(), stagingGroup.getLiveGroupId(), privateLayout,
306             stagingGroup.getGroupId(), privateLayout);
307     }
308 
309     protected void copyLayouts(
310             long creatorUserId, long sourceGroupId, boolean sourcePrivateLayout,
311             long targetGroupId, boolean targetPrivateLayout)
312         throws Exception{
313 
314         Map parameterMap = new HashMap();
315 
316         parameterMap.put(
317             PortletDataHandlerKeys.EXPORT_PERMISSIONS, Boolean.TRUE.toString());
318         parameterMap.put(
319             PortletDataHandlerKeys.EXPORT_PORTLET_DATA,
320             Boolean.FALSE.toString());
321         parameterMap.put(
322             PortletDataHandlerKeys.EXPORT_PORTLET_PREFERENCES,
323             Boolean.TRUE.toString());
324         parameterMap.put(
325             PortletDataHandlerKeys.EXPORT_THEME, Boolean.FALSE.toString());
326         parameterMap.put(
327             PortletDataHandlerKeys.IMPORT_PERMISSIONS, Boolean.TRUE.toString());
328         parameterMap.put(
329             PortletDataHandlerKeys.IMPORT_PORTLET_DATA,
330             Boolean.FALSE.toString());
331         parameterMap.put(
332             PortletDataHandlerKeys.IMPORT_PORTLET_PREFERENCES,
333             Boolean.TRUE.toString());
334         parameterMap.put(
335             PortletDataHandlerKeys.IMPORT_THEME, Boolean.FALSE.toString());
336 
337         byte[] data = LayoutLocalServiceUtil.exportLayouts(
338             sourceGroupId, sourcePrivateLayout, parameterMap);
339 
340         ByteArrayInputStream bais = new ByteArrayInputStream(data);
341 
342         LayoutLocalServiceUtil.importLayouts(
343             creatorUserId, targetGroupId, targetPrivateLayout, parameterMap,
344             bais);
345     }
346 
347     protected void copyPreferences(
348             ActionRequest req, Layout layout, Layout copyLayout)
349         throws Exception {
350 
351         long companyId = layout.getCompanyId();
352 
353         LayoutTypePortlet copyLayoutTypePortlet =
354             (LayoutTypePortlet)copyLayout.getLayoutType();
355 
356         List copyPortletIds = copyLayoutTypePortlet.getPortletIds();
357 
358         for (int i = 0; i < copyPortletIds.size(); i++) {
359             String copyPortletId = (String)copyPortletIds.get(i);
360 
361             HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
362 
363             // Copy preference
364 
365             PortletPreferencesIds portletPreferencesIds =
366                 PortletPreferencesFactoryUtil.getPortletPreferencesIds(
367                     httpReq, layout, copyPortletId);
368 
369             PortletPreferencesLocalServiceUtil.getPreferences(
370                 portletPreferencesIds);
371 
372             PortletPreferencesIds copyPortletPreferencesIds =
373                 PortletPreferencesFactoryUtil.getPortletPreferencesIds(
374                     httpReq, copyLayout, copyPortletId);
375 
376             PortletPreferences copyPrefs =
377                 PortletPreferencesLocalServiceUtil.getPreferences(
378                     copyPortletPreferencesIds);
379 
380             PortletPreferencesLocalServiceUtil.updatePreferences(
381                 portletPreferencesIds.getOwnerId(),
382                 portletPreferencesIds.getOwnerType(),
383                 portletPreferencesIds.getPlid(),
384                 portletPreferencesIds.getPortletId(), copyPrefs);
385 
386             // Copy portlet setup
387 
388             PortletPreferencesLocalServiceUtil.getPreferences(
389                 companyId, PortletKeys.PREFS_OWNER_ID_DEFAULT,
390                 PortletKeys.PREFS_OWNER_TYPE_LAYOUT, layout.getPlid(),
391                 copyPortletId);
392 
393             copyPrefs =
394                 PortletPreferencesLocalServiceUtil.getPreferences(
395                     companyId, PortletKeys.PREFS_OWNER_ID_DEFAULT,
396                     PortletKeys.PREFS_OWNER_TYPE_LAYOUT, copyLayout.getPlid(),
397                     copyPortletId);
398 
399             PortletPreferencesLocalServiceUtil.updatePreferences(
400                 PortletKeys.PREFS_OWNER_ID_DEFAULT,
401                 PortletKeys.PREFS_OWNER_TYPE_LAYOUT, layout.getPlid(),
402                 copyPortletId, copyPrefs);
403         }
404     }
405 
406     protected void deleteLayout(ActionRequest req) throws Exception {
407         long groupId = ParamUtil.getLong(req, "groupId");
408         boolean privateLayout = ParamUtil.getBoolean(req, "privateLayout");
409         long layoutId = ParamUtil.getLong(req, "layoutId");
410 
411         LayoutServiceUtil.deleteLayout(groupId, privateLayout, layoutId);
412     }
413 
414     protected void publishToLive(ActionRequest req) throws Exception{
415         User user = PortalUtil.getUser(req);
416 
417         String tabs2 = ParamUtil.getString(req, "tabs2");
418 
419         long stagingGroupId = ParamUtil.getLong(req, "stagingGroupId");
420 
421         Group stagingGroup = GroupLocalServiceUtil.getGroup(stagingGroupId);
422 
423         boolean privateLayout = true;
424 
425         if (tabs2.equals("public")) {
426             privateLayout = false;
427         }
428 
429         if (_log.isDebugEnabled()) {
430             _log.debug(
431                 "Copying live to staging for group " +
432                     stagingGroup.getLiveGroupId());
433         }
434 
435         copyLayouts(
436             user.getUserId(), stagingGroup.getGroupId(), privateLayout,
437             stagingGroup.getLiveGroupId(), privateLayout);
438     }
439 
440     protected void updateDisplayOrder(ActionRequest req) throws Exception {
441         long groupId = ParamUtil.getLong(req, "groupId");
442         boolean privateLayout = ParamUtil.getBoolean(req, "privateLayout");
443         long parentLayoutId = ParamUtil.getLong(req, "parentLayoutId");
444         long[] layoutIds = StringUtil.split(
445             ParamUtil.getString(req, "layoutIds"), 0L);
446 
447         LayoutServiceUtil.setLayouts(
448             groupId, privateLayout, parentLayoutId, layoutIds);
449     }
450 
451     protected void updateLayout(PageForm pageForm, ActionRequest req)
452         throws Exception {
453 
454         UploadPortletRequest uploadReq =
455             PortalUtil.getUploadPortletRequest(req);
456 
457         String cmd = ParamUtil.getString(uploadReq, Constants.CMD);
458 
459         long groupId = ParamUtil.getLong(req, "groupId");
460         boolean privateLayout = ParamUtil.getBoolean(req, "privateLayout");
461         long layoutId = ParamUtil.getLong(req, "layoutId");
462         long parentLayoutId = ParamUtil.getLong(uploadReq, "parentLayoutId");
463         String name = ParamUtil.getString(uploadReq, "name");
464         String title = ParamUtil.getString(uploadReq, "title");
465         String languageId = ParamUtil.getString(uploadReq, "curLanguageId");
466         String description = ParamUtil.getString(uploadReq, "description");
467         String type = ParamUtil.getString(uploadReq, "type");
468         boolean hidden = ParamUtil.getBoolean(uploadReq, "hidden");
469         String friendlyURL = ParamUtil.getString(uploadReq, "friendlyURL");
470         boolean iconImage = ParamUtil.getBoolean(uploadReq, "iconImage");
471         byte[] iconBytes = FileUtil.getBytes(
472             uploadReq.getFile("iconFileName"));
473 
474         boolean inheritFromParentLayoutId = ParamUtil.getBoolean(
475             uploadReq, "inheritFromParentLayoutId");
476 
477         long copyLayoutId = ParamUtil.getLong(uploadReq, "copyLayoutId");
478 
479         if (cmd.equals(Constants.ADD)) {
480 
481             // Add layout
482 
483             if (inheritFromParentLayoutId && (parentLayoutId > 0)) {
484                 Layout parentLayout = LayoutLocalServiceUtil.getLayout(
485                     groupId, privateLayout, parentLayoutId);
486 
487                 Layout layout = LayoutServiceUtil.addLayout(
488                     groupId, privateLayout, parentLayoutId, name, title,
489                     description, parentLayout.getType(),
490                     parentLayout.isHidden(), friendlyURL);
491 
492                 LayoutServiceUtil.updateLayout(
493                     layout.getGroupId(), layout.isPrivateLayout(),
494                     layout.getLayoutId(), parentLayout.getTypeSettings());
495             }
496             else {
497                 Layout layout = LayoutServiceUtil.addLayout(
498                     groupId, privateLayout, parentLayoutId, name, title,
499                     description, type, hidden, friendlyURL);
500 
501                 if (type.equals(LayoutImpl.TYPE_PORTLET)) {
502                     LayoutTypePortlet layoutTypePortlet =
503                         (LayoutTypePortlet)layout.getLayoutType();
504 
505                     layoutTypePortlet.setLayoutTemplateId(
506                         0, PropsUtil.get(PropsUtil.LAYOUT_DEFAULT_TEMPLATE_ID),
507                         false);
508 
509                     LayoutServiceUtil.updateLayout(
510                         layout.getGroupId(), layout.isPrivateLayout(),
511                         layout.getLayoutId(), layout.getTypeSettings());
512                 }
513             }
514         }
515         else {
516 
517             // Update layout
518 
519             Layout layout = LayoutLocalServiceUtil.getLayout(
520                 groupId, privateLayout, layoutId);
521 
522             layout = LayoutServiceUtil.updateLayout(
523                 groupId, privateLayout, layoutId, layout.getParentLayoutId(),
524                 name, title, languageId, description, type, hidden, friendlyURL,
525                 Boolean.valueOf(iconImage), iconBytes);
526 
527             if (type.equals(LayoutImpl.TYPE_PORTLET)) {
528                 if ((copyLayoutId > 0) &&
529                     (copyLayoutId != layout.getLayoutId())) {
530 
531                     try {
532                         Layout copyLayout = LayoutLocalServiceUtil.getLayout(
533                             groupId, privateLayout, copyLayoutId);
534 
535                         if (copyLayout.getType().equals(
536                                 LayoutImpl.TYPE_PORTLET)) {
537 
538                             LayoutServiceUtil.updateLayout(
539                                 groupId, privateLayout, layoutId,
540                                 copyLayout.getTypeSettings());
541 
542                             copyPreferences(req, layout, copyLayout);
543                         }
544                     }
545                     catch (NoSuchLayoutException nsle) {
546                     }
547                 }
548                 else {
549                     Properties formProperties =
550                         pageForm.getTypeSettingsProperties();
551 
552                     Properties layoutProperties =
553                         layout.getTypeSettingsProperties();
554 
555                     layoutProperties.setProperty(
556                         "meta-robots",
557                         formProperties.getProperty("meta-robots"));
558                     layoutProperties.setProperty(
559                         "meta-description",
560                         formProperties.getProperty("meta-description"));
561                     layoutProperties.setProperty(
562                         "meta-keywords",
563                         formProperties.getProperty("meta-keywords"));
564 
565                     layoutProperties.setProperty(
566                         "javascript-1",
567                         formProperties.getProperty("javascript-1"));
568                     layoutProperties.setProperty(
569                         "javascript-2",
570                         formProperties.getProperty("javascript-2"));
571                     layoutProperties.setProperty(
572                         "javascript-3",
573                         formProperties.getProperty("javascript-3"));
574                     layoutProperties.setProperty(
575                         "sitemap-include",
576                         formProperties.getProperty("sitemap-include"));
577                     layoutProperties.setProperty(
578                         "sitemap-priority",
579                         formProperties.getProperty("sitemap-priority"));
580                     layoutProperties.setProperty(
581                         "sitemap-changefreq",
582                         formProperties.getProperty("sitemap-changefreq"));
583 
584                     LayoutServiceUtil.updateLayout(
585                         groupId, privateLayout, layoutId,
586                         layout.getTypeSettings());
587                 }
588             }
589             else {
590                 layout.setTypeSettingsProperties(
591                     pageForm.getTypeSettingsProperties());
592 
593                 LayoutServiceUtil.updateLayout(
594                     groupId, privateLayout, layoutId, layout.getTypeSettings());
595             }
596         }
597     }
598 
599     protected void updateLogo(ActionRequest req) throws Exception {
600         UploadPortletRequest uploadReq =
601             PortalUtil.getUploadPortletRequest(req);
602 
603         long groupId = ParamUtil.getLong(req, "groupId");
604         boolean privateLayout = ParamUtil.getBoolean(req, "privateLayout");
605         boolean logo = ParamUtil.getBoolean(req, "logo");
606 
607         File file = uploadReq.getFile("logoFileName");
608         byte[] bytes = FileUtil.getBytes(file);
609 
610         if (logo && ((bytes == null) || (bytes.length == 0))) {
611             throw new UploadException();
612         }
613 
614         LayoutSetServiceUtil.updateLogo(groupId, privateLayout, logo, file);
615     }
616 
617     protected void updateLookAndFeel(ActionRequest req) throws Exception {
618         long companyId = PortalUtil.getCompanyId(req);
619 
620         long groupId = ParamUtil.getLong(req, "groupId");
621         boolean privateLayout = ParamUtil.getBoolean(req, "privateLayout");
622         long layoutId = ParamUtil.getLong(req, "layoutId");
623         String themeId = ParamUtil.getString(req, "themeId");
624         String colorSchemeId = ParamUtil.getString(req, "colorSchemeId");
625         String css = ParamUtil.getString(req, "css");
626         boolean wapTheme = ParamUtil.getBoolean(req, "wapTheme");
627 
628         if (Validator.isNotNull(themeId) && Validator.isNull(colorSchemeId)) {
629             ColorScheme colorScheme = ThemeLocalUtil.getColorScheme(
630                 companyId, themeId, colorSchemeId, wapTheme);
631 
632             colorSchemeId = colorScheme.getColorSchemeId();
633         }
634 
635         if (layoutId <= 0) {
636 
637             // Update layout set
638 
639             LayoutSetServiceUtil.updateLookAndFeel(
640                 groupId, privateLayout, themeId, colorSchemeId, css, wapTheme);
641         }
642         else {
643 
644             // Update layout
645 
646             LayoutServiceUtil.updateLookAndFeel(
647                 groupId, privateLayout, layoutId, themeId, colorSchemeId, css,
648                 wapTheme);
649         }
650     }
651 
652     protected void updateMergePages(ActionRequest req) throws Exception {
653         long groupId = ParamUtil.getLong(req, "groupId");
654 
655         Group group = GroupLocalServiceUtil.getGroup(groupId);
656 
657         boolean mergeGuestPublicPages = ParamUtil.getBoolean(
658             req, "mergeGuestPublicPages");
659 
660         Properties props = group.getTypeSettingsProperties();
661 
662         props.setProperty(
663             "mergeGuestPublicPages", String.valueOf(mergeGuestPublicPages));
664 
665         GroupServiceUtil.updateGroup(groupId, group.getTypeSettings());
666     }
667 
668     protected void updateMonitoring(ActionRequest req) throws Exception {
669         long groupId = ParamUtil.getLong(req, "groupId");
670 
671         Group group = GroupLocalServiceUtil.getGroup(groupId);
672 
673         String googleAnalyticsId = ParamUtil.getString(
674             req, "googleAnalyticsId");
675 
676         Properties props = group.getTypeSettingsProperties();
677 
678         props.setProperty("googleAnalyticsId", googleAnalyticsId);
679 
680         GroupServiceUtil.updateGroup(groupId, group.getTypeSettings());
681     }
682 
683     protected void updateStagingState(ActionRequest req) throws Exception {
684         User user = PortalUtil.getUser(req);
685 
686         long liveGroupId = ParamUtil.getLong(req, "liveGroupId");
687         long stagingGroupId = ParamUtil.getLong(req, "stagingGroupId");
688         boolean activateStaging = ParamUtil.getBoolean(req, "activateStaging");
689 
690         if ((stagingGroupId > 0) && !activateStaging) {
691             GroupServiceUtil.deleteGroup(stagingGroupId);
692         }
693         else if ((stagingGroupId == 0) && activateStaging) {
694             Group group = GroupServiceUtil.getGroup(liveGroupId);
695 
696             Group stagingGroup = GroupServiceUtil.addGroup(
697                 group.getGroupId(), group.getName() + " (Staging)",
698                 group.getDescription(), GroupImpl.TYPE_COMMUNITY_CLOSED, null,
699                 group.isActive());
700 
701             if (group.hasPrivateLayouts()) {
702                 copyLayouts(
703                     user.getUserId(), group.getGroupId(), true,
704                     stagingGroup.getGroupId(), true);
705             }
706 
707             if (group.hasPublicLayouts()) {
708                 copyLayouts(
709                     user.getUserId(), group.getGroupId(), false,
710                     stagingGroup.getGroupId(), false);
711             }
712         }
713     }
714 
715     protected void updateVirtualHost(ActionRequest req) throws Exception {
716 
717         // Public virtual host
718 
719         long groupId = ParamUtil.getLong(req, "groupId");
720 
721         String publicVirtualHost = ParamUtil.getString(
722             req, "publicVirtualHost");
723 
724         LayoutSetServiceUtil.updateVirtualHost(
725             groupId, false, publicVirtualHost);
726 
727         // Private virtual host
728 
729         String privateVirtualHost = ParamUtil.getString(
730             req, "privateVirtualHost");
731 
732         LayoutSetServiceUtil.updateVirtualHost(
733             groupId, true, privateVirtualHost);
734 
735         // Friendly URL
736 
737         String friendlyURL = ParamUtil.getString(req, "friendlyURL");
738 
739         Group group = GroupLocalServiceUtil.getGroup(groupId);
740 
741         GroupServiceUtil.updateGroup(
742             groupId, group.getName(), group.getDescription(), group.getType(),
743             friendlyURL, group.isActive());
744     }
745 
746     private static Log _log = LogFactory.getLog(EditPagesAction.class);
747 
748 }