001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portlet.communities.action;
022:
023: import com.germinus.easyconf.Filter;
024:
025: import com.liferay.portal.LayoutFriendlyURLException;
026: import com.liferay.portal.LayoutHiddenException;
027: import com.liferay.portal.LayoutNameException;
028: import com.liferay.portal.LayoutParentLayoutIdException;
029: import com.liferay.portal.LayoutSetVirtualHostException;
030: import com.liferay.portal.LayoutTypeException;
031: import com.liferay.portal.NoSuchGroupException;
032: import com.liferay.portal.NoSuchLayoutException;
033: import com.liferay.portal.PortalException;
034: import com.liferay.portal.RequiredLayoutException;
035: import com.liferay.portal.SystemException;
036: import com.liferay.portal.events.EventsProcessor;
037: import com.liferay.portal.kernel.language.LanguageUtil;
038: import com.liferay.portal.kernel.lar.PortletDataHandlerKeys;
039: import com.liferay.portal.kernel.lar.UserIdStrategy;
040: import com.liferay.portal.kernel.security.permission.ActionKeys;
041: import com.liferay.portal.kernel.security.permission.PermissionChecker;
042: import com.liferay.portal.kernel.util.Constants;
043: import com.liferay.portal.kernel.util.LocaleUtil;
044: import com.liferay.portal.kernel.util.ParamUtil;
045: import com.liferay.portal.kernel.util.StringUtil;
046: import com.liferay.portal.kernel.util.Validator;
047: import com.liferay.portal.model.ColorScheme;
048: import com.liferay.portal.model.Group;
049: import com.liferay.portal.model.Layout;
050: import com.liferay.portal.model.LayoutTypePortlet;
051: import com.liferay.portal.model.PortletPreferencesIds;
052: import com.liferay.portal.model.User;
053: import com.liferay.portal.model.impl.GroupImpl;
054: import com.liferay.portal.model.impl.LayoutImpl;
055: import com.liferay.portal.security.auth.PrincipalException;
056: import com.liferay.portal.service.GroupLocalServiceUtil;
057: import com.liferay.portal.service.GroupServiceUtil;
058: import com.liferay.portal.service.LayoutLocalServiceUtil;
059: import com.liferay.portal.service.LayoutServiceUtil;
060: import com.liferay.portal.service.LayoutSetServiceUtil;
061: import com.liferay.portal.service.PortletPreferencesLocalServiceUtil;
062: import com.liferay.portal.service.UserLocalServiceUtil;
063: import com.liferay.portal.service.impl.ThemeLocalUtil;
064: import com.liferay.portal.service.permission.GroupPermissionUtil;
065: import com.liferay.portal.service.permission.OrganizationPermissionUtil;
066: import com.liferay.portal.service.permission.UserPermissionUtil;
067: import com.liferay.portal.struts.PortletAction;
068: import com.liferay.portal.theme.ThemeDisplay;
069: import com.liferay.portal.util.PortalUtil;
070: import com.liferay.portal.util.PortletKeys;
071: import com.liferay.portal.util.PropsUtil;
072: import com.liferay.portal.util.PropsValues;
073: import com.liferay.portal.util.WebKeys;
074: import com.liferay.portlet.ActionResponseImpl;
075: import com.liferay.portlet.PortletPreferencesFactoryUtil;
076: import com.liferay.portlet.communities.form.PageForm;
077: import com.liferay.portlet.communities.util.CommunitiesUtil;
078: import com.liferay.util.FileUtil;
079: import com.liferay.util.servlet.SessionErrors;
080: import com.liferay.util.servlet.UploadException;
081: import com.liferay.util.servlet.UploadPortletRequest;
082:
083: import java.io.ByteArrayInputStream;
084: import java.io.File;
085:
086: import java.util.ArrayList;
087: import java.util.HashMap;
088: import java.util.Iterator;
089: import java.util.LinkedHashMap;
090: import java.util.List;
091: import java.util.Locale;
092: import java.util.Map.Entry;
093: import java.util.Map;
094: import java.util.Properties;
095:
096: import javax.portlet.ActionRequest;
097: import javax.portlet.ActionResponse;
098: import javax.portlet.PortletConfig;
099: import javax.portlet.PortletPreferences;
100: import javax.portlet.PortletRequest;
101: import javax.portlet.RenderRequest;
102: import javax.portlet.RenderResponse;
103:
104: import javax.servlet.http.HttpServletRequest;
105: import javax.servlet.http.HttpServletResponse;
106:
107: import org.apache.commons.logging.Log;
108: import org.apache.commons.logging.LogFactory;
109: import org.apache.struts.action.ActionForm;
110: import org.apache.struts.action.ActionForward;
111: import org.apache.struts.action.ActionMapping;
112:
113: /**
114: * <a href="EditPagesAction.java.html"><b><i>View Source</i></b></a>
115: *
116: * @author Brian Wing Shun Chan
117: *
118: */
119: public class EditPagesAction extends PortletAction {
120:
121: public void processAction(ActionMapping mapping, ActionForm form,
122: PortletConfig config, ActionRequest req, ActionResponse res)
123: throws Exception {
124:
125: try {
126: checkPermissions(req);
127: } catch (PrincipalException pe) {
128: return;
129: }
130:
131: PageForm pageForm = (PageForm) form;
132:
133: String cmd = ParamUtil.getString(req, Constants.CMD);
134:
135: try {
136: if (cmd.equals(Constants.ADD)
137: || cmd.equals(Constants.UPDATE)) {
138: updateLayout(pageForm, req, res);
139: } else if (cmd.equals(Constants.DELETE)) {
140: CommunitiesUtil.deleteLayout(req, res);
141: } else if (cmd.equals("copy_from_live")) {
142: copyFromLive(req);
143: } else if (cmd.equals("display_order")) {
144: updateDisplayOrder(req);
145: } else if (cmd.equals("logo")) {
146: updateLogo(req);
147: } else if (cmd.equals("look_and_feel")) {
148: updateLookAndFeel(req);
149: } else if (cmd.equals("merge_pages")) {
150: updateMergePages(req);
151: } else if (cmd.equals("monitoring")) {
152: updateMonitoring(req);
153: } else if (cmd.equals("publish_to_live")) {
154: publishToLive(req);
155: } else if (cmd.equals("update_staging_state")) {
156: updateStagingState(req);
157: } else if (cmd.equals("virtual_host")) {
158: updateVirtualHost(req);
159: }
160:
161: String redirect = ParamUtil.getString(req, "pagesRedirect");
162:
163: sendRedirect(req, res, redirect);
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: } else if (e instanceof LayoutFriendlyURLException
172: || e instanceof LayoutHiddenException
173: || e instanceof LayoutNameException
174: || e instanceof LayoutParentLayoutIdException
175: || e instanceof LayoutSetVirtualHostException
176: || e instanceof LayoutTypeException
177: || e instanceof RequiredLayoutException
178: || e instanceof UploadException) {
179:
180: if (e instanceof LayoutFriendlyURLException) {
181: SessionErrors.add(req,
182: LayoutFriendlyURLException.class.getName(),
183: e);
184: } else {
185: SessionErrors.add(req, e.getClass().getName(), e);
186: }
187: } else {
188: throw e;
189: }
190: }
191: }
192:
193: public ActionForward render(ActionMapping mapping, ActionForm form,
194: PortletConfig config, RenderRequest req, RenderResponse res)
195: throws Exception {
196:
197: try {
198: checkPermissions(req);
199: } catch (PrincipalException pe) {
200: SessionErrors.add(req, PrincipalException.class.getName());
201:
202: return mapping.findForward("portlet.communities.error");
203: }
204:
205: try {
206: ActionUtil.getGroup(req);
207: } catch (Exception e) {
208: if (e instanceof NoSuchGroupException
209: || e instanceof PrincipalException) {
210:
211: SessionErrors.add(req, e.getClass().getName());
212:
213: return mapping.findForward("portlet.communities.error");
214: } else {
215: throw e;
216: }
217: }
218:
219: return mapping.findForward(getForward(req,
220: "portlet.communities.edit_pages"));
221: }
222:
223: protected void checkPermissions(PortletRequest req)
224: throws Exception {
225:
226: // LEP-850
227:
228: ThemeDisplay themeDisplay = (ThemeDisplay) req
229: .getAttribute(WebKeys.THEME_DISPLAY);
230:
231: PermissionChecker permissionChecker = themeDisplay
232: .getPermissionChecker();
233:
234: long groupId = ParamUtil.getLong(req, "groupId");
235:
236: Group group = GroupLocalServiceUtil.getGroup(groupId);
237:
238: if (group.isCommunity()) {
239: GroupPermissionUtil.check(permissionChecker, group
240: .getGroupId(), ActionKeys.MANAGE_LAYOUTS);
241: } else if (group.isOrganization()) {
242: long organizationId = group.getClassPK();
243:
244: OrganizationPermissionUtil.check(permissionChecker,
245: organizationId, ActionKeys.MANAGE_LAYOUTS);
246: } else if (group.isUser()) {
247: long groupUserId = group.getClassPK();
248:
249: User groupUser = UserLocalServiceUtil
250: .getUserById(groupUserId);
251:
252: long[] organizationIds = groupUser.getOrganizationIds();
253:
254: UserPermissionUtil.check(permissionChecker, groupUserId,
255: organizationIds, ActionKeys.UPDATE);
256:
257: if (!groupUser.isLayoutsRequired()) {
258: throw new PrincipalException();
259: }
260: }
261: }
262:
263: protected void copyFromLive(ActionRequest req) throws Exception {
264: String tabs2 = ParamUtil.getString(req, "tabs2");
265:
266: long stagingGroupId = ParamUtil.getLong(req, "stagingGroupId");
267:
268: Group stagingGroup = GroupLocalServiceUtil
269: .getGroup(stagingGroupId);
270:
271: boolean privateLayout = true;
272:
273: if (tabs2.equals("public")) {
274: privateLayout = false;
275: }
276:
277: if (_log.isDebugEnabled()) {
278: _log.debug("Copying live to staging for group "
279: + stagingGroup.getLiveGroupId());
280: }
281:
282: String scope = ParamUtil.getString(req, "scope");
283:
284: if (scope.equals("all-pages")) {
285: copyLayouts(stagingGroup.getLiveGroupId(), stagingGroup
286: .getGroupId(), privateLayout);
287: } else if (scope.equals("selected-pages")) {
288: Map layoutIdMap = new LinkedHashMap();
289:
290: long[] rowIds = ParamUtil.getLongValues(req, "rowIds");
291:
292: for (int i = 0; i < rowIds.length; i++) {
293: long selPlid = rowIds[i];
294: boolean includeChildren = ParamUtil.getBoolean(req,
295: "includeChildren_" + selPlid);
296:
297: layoutIdMap.put(new Long(selPlid), new Boolean(
298: includeChildren));
299: }
300:
301: publishLayouts(layoutIdMap, stagingGroup.getLiveGroupId(),
302: stagingGroup.getGroupId(), privateLayout);
303: }
304: }
305:
306: protected void copyLayouts(long sourceGroupId, long targetGroupId,
307: boolean privateLayout) throws Exception {
308:
309: Map parameterMap = getStagingParameters();
310:
311: byte[] data = LayoutServiceUtil.exportLayouts(sourceGroupId,
312: privateLayout, parameterMap);
313:
314: ByteArrayInputStream bais = new ByteArrayInputStream(data);
315:
316: LayoutServiceUtil.importLayouts(targetGroupId, privateLayout,
317: parameterMap, bais);
318: }
319:
320: protected void copyPreferences(ActionRequest req, Layout layout,
321: Layout copyLayout) throws Exception {
322:
323: long companyId = layout.getCompanyId();
324:
325: LayoutTypePortlet copyLayoutTypePortlet = (LayoutTypePortlet) copyLayout
326: .getLayoutType();
327:
328: List copyPortletIds = copyLayoutTypePortlet.getPortletIds();
329:
330: for (int i = 0; i < copyPortletIds.size(); i++) {
331: String copyPortletId = (String) copyPortletIds.get(i);
332:
333: HttpServletRequest httpReq = PortalUtil
334: .getHttpServletRequest(req);
335:
336: // Copy preference
337:
338: PortletPreferencesIds portletPreferencesIds = PortletPreferencesFactoryUtil
339: .getPortletPreferencesIds(httpReq, layout,
340: copyPortletId);
341:
342: PortletPreferencesLocalServiceUtil
343: .getPreferences(portletPreferencesIds);
344:
345: PortletPreferencesIds copyPortletPreferencesIds = PortletPreferencesFactoryUtil
346: .getPortletPreferencesIds(httpReq, copyLayout,
347: copyPortletId);
348:
349: PortletPreferences copyPrefs = PortletPreferencesLocalServiceUtil
350: .getPreferences(copyPortletPreferencesIds);
351:
352: PortletPreferencesLocalServiceUtil.updatePreferences(
353: portletPreferencesIds.getOwnerId(),
354: portletPreferencesIds.getOwnerType(),
355: portletPreferencesIds.getPlid(),
356: portletPreferencesIds.getPortletId(), copyPrefs);
357:
358: // Copy portlet setup
359:
360: PortletPreferencesLocalServiceUtil.getPreferences(
361: companyId, PortletKeys.PREFS_OWNER_ID_DEFAULT,
362: PortletKeys.PREFS_OWNER_TYPE_LAYOUT, layout
363: .getPlid(), copyPortletId);
364:
365: copyPrefs = PortletPreferencesLocalServiceUtil
366: .getPreferences(companyId,
367: PortletKeys.PREFS_OWNER_ID_DEFAULT,
368: PortletKeys.PREFS_OWNER_TYPE_LAYOUT,
369: copyLayout.getPlid(), copyPortletId);
370:
371: PortletPreferencesLocalServiceUtil.updatePreferences(
372: PortletKeys.PREFS_OWNER_ID_DEFAULT,
373: PortletKeys.PREFS_OWNER_TYPE_LAYOUT, layout
374: .getPlid(), copyPortletId, copyPrefs);
375: }
376: }
377:
378: protected List getMissingParents(Layout layout, long liveGroupId)
379: throws PortalException, SystemException {
380:
381: List missingParents = new ArrayList();
382:
383: long parentLayoutId = layout.getParentLayoutId();
384:
385: while (parentLayoutId > 0) {
386: try {
387: LayoutLocalServiceUtil.getLayout(liveGroupId, layout
388: .isPrivateLayout(), parentLayoutId);
389:
390: // If one parent is found all others are assumed to exist
391:
392: break;
393: } catch (NoSuchLayoutException nsle) {
394: Layout parent = LayoutLocalServiceUtil.getLayout(layout
395: .getGroupId(), layout.isPrivateLayout(),
396: parentLayoutId);
397:
398: missingParents.add(parent);
399:
400: parentLayoutId = parent.getParentLayoutId();
401: }
402: }
403:
404: return missingParents;
405: }
406:
407: protected Map getStagingParameters() {
408: Map parameterMap = new HashMap();
409:
410: parameterMap.put(PortletDataHandlerKeys.PERMISSIONS,
411: Boolean.TRUE.toString());
412: parameterMap.put(PortletDataHandlerKeys.USER_PERMISSIONS,
413: Boolean.FALSE.toString());
414: parameterMap.put(PortletDataHandlerKeys.PORTLET_DATA,
415: Boolean.TRUE.toString());
416: parameterMap.put(PortletDataHandlerKeys.PORTLET_DATA_ALL,
417: Boolean.TRUE.toString());
418: parameterMap.put(PortletDataHandlerKeys.PORTLET_SETUP,
419: Boolean.TRUE.toString());
420: parameterMap.put(
421: PortletDataHandlerKeys.PORTLET_USER_PREFERENCES,
422: Boolean.TRUE.toString());
423: parameterMap.put(PortletDataHandlerKeys.THEME, Boolean.FALSE
424: .toString());
425: parameterMap.put(PortletDataHandlerKeys.DELETE_MISSING_LAYOUTS,
426: Boolean.TRUE.toString());
427: parameterMap.put(PortletDataHandlerKeys.DELETE_PORTLET_DATA,
428: Boolean.FALSE.toString());
429: parameterMap.put(PortletDataHandlerKeys.DATA_STRATEGY,
430: PortletDataHandlerKeys.DATA_STRATEGY_MIRROR);
431: parameterMap.put(PortletDataHandlerKeys.USER_ID_STRATEGY,
432: UserIdStrategy.CURRENT_USER_ID);
433:
434: return parameterMap;
435: }
436:
437: protected void publishLayout(long plid, long liveGroupId,
438: boolean includeChildren) throws Exception {
439:
440: Map parameterMap = getStagingParameters();
441:
442: parameterMap.put(PortletDataHandlerKeys.DELETE_MISSING_LAYOUTS,
443: Boolean.FALSE.toString());
444:
445: Layout layout = LayoutLocalServiceUtil.getLayout(plid);
446:
447: List layouts = new ArrayList();
448:
449: layouts.add(layout);
450:
451: layouts.addAll(getMissingParents(layout, liveGroupId));
452:
453: if (includeChildren) {
454: layouts.addAll(layout.getAllChildren());
455: }
456:
457: Iterator itr = layouts.iterator();
458:
459: long[] layoutIds = new long[layouts.size()];
460:
461: for (int i = 0; itr.hasNext(); i++) {
462: Layout curLayout = (Layout) itr.next();
463:
464: layoutIds[i] = curLayout.getLayoutId();
465: }
466:
467: byte[] data = LayoutServiceUtil.exportLayouts(layout
468: .getGroupId(), layout.isPrivateLayout(), layoutIds,
469: parameterMap);
470:
471: ByteArrayInputStream bais = new ByteArrayInputStream(data);
472:
473: LayoutServiceUtil.importLayouts(liveGroupId, layout
474: .isPrivateLayout(), parameterMap, bais);
475: }
476:
477: protected void publishLayouts(Map layoutIdMap, long stagingGroupId,
478: long liveGroupId, boolean privateLayout) throws Exception {
479:
480: Map parameterMap = getStagingParameters();
481:
482: parameterMap.put(PortletDataHandlerKeys.DELETE_MISSING_LAYOUTS,
483: Boolean.FALSE.toString());
484:
485: List layouts = new ArrayList();
486:
487: Iterator itr1 = layoutIdMap.entrySet().iterator();
488:
489: while (itr1.hasNext()) {
490: Entry entry = (Entry) itr1.next();
491:
492: long plid = ((Long) entry.getKey()).longValue();
493: boolean includeChildren = ((Boolean) entry.getValue())
494: .booleanValue();
495:
496: Layout layout = LayoutLocalServiceUtil.getLayout(plid);
497:
498: if (!layouts.contains(layout)) {
499: layouts.add(layout);
500: }
501:
502: Iterator itr2 = getMissingParents(layout, liveGroupId)
503: .iterator();
504:
505: while (itr2.hasNext()) {
506: Layout parentLayout = (Layout) itr2.next();
507:
508: if (!layouts.contains(parentLayout)) {
509: layouts.add(parentLayout);
510: }
511: }
512:
513: if (includeChildren) {
514: itr2 = layout.getAllChildren().iterator();
515:
516: while (itr2.hasNext()) {
517: Layout childLayout = (Layout) itr2.next();
518:
519: if (!layouts.contains(childLayout)) {
520: layouts.add(childLayout);
521: }
522: }
523: }
524: }
525:
526: itr1 = layouts.iterator();
527:
528: long[] layoutIds = new long[layouts.size()];
529:
530: for (int i = 0; itr1.hasNext(); i++) {
531: Layout curLayout = (Layout) itr1.next();
532:
533: layoutIds[i] = curLayout.getLayoutId();
534: }
535:
536: byte[] data = LayoutServiceUtil.exportLayouts(stagingGroupId,
537: privateLayout, layoutIds, parameterMap);
538:
539: ByteArrayInputStream bais = new ByteArrayInputStream(data);
540:
541: LayoutServiceUtil.importLayouts(liveGroupId, privateLayout,
542: parameterMap, bais);
543: }
544:
545: protected void publishToLive(ActionRequest req) throws Exception {
546: String tabs2 = ParamUtil.getString(req, "tabs2");
547:
548: long stagingGroupId = ParamUtil.getLong(req, "stagingGroupId");
549:
550: Group stagingGroup = GroupLocalServiceUtil
551: .getGroup(stagingGroupId);
552:
553: boolean privateLayout = true;
554:
555: if (tabs2.equals("public")) {
556: privateLayout = false;
557: }
558:
559: if (_log.isDebugEnabled()) {
560: _log.debug("Copying staging to live for group "
561: + stagingGroup.getLiveGroupId());
562: }
563:
564: String scope = ParamUtil.getString(req, "scope");
565:
566: if (scope.equals("all-pages")) {
567: copyLayouts(stagingGroup.getGroupId(), stagingGroup
568: .getLiveGroupId(), privateLayout);
569: } else if (scope.equals("selected-pages")) {
570: Map layoutIdMap = new LinkedHashMap();
571:
572: long[] rowIds = ParamUtil.getLongValues(req, "rowIds");
573:
574: for (int i = 0; i < rowIds.length; i++) {
575: long selPlid = rowIds[i];
576: boolean includeChildren = ParamUtil.getBoolean(req,
577: "includeChildren_" + selPlid);
578:
579: layoutIdMap.put(new Long(selPlid), new Boolean(
580: includeChildren));
581: }
582:
583: publishLayouts(layoutIdMap, stagingGroup.getGroupId(),
584: stagingGroup.getLiveGroupId(), privateLayout);
585: }
586: }
587:
588: protected void updateDisplayOrder(ActionRequest req)
589: throws Exception {
590: long groupId = ParamUtil.getLong(req, "groupId");
591: boolean privateLayout = ParamUtil.getBoolean(req,
592: "privateLayout");
593: long parentLayoutId = ParamUtil.getLong(req, "parentLayoutId");
594: long[] layoutIds = StringUtil.split(ParamUtil.getString(req,
595: "layoutIds"), 0L);
596:
597: LayoutServiceUtil.setLayouts(groupId, privateLayout,
598: parentLayoutId, layoutIds);
599: }
600:
601: protected void updateLayout(PageForm pageForm, ActionRequest req,
602: ActionResponse res) throws Exception {
603:
604: UploadPortletRequest uploadReq = PortalUtil
605: .getUploadPortletRequest(req);
606:
607: String cmd = ParamUtil.getString(uploadReq, Constants.CMD);
608:
609: long groupId = ParamUtil.getLong(req, "groupId");
610: boolean privateLayout = ParamUtil.getBoolean(req,
611: "privateLayout");
612: long layoutId = ParamUtil.getLong(req, "layoutId");
613: long parentLayoutId = ParamUtil.getLong(uploadReq,
614: "parentLayoutId");
615: String description = ParamUtil.getString(uploadReq,
616: "description");
617: String type = ParamUtil.getString(uploadReq, "type");
618: boolean hidden = ParamUtil.getBoolean(uploadReq, "hidden");
619: String friendlyURL = ParamUtil.getString(uploadReq,
620: "friendlyURL");
621: boolean iconImage = ParamUtil
622: .getBoolean(uploadReq, "iconImage");
623: byte[] iconBytes = FileUtil.getBytes(uploadReq
624: .getFile("iconFileName"));
625:
626: boolean inheritFromParentLayoutId = ParamUtil.getBoolean(
627: uploadReq, "inheritFromParentLayoutId");
628:
629: long copyLayoutId = ParamUtil
630: .getLong(uploadReq, "copyLayoutId");
631:
632: Locale[] locales = LanguageUtil.getAvailableLocales();
633:
634: Map localeNamesMap = new HashMap();
635: Map localeTitlesMap = new HashMap();
636:
637: for (int i = 0; i < locales.length; i++) {
638: String languageId = LocaleUtil.toLanguageId(locales[i]);
639:
640: localeNamesMap.put(locales[i], ParamUtil.getString(
641: uploadReq, "name_" + languageId));
642: localeTitlesMap.put(locales[i], ParamUtil.getString(
643: uploadReq, "title_" + languageId));
644: }
645:
646: if (cmd.equals(Constants.ADD)) {
647:
648: // Add layout
649:
650: if (inheritFromParentLayoutId && (parentLayoutId > 0)) {
651: Layout parentLayout = LayoutLocalServiceUtil.getLayout(
652: groupId, privateLayout, parentLayoutId);
653:
654: Layout layout = LayoutServiceUtil.addLayout(groupId,
655: privateLayout, parentLayoutId, localeNamesMap,
656: localeTitlesMap, description, parentLayout
657: .getType(), parentLayout.isHidden(),
658: friendlyURL);
659:
660: LayoutServiceUtil.updateLayout(layout.getGroupId(),
661: layout.isPrivateLayout(), layout.getLayoutId(),
662: parentLayout.getTypeSettings());
663: } else {
664: Layout layout = LayoutServiceUtil.addLayout(groupId,
665: privateLayout, parentLayoutId, localeNamesMap,
666: localeTitlesMap, description, type, hidden,
667: friendlyURL);
668:
669: if (type.equals(LayoutImpl.TYPE_PORTLET)) {
670: LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) layout
671: .getLayoutType();
672:
673: if (Validator.isNull(layoutTypePortlet
674: .getLayoutTemplateId())) {
675:
676: layoutTypePortlet.setLayoutTemplateId(0,
677: PropsValues.LAYOUT_DEFAULT_TEMPLATE_ID,
678: false);
679:
680: LayoutServiceUtil.updateLayout(layout
681: .getGroupId(),
682: layout.isPrivateLayout(), layout
683: .getLayoutId(), layout
684: .getTypeSettings());
685: }
686: }
687: }
688: } else {
689:
690: // Update layout
691:
692: Layout layout = LayoutLocalServiceUtil.getLayout(groupId,
693: privateLayout, layoutId);
694:
695: layout = LayoutServiceUtil.updateLayout(groupId,
696: privateLayout, layoutId,
697: layout.getParentLayoutId(), localeNamesMap,
698: localeTitlesMap, description, type, hidden,
699: friendlyURL, Boolean.valueOf(iconImage), iconBytes);
700:
701: if (type.equals(LayoutImpl.TYPE_PORTLET)) {
702: if ((copyLayoutId > 0)
703: && (copyLayoutId != layout.getLayoutId())) {
704:
705: try {
706: Layout copyLayout = LayoutLocalServiceUtil
707: .getLayout(groupId, privateLayout,
708: copyLayoutId);
709:
710: if (copyLayout.getType().equals(
711: LayoutImpl.TYPE_PORTLET)) {
712:
713: LayoutServiceUtil.updateLayout(groupId,
714: privateLayout, layoutId, copyLayout
715: .getTypeSettings());
716:
717: copyPreferences(req, layout, copyLayout);
718: }
719: } catch (NoSuchLayoutException nsle) {
720: }
721: } else {
722: Properties formProperties = pageForm
723: .getTypeSettingsProperties();
724:
725: Properties layoutProperties = layout
726: .getTypeSettingsProperties();
727:
728: layoutProperties.setProperty("meta-robots",
729: formProperties.getProperty("meta-robots"));
730: layoutProperties.setProperty("meta-description",
731: formProperties
732: .getProperty("meta-description"));
733: layoutProperties
734: .setProperty(
735: "meta-keywords",
736: formProperties
737: .getProperty("meta-keywords"));
738:
739: layoutProperties.setProperty("javascript-1",
740: formProperties.getProperty("javascript-1"));
741: layoutProperties.setProperty("javascript-2",
742: formProperties.getProperty("javascript-2"));
743: layoutProperties.setProperty("javascript-3",
744: formProperties.getProperty("javascript-3"));
745: layoutProperties.setProperty("sitemap-include",
746: formProperties
747: .getProperty("sitemap-include"));
748: layoutProperties.setProperty("sitemap-priority",
749: formProperties
750: .getProperty("sitemap-priority"));
751: layoutProperties.setProperty("sitemap-changefreq",
752: formProperties
753: .getProperty("sitemap-changefreq"));
754:
755: LayoutServiceUtil.updateLayout(groupId,
756: privateLayout, layoutId, layout
757: .getTypeSettings());
758: }
759: } else {
760: layout.setTypeSettingsProperties(pageForm
761: .getTypeSettingsProperties());
762:
763: LayoutServiceUtil.updateLayout(groupId, privateLayout,
764: layoutId, layout.getTypeSettings());
765: }
766:
767: HttpServletResponse httpRes = (HttpServletResponse) ((ActionResponseImpl) res)
768: .getHttpServletResponse();
769:
770: String[] eventClasses = StringUtil
771: .split(PropsUtil
772: .getComponentProperties()
773: .getString(
774: PropsUtil.LAYOUT_CONFIGURATION_ACTION_UPDATE,
775: Filter.by(type)));
776:
777: EventsProcessor.process(eventClasses, uploadReq, httpRes);
778: }
779: }
780:
781: protected void updateLogo(ActionRequest req) throws Exception {
782: UploadPortletRequest uploadReq = PortalUtil
783: .getUploadPortletRequest(req);
784:
785: long groupId = ParamUtil.getLong(req, "groupId");
786: boolean privateLayout = ParamUtil.getBoolean(req,
787: "privateLayout");
788: boolean logo = ParamUtil.getBoolean(req, "logo");
789:
790: File file = uploadReq.getFile("logoFileName");
791: byte[] bytes = FileUtil.getBytes(file);
792:
793: if (logo && ((bytes == null) || (bytes.length == 0))) {
794: throw new UploadException();
795: }
796:
797: LayoutSetServiceUtil.updateLogo(groupId, privateLayout, logo,
798: file);
799: }
800:
801: protected void updateLookAndFeel(ActionRequest req)
802: throws Exception {
803: long companyId = PortalUtil.getCompanyId(req);
804:
805: long groupId = ParamUtil.getLong(req, "groupId");
806: boolean privateLayout = ParamUtil.getBoolean(req,
807: "privateLayout");
808: long layoutId = ParamUtil.getLong(req, "layoutId");
809: String themeId = ParamUtil.getString(req, "themeId");
810: String colorSchemeId = ParamUtil
811: .getString(req, "colorSchemeId");
812: String css = ParamUtil.getString(req, "css");
813: boolean wapTheme = ParamUtil.getBoolean(req, "wapTheme");
814:
815: if (Validator.isNotNull(themeId)
816: && Validator.isNull(colorSchemeId)) {
817: ColorScheme colorScheme = ThemeLocalUtil.getColorScheme(
818: companyId, themeId, colorSchemeId, wapTheme);
819:
820: colorSchemeId = colorScheme.getColorSchemeId();
821: }
822:
823: if (layoutId <= 0) {
824:
825: // Update layout set
826:
827: LayoutSetServiceUtil.updateLookAndFeel(groupId,
828: privateLayout, themeId, colorSchemeId, css,
829: wapTheme);
830: } else {
831:
832: // Update layout
833:
834: LayoutServiceUtil.updateLookAndFeel(groupId, privateLayout,
835: layoutId, themeId, colorSchemeId, css, wapTheme);
836: }
837: }
838:
839: protected void updateMergePages(ActionRequest req) throws Exception {
840: long groupId = ParamUtil.getLong(req, "groupId");
841:
842: Group group = GroupLocalServiceUtil.getGroup(groupId);
843:
844: boolean mergeGuestPublicPages = ParamUtil.getBoolean(req,
845: "mergeGuestPublicPages");
846:
847: Properties props = group.getTypeSettingsProperties();
848:
849: props.setProperty("mergeGuestPublicPages", String
850: .valueOf(mergeGuestPublicPages));
851:
852: GroupServiceUtil.updateGroup(groupId, group.getTypeSettings());
853: }
854:
855: protected void updateMonitoring(ActionRequest req) throws Exception {
856: long groupId = ParamUtil.getLong(req, "groupId");
857:
858: Group group = GroupLocalServiceUtil.getGroup(groupId);
859:
860: String googleAnalyticsId = ParamUtil.getString(req,
861: "googleAnalyticsId");
862:
863: Properties props = group.getTypeSettingsProperties();
864:
865: props.setProperty("googleAnalyticsId", googleAnalyticsId);
866:
867: GroupServiceUtil.updateGroup(groupId, group.getTypeSettings());
868: }
869:
870: protected void updateStagingState(ActionRequest req)
871: throws Exception {
872: long liveGroupId = ParamUtil.getLong(req, "liveGroupId");
873: long stagingGroupId = ParamUtil.getLong(req, "stagingGroupId");
874: boolean activateStaging = ParamUtil.getBoolean(req,
875: "activateStaging");
876:
877: if ((stagingGroupId > 0) && !activateStaging) {
878: GroupServiceUtil.deleteGroup(stagingGroupId);
879: } else if ((stagingGroupId == 0) && activateStaging) {
880: Group group = GroupServiceUtil.getGroup(liveGroupId);
881:
882: Group stagingGroup = GroupServiceUtil.addGroup(group
883: .getGroupId(), group.getName() + " (Staging)",
884: group.getDescription(),
885: GroupImpl.TYPE_COMMUNITY_PRIVATE, null, group
886: .isActive());
887:
888: if (group.hasPrivateLayouts()) {
889: copyLayouts(group.getGroupId(), stagingGroup
890: .getGroupId(), true);
891: }
892:
893: if (group.hasPublicLayouts()) {
894: copyLayouts(group.getGroupId(), stagingGroup
895: .getGroupId(), false);
896: }
897: }
898: }
899:
900: protected void updateVirtualHost(ActionRequest req)
901: throws Exception {
902:
903: // Public virtual host
904:
905: long groupId = ParamUtil.getLong(req, "groupId");
906:
907: String publicVirtualHost = ParamUtil.getString(req,
908: "publicVirtualHost");
909:
910: LayoutSetServiceUtil.updateVirtualHost(groupId, false,
911: publicVirtualHost);
912:
913: // Private virtual host
914:
915: String privateVirtualHost = ParamUtil.getString(req,
916: "privateVirtualHost");
917:
918: LayoutSetServiceUtil.updateVirtualHost(groupId, true,
919: privateVirtualHost);
920:
921: // Friendly URL
922:
923: String friendlyURL = ParamUtil.getString(req, "friendlyURL");
924:
925: Group group = GroupLocalServiceUtil.getGroup(groupId);
926:
927: GroupServiceUtil.updateGroup(groupId, group.getName(), group
928: .getDescription(), group.getType(), friendlyURL, group
929: .isActive());
930: }
931:
932: private static Log _log = LogFactory.getLog(EditPagesAction.class);
933:
934: }
|