001
014
015 package com.liferay.portlet.layoutsadmin.action;
016
017 import com.liferay.portal.DuplicateLockException;
018 import com.liferay.portal.ImageTypeException;
019 import com.liferay.portal.LayoutFriendlyURLException;
020 import com.liferay.portal.LayoutHiddenException;
021 import com.liferay.portal.LayoutNameException;
022 import com.liferay.portal.LayoutParentLayoutIdException;
023 import com.liferay.portal.LayoutPrototypeException;
024 import com.liferay.portal.LayoutSetVirtualHostException;
025 import com.liferay.portal.LayoutTypeException;
026 import com.liferay.portal.NoSuchGroupException;
027 import com.liferay.portal.NoSuchLayoutException;
028 import com.liferay.portal.RemoteExportException;
029 import com.liferay.portal.RemoteOptionsException;
030 import com.liferay.portal.RequiredLayoutException;
031 import com.liferay.portal.SitemapChangeFrequencyException;
032 import com.liferay.portal.SitemapIncludeException;
033 import com.liferay.portal.SitemapPagePriorityException;
034 import com.liferay.portal.events.EventsProcessorUtil;
035 import com.liferay.portal.kernel.exception.PortalException;
036 import com.liferay.portal.kernel.exception.SystemException;
037 import com.liferay.portal.kernel.log.Log;
038 import com.liferay.portal.kernel.log.LogFactoryUtil;
039 import com.liferay.portal.kernel.servlet.SessionErrors;
040 import com.liferay.portal.kernel.staging.StagingUtil;
041 import com.liferay.portal.kernel.upload.UploadException;
042 import com.liferay.portal.kernel.upload.UploadPortletRequest;
043 import com.liferay.portal.kernel.util.Constants;
044 import com.liferay.portal.kernel.util.FileUtil;
045 import com.liferay.portal.kernel.util.HttpUtil;
046 import com.liferay.portal.kernel.util.LocalizationUtil;
047 import com.liferay.portal.kernel.util.ParamUtil;
048 import com.liferay.portal.kernel.util.PropertiesParamUtil;
049 import com.liferay.portal.kernel.util.PropsKeys;
050 import com.liferay.portal.kernel.util.StringPool;
051 import com.liferay.portal.kernel.util.StringUtil;
052 import com.liferay.portal.kernel.util.UnicodeProperties;
053 import com.liferay.portal.kernel.util.Validator;
054 import com.liferay.portal.kernel.workflow.WorkflowConstants;
055 import com.liferay.portal.model.ColorScheme;
056 import com.liferay.portal.model.Group;
057 import com.liferay.portal.model.Layout;
058 import com.liferay.portal.model.LayoutConstants;
059 import com.liferay.portal.model.LayoutPrototype;
060 import com.liferay.portal.model.LayoutRevision;
061 import com.liferay.portal.model.LayoutSet;
062 import com.liferay.portal.model.LayoutSetBranch;
063 import com.liferay.portal.model.LayoutTypePortlet;
064 import com.liferay.portal.model.Theme;
065 import com.liferay.portal.model.ThemeSetting;
066 import com.liferay.portal.model.User;
067 import com.liferay.portal.model.impl.ThemeImpl;
068 import com.liferay.portal.model.impl.ThemeSettingImpl;
069 import com.liferay.portal.security.auth.PrincipalException;
070 import com.liferay.portal.security.permission.ActionKeys;
071 import com.liferay.portal.security.permission.PermissionChecker;
072 import com.liferay.portal.service.LayoutLocalServiceUtil;
073 import com.liferay.portal.service.LayoutPrototypeServiceUtil;
074 import com.liferay.portal.service.LayoutRevisionLocalServiceUtil;
075 import com.liferay.portal.service.LayoutServiceUtil;
076 import com.liferay.portal.service.LayoutSetBranchLocalServiceUtil;
077 import com.liferay.portal.service.LayoutSetLocalServiceUtil;
078 import com.liferay.portal.service.ServiceContext;
079 import com.liferay.portal.service.ServiceContextFactory;
080 import com.liferay.portal.service.ThemeLocalServiceUtil;
081 import com.liferay.portal.service.UserLocalServiceUtil;
082 import com.liferay.portal.service.permission.GroupPermissionUtil;
083 import com.liferay.portal.service.permission.LayoutPermissionUtil;
084 import com.liferay.portal.service.permission.LayoutPrototypePermissionUtil;
085 import com.liferay.portal.service.permission.LayoutSetPrototypePermissionUtil;
086 import com.liferay.portal.service.permission.UserPermissionUtil;
087 import com.liferay.portal.struts.PortletAction;
088 import com.liferay.portal.theme.ThemeDisplay;
089 import com.liferay.portal.util.LayoutSettings;
090 import com.liferay.portal.util.PortalUtil;
091 import com.liferay.portal.util.PropsValues;
092 import com.liferay.portal.util.WebKeys;
093 import com.liferay.portlet.mobiledevicerules.model.MDRAction;
094 import com.liferay.portlet.mobiledevicerules.model.MDRRuleGroupInstance;
095 import com.liferay.portlet.mobiledevicerules.service.MDRActionLocalServiceUtil;
096 import com.liferay.portlet.mobiledevicerules.service.MDRActionServiceUtil;
097 import com.liferay.portlet.mobiledevicerules.service.MDRRuleGroupInstanceLocalServiceUtil;
098 import com.liferay.portlet.mobiledevicerules.service.MDRRuleGroupInstanceServiceUtil;
099 import com.liferay.portlet.sites.action.ActionUtil;
100 import com.liferay.portlet.sites.util.SitesUtil;
101
102 import java.io.IOException;
103 import java.io.InputStream;
104
105 import java.util.Iterator;
106 import java.util.List;
107 import java.util.Locale;
108 import java.util.Map;
109 import java.util.Set;
110
111 import javax.portlet.ActionRequest;
112 import javax.portlet.ActionResponse;
113 import javax.portlet.PortletConfig;
114 import javax.portlet.PortletContext;
115 import javax.portlet.PortletRequest;
116 import javax.portlet.PortletRequestDispatcher;
117 import javax.portlet.RenderRequest;
118 import javax.portlet.RenderResponse;
119 import javax.portlet.ResourceRequest;
120 import javax.portlet.ResourceResponse;
121
122 import javax.servlet.http.HttpServletRequest;
123 import javax.servlet.http.HttpServletResponse;
124
125 import org.apache.struts.action.ActionForm;
126 import org.apache.struts.action.ActionForward;
127 import org.apache.struts.action.ActionMapping;
128
129
133 public class EditLayoutsAction extends PortletAction {
134
135 @Override
136 public void processAction(
137 ActionMapping actionMapping, ActionForm actionForm,
138 PortletConfig portletConfig, ActionRequest actionRequest,
139 ActionResponse actionResponse)
140 throws Exception {
141
142 try {
143 checkPermissions(actionRequest);
144 }
145 catch (PrincipalException pe) {
146 return;
147 }
148
149 ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(
150 WebKeys.THEME_DISPLAY);
151
152 String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
153
154 String redirect = ParamUtil.getString(actionRequest, "redirect");
155 String closeRedirect = ParamUtil.getString(
156 actionRequest, "closeRedirect");
157
158 try {
159 Layout layout = null;
160 String oldFriendlyURL = StringPool.BLANK;
161
162 if (cmd.equals(Constants.ADD) || cmd.equals(Constants.UPDATE)) {
163 Object[] returnValue = updateLayout(
164 actionRequest, actionResponse);
165
166 layout = (Layout)returnValue[0];
167 oldFriendlyURL = (String)returnValue[1];
168
169 redirect = updateCloseRedirect(
170 redirect, null, layout, oldFriendlyURL);
171 closeRedirect = updateCloseRedirect(
172 closeRedirect, null, layout, oldFriendlyURL);
173 }
174 else if (cmd.equals(Constants.DELETE)) {
175 long plid = ParamUtil.getLong(actionRequest, "plid");
176
177 if (plid <= 0) {
178 long groupId = ParamUtil.getLong(actionRequest, "groupId");
179 boolean privateLayout = ParamUtil.getBoolean(
180 actionRequest, "privateLayout");
181 long layoutId = ParamUtil.getLong(
182 actionRequest, "layoutId");
183
184 layout = LayoutLocalServiceUtil.getLayout(
185 groupId, privateLayout, layoutId);
186
187 plid = layout.getPlid();
188 }
189
190 Object[] returnValue = SitesUtil.deleteLayout(
191 actionRequest, actionResponse);
192
193 Group group = (Group)returnValue[0];
194 oldFriendlyURL = (String)returnValue[1];
195 long newRefererPlid = (Long)returnValue[2];
196
197 redirect = updateCloseRedirect(
198 redirect, group, null, oldFriendlyURL);
199
200 long refererPlid = themeDisplay.getRefererPlid();
201
202 if (plid == refererPlid) {
203 redirect = HttpUtil.setParameter(
204 redirect, "refererPlid", newRefererPlid);
205 }
206
207 closeRedirect = updateCloseRedirect(
208 closeRedirect, group, null, oldFriendlyURL);
209 }
210 else if (cmd.equals("copy_from_live")) {
211 StagingUtil.copyFromLive(actionRequest);
212 }
213 else if (cmd.equals("display_order")) {
214 updateDisplayOrder(actionRequest);
215 }
216 else if (cmd.equals("delete_layout_revision")) {
217 deleteLayoutRevision(actionRequest);
218 }
219 else if (cmd.equals("enable")) {
220 enableLayout(actionRequest);
221 }
222 else if (cmd.equals("publish_to_live")) {
223 StagingUtil.publishToLive(actionRequest);
224 }
225 else if (cmd.equals("publish_to_remote")) {
226 StagingUtil.publishToRemote(actionRequest);
227 }
228 else if (cmd.equals("reset_customized_view")) {
229 LayoutTypePortlet layoutTypePortlet =
230 themeDisplay.getLayoutTypePortlet();
231
232 if ((layoutTypePortlet != null) &&
233 layoutTypePortlet.isCustomizable() &&
234 layoutTypePortlet.isCustomizedView()) {
235
236 layoutTypePortlet.resetUserPreferences();
237 }
238 }
239 else if (cmd.equals("reset_prototype")) {
240 SitesUtil.resetPrototype(themeDisplay.getLayout());
241 }
242 else if (cmd.equals("schedule_copy_from_live")) {
243 StagingUtil.scheduleCopyFromLive(actionRequest);
244 }
245 else if (cmd.equals("schedule_publish_to_live")) {
246 StagingUtil.schedulePublishToLive(actionRequest);
247 }
248 else if (cmd.equals("schedule_publish_to_remote")) {
249 StagingUtil.schedulePublishToRemote(actionRequest);
250 }
251 else if (cmd.equals("select_layout_set_branch")) {
252 selectLayoutSetBranch(actionRequest);
253 }
254 else if (cmd.equals("select_layout_branch")) {
255 selectLayoutBranch(actionRequest);
256 }
257 else if (cmd.equals("unschedule_copy_from_live")) {
258 StagingUtil.unscheduleCopyFromLive(actionRequest);
259 }
260 else if (cmd.equals("unschedule_publish_to_live")) {
261 StagingUtil.unschedulePublishToLive(actionRequest);
262 }
263 else if (cmd.equals("unschedule_publish_to_remote")) {
264 StagingUtil.unschedulePublishToRemote(actionRequest);
265 }
266 else if (cmd.equals("update_layout_revision")) {
267 updateLayoutRevision(actionRequest, themeDisplay);
268 }
269
270 sendRedirect(
271 portletConfig, actionRequest, actionResponse, redirect,
272 closeRedirect);
273 }
274 catch (Exception e) {
275 if (e instanceof NoSuchLayoutException ||
276 e instanceof PrincipalException) {
277
278 SessionErrors.add(actionRequest, e.getClass());
279
280 setForward(actionRequest, "portlet.layouts_admin.error");
281 }
282 else if (e instanceof ImageTypeException ||
283 e instanceof LayoutFriendlyURLException ||
284 e instanceof LayoutHiddenException ||
285 e instanceof LayoutNameException ||
286 e instanceof LayoutParentLayoutIdException ||
287 e instanceof LayoutSetVirtualHostException ||
288 e instanceof LayoutTypeException ||
289 e instanceof RequiredLayoutException ||
290 e instanceof SitemapChangeFrequencyException ||
291 e instanceof SitemapIncludeException ||
292 e instanceof SitemapPagePriorityException ||
293 e instanceof UploadException) {
294
295 if (e instanceof LayoutFriendlyURLException) {
296 SessionErrors.add(
297 actionRequest,
298 LayoutFriendlyURLException.class.getName(), e);
299 }
300 else {
301 SessionErrors.add(actionRequest, e.getClass(), e);
302 }
303
304 sendRedirect(
305 portletConfig, actionRequest, actionResponse, redirect,
306 closeRedirect);
307 }
308 else if (e instanceof DuplicateLockException ||
309 e instanceof LayoutPrototypeException ||
310 e instanceof RemoteExportException ||
311 e instanceof RemoteOptionsException ||
312 e instanceof SystemException) {
313
314 SessionErrors.add(actionRequest, e.getClass(), e);
315
316 redirect = ParamUtil.getString(actionRequest, "pagesRedirect");
317
318 sendRedirect(
319 portletConfig, actionRequest, actionResponse, redirect,
320 closeRedirect);
321 }
322 else {
323 throw e;
324 }
325 }
326 }
327
328 @Override
329 public ActionForward render(
330 ActionMapping actionMapping, ActionForm actionForm,
331 PortletConfig portletConfig, RenderRequest renderRequest,
332 RenderResponse renderResponse)
333 throws Exception {
334
335 try {
336 checkPermissions(renderRequest);
337 }
338 catch (PrincipalException pe) {
339 SessionErrors.add(
340 renderRequest, PrincipalException.class.getName());
341
342 return actionMapping.findForward("portlet.layouts_admin.error");
343 }
344
345 try {
346 getGroup(renderRequest);
347 }
348 catch (Exception e) {
349 if (e instanceof NoSuchGroupException ||
350 e instanceof PrincipalException) {
351
352 SessionErrors.add(renderRequest, e.getClass());
353
354 return actionMapping.findForward("portlet.layouts_admin.error");
355 }
356 else {
357 throw e;
358 }
359 }
360
361 return actionMapping.findForward(
362 getForward(renderRequest, "portlet.layouts_admin.edit_layouts"));
363 }
364
365 @Override
366 public void serveResource(
367 ActionMapping actionMapping, ActionForm actionForm,
368 PortletConfig portletConfig, ResourceRequest resourceRequest,
369 ResourceResponse resourceResponse)
370 throws Exception {
371
372 String cmd = ParamUtil.getString(resourceRequest, Constants.CMD);
373
374 PortletContext portletContext = portletConfig.getPortletContext();
375
376 PortletRequestDispatcher portletRequestDispatcher = null;
377
378 if (cmd.equals(ActionKeys.PUBLISH_STAGING)) {
379 portletRequestDispatcher = portletContext.getRequestDispatcher(
380 "/html/portlet/layouts_admin/scheduled_publishing_events.jsp");
381 }
382 else if (cmd.equals(ActionKeys.VIEW_TREE)) {
383 getGroup(resourceRequest);
384
385 portletRequestDispatcher = portletContext.getRequestDispatcher(
386 "/html/portlet/layouts_admin/tree_js.jsp");
387 }
388 else {
389 getGroup(resourceRequest);
390
391 portletRequestDispatcher = portletContext.getRequestDispatcher(
392 "/html/portlet/layouts_admin/view_resources.jsp");
393 }
394
395 portletRequestDispatcher.include(resourceRequest, resourceResponse);
396 }
397
398 protected void checkPermission(
399 PermissionChecker permissionChecker, Group group, Layout layout,
400 long selPlid)
401 throws PortalException, SystemException {
402
403 if (selPlid > 0) {
404 LayoutPermissionUtil.check(
405 permissionChecker, layout, ActionKeys.VIEW);
406 }
407 else {
408 GroupPermissionUtil.check(
409 permissionChecker, group, ActionKeys.VIEW);
410 }
411 }
412
413 protected void checkPermissions(PortletRequest portletRequest)
414 throws Exception {
415
416 Group group = getGroup(portletRequest);
417
418 if (group == null) {
419 throw new PrincipalException();
420 }
421
422 ThemeDisplay themeDisplay = (ThemeDisplay)portletRequest.getAttribute(
423 WebKeys.THEME_DISPLAY);
424
425 PermissionChecker permissionChecker =
426 themeDisplay.getPermissionChecker();
427
428 Layout layout = themeDisplay.getLayout();
429
430 String cmd = ParamUtil.getString(portletRequest, Constants.CMD);
431
432 long selPlid = ParamUtil.getLong(portletRequest, "selPlid");
433
434 if (selPlid > 0) {
435 layout = LayoutLocalServiceUtil.getLayout(selPlid);
436 }
437
438 if (cmd.equals(Constants.ADD)) {
439 long parentPlid = ParamUtil.getLong(portletRequest, "parentPlid");
440
441 if (parentPlid == LayoutConstants.DEFAULT_PARENT_LAYOUT_ID) {
442 if (!GroupPermissionUtil.contains(
443 permissionChecker, group.getGroupId(),
444 ActionKeys.ADD_LAYOUT)) {
445
446 throw new PrincipalException();
447 }
448 }
449 else {
450 layout = LayoutLocalServiceUtil.getLayout(parentPlid);
451
452 if (!LayoutPermissionUtil.contains(
453 permissionChecker, layout, ActionKeys.ADD_LAYOUT)) {
454
455 throw new PrincipalException();
456 }
457 }
458 }
459 else if (cmd.equals(Constants.DELETE)) {
460 if (!LayoutPermissionUtil.contains(
461 permissionChecker, layout, ActionKeys.DELETE)) {
462
463 throw new PrincipalException();
464 }
465 }
466 else if (cmd.equals(Constants.UPDATE)) {
467 if (group.isCompany()) {
468 if (!permissionChecker.isCompanyAdmin()) {
469 throw new PrincipalException();
470 }
471 }
472 else if (group.isLayoutPrototype()) {
473 LayoutPrototypePermissionUtil.check(
474 permissionChecker, group.getClassPK(), ActionKeys.UPDATE);
475 }
476 else if (group.isLayoutSetPrototype()) {
477 LayoutSetPrototypePermissionUtil.check(
478 permissionChecker, group.getClassPK(), ActionKeys.UPDATE);
479 }
480 else if (group.isUser()) {
481 long groupUserId = group.getClassPK();
482
483 User groupUser = UserLocalServiceUtil.getUserById(groupUserId);
484
485 long[] organizationIds = groupUser.getOrganizationIds();
486
487 UserPermissionUtil.check(
488 permissionChecker, groupUserId, organizationIds,
489 ActionKeys.UPDATE);
490 }
491 else {
492 checkPermission(permissionChecker, group, layout, selPlid);
493 }
494 }
495 else if (cmd.equals("publish_to_live") ||
496 cmd.equals("publish_to_remote")) {
497
498 boolean hasUpdateLayoutPermission = false;
499
500 if (layout != null) {
501 hasUpdateLayoutPermission = LayoutPermissionUtil.contains(
502 permissionChecker, layout, ActionKeys.UPDATE);
503 }
504
505 if (group.isCompany() || group.isSite()) {
506 boolean publishToLive = GroupPermissionUtil.contains(
507 permissionChecker, group.getGroupId(),
508 ActionKeys.PUBLISH_STAGING);
509
510 if (!hasUpdateLayoutPermission && !publishToLive) {
511 throw new PrincipalException();
512 }
513 }
514 else {
515 checkPermission(permissionChecker, group, layout, selPlid);
516 }
517 }
518 else if (cmd.equals("reset_customized_view")) {
519 if (!LayoutPermissionUtil.contains(
520 permissionChecker, layout, ActionKeys.CUSTOMIZE)) {
521
522 throw new PrincipalException();
523 }
524 }
525 else if (cmd.equals("reset_prototype")) {
526 if (!LayoutPermissionUtil.contains(
527 permissionChecker, layout, ActionKeys.UPDATE)) {
528
529 throw new PrincipalException();
530 }
531 else if (!group.isUser() &&
532 !GroupPermissionUtil.contains(
533 permissionChecker, layout.getGroupId(),
534 ActionKeys.UPDATE)) {
535
536 throw new PrincipalException();
537 }
538 else if (group.isUser() &&
539 (permissionChecker.getUserId() != group.getClassPK())) {
540
541 throw new PrincipalException();
542 }
543 }
544 else {
545 checkPermission(permissionChecker, group, layout, selPlid);
546 }
547 }
548
549 protected void deleteLayoutRevision(ActionRequest actionRequest)
550 throws Exception {
551
552 HttpServletRequest request = PortalUtil.getHttpServletRequest(
553 actionRequest);
554
555 long layoutRevisionId = ParamUtil.getLong(
556 actionRequest, "layoutRevisionId");
557
558 LayoutRevision layoutRevision =
559 LayoutRevisionLocalServiceUtil.getLayoutRevision(layoutRevisionId);
560
561 LayoutRevisionLocalServiceUtil.deleteLayoutRevision(layoutRevision);
562
563 boolean updateRecentLayoutRevisionId = ParamUtil.getBoolean(
564 actionRequest, "updateRecentLayoutRevisionId");
565
566 if (updateRecentLayoutRevisionId) {
567 StagingUtil.setRecentLayoutRevisionId(
568 request, layoutRevision.getLayoutSetBranchId(),
569 layoutRevision.getPlid(),
570 layoutRevision.getParentLayoutRevisionId());
571 }
572 }
573
574 protected void deleteThemeSettingsProperties(
575 UnicodeProperties typeSettingsProperties, String device) {
576
577 String keyPrefix = ThemeSettingImpl.namespaceProperty(device);
578
579 Set<String> keys = typeSettingsProperties.keySet();
580
581 Iterator<String> itr = keys.iterator();
582
583 while (itr.hasNext()) {
584 String key = itr.next();
585
586 if (key.startsWith(keyPrefix)) {
587 itr.remove();
588 }
589 }
590 }
591
592 protected void enableLayout(ActionRequest actionRequest) throws Exception {
593 long incompleteLayoutRevisionId = ParamUtil.getLong(
594 actionRequest, "incompleteLayoutRevisionId");
595
596 LayoutRevision incompleteLayoutRevision =
597 LayoutRevisionLocalServiceUtil.getLayoutRevision(
598 incompleteLayoutRevisionId);
599
600 long layoutBranchId = ParamUtil.getLong(
601 actionRequest, "layoutBranchId",
602 incompleteLayoutRevision.getLayoutBranchId());
603
604 ServiceContext serviceContext = ServiceContextFactory.getInstance(
605 actionRequest);
606
607 serviceContext.setWorkflowAction(WorkflowConstants.ACTION_SAVE_DRAFT);
608
609 LayoutRevisionLocalServiceUtil.updateLayoutRevision(
610 serviceContext.getUserId(),
611 incompleteLayoutRevision.getLayoutRevisionId(), layoutBranchId,
612 incompleteLayoutRevision.getName(),
613 incompleteLayoutRevision.getTitle(),
614 incompleteLayoutRevision.getDescription(),
615 incompleteLayoutRevision.getKeywords(),
616 incompleteLayoutRevision.getRobots(),
617 incompleteLayoutRevision.getTypeSettings(),
618 incompleteLayoutRevision.getIconImage(),
619 incompleteLayoutRevision.getIconImageId(),
620 incompleteLayoutRevision.getThemeId(),
621 incompleteLayoutRevision.getColorSchemeId(),
622 incompleteLayoutRevision.getWapThemeId(),
623 incompleteLayoutRevision.getWapColorSchemeId(),
624 incompleteLayoutRevision.getCss(), serviceContext);
625 }
626
627 protected String getColorSchemeId(
628 long companyId, String themeId, String colorSchemeId,
629 boolean wapTheme)
630 throws Exception {
631
632 Theme theme = ThemeLocalServiceUtil.getTheme(
633 companyId, themeId, wapTheme);
634
635 if (!theme.hasColorSchemes()) {
636 colorSchemeId = StringPool.BLANK;
637 }
638
639 if (Validator.isNull(colorSchemeId)) {
640 ColorScheme colorScheme = ThemeLocalServiceUtil.getColorScheme(
641 companyId, themeId, colorSchemeId, wapTheme);
642
643 colorSchemeId = colorScheme.getColorSchemeId();
644 }
645
646 return colorSchemeId;
647 }
648
649 protected Group getGroup(PortletRequest portletRequest) throws Exception {
650 return ActionUtil.getGroup(portletRequest);
651 }
652
653 protected byte[] getIconBytes(
654 UploadPortletRequest uploadPortletRequest, String iconFileName) {
655
656 InputStream inputStream = null;
657
658 try {
659 inputStream = uploadPortletRequest.getFileAsStream(iconFileName);
660
661 if (inputStream != null) {
662 return FileUtil.getBytes(inputStream);
663 }
664 }
665 catch (IOException ioe) {
666 if (_log.isWarnEnabled()) {
667 _log.warn("Unable to retrieve icon", ioe);
668 }
669 }
670
671 return new byte[0];
672 }
673
674 protected void inheritMobileRuleGroups(
675 Layout layout, ServiceContext serviceContext)
676 throws PortalException, SystemException {
677
678 List<MDRRuleGroupInstance> parentMDRRuleGroupInstances =
679 MDRRuleGroupInstanceLocalServiceUtil.getRuleGroupInstances(
680 Layout.class.getName(), layout.getParentPlid());
681
682 for (MDRRuleGroupInstance parentMDRRuleGroupInstance :
683 parentMDRRuleGroupInstances) {
684
685 MDRRuleGroupInstance mdrRuleGroupInstance =
686 MDRRuleGroupInstanceServiceUtil.addRuleGroupInstance(
687 layout.getGroupId(), Layout.class.getName(),
688 layout.getPlid(),
689 parentMDRRuleGroupInstance.getRuleGroupId(),
690 parentMDRRuleGroupInstance.getPriority(), serviceContext);
691
692 List<MDRAction> parentMDRActions =
693 MDRActionLocalServiceUtil.getActions(
694 parentMDRRuleGroupInstance.getRuleGroupInstanceId());
695
696 for (MDRAction mdrAction : parentMDRActions) {
697 MDRActionServiceUtil.addAction(
698 mdrRuleGroupInstance.getRuleGroupInstanceId(),
699 mdrAction.getNameMap(), mdrAction.getDescriptionMap(),
700 mdrAction.getType(), mdrAction.getTypeSettings(),
701 serviceContext);
702 }
703 }
704 }
705
706 @Override
707 protected boolean isCheckMethodOnProcessAction() {
708 return _CHECK_METHOD_ON_PROCESS_ACTION;
709 }
710
711 protected void selectLayoutBranch(ActionRequest actionRequest)
712 throws Exception {
713
714 HttpServletRequest request = PortalUtil.getHttpServletRequest(
715 actionRequest);
716
717 ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(
718 WebKeys.THEME_DISPLAY);
719
720 long layoutSetBranchId = ParamUtil.getLong(
721 actionRequest, "layoutSetBranchId");
722
723 long layoutBranchId = ParamUtil.getLong(
724 actionRequest, "layoutBranchId");
725
726 StagingUtil.setRecentLayoutBranchId(
727 request, layoutSetBranchId, themeDisplay.getPlid(), layoutBranchId);
728 }
729
730 protected void selectLayoutSetBranch(ActionRequest actionRequest)
731 throws Exception {
732
733 HttpServletRequest request = PortalUtil.getHttpServletRequest(
734 actionRequest);
735
736 long groupId = ParamUtil.getLong(actionRequest, "groupId");
737 boolean privateLayout = ParamUtil.getBoolean(
738 actionRequest, "privateLayout");
739
740 LayoutSet layoutSet = LayoutSetLocalServiceUtil.getLayoutSet(
741 groupId, privateLayout);
742
743 long layoutSetBranchId = ParamUtil.getLong(
744 actionRequest, "layoutSetBranchId");
745
746
747
748 LayoutSetBranch layoutSetBranch =
749 LayoutSetBranchLocalServiceUtil.getLayoutSetBranch(
750 layoutSetBranchId);
751
752 StagingUtil.setRecentLayoutSetBranchId(
753 request, layoutSet.getLayoutSetId(),
754 layoutSetBranch.getLayoutSetBranchId());
755 }
756
757 protected void setThemeSettingProperties(
758 ActionRequest actionRequest,
759 UnicodeProperties typeSettingsProperties, String themeId,
760 Map<String, ThemeSetting> themeSettings, String device,
761 String deviceThemeId)
762 throws PortalException, SystemException {
763
764 long groupId = ParamUtil.getLong(actionRequest, "groupId");
765 boolean privateLayout = ParamUtil.getBoolean(
766 actionRequest, "privateLayout");
767 long layoutId = ParamUtil.getLong(actionRequest, "layoutId");
768
769 Layout layout = LayoutLocalServiceUtil.getLayout(
770 groupId, privateLayout, layoutId);
771
772 LayoutSet layoutSet = layout.getLayoutSet();
773
774 for (String key : themeSettings.keySet()) {
775 ThemeSetting themeSetting = themeSettings.get(key);
776
777 String value = null;
778
779 if (!themeId.equals(deviceThemeId)) {
780 value = themeSetting.getValue();
781 }
782 else {
783 String property =
784 device + "ThemeSettingsProperties--" + key +
785 StringPool.DOUBLE_DASH;
786
787 value = ParamUtil.getString(actionRequest, property);
788 }
789
790 if (!Validator.equals(
791 value, layoutSet.getThemeSetting(key, device))) {
792
793 typeSettingsProperties.setProperty(
794 ThemeSettingImpl.namespaceProperty(device, key), value);
795 }
796 }
797 }
798
799 protected String updateCloseRedirect(
800 String closeRedirect, Group group, Layout layout,
801 String oldLayoutFriendlyURL) {
802
803 if (Validator.isNull(closeRedirect) ||
804 Validator.isNull(oldLayoutFriendlyURL)) {
805
806 return closeRedirect;
807 }
808
809 if (layout != null) {
810 String oldPath = oldLayoutFriendlyURL;
811 String newPath = layout.getFriendlyURL();
812
813 return PortalUtil.updateRedirect(closeRedirect, oldPath, newPath);
814 }
815 else if (group != null) {
816 String oldPath = group.getFriendlyURL() + oldLayoutFriendlyURL;
817 String newPath = group.getFriendlyURL();
818
819 return PortalUtil.updateRedirect(closeRedirect, oldPath, newPath);
820 }
821
822 return closeRedirect;
823 }
824
825 protected void updateDisplayOrder(ActionRequest actionRequest)
826 throws Exception {
827
828 long groupId = ParamUtil.getLong(actionRequest, "groupId");
829 boolean privateLayout = ParamUtil.getBoolean(
830 actionRequest, "privateLayout");
831 long parentLayoutId = ParamUtil.getLong(
832 actionRequest, "parentLayoutId");
833 long[] layoutIds = StringUtil.split(
834 ParamUtil.getString(actionRequest, "layoutIds"), 0L);
835
836 ServiceContext serviceContext = ServiceContextFactory.getInstance(
837 actionRequest);
838
839 LayoutServiceUtil.setLayouts(
840 groupId, privateLayout, parentLayoutId, layoutIds, serviceContext);
841 }
842
843 protected Object[] updateLayout(
844 ActionRequest actionRequest, ActionResponse actionResponse)
845 throws Exception {
846
847 UploadPortletRequest uploadPortletRequest =
848 PortalUtil.getUploadPortletRequest(actionRequest);
849
850 ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(
851 WebKeys.THEME_DISPLAY);
852
853 String cmd = ParamUtil.getString(uploadPortletRequest, Constants.CMD);
854
855 long groupId = ParamUtil.getLong(actionRequest, "groupId");
856 long liveGroupId = ParamUtil.getLong(actionRequest, "liveGroupId");
857 long stagingGroupId = ParamUtil.getLong(
858 actionRequest, "stagingGroupId");
859 boolean privateLayout = ParamUtil.getBoolean(
860 actionRequest, "privateLayout");
861 long layoutId = ParamUtil.getLong(actionRequest, "layoutId");
862 long parentLayoutId = ParamUtil.getLong(
863 uploadPortletRequest, "parentLayoutId");
864 Map<Locale, String> nameMap = LocalizationUtil.getLocalizationMap(
865 actionRequest, "name");
866 Map<Locale, String> titleMap = LocalizationUtil.getLocalizationMap(
867 actionRequest, "title");
868 Map<Locale, String> descriptionMap =
869 LocalizationUtil.getLocalizationMap(actionRequest, "description");
870 Map<Locale, String> keywordsMap = LocalizationUtil.getLocalizationMap(
871 actionRequest, "keywords");
872 Map<Locale, String> robotsMap = LocalizationUtil.getLocalizationMap(
873 actionRequest, "robots");
874 String type = ParamUtil.getString(uploadPortletRequest, "type");
875 boolean hidden = ParamUtil.getBoolean(uploadPortletRequest, "hidden");
876 String friendlyURL = ParamUtil.getString(
877 uploadPortletRequest, "friendlyURL");
878 boolean iconImage = ParamUtil.getBoolean(
879 uploadPortletRequest, "iconImage");
880 byte[] iconBytes = getIconBytes(uploadPortletRequest, "iconFileName");
881 long layoutPrototypeId = ParamUtil.getLong(
882 uploadPortletRequest, "layoutPrototypeId");
883
884 ServiceContext serviceContext = ServiceContextFactory.getInstance(
885 Layout.class.getName(), actionRequest);
886
887 Layout layout = null;
888 UnicodeProperties layoutTypeSettingsProperties = null;
889 String oldFriendlyURL = StringPool.BLANK;
890
891 if (cmd.equals(Constants.ADD)) {
892
893
894
895 boolean inheritFromParentLayoutId = ParamUtil.getBoolean(
896 uploadPortletRequest, "inheritFromParentLayoutId");
897
898 if (inheritFromParentLayoutId && (parentLayoutId > 0)) {
899 Layout parentLayout = LayoutLocalServiceUtil.getLayout(
900 groupId, privateLayout, parentLayoutId);
901
902 layout = LayoutServiceUtil.addLayout(
903 groupId, privateLayout, parentLayoutId, nameMap, titleMap,
904 parentLayout.getDescriptionMap(),
905 parentLayout.getKeywordsMap(), parentLayout.getRobotsMap(),
906 parentLayout.getType(), hidden, friendlyURL,
907 serviceContext);
908
909 LayoutServiceUtil.updateLayout(
910 layout.getGroupId(), layout.isPrivateLayout(),
911 layout.getLayoutId(), parentLayout.getTypeSettings());
912
913 inheritMobileRuleGroups(layout, serviceContext);
914
915 if (parentLayout.isTypePortlet()) {
916 ActionUtil.copyPreferences(
917 actionRequest, layout, parentLayout);
918
919 SitesUtil.copyLookAndFeel(layout, parentLayout);
920 }
921 }
922 else if (layoutPrototypeId > 0) {
923 LayoutPrototype layoutPrototype =
924 LayoutPrototypeServiceUtil.getLayoutPrototype(
925 layoutPrototypeId);
926
927 String layoutPrototypeLinkEnabled= ParamUtil.getString(
928 uploadPortletRequest, "layoutPrototypeLinkEnabled");
929
930 if (Validator.isNotNull(layoutPrototypeLinkEnabled)) {
931 serviceContext.setAttribute(
932 "layoutPrototypeLinkEnabled",
933 layoutPrototypeLinkEnabled);
934 }
935
936 serviceContext.setAttribute(
937 "layoutPrototypeUuid", layoutPrototype.getUuid());
938
939 layout = LayoutServiceUtil.addLayout(
940 groupId, privateLayout, parentLayoutId, nameMap, titleMap,
941 descriptionMap, keywordsMap, robotsMap,
942 LayoutConstants.TYPE_PORTLET, hidden, friendlyURL,
943 serviceContext);
944 }
945 else {
946 layout = LayoutServiceUtil.addLayout(
947 groupId, privateLayout, parentLayoutId, nameMap, titleMap,
948 descriptionMap, keywordsMap, robotsMap, type, hidden,
949 friendlyURL, serviceContext);
950 }
951
952 layoutTypeSettingsProperties = layout.getTypeSettingsProperties();
953 }
954 else {
955
956
957
958 layout = LayoutLocalServiceUtil.getLayout(
959 groupId, privateLayout, layoutId);
960
961 oldFriendlyURL = layout.getFriendlyURL();
962
963 layout = LayoutServiceUtil.updateLayout(
964 groupId, privateLayout, layoutId, layout.getParentLayoutId(),
965 nameMap, titleMap, descriptionMap, keywordsMap, robotsMap, type,
966 hidden, friendlyURL, Boolean.valueOf(iconImage), iconBytes,
967 serviceContext);
968
969 layoutTypeSettingsProperties = layout.getTypeSettingsProperties();
970
971 if (oldFriendlyURL.equals(layout.getFriendlyURL())) {
972 oldFriendlyURL = StringPool.BLANK;
973 }
974
975 UnicodeProperties formTypeSettingsProperties =
976 PropertiesParamUtil.getProperties(
977 actionRequest, "TypeSettingsProperties--");
978
979 if (type.equals(LayoutConstants.TYPE_PORTLET)) {
980 LayoutTypePortlet layoutTypePortlet =
981 (LayoutTypePortlet)layout.getLayoutType();
982
983 String layoutTemplateId = ParamUtil.getString(
984 uploadPortletRequest, "layoutTemplateId",
985 PropsValues.DEFAULT_LAYOUT_TEMPLATE_ID);
986
987 layoutTypePortlet.setLayoutTemplateId(
988 themeDisplay.getUserId(), layoutTemplateId);
989
990 long copyLayoutId = ParamUtil.getLong(
991 uploadPortletRequest, "copyLayoutId");
992
993 if ((copyLayoutId > 0) &&
994 (copyLayoutId != layout.getLayoutId())) {
995
996 try {
997 Layout copyLayout = LayoutLocalServiceUtil.getLayout(
998 groupId, privateLayout, copyLayoutId);
999
1000 if (copyLayout.isTypePortlet()) {
1001 layoutTypeSettingsProperties =
1002 copyLayout.getTypeSettingsProperties();
1003
1004 ActionUtil.copyPreferences(
1005 actionRequest, layout, copyLayout);
1006
1007 SitesUtil.copyLookAndFeel(layout, copyLayout);
1008 }
1009 }
1010 catch (NoSuchLayoutException nsle) {
1011 }
1012 }
1013 else {
1014 layoutTypeSettingsProperties.putAll(
1015 formTypeSettingsProperties);
1016
1017 LayoutServiceUtil.updateLayout(
1018 groupId, privateLayout, layoutId,
1019 layout.getTypeSettings());
1020 }
1021 }
1022 else {
1023 layout.setTypeSettingsProperties(formTypeSettingsProperties);
1024
1025 layoutTypeSettingsProperties.putAll(
1026 layout.getTypeSettingsProperties());
1027
1028 LayoutServiceUtil.updateLayout(
1029 groupId, privateLayout, layoutId, layout.getTypeSettings());
1030 }
1031
1032 HttpServletResponse response = PortalUtil.getHttpServletResponse(
1033 actionResponse);
1034
1035 LayoutSettings layoutSettings = LayoutSettings.getInstance(layout);
1036
1037 EventsProcessorUtil.process(
1038 PropsKeys.LAYOUT_CONFIGURATION_ACTION_UPDATE,
1039 layoutSettings.getConfigurationActionUpdate(),
1040 uploadPortletRequest, response);
1041 }
1042
1043 updateLookAndFeel(
1044 actionRequest, themeDisplay.getCompanyId(), liveGroupId,
1045 stagingGroupId, privateLayout, layout.getLayoutId(),
1046 layoutTypeSettingsProperties, layout.getThemeId());
1047
1048 return new Object[] {layout, oldFriendlyURL};
1049 }
1050
1051 protected void updateLayoutRevision(
1052 ActionRequest actionRequest, ThemeDisplay themeDisplay)
1053 throws Exception {
1054
1055 long layoutRevisionId = ParamUtil.getLong(
1056 actionRequest, "layoutRevisionId");
1057
1058 LayoutRevision layoutRevision =
1059 LayoutRevisionLocalServiceUtil.getLayoutRevision(layoutRevisionId);
1060
1061 ServiceContext serviceContext = ServiceContextFactory.getInstance(
1062 actionRequest);
1063
1064 LayoutRevision enableLayoutRevision =
1065 LayoutRevisionLocalServiceUtil.updateLayoutRevision(
1066 serviceContext.getUserId(), layoutRevisionId,
1067 layoutRevision.getLayoutBranchId(), layoutRevision.getName(),
1068 layoutRevision.getTitle(), layoutRevision.getDescription(),
1069 layoutRevision.getKeywords(), layoutRevision.getRobots(),
1070 layoutRevision.getTypeSettings(), layoutRevision.getIconImage(),
1071 layoutRevision.getIconImageId(), layoutRevision.getThemeId(),
1072 layoutRevision.getColorSchemeId(),
1073 layoutRevision.getWapThemeId(),
1074 layoutRevision.getWapColorSchemeId(), layoutRevision.getCss(),
1075 serviceContext);
1076
1077 if (layoutRevision.getStatus() == WorkflowConstants.STATUS_INCOMPLETE) {
1078 LayoutRevision lastLayoutRevision =
1079 LayoutRevisionLocalServiceUtil.fetchLastLayoutRevision(
1080 enableLayoutRevision.getPlid(), true);
1081
1082 if (lastLayoutRevision != null) {
1083 LayoutRevision newLayoutRevision =
1084 LayoutRevisionLocalServiceUtil.addLayoutRevision(
1085 serviceContext.getUserId(),
1086 layoutRevision.getLayoutSetBranchId(),
1087 layoutRevision.getLayoutBranchId(),
1088 enableLayoutRevision.getLayoutRevisionId(), false,
1089 layoutRevision.getPlid(),
1090 lastLayoutRevision.getLayoutRevisionId(),
1091 lastLayoutRevision.getPrivateLayout(),
1092 lastLayoutRevision.getName(),
1093 lastLayoutRevision.getTitle(),
1094 lastLayoutRevision.getDescription(),
1095 lastLayoutRevision.getKeywords(),
1096 lastLayoutRevision.getRobots(),
1097 lastLayoutRevision.getTypeSettings(),
1098 lastLayoutRevision.isIconImage(),
1099 lastLayoutRevision.getIconImageId(),
1100 lastLayoutRevision.getThemeId(),
1101 lastLayoutRevision.getColorSchemeId(),
1102 lastLayoutRevision.getWapThemeId(),
1103 lastLayoutRevision.getWapColorSchemeId(),
1104 lastLayoutRevision.getCss(), serviceContext);
1105
1106 StagingUtil.setRecentLayoutRevisionId(
1107 themeDisplay.getUser(),
1108 newLayoutRevision.getLayoutSetBranchId(),
1109 newLayoutRevision.getPlid(),
1110 newLayoutRevision.getLayoutRevisionId());
1111 }
1112 }
1113 }
1114
1115 protected void updateLookAndFeel(
1116 ActionRequest actionRequest, long companyId, long liveGroupId,
1117 long stagingGroupId, boolean privateLayout, long layoutId,
1118 UnicodeProperties typeSettingsProperties, String themeId)
1119 throws Exception {
1120
1121 String[] devices = StringUtil.split(
1122 ParamUtil.getString(actionRequest, "devices"));
1123
1124 for (String device : devices) {
1125 String deviceThemeId = ParamUtil.getString(
1126 actionRequest, device + "ThemeId");
1127 String deviceColorSchemeId = ParamUtil.getString(
1128 actionRequest, device + "ColorSchemeId");
1129 String deviceCss = ParamUtil.getString(
1130 actionRequest, device + "Css");
1131 boolean deviceWapTheme = device.equals("wap");
1132
1133 boolean deviceInheritLookAndFeel = ParamUtil.getBoolean(
1134 actionRequest, device + "InheritLookAndFeel");
1135
1136 if (deviceInheritLookAndFeel) {
1137 deviceThemeId = ThemeImpl.getDefaultRegularThemeId(companyId);
1138 deviceColorSchemeId = StringPool.BLANK;
1139
1140 deleteThemeSettingsProperties(typeSettingsProperties, device);
1141 }
1142 else if (Validator.isNotNull(deviceThemeId)) {
1143 deviceColorSchemeId = getColorSchemeId(
1144 companyId, deviceThemeId, deviceColorSchemeId,
1145 deviceWapTheme);
1146
1147 updateThemeSettingsProperties(
1148 actionRequest, companyId, typeSettingsProperties, themeId,
1149 device, deviceThemeId, deviceWapTheme);
1150 }
1151
1152 long groupId = liveGroupId;
1153
1154 if (stagingGroupId > 0) {
1155 groupId = stagingGroupId;
1156 }
1157
1158 LayoutServiceUtil.updateLayout(
1159 groupId, privateLayout, layoutId,
1160 typeSettingsProperties.toString());
1161
1162 LayoutServiceUtil.updateLookAndFeel(
1163 groupId, privateLayout, layoutId, deviceThemeId,
1164 deviceColorSchemeId, deviceCss, deviceWapTheme);
1165 }
1166 }
1167
1168 protected UnicodeProperties updateThemeSettingsProperties(
1169 ActionRequest actionRequest, long companyId,
1170 UnicodeProperties typeSettingsProperties, String themeId,
1171 String device, String deviceThemeId, boolean wapTheme)
1172 throws Exception {
1173
1174 Theme theme = ThemeLocalServiceUtil.getTheme(
1175 companyId, deviceThemeId, wapTheme);
1176
1177 deleteThemeSettingsProperties(typeSettingsProperties, device);
1178
1179 Map<String, ThemeSetting> themeSettings =
1180 theme.getConfigurableSettings();
1181
1182 if (themeSettings.isEmpty()) {
1183 return typeSettingsProperties;
1184 }
1185
1186 setThemeSettingProperties(
1187 actionRequest, typeSettingsProperties, themeId, themeSettings,
1188 device, deviceThemeId);
1189
1190 return typeSettingsProperties;
1191 }
1192
1193 private static final boolean _CHECK_METHOD_ON_PROCESS_ACTION = false;
1194
1195 private static Log _log = LogFactoryUtil.getLog(EditLayoutsAction.class);
1196
1197 }