001
014
015 package com.liferay.portal.events;
016
017 import com.liferay.portal.LayoutPermissionException;
018 import com.liferay.portal.NoSuchGroupException;
019 import com.liferay.portal.NoSuchLayoutException;
020 import com.liferay.portal.NoSuchUserException;
021 import com.liferay.portal.kernel.dao.orm.QueryUtil;
022 import com.liferay.portal.kernel.events.Action;
023 import com.liferay.portal.kernel.events.ActionException;
024 import com.liferay.portal.kernel.exception.PortalException;
025 import com.liferay.portal.kernel.exception.SystemException;
026 import com.liferay.portal.kernel.image.ImageToolUtil;
027 import com.liferay.portal.kernel.lar.PortletDataHandlerKeys;
028 import com.liferay.portal.kernel.log.Log;
029 import com.liferay.portal.kernel.log.LogFactoryUtil;
030 import com.liferay.portal.kernel.portlet.LiferayPortletURL;
031 import com.liferay.portal.kernel.portlet.LiferayWindowState;
032 import com.liferay.portal.kernel.servlet.BrowserSnifferUtil;
033 import com.liferay.portal.kernel.servlet.HttpHeaders;
034 import com.liferay.portal.kernel.servlet.SessionErrors;
035 import com.liferay.portal.kernel.util.ColorSchemeFactoryUtil;
036 import com.liferay.portal.kernel.util.CookieKeys;
037 import com.liferay.portal.kernel.util.FriendlyURLNormalizerUtil;
038 import com.liferay.portal.kernel.util.GetterUtil;
039 import com.liferay.portal.kernel.util.HttpUtil;
040 import com.liferay.portal.kernel.util.LocaleUtil;
041 import com.liferay.portal.kernel.util.ParamUtil;
042 import com.liferay.portal.kernel.util.PropsKeys;
043 import com.liferay.portal.kernel.util.ServerDetector;
044 import com.liferay.portal.kernel.util.SessionParamUtil;
045 import com.liferay.portal.kernel.util.StringBundler;
046 import com.liferay.portal.kernel.util.StringPool;
047 import com.liferay.portal.kernel.util.StringUtil;
048 import com.liferay.portal.kernel.util.UnicodeProperties;
049 import com.liferay.portal.kernel.util.Validator;
050 import com.liferay.portal.model.ColorScheme;
051 import com.liferay.portal.model.Company;
052 import com.liferay.portal.model.Group;
053 import com.liferay.portal.model.GroupConstants;
054 import com.liferay.portal.model.Image;
055 import com.liferay.portal.model.Layout;
056 import com.liferay.portal.model.LayoutConstants;
057 import com.liferay.portal.model.LayoutSet;
058 import com.liferay.portal.model.LayoutTemplate;
059 import com.liferay.portal.model.LayoutTypePortlet;
060 import com.liferay.portal.model.LayoutTypePortletConstants;
061 import com.liferay.portal.model.Portlet;
062 import com.liferay.portal.model.RoleConstants;
063 import com.liferay.portal.model.Theme;
064 import com.liferay.portal.model.User;
065 import com.liferay.portal.model.impl.VirtualLayout;
066 import com.liferay.portal.security.auth.PrincipalException;
067 import com.liferay.portal.security.permission.ActionKeys;
068 import com.liferay.portal.security.permission.PermissionChecker;
069 import com.liferay.portal.security.permission.PermissionCheckerFactoryUtil;
070 import com.liferay.portal.security.permission.PermissionThreadLocal;
071 import com.liferay.portal.service.GroupLocalServiceUtil;
072 import com.liferay.portal.service.ImageLocalServiceUtil;
073 import com.liferay.portal.service.LayoutLocalServiceUtil;
074 import com.liferay.portal.service.LayoutSetLocalServiceUtil;
075 import com.liferay.portal.service.PortletLocalServiceUtil;
076 import com.liferay.portal.service.RoleLocalServiceUtil;
077 import com.liferay.portal.service.ServiceContext;
078 import com.liferay.portal.service.ServiceContextFactory;
079 import com.liferay.portal.service.ServiceContextThreadLocal;
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.PortalPermissionUtil;
085 import com.liferay.portal.service.permission.PortletPermissionUtil;
086 import com.liferay.portal.theme.ThemeDisplay;
087 import com.liferay.portal.theme.ThemeDisplayFactory;
088 import com.liferay.portal.util.LayoutClone;
089 import com.liferay.portal.util.LayoutCloneFactory;
090 import com.liferay.portal.util.PortalUtil;
091 import com.liferay.portal.util.PortletCategoryKeys;
092 import com.liferay.portal.util.PortletKeys;
093 import com.liferay.portal.util.PrefsPropsUtil;
094 import com.liferay.portal.util.PropsUtil;
095 import com.liferay.portal.util.PropsValues;
096 import com.liferay.portal.util.WebKeys;
097 import com.liferay.portal.webserver.WebServerServletTokenUtil;
098 import com.liferay.portlet.PortalPreferences;
099 import com.liferay.portlet.PortletPreferencesFactoryUtil;
100 import com.liferay.portlet.PortletURLImpl;
101 import com.liferay.portlet.asset.model.AssetEntry;
102 import com.liferay.portlet.asset.service.AssetEntryLocalServiceUtil;
103 import com.liferay.portlet.journal.NoSuchArticleException;
104 import com.liferay.portlet.journal.model.JournalArticle;
105 import com.liferay.portlet.journal.service.JournalArticleServiceUtil;
106 import com.liferay.portlet.sites.util.SitesUtil;
107
108 import java.io.File;
109
110 import java.util.ArrayList;
111 import java.util.HashMap;
112 import java.util.LinkedHashMap;
113 import java.util.List;
114 import java.util.Locale;
115 import java.util.Map;
116 import java.util.TimeZone;
117
118 import javax.portlet.PortletMode;
119 import javax.portlet.PortletRequest;
120 import javax.portlet.PortletURL;
121 import javax.portlet.WindowState;
122
123 import javax.servlet.http.HttpServletRequest;
124 import javax.servlet.http.HttpServletResponse;
125 import javax.servlet.http.HttpSession;
126
127 import org.apache.commons.lang.time.StopWatch;
128
129
134 public class ServicePreAction extends Action {
135
136 public ServicePreAction() {
137 initImportLARFiles();
138 }
139
140 public ThemeDisplay initThemeDisplay(
141 HttpServletRequest request, HttpServletResponse response)
142 throws Exception {
143
144 HttpSession session = request.getSession();
145
146
147
148 Company company = PortalUtil.getCompany(request);
149
150 long companyId = company.getCompanyId();
151
152
153
154 String cdnHost = PortalUtil.getCDNHost(request);
155
156 String dynamicResourcesCDNHost = StringPool.BLANK;
157
158 boolean cdnDynamicResourceEnabled =
159 PortalUtil.isCDNDynamicResourcesEnabled(request);
160
161 if (cdnDynamicResourceEnabled) {
162 dynamicResourcesCDNHost = cdnHost;
163 }
164
165
166
167 String portalURL = PortalUtil.getPortalURL(request);
168
169
170
171 String contextPath = PortalUtil.getPathContext();
172 String friendlyURLPrivateGroupPath =
173 PortalUtil.getPathFriendlyURLPrivateGroup();
174 String friendlyURLPrivateUserPath =
175 PortalUtil.getPathFriendlyURLPrivateUser();
176 String friendlyURLPublicPath = PortalUtil.getPathFriendlyURLPublic();
177 String imagePath = dynamicResourcesCDNHost.concat(
178 PortalUtil.getPathImage());
179 String mainPath = PortalUtil.getPathMain();
180
181 String i18nPath = (String)request.getAttribute(WebKeys.I18N_PATH);
182
183 if (Validator.isNotNull(i18nPath)) {
184 if (Validator.isNotNull(contextPath)) {
185 String i18nContextPath = contextPath.concat(i18nPath);
186
187 friendlyURLPrivateGroupPath = StringUtil.replaceFirst(
188 friendlyURLPrivateGroupPath, contextPath, i18nContextPath);
189 friendlyURLPrivateUserPath = StringUtil.replaceFirst(
190 friendlyURLPrivateUserPath, contextPath, i18nContextPath);
191 friendlyURLPublicPath = StringUtil.replaceFirst(
192 friendlyURLPublicPath, contextPath, i18nContextPath);
193 mainPath = StringUtil.replaceFirst(
194 mainPath, contextPath, i18nContextPath);
195 }
196 else {
197 friendlyURLPrivateGroupPath = i18nPath.concat(
198 friendlyURLPrivateGroupPath);
199 friendlyURLPrivateUserPath = i18nPath.concat(
200 friendlyURLPrivateUserPath);
201 friendlyURLPublicPath = i18nPath.concat(friendlyURLPublicPath);
202 mainPath = i18nPath.concat(mainPath);
203 }
204 }
205
206
207
208 StringBundler sb = new StringBundler(5);
209
210 sb.append(imagePath);
211 sb.append("/company_logo?img_id=");
212 sb.append(company.getLogoId());
213 sb.append("&t=");
214 sb.append(WebServerServletTokenUtil.getToken(company.getLogoId()));
215
216 String companyLogo = sb.toString();
217
218 int companyLogoHeight = 0;
219 int companyLogoWidth = 0;
220
221 Image companyLogoImage = null;
222
223 if (company.getLogoId() > 0) {
224 companyLogoImage = ImageLocalServiceUtil.getCompanyLogo(
225 company.getLogoId());
226 }
227 else {
228 companyLogoImage = ImageToolUtil.getDefaultCompanyLogo();
229 }
230
231 if (companyLogoImage != null) {
232 companyLogoHeight = companyLogoImage.getHeight();
233 companyLogoWidth = companyLogoImage.getWidth();
234 }
235
236 String realCompanyLogo = companyLogo;
237 int realCompanyLogoHeight = companyLogoHeight;
238 int realCompanyLogoWidth = companyLogoWidth;
239
240
241
242 User user = null;
243
244 try {
245 user = PortalUtil.initUser(request);
246 }
247 catch (NoSuchUserException nsue) {
248 return null;
249 }
250
251 boolean signedIn = !user.isDefaultUser();
252
253 if (PropsValues.BROWSER_CACHE_DISABLED ||
254 (PropsValues.BROWSER_CACHE_SIGNED_IN_DISABLED && signedIn)) {
255
256 response.setDateHeader(HttpHeaders.EXPIRES, 0);
257 response.setHeader(
258 HttpHeaders.CACHE_CONTROL,
259 HttpHeaders.CACHE_CONTROL_NO_CACHE_VALUE);
260 response.setHeader(
261 HttpHeaders.PRAGMA, HttpHeaders.PRAGMA_NO_CACHE_VALUE);
262 }
263
264 User realUser = user;
265
266 Long realUserId = (Long)session.getAttribute(WebKeys.USER_ID);
267
268 if (realUserId != null) {
269 if (user.getUserId() != realUserId.longValue()) {
270 realUser = UserLocalServiceUtil.getUserById(
271 realUserId.longValue());
272 }
273 }
274
275 String doAsUserId = ParamUtil.getString(request, "doAsUserId");
276 String doAsUserLanguageId = ParamUtil.getString(
277 request, "doAsUserLanguageId");
278 long doAsGroupId = ParamUtil.getLong(request, "doAsGroupId");
279
280 long refererGroupId = ParamUtil.getLong(request, "refererGroupId");
281
282 long refererPlid = ParamUtil.getLong(request, "refererPlid");
283
284 if (LayoutLocalServiceUtil.fetchLayout(refererPlid) == null) {
285 refererPlid = 0;
286 }
287
288 String controlPanelCategory = ParamUtil.getString(
289 request, "controlPanelCategory");
290
291
292
293 PermissionChecker permissionChecker =
294 PermissionCheckerFactoryUtil.create(user);
295
296 PermissionThreadLocal.setPermissionChecker(permissionChecker);
297
298
299
300 try {
301
302
303
304 CookieKeys.validateSupportCookie(request);
305 }
306 catch (Exception e) {
307 CookieKeys.addSupportCookie(request, response);
308 }
309
310
311
312 TimeZone timeZone = user.getTimeZone();
313
314 if (timeZone == null) {
315 timeZone = company.getTimeZone();
316 }
317
318
319
320 if (signedIn) {
321 updateUserLayouts(user);
322 }
323
324 Layout layout = null;
325 List<Layout> layouts = null;
326
327 long plid = ParamUtil.getLong(request, "p_l_id");
328
329 boolean viewableSourceGroup = true;
330
331 if (plid > 0) {
332 layout = LayoutLocalServiceUtil.getLayout(plid);
333
334 long sourceGroupId = ParamUtil.getLong(request, "p_v_l_s_g_id");
335
336 if ((sourceGroupId > 0) && (sourceGroupId != layout.getGroupId())) {
337 Group sourceGroup = GroupLocalServiceUtil.getGroup(
338 sourceGroupId);
339
340 if (layout.isPublicLayout() ||
341 SitesUtil.isUserGroupLayoutSetViewable(
342 permissionChecker, layout.getGroup())) {
343
344 layout = new VirtualLayout(layout, sourceGroup);
345 }
346 else {
347 viewableSourceGroup = false;
348 }
349 }
350 }
351 else {
352 long groupId = ParamUtil.getLong(request, "groupId");
353 boolean privateLayout = ParamUtil.getBoolean(
354 request, "privateLayout");
355 long layoutId = ParamUtil.getLong(request, "layoutId");
356
357 if ((groupId > 0) && (layoutId > 0)) {
358 layout = LayoutLocalServiceUtil.getLayout(
359 groupId, privateLayout, layoutId);
360 }
361 }
362
363 String ppid = ParamUtil.getString(request, "p_p_id");
364
365 Boolean redirectToDefaultLayout = (Boolean)request.getAttribute(
366 WebKeys.REDIRECT_TO_DEFAULT_LAYOUT);
367
368 if (redirectToDefaultLayout == null) {
369 redirectToDefaultLayout = Boolean.FALSE;
370 }
371
372 if (layout != null) {
373 Group group = layout.getGroup();
374
375 if (!signedIn && PropsValues.AUTH_FORWARD_BY_REDIRECT) {
376 request.setAttribute(WebKeys.REQUESTED_LAYOUT, layout);
377 }
378
379 if ((Validator.isNull(controlPanelCategory) ||
380 controlPanelCategory.equals(PortletCategoryKeys.MY) ||
381 controlPanelCategory.equals(PortletCategoryKeys.PORTLET)) &&
382 Validator.isNotNull(ppid) &&
383 (LiferayWindowState.isPopUp(request) ||
384 LiferayWindowState.isExclusive(request))) {
385
386 controlPanelCategory = PortletCategoryKeys.PORTLET;
387 }
388 else if (Validator.isNotNull(ppid)) {
389 Portlet portlet = PortletLocalServiceUtil.getPortletById(
390 companyId, ppid);
391
392 String portletControlPanelEntryCategory =
393 portlet.getControlPanelEntryCategory();
394
395 if (!controlPanelCategory.startsWith(
396 PortletCategoryKeys.CURRENT_SITE) &&
397 portletControlPanelEntryCategory.startsWith(
398 PortletCategoryKeys.SITE_ADMINISTRATION)) {
399
400 portletControlPanelEntryCategory =
401 PortletCategoryKeys.SITES;
402 }
403
404 if (!controlPanelCategory.startsWith(
405 PortletCategoryKeys.CURRENT_SITE) &&
406 Validator.isNotNull(portletControlPanelEntryCategory)) {
407
408 controlPanelCategory = portletControlPanelEntryCategory;
409 }
410 }
411
412 boolean viewableGroup = hasAccessPermission(
413 permissionChecker, layout, doAsGroupId, controlPanelCategory,
414 true);
415 boolean viewableStaging =
416 !group.isControlPanel() &&
417 GroupPermissionUtil.contains(
418 permissionChecker, group.getGroupId(),
419 ActionKeys.VIEW_STAGING);
420
421 if (viewableStaging) {
422 layouts = LayoutLocalServiceUtil.getLayouts(
423 layout.getGroupId(), layout.isPrivateLayout(),
424 LayoutConstants.DEFAULT_PARENT_LAYOUT_ID);
425 }
426 else if ((!viewableGroup || !viewableSourceGroup) &&
427 group.isStagingGroup()) {
428
429 layout = null;
430 }
431 else if (!isLoginRequest(request) &&
432 ((!viewableGroup || !viewableSourceGroup) ||
433 (!redirectToDefaultLayout &&
434 !hasAccessPermission(
435 permissionChecker, layout, doAsGroupId,
436 controlPanelCategory, false)))) {
437
438 if (user.isDefaultUser() &&
439 PropsValues.AUTH_LOGIN_PROMPT_ENABLED) {
440
441 throw new PrincipalException("User is not authenticated");
442 }
443
444 sb = new StringBundler(6);
445
446 sb.append("User ");
447 sb.append(user.getUserId());
448 sb.append(" is not allowed to access the ");
449 sb.append(layout.isPrivateLayout() ? "private": "public");
450 sb.append(" pages of group ");
451 sb.append(layout.getGroupId());
452
453 if (_log.isWarnEnabled()) {
454 _log.warn(sb.toString());
455 }
456
457 throw new NoSuchLayoutException(sb.toString());
458 }
459 else if (isLoginRequest(request) && !viewableGroup) {
460 layout = null;
461 }
462 else if (group.isLayoutPrototype()) {
463 layouts = new ArrayList<Layout>();
464 }
465 else {
466 layouts = LayoutLocalServiceUtil.getLayouts(
467 layout.getGroupId(), layout.isPrivateLayout(),
468 LayoutConstants.DEFAULT_PARENT_LAYOUT_ID);
469
470 if (!group.isControlPanel()) {
471 doAsGroupId = 0;
472 }
473 }
474 }
475
476 List<Layout> unfilteredLayouts = layouts;
477
478 if (layout == null) {
479 Object[] defaultLayout = getDefaultLayout(request, user, signedIn);
480
481 layout = (Layout)defaultLayout[0];
482 layouts = (List<Layout>)defaultLayout[1];
483
484 request.setAttribute(WebKeys.LAYOUT_DEFAULT, Boolean.TRUE);
485 }
486
487 Object[] viewableLayouts = getViewableLayouts(
488 request, user, permissionChecker, layout, layouts, doAsGroupId,
489 controlPanelCategory);
490
491 String layoutSetLogo = null;
492
493 layout = (Layout)viewableLayouts[0];
494 layouts = (List<Layout>)viewableLayouts[1];
495
496 Group group = null;
497
498 if (layout != null) {
499 group = layout.getGroup();
500
501 if (!group.isControlPanel()) {
502 rememberVisitedGroupIds(request, group.getGroupId());
503 }
504 }
505
506 LayoutTypePortlet layoutTypePortlet = null;
507
508 layouts = mergeAdditionalLayouts(
509 request, user, permissionChecker, layout, layouts, doAsGroupId,
510 controlPanelCategory);
511
512 LayoutSet layoutSet = null;
513
514 boolean hasCustomizeLayoutPermission = false;
515 boolean hasDeleteLayoutPermission = false;
516 boolean hasUpdateLayoutPermission = false;
517
518 boolean customizedView = SessionParamUtil.getBoolean(
519 request, "customized_view", true);
520
521 if (layout != null) {
522 if (!layout.isTypeControlPanel()) {
523 hasCustomizeLayoutPermission = LayoutPermissionUtil.contains(
524 permissionChecker, layout, ActionKeys.CUSTOMIZE);
525 hasDeleteLayoutPermission = LayoutPermissionUtil.contains(
526 permissionChecker, layout, ActionKeys.DELETE);
527 hasUpdateLayoutPermission = LayoutPermissionUtil.contains(
528 permissionChecker, layout, ActionKeys.UPDATE);
529 }
530
531 layoutSet = layout.getLayoutSet();
532
533 if (company.isSiteLogo()) {
534 long logoId = 0;
535
536 if (layoutSet.isLogo()) {
537 logoId = layoutSet.getLogoId();
538
539 if (logoId == 0) {
540 logoId = layoutSet.getLiveLogoId();
541 }
542 }
543 else {
544 LayoutSet siblingLayoutSet =
545 LayoutSetLocalServiceUtil.getLayoutSet(
546 layout.getGroupId(), !layout.isPrivateLayout());
547
548 if (siblingLayoutSet.isLogo()) {
549 logoId = siblingLayoutSet.getLogoId();
550 }
551 }
552
553 if (logoId > 0) {
554 sb = new StringBundler(5);
555
556 sb.append(imagePath);
557 sb.append("/layout_set_logo?img_id=");
558 sb.append(logoId);
559 sb.append("&t=");
560 sb.append(WebServerServletTokenUtil.getToken(logoId));
561
562 layoutSetLogo = sb.toString();
563
564 Image layoutSetLogoImage =
565 ImageLocalServiceUtil.getCompanyLogo(logoId);
566
567 companyLogo = layoutSetLogo;
568 companyLogoHeight = layoutSetLogoImage.getHeight();
569 companyLogoWidth = layoutSetLogoImage.getWidth();
570 }
571 }
572
573 plid = layout.getPlid();
574
575
576
577
578 layout = (Layout)layout.clone();
579
580 layoutTypePortlet = (LayoutTypePortlet)layout.getLayoutType();
581
582 boolean customizable = layoutTypePortlet.isCustomizable();
583
584 if (!customizable ||
585 group.isLayoutPrototype() || group.isLayoutSetPrototype() ||
586 group.isStagingGroup()) {
587
588 customizedView = false;
589 }
590
591 layoutTypePortlet.setCustomizedView(customizedView);
592 layoutTypePortlet.setUpdatePermission(hasUpdateLayoutPermission);
593
594 if (signedIn && customizable && customizedView &&
595 hasCustomizeLayoutPermission) {
596
597 PortalPreferences portalPreferences =
598 PortletPreferencesFactoryUtil.getPortalPreferences(
599 user.getUserId(), true);
600
601 layoutTypePortlet.setPortalPreferences(portalPreferences);
602 }
603
604 LayoutClone layoutClone = LayoutCloneFactory.getInstance();
605
606 if (layoutClone != null) {
607 String typeSettings = layoutClone.get(request, plid);
608
609 if (typeSettings != null) {
610 UnicodeProperties typeSettingsProperties =
611 new UnicodeProperties(true);
612
613 typeSettingsProperties.load(typeSettings);
614
615 String stateMax = typeSettingsProperties.getProperty(
616 LayoutTypePortletConstants.STATE_MAX);
617 String stateMin = typeSettingsProperties.getProperty(
618 LayoutTypePortletConstants.STATE_MIN);
619 String modeAbout = typeSettingsProperties.getProperty(
620 LayoutTypePortletConstants.MODE_ABOUT);
621 String modeConfig = typeSettingsProperties.getProperty(
622 LayoutTypePortletConstants.MODE_CONFIG);
623 String modeEdit = typeSettingsProperties.getProperty(
624 LayoutTypePortletConstants.MODE_EDIT);
625 String modeEditDefaults =
626 typeSettingsProperties.getProperty(
627 LayoutTypePortletConstants.MODE_EDIT_DEFAULTS);
628 String modeEditGuest = typeSettingsProperties.getProperty(
629 LayoutTypePortletConstants.MODE_EDIT_GUEST);
630 String modeHelp = typeSettingsProperties.getProperty(
631 LayoutTypePortletConstants.MODE_HELP);
632 String modePreview = typeSettingsProperties.getProperty(
633 LayoutTypePortletConstants.MODE_PREVIEW);
634 String modePrint = typeSettingsProperties.getProperty(
635 LayoutTypePortletConstants.MODE_PRINT);
636
637 layoutTypePortlet.setStateMax(stateMax);
638 layoutTypePortlet.setStateMin(stateMin);
639 layoutTypePortlet.setModeAbout(modeAbout);
640 layoutTypePortlet.setModeConfig(modeConfig);
641 layoutTypePortlet.setModeEdit(modeEdit);
642 layoutTypePortlet.setModeEditDefaults(modeEditDefaults);
643 layoutTypePortlet.setModeEditGuest(modeEditGuest);
644 layoutTypePortlet.setModeHelp(modeHelp);
645 layoutTypePortlet.setModePreview(modePreview);
646 layoutTypePortlet.setModePrint(modePrint);
647 }
648 }
649
650 request.setAttribute(WebKeys.LAYOUT, layout);
651 request.setAttribute(WebKeys.LAYOUTS, layouts);
652 }
653
654
655
656 String i18nLanguageId = (String)request.getAttribute(
657 WebKeys.I18N_LANGUAGE_ID);
658
659 Locale locale = PortalUtil.getLocale(request, response, true);
660
661
662
663 long scopeGroupId = PortalUtil.getScopeGroupId(request);
664
665 if ((scopeGroupId <= 0) && (doAsGroupId > 0)) {
666 scopeGroupId = doAsGroupId;
667 }
668
669 long siteGroupId = 0;
670
671 if (layout != null) {
672 if (layout.isTypeControlPanel()) {
673 siteGroupId = PortalUtil.getSiteGroupId(scopeGroupId);
674 }
675 else {
676 siteGroupId = PortalUtil.getSiteGroupId(layout.getGroupId());
677 }
678 }
679
680
681
682 Theme theme = null;
683 ColorScheme colorScheme = null;
684
685 boolean wapTheme = BrowserSnifferUtil.isWap(request);
686
687 if ((layout != null) && group.isControlPanel()) {
688 String themeId = PrefsPropsUtil.getString(
689 companyId, PropsKeys.CONTROL_PANEL_LAYOUT_REGULAR_THEME_ID);
690 String colorSchemeId =
691 ColorSchemeFactoryUtil.getDefaultRegularColorSchemeId();
692
693 theme = ThemeLocalServiceUtil.getTheme(
694 companyId, themeId, wapTheme);
695 colorScheme = ThemeLocalServiceUtil.getColorScheme(
696 companyId, theme.getThemeId(), colorSchemeId, wapTheme);
697
698 if (!wapTheme && theme.isWapTheme()) {
699 theme = ThemeLocalServiceUtil.getTheme(
700 companyId,
701 PropsValues.CONTROL_PANEL_LAYOUT_REGULAR_THEME_ID, false);
702 colorScheme = ThemeLocalServiceUtil.getColorScheme(
703 companyId, theme.getThemeId(), colorSchemeId, false);
704 }
705
706 request.setAttribute(WebKeys.THEME, theme);
707 request.setAttribute(WebKeys.COLOR_SCHEME, colorScheme);
708 }
709
710 boolean themeCssFastLoad = SessionParamUtil.getBoolean(
711 request, "css_fast_load", PropsValues.THEME_CSS_FAST_LOAD);
712 boolean themeImagesFastLoad = SessionParamUtil.getBoolean(
713 request, "images_fast_load", PropsValues.THEME_IMAGES_FAST_LOAD);
714
715 boolean themeJsBarebone = PropsValues.JAVASCRIPT_BAREBONE_ENABLED;
716
717 if (themeJsBarebone) {
718 if (signedIn) {
719 themeJsBarebone = false;
720 }
721 }
722
723 boolean themeJsFastLoad = SessionParamUtil.getBoolean(
724 request, "js_fast_load", PropsValues.JAVASCRIPT_FAST_LOAD);
725
726 String lifecycle = ParamUtil.getString(request, "p_p_lifecycle", "0");
727
728 lifecycle = ParamUtil.getString(request, "p_t_lifecycle", lifecycle);
729
730 boolean isolated = ParamUtil.getBoolean(request, "p_p_isolated");
731
732 String facebookCanvasPageURL = (String)request.getAttribute(
733 WebKeys.FACEBOOK_CANVAS_PAGE_URL);
734
735 boolean widget = false;
736
737 Boolean widgetObj = (Boolean)request.getAttribute(WebKeys.WIDGET);
738
739 if (widgetObj != null) {
740 widget = widgetObj.booleanValue();
741 }
742
743
744
745 ThemeDisplay themeDisplay = ThemeDisplayFactory.create();
746
747 themeDisplay.setRequest(request);
748
749
750
751
752 themeDisplay.setCDNHost(cdnHost);
753 themeDisplay.setCDNDynamicResourcesHost(dynamicResourcesCDNHost);
754 themeDisplay.setFacebookCanvasPageURL(facebookCanvasPageURL);
755 themeDisplay.setPortalURL(portalURL);
756 themeDisplay.setSecure(request.isSecure());
757 themeDisplay.setServerName(request.getServerName());
758 themeDisplay.setServerPort(request.getServerPort());
759 themeDisplay.setWidget(widget);
760
761 themeDisplay.setCompany(company);
762 themeDisplay.setCompanyLogo(companyLogo);
763 themeDisplay.setCompanyLogoHeight(companyLogoHeight);
764 themeDisplay.setCompanyLogoWidth(companyLogoWidth);
765 themeDisplay.setControlPanelCategory(controlPanelCategory);
766 themeDisplay.setDoAsGroupId(doAsGroupId);
767 themeDisplay.setDoAsUserId(doAsUserId);
768 themeDisplay.setDoAsUserLanguageId(doAsUserLanguageId);
769 themeDisplay.setI18nLanguageId(i18nLanguageId);
770 themeDisplay.setI18nPath(i18nPath);
771 themeDisplay.setIsolated(isolated);
772 themeDisplay.setLanguageId(LocaleUtil.toLanguageId(locale));
773 themeDisplay.setLayout(layout);
774 themeDisplay.setLayouts(layouts);
775 themeDisplay.setLayoutSet(layoutSet);
776 themeDisplay.setLayoutSetLogo(layoutSetLogo);
777 themeDisplay.setLayoutTypePortlet(layoutTypePortlet);
778 themeDisplay.setLifecycle(lifecycle);
779 themeDisplay.setLifecycleAction(lifecycle.equals("1"));
780 themeDisplay.setLifecycleEvent(lifecycle.equals("3"));
781 themeDisplay.setLifecycleRender(lifecycle.equals("0"));
782 themeDisplay.setLifecycleResource(lifecycle.equals("2"));
783 themeDisplay.setLocale(locale);
784 themeDisplay.setLookAndFeel(theme, colorScheme);
785 themeDisplay.setPathApplet(contextPath.concat("/applets"));
786 themeDisplay.setPathCms(contextPath.concat("/cms"));
787 themeDisplay.setPathContext(contextPath);
788 themeDisplay.setPathFlash(contextPath.concat("/flash"));
789 themeDisplay.setPathFriendlyURLPrivateGroup(
790 friendlyURLPrivateGroupPath);
791 themeDisplay.setPathFriendlyURLPrivateUser(friendlyURLPrivateUserPath);
792 themeDisplay.setPathFriendlyURLPublic(friendlyURLPublicPath);
793 themeDisplay.setPathImage(imagePath);
794 themeDisplay.setPathJavaScript(contextPath.concat("/html/js"));
795 themeDisplay.setPathMain(mainPath);
796 themeDisplay.setPathSound(contextPath.concat("/html/sound"));
797 themeDisplay.setPermissionChecker(permissionChecker);
798 themeDisplay.setPlid(plid);
799 themeDisplay.setPpid(ppid);
800 themeDisplay.setRealCompanyLogo(realCompanyLogo);
801 themeDisplay.setRealCompanyLogoHeight(realCompanyLogoHeight);
802 themeDisplay.setRealCompanyLogoWidth(realCompanyLogoWidth);
803 themeDisplay.setRealUser(realUser);
804 themeDisplay.setRefererGroupId(refererGroupId);
805 themeDisplay.setRefererPlid(refererPlid);
806 themeDisplay.setScopeGroupId(scopeGroupId);
807 themeDisplay.setSignedIn(signedIn);
808 themeDisplay.setSiteDefaultLocale(
809 PortalUtil.getSiteDefaultLocale(siteGroupId));
810 themeDisplay.setSiteGroupId(siteGroupId);
811 themeDisplay.setStateExclusive(LiferayWindowState.isExclusive(request));
812 themeDisplay.setStateMaximized(LiferayWindowState.isMaximized(request));
813 themeDisplay.setStatePopUp(LiferayWindowState.isPopUp(request));
814 themeDisplay.setThemeCssFastLoad(themeCssFastLoad);
815 themeDisplay.setThemeImagesFastLoad(themeImagesFastLoad);
816 themeDisplay.setThemeJsBarebone(themeJsBarebone);
817 themeDisplay.setThemeJsFastLoad(themeJsFastLoad);
818 themeDisplay.setTimeZone(timeZone);
819 themeDisplay.setUnfilteredLayouts(unfilteredLayouts);
820 themeDisplay.setUser(user);
821
822
823
824 themeDisplay.setShowAddContentIcon(false);
825
826 boolean showControlPanelIcon = false;
827
828 if (signedIn &&
829 PortalPermissionUtil.contains(
830 permissionChecker, ActionKeys.VIEW_CONTROL_PANEL)) {
831
832 showControlPanelIcon = true;
833 }
834
835 themeDisplay.setShowControlPanelIcon(showControlPanelIcon);
836
837 themeDisplay.setShowHomeIcon(true);
838 themeDisplay.setShowMyAccountIcon(signedIn);
839 themeDisplay.setShowPageSettingsIcon(hasDeleteLayoutPermission);
840 themeDisplay.setShowPortalIcon(true);
841 themeDisplay.setShowSignInIcon(!signedIn);
842
843 boolean showSignOutIcon = signedIn;
844
845 if (themeDisplay.isImpersonated()) {
846 showSignOutIcon = false;
847 }
848
849 themeDisplay.setShowSignOutIcon(showSignOutIcon);
850
851 themeDisplay.setShowStagingIcon(false);
852
853 boolean showSiteAdministrationIcon = false;
854
855 if (signedIn &&
856 GroupPermissionUtil.contains(
857 permissionChecker, group,
858 ActionKeys.VIEW_SITE_ADMINISTRATION)) {
859
860 showSiteAdministrationIcon = true;
861 }
862
863 themeDisplay.setShowSiteAdministrationIcon(showSiteAdministrationIcon);
864
865
866
867 if (PropsValues.SESSION_ENABLE_URL_WITH_SESSION_ID &&
868 !CookieKeys.hasSessionId(request)) {
869
870 themeDisplay.setAddSessionIdToURL(true);
871 themeDisplay.setSessionId(session.getId());
872 }
873
874
875
876 String urlControlPanel = friendlyURLPrivateGroupPath.concat(
877 GroupConstants.CONTROL_PANEL_FRIENDLY_URL);
878
879 if (Validator.isNotNull(doAsUserId)) {
880 urlControlPanel = HttpUtil.addParameter(
881 urlControlPanel, "doAsUserId", doAsUserId);
882 }
883
884 if (refererGroupId > 0) {
885 urlControlPanel = HttpUtil.addParameter(
886 urlControlPanel, "refererGroupId", refererGroupId);
887 }
888 else if (scopeGroupId > 0) {
889 Layout refererLayout = LayoutLocalServiceUtil.fetchLayout(plid);
890
891 if (refererLayout != null) {
892 Group refererLayoutGroup = refererLayout.getGroup();
893
894 if (refererLayoutGroup.isUserGroup()) {
895 urlControlPanel = HttpUtil.addParameter(
896 urlControlPanel, "refererGroupId", scopeGroupId);
897 }
898 }
899 }
900
901 if (refererPlid > 0) {
902 urlControlPanel = HttpUtil.addParameter(
903 urlControlPanel, "refererPlid", refererPlid);
904 }
905 else if (plid > 0) {
906 urlControlPanel = HttpUtil.addParameter(
907 urlControlPanel, "refererPlid", plid);
908 }
909
910 if (themeDisplay.isAddSessionIdToURL()) {
911 urlControlPanel = PortalUtil.getURLWithSessionId(
912 urlControlPanel, session.getId());
913 }
914
915 themeDisplay.setURLControlPanel(urlControlPanel);
916
917 String currentURL = PortalUtil.getCurrentURL(request);
918
919 themeDisplay.setURLCurrent(currentURL);
920
921 String urlHome = PortalUtil.getHomeURL(request);
922
923 themeDisplay.setURLHome(urlHome);
924
925 String siteAdministrationURL = urlControlPanel;
926
927 siteAdministrationURL = HttpUtil.addParameter(
928 siteAdministrationURL, "controlPanelCategory",
929 PortletCategoryKeys.CURRENT_SITE);
930 siteAdministrationURL = HttpUtil.addParameter(
931 siteAdministrationURL, "doAsGroupId", siteGroupId);
932
933 themeDisplay.setURLSiteAdministration(siteAdministrationURL);
934
935 long controlPanelPlid = PortalUtil.getControlPanelPlid(companyId);
936
937 if (layout != null) {
938 if (layout.isTypePortlet()) {
939 boolean freeformLayout =
940 layoutTypePortlet.getLayoutTemplateId().equals("freeform");
941
942 themeDisplay.setFreeformLayout(freeformLayout);
943
944 if (hasUpdateLayoutPermission) {
945 themeDisplay.setShowAddContentIconPermission(true);
946
947 if (!LiferayWindowState.isMaximized(request)) {
948 themeDisplay.setShowAddContentIcon(true);
949 }
950
951 themeDisplay.setShowLayoutTemplatesIcon(true);
952
953 if (!group.isUser()) {
954 themeDisplay.setShowPageCustomizationIcon(true);
955 }
956
957 themeDisplay.setURLAddContent(
958 "Liferay.Dockbar.loadAddPanel();");
959 }
960
961 if (hasCustomizeLayoutPermission && customizedView) {
962 themeDisplay.setShowAddContentIconPermission(true);
963
964 if (!LiferayWindowState.isMaximized(request)) {
965 themeDisplay.setShowAddContentIcon(true);
966 }
967
968 themeDisplay.setURLAddContent(
969 "Liferay.Dockbar.loadAddPanel();");
970 }
971 }
972
973 if (hasUpdateLayoutPermission) {
974 themeDisplay.setShowPageSettingsIcon(true);
975
976 LiferayPortletURL pageSettingsURL = new PortletURLImpl(
977 request, PortletKeys.GROUP_PAGES, controlPanelPlid,
978 PortletRequest.RENDER_PHASE);
979
980 pageSettingsURL.setDoAsGroupId(scopeGroupId);
981 pageSettingsURL.setParameter(
982 "struts_action", "/group_pages/edit_layouts");
983
984 if (layout.isPrivateLayout()) {
985 pageSettingsURL.setParameter("tabs1", "private-pages");
986 }
987 else {
988 pageSettingsURL.setParameter("tabs1", "public-pages");
989 }
990
991 pageSettingsURL.setParameter(
992 "groupId", String.valueOf(scopeGroupId));
993 pageSettingsURL.setParameter("selPlid", String.valueOf(plid));
994 pageSettingsURL.setPortletMode(PortletMode.VIEW);
995
996 if (PropsValues.DOCKBAR_ADMINISTRATIVE_LINKS_SHOW_IN_POP_UP) {
997 pageSettingsURL.setControlPanelCategory(
998 PortletCategoryKeys.PORTLET);
999 pageSettingsURL.setParameter("closeRedirect", currentURL);
1000 pageSettingsURL.setWindowState(LiferayWindowState.POP_UP);
1001 }
1002 else {
1003 pageSettingsURL.setParameter(
1004 "redirect", themeDisplay.getURLHome());
1005 pageSettingsURL.setPlid(plid);
1006 pageSettingsURL.setWindowState(WindowState.MAXIMIZED);
1007 }
1008
1009 themeDisplay.setURLPageSettings(pageSettingsURL);
1010
1011 boolean site = group.isSite();
1012
1013 if (!site && group.isStagingGroup()) {
1014 Group liveGroup = group.getLiveGroup();
1015
1016 site = liveGroup.isSite();
1017 }
1018
1019 if (site &&
1020 GroupPermissionUtil.contains(
1021 permissionChecker, scopeGroupId,
1022 ActionKeys.ASSIGN_MEMBERS)) {
1023
1024 themeDisplay.setShowManageSiteMembershipsIcon(true);
1025
1026 LiferayPortletURL manageSiteMembershipsURL =
1027 new PortletURLImpl(
1028 request, PortletKeys.SITE_MEMBERSHIPS_ADMIN,
1029 controlPanelPlid, PortletRequest.RENDER_PHASE);
1030
1031 manageSiteMembershipsURL.setDoAsGroupId(scopeGroupId);
1032 manageSiteMembershipsURL.setParameter(
1033 "struts_action", "/sites_admin/edit_site_assignments");
1034 manageSiteMembershipsURL.setParameter(
1035 "groupId", String.valueOf(scopeGroupId));
1036 manageSiteMembershipsURL.setParameter(
1037 "selPlid", String.valueOf(plid));
1038 manageSiteMembershipsURL.setPortletMode(PortletMode.VIEW);
1039
1040 if (PropsValues.
1041 DOCKBAR_ADMINISTRATIVE_LINKS_SHOW_IN_POP_UP) {
1042
1043 manageSiteMembershipsURL.setControlPanelCategory(
1044 PortletCategoryKeys.PORTLET);
1045 manageSiteMembershipsURL.setWindowState(
1046 LiferayWindowState.POP_UP);
1047 }
1048 else {
1049 manageSiteMembershipsURL.setParameter(
1050 "redirect", themeDisplay.getURLHome());
1051 manageSiteMembershipsURL.setParameter(
1052 "showBackURL", Boolean.FALSE.toString());
1053 manageSiteMembershipsURL.setPlid(plid);
1054 manageSiteMembershipsURL.setWindowState(
1055 WindowState.MAXIMIZED);
1056 }
1057
1058 themeDisplay.setURLManageSiteMemberships(
1059 manageSiteMembershipsURL);
1060 }
1061 else {
1062 themeDisplay.setShowManageSiteMembershipsIcon(false);
1063 }
1064 }
1065
1066 boolean hasAddLayoutGroupPermission = GroupPermissionUtil.contains(
1067 permissionChecker, scopeGroupId, ActionKeys.ADD_LAYOUT);
1068 boolean hasAddLayoutLayoutPermission =
1069 !layout.isTypeControlPanel() &&
1070 LayoutPermissionUtil.contains(
1071 permissionChecker, layout, ActionKeys.ADD_LAYOUT);
1072 boolean hasManageLayoutsGroupPermission =
1073 GroupPermissionUtil.contains(
1074 permissionChecker, scopeGroupId, ActionKeys.MANAGE_LAYOUTS);
1075 boolean hasManageStagingPermission = GroupPermissionUtil.contains(
1076 permissionChecker, scopeGroupId, ActionKeys.MANAGE_STAGING);
1077 boolean hasPublishStagingPermission = GroupPermissionUtil.contains(
1078 permissionChecker, scopeGroupId, ActionKeys.PUBLISH_STAGING);
1079 boolean hasUpdateGroupPermission = GroupPermissionUtil.contains(
1080 permissionChecker, scopeGroupId, ActionKeys.UPDATE);
1081 boolean hasViewStagingPermission = GroupPermissionUtil.contains(
1082 permissionChecker, scopeGroupId, ActionKeys.VIEW_STAGING);
1083
1084 if (!group.isControlPanel() && !group.isUser() &&
1085 !group.isUserGroup() && hasUpdateGroupPermission) {
1086
1087 themeDisplay.setShowSiteSettingsIcon(true);
1088
1089 LiferayPortletURL siteSettingsURL = new PortletURLImpl(
1090 request, PortletKeys.SITE_SETTINGS, controlPanelPlid,
1091 PortletRequest.RENDER_PHASE);
1092
1093 siteSettingsURL.setDoAsGroupId(scopeGroupId);
1094 siteSettingsURL.setParameter(
1095 "struts_action", "/sites_admin/edit_site");
1096 siteSettingsURL.setParameter(
1097 "groupId", String.valueOf(scopeGroupId));
1098 siteSettingsURL.setParameter(
1099 "showBackURL", Boolean.FALSE.toString());
1100 siteSettingsURL.setPortletMode(PortletMode.VIEW);
1101
1102 if (PropsValues.DOCKBAR_ADMINISTRATIVE_LINKS_SHOW_IN_POP_UP) {
1103 siteSettingsURL.setControlPanelCategory(
1104 PortletCategoryKeys.PORTLET);
1105 siteSettingsURL.setParameter("closeRedirect", currentURL);
1106 siteSettingsURL.setWindowState(LiferayWindowState.POP_UP);
1107 }
1108 else {
1109 siteSettingsURL.setParameter(
1110 "redirect", themeDisplay.getURLHome());
1111 siteSettingsURL.setPlid(plid);
1112 siteSettingsURL.setWindowState(
1113 LiferayWindowState.MAXIMIZED);
1114 }
1115
1116 themeDisplay.setURLSiteSettings(siteSettingsURL);
1117 }
1118
1119 if (!group.isLayoutPrototype() &&
1120 (hasAddLayoutGroupPermission || hasAddLayoutLayoutPermission ||
1121 hasManageLayoutsGroupPermission || hasUpdateGroupPermission)) {
1122
1123 themeDisplay.setShowSiteMapSettingsIcon(true);
1124
1125 LiferayPortletURL siteMapSettingsURL = new PortletURLImpl(
1126 request, PortletKeys.GROUP_PAGES, controlPanelPlid,
1127 PortletRequest.RENDER_PHASE);
1128
1129 siteMapSettingsURL.setDoAsGroupId(scopeGroupId);
1130 siteMapSettingsURL.setParameter(
1131 "struts_action", "/group_pages/edit_layouts");
1132
1133 if (layout.isPrivateLayout()) {
1134 siteMapSettingsURL.setParameter("tabs1", "private-pages");
1135 }
1136 else {
1137 siteMapSettingsURL.setParameter("tabs1", "public-pages");
1138 }
1139
1140 siteMapSettingsURL.setParameter(
1141 "groupId", String.valueOf(scopeGroupId));
1142 siteMapSettingsURL.setPortletMode(PortletMode.VIEW);
1143
1144 if (PropsValues.DOCKBAR_ADMINISTRATIVE_LINKS_SHOW_IN_POP_UP) {
1145 siteMapSettingsURL.setControlPanelCategory(
1146 PortletCategoryKeys.PORTLET);
1147 siteMapSettingsURL.setParameter(
1148 "closeRedirect", currentURL);
1149 siteMapSettingsURL.setWindowState(
1150 LiferayWindowState.POP_UP);
1151 }
1152 else {
1153 siteMapSettingsURL.setParameter(
1154 "redirect", themeDisplay.getURLHome());
1155 siteMapSettingsURL.setPlid(plid);
1156 siteMapSettingsURL.setWindowState(
1157 LiferayWindowState.MAXIMIZED);
1158 }
1159
1160 themeDisplay.setURLSiteMapSettings(siteMapSettingsURL);
1161 }
1162
1163 if (group.hasStagingGroup() && !group.isStagingGroup()) {
1164 themeDisplay.setShowAddContentIcon(false);
1165 themeDisplay.setShowLayoutTemplatesIcon(false);
1166 themeDisplay.setURLPublishToLive(null);
1167 }
1168
1169 if (group.isControlPanel()) {
1170 themeDisplay.setShowPageSettingsIcon(false);
1171 themeDisplay.setURLPublishToLive(null);
1172 }
1173
1174
1175
1176 if (group.isStaged() || group.isStagingGroup()) {
1177 if (hasManageStagingPermission || hasPublishStagingPermission ||
1178 hasUpdateLayoutPermission || hasViewStagingPermission) {
1179
1180 themeDisplay.setShowStagingIcon(true);
1181 }
1182
1183 if (hasPublishStagingPermission) {
1184 PortletURL publishToLiveURL = new PortletURLImpl(
1185 request, PortletKeys.LAYOUTS_ADMIN, plid,
1186 PortletRequest.RENDER_PHASE);
1187
1188 publishToLiveURL.setParameter(
1189 "struts_action", "/layouts_admin/publish_layouts");
1190
1191 if (layout.isPrivateLayout()) {
1192 publishToLiveURL.setParameter("tabs1", "private-pages");
1193 }
1194 else {
1195 publishToLiveURL.setParameter("tabs1", "public-pages");
1196 }
1197
1198 publishToLiveURL.setParameter("pagesRedirect", currentURL);
1199 publishToLiveURL.setParameter(
1200 "groupId", String.valueOf(scopeGroupId));
1201 publishToLiveURL.setParameter(
1202 "selPlid", String.valueOf(plid));
1203 publishToLiveURL.setPortletMode(PortletMode.VIEW);
1204 publishToLiveURL.setWindowState(
1205 LiferayWindowState.EXCLUSIVE);
1206
1207 themeDisplay.setURLPublishToLive(publishToLiveURL);
1208 }
1209 }
1210
1211 Portlet myAccountPortlet = PortalUtil.getFirstMyAccountPortlet(
1212 themeDisplay);
1213
1214 if (myAccountPortlet != null) {
1215 PortletURLImpl myAccountURL = new PortletURLImpl(
1216 request, myAccountPortlet.getPortletId(), controlPanelPlid,
1217 PortletRequest.RENDER_PHASE);
1218
1219 if (signedIn) {
1220 myAccountURL.setDoAsGroupId(user.getGroupId());
1221 }
1222 else if (scopeGroupId > 0) {
1223 myAccountURL.setDoAsGroupId(scopeGroupId);
1224 }
1225
1226 if (refererPlid > 0) {
1227 myAccountURL.setRefererPlid(refererPlid);
1228 }
1229 else {
1230 myAccountURL.setRefererPlid(plid);
1231 }
1232
1233 myAccountURL.setWindowState(WindowState.MAXIMIZED);
1234
1235 themeDisplay.setURLMyAccount(myAccountURL);
1236 }
1237 }
1238
1239 if (!user.isActive() ||
1240 (PrefsPropsUtil.getBoolean(
1241 companyId, PropsKeys.TERMS_OF_USE_REQUIRED) &&
1242 !user.isAgreedToTermsOfUse())) {
1243
1244 themeDisplay.setShowAddContentIcon(false);
1245 themeDisplay.setShowMyAccountIcon(false);
1246 themeDisplay.setShowPageSettingsIcon(false);
1247 }
1248
1249 if (layout.isLayoutPrototypeLinkActive()) {
1250 themeDisplay.setShowPageCustomizationIcon(false);
1251 }
1252
1253 if (group.isLayoutPrototype()) {
1254 themeDisplay.setShowHomeIcon(false);
1255 themeDisplay.setShowManageSiteMembershipsIcon(false);
1256 themeDisplay.setShowMyAccountIcon(false);
1257 themeDisplay.setShowPageCustomizationIcon(false);
1258 themeDisplay.setShowPageSettingsIcon(true);
1259 themeDisplay.setShowPortalIcon(false);
1260 themeDisplay.setShowSignInIcon(false);
1261 themeDisplay.setShowSignOutIcon(false);
1262 themeDisplay.setShowSiteAdministrationIcon(false);
1263 themeDisplay.setShowSiteSettingsIcon(false);
1264 themeDisplay.setShowStagingIcon(false);
1265 }
1266
1267 if (group.isLayoutSetPrototype()) {
1268 themeDisplay.setShowPageCustomizationIcon(false);
1269 themeDisplay.setShowSiteSettingsIcon(false);
1270 }
1271
1272 if (group.hasStagingGroup() && !group.isStagingGroup()) {
1273 themeDisplay.setShowLayoutTemplatesIcon(false);
1274 themeDisplay.setShowPageCustomizationIcon(false);
1275 themeDisplay.setShowSiteMapSettingsIcon(false);
1276 themeDisplay.setShowSiteSettingsIcon(false);
1277 }
1278
1279 themeDisplay.setURLPortal(portalURL.concat(contextPath));
1280
1281 boolean secure = false;
1282
1283 if (PropsValues.COMPANY_SECURITY_AUTH_REQUIRES_HTTPS ||
1284 request.isSecure()) {
1285
1286 secure = true;
1287 }
1288
1289 String securePortalURL = PortalUtil.getPortalURL(request, secure);
1290
1291 String urlSignIn = securePortalURL.concat(mainPath).concat(
1292 _PATH_PORTAL_LOGIN);
1293
1294 if (layout != null) {
1295 urlSignIn = HttpUtil.addParameter(
1296 urlSignIn, "p_l_id", layout.getPlid());
1297 }
1298
1299 themeDisplay.setURLSignIn(urlSignIn);
1300
1301 themeDisplay.setURLSignOut(mainPath.concat(_PATH_PORTAL_LOGOUT));
1302
1303 PortletURL updateManagerURL = new PortletURLImpl(
1304 request, PortletKeys.MARKETPLACE_STORE, controlPanelPlid,
1305 PortletRequest.RENDER_PHASE);
1306
1307 themeDisplay.setURLUpdateManager(updateManagerURL);
1308
1309 return themeDisplay;
1310 }
1311
1312 @Override
1313 public void run(HttpServletRequest request, HttpServletResponse response)
1314 throws ActionException {
1315
1316 StopWatch stopWatch = new StopWatch();
1317
1318 stopWatch.start();
1319
1320 try {
1321 servicePre(request, response);
1322 }
1323 catch (Exception e) {
1324 throw new ActionException(e);
1325 }
1326
1327 if (_log.isDebugEnabled()) {
1328 _log.debug("Running takes " + stopWatch.getTime() + " ms");
1329 }
1330 }
1331
1332 protected void addDefaultLayoutsByLAR(
1333 long userId, long groupId, boolean privateLayout, File larFile)
1334 throws PortalException, SystemException {
1335
1336 Map<String, String[]> parameterMap = new HashMap<String, String[]>();
1337
1338 parameterMap.put(
1339 PortletDataHandlerKeys.PERMISSIONS,
1340 new String[] {Boolean.TRUE.toString()});
1341 parameterMap.put(
1342 PortletDataHandlerKeys.PORTLET_ARCHIVED_SETUPS_ALL,
1343 new String[] {Boolean.TRUE.toString()});
1344 parameterMap.put(
1345 PortletDataHandlerKeys.PORTLET_CONFIGURATION,
1346 new String[] {Boolean.TRUE.toString()});
1347 parameterMap.put(
1348 PortletDataHandlerKeys.PORTLET_CONFIGURATION_ALL,
1349 new String[] {Boolean.TRUE.toString()});
1350 parameterMap.put(
1351 PortletDataHandlerKeys.PORTLET_DATA,
1352 new String[] {Boolean.TRUE.toString()});
1353 parameterMap.put(
1354 PortletDataHandlerKeys.PORTLET_DATA_ALL,
1355 new String[] {Boolean.TRUE.toString()});
1356 parameterMap.put(
1357 PortletDataHandlerKeys.PORTLET_DATA_CONTROL_DEFAULT,
1358 new String[] {Boolean.TRUE.toString()});
1359 parameterMap.put(
1360 PortletDataHandlerKeys.PORTLET_SETUP_ALL,
1361 new String[] {Boolean.TRUE.toString()});
1362 parameterMap.put(
1363 PortletDataHandlerKeys.PORTLET_USER_PREFERENCES_ALL,
1364 new String[] {Boolean.TRUE.toString()});
1365 parameterMap.put(
1366 PortletDataHandlerKeys.THEME_REFERENCE,
1367 new String[] {Boolean.TRUE.toString()});
1368
1369 LayoutLocalServiceUtil.importLayouts(
1370 userId, groupId, privateLayout, parameterMap, larFile);
1371 }
1372
1373 protected void addDefaultUserPrivateLayoutByProperties(
1374 long userId, long groupId)
1375 throws PortalException, SystemException {
1376
1377 String friendlyURL = getFriendlyURL(
1378 PropsValues.DEFAULT_USER_PRIVATE_LAYOUT_FRIENDLY_URL);
1379
1380 ServiceContext serviceContext = new ServiceContext();
1381
1382 Layout layout = LayoutLocalServiceUtil.addLayout(
1383 userId, groupId, true, LayoutConstants.DEFAULT_PARENT_LAYOUT_ID,
1384 PropsValues.DEFAULT_USER_PRIVATE_LAYOUT_NAME, StringPool.BLANK,
1385 StringPool.BLANK, LayoutConstants.TYPE_PORTLET, false, friendlyURL,
1386 serviceContext);
1387
1388 LayoutTypePortlet layoutTypePortlet =
1389 (LayoutTypePortlet)layout.getLayoutType();
1390
1391 layoutTypePortlet.setLayoutTemplateId(
1392 0, PropsValues.DEFAULT_USER_PRIVATE_LAYOUT_TEMPLATE_ID, false);
1393
1394 LayoutTemplate layoutTemplate = layoutTypePortlet.getLayoutTemplate();
1395
1396 for (String columnId : layoutTemplate.getColumns()) {
1397 String keyPrefix = PropsKeys.DEFAULT_USER_PRIVATE_LAYOUT_PREFIX;
1398
1399 String portletIds = PropsUtil.get(keyPrefix.concat(columnId));
1400
1401 layoutTypePortlet.addPortletIds(
1402 0, StringUtil.split(portletIds), columnId, false);
1403 }
1404
1405 LayoutLocalServiceUtil.updateLayout(
1406 layout.getGroupId(), layout.isPrivateLayout(), layout.getLayoutId(),
1407 layout.getTypeSettings());
1408
1409 boolean updateLayoutSet = false;
1410
1411 LayoutSet layoutSet = layout.getLayoutSet();
1412
1413 if (Validator.isNotNull(
1414 PropsValues.DEFAULT_USER_PRIVATE_LAYOUT_REGULAR_THEME_ID)) {
1415
1416 layoutSet.setThemeId(
1417 PropsValues.DEFAULT_USER_PRIVATE_LAYOUT_REGULAR_THEME_ID);
1418
1419 updateLayoutSet = true;
1420 }
1421
1422 if (Validator.isNotNull(
1423 PropsValues.
1424 DEFAULT_USER_PRIVATE_LAYOUT_REGULAR_COLOR_SCHEME_ID)) {
1425
1426 layoutSet.setColorSchemeId(
1427 PropsValues.
1428 DEFAULT_USER_PRIVATE_LAYOUT_REGULAR_COLOR_SCHEME_ID);
1429
1430 updateLayoutSet = true;
1431 }
1432
1433 if (Validator.isNotNull(
1434 PropsValues.DEFAULT_USER_PRIVATE_LAYOUT_WAP_THEME_ID)) {
1435
1436 layoutSet.setWapThemeId(
1437 PropsValues.DEFAULT_USER_PRIVATE_LAYOUT_WAP_THEME_ID);
1438
1439 updateLayoutSet = true;
1440 }
1441
1442 if (Validator.isNotNull(
1443 PropsValues.DEFAULT_USER_PRIVATE_LAYOUT_WAP_COLOR_SCHEME_ID)) {
1444
1445 layoutSet.setWapColorSchemeId(
1446 PropsValues.DEFAULT_USER_PRIVATE_LAYOUT_WAP_COLOR_SCHEME_ID);
1447
1448 updateLayoutSet = true;
1449 }
1450
1451 if (updateLayoutSet) {
1452 LayoutSetLocalServiceUtil.updateLayoutSet(layoutSet);
1453 }
1454 }
1455
1456 protected void addDefaultUserPrivateLayouts(User user)
1457 throws PortalException, SystemException {
1458
1459 Group userGroup = user.getGroup();
1460
1461 if (privateLARFile != null) {
1462 addDefaultLayoutsByLAR(
1463 user.getUserId(), userGroup.getGroupId(), true, privateLARFile);
1464 }
1465 else {
1466 addDefaultUserPrivateLayoutByProperties(
1467 user.getUserId(), userGroup.getGroupId());
1468 }
1469 }
1470
1471 protected void addDefaultUserPublicLayoutByProperties(
1472 long userId, long groupId)
1473 throws PortalException, SystemException {
1474
1475 String friendlyURL = getFriendlyURL(
1476 PropsValues.DEFAULT_USER_PUBLIC_LAYOUT_FRIENDLY_URL);
1477
1478 ServiceContext serviceContext = new ServiceContext();
1479
1480 Layout layout = LayoutLocalServiceUtil.addLayout(
1481 userId, groupId, false, LayoutConstants.DEFAULT_PARENT_LAYOUT_ID,
1482 PropsValues.DEFAULT_USER_PUBLIC_LAYOUT_NAME, StringPool.BLANK,
1483 StringPool.BLANK, LayoutConstants.TYPE_PORTLET, false, friendlyURL,
1484 serviceContext);
1485
1486 LayoutTypePortlet layoutTypePortlet =
1487 (LayoutTypePortlet)layout.getLayoutType();
1488
1489 layoutTypePortlet.setLayoutTemplateId(
1490 0, PropsValues.DEFAULT_USER_PUBLIC_LAYOUT_TEMPLATE_ID, false);
1491
1492 LayoutTemplate layoutTemplate = layoutTypePortlet.getLayoutTemplate();
1493
1494 for (String columnId : layoutTemplate.getColumns()) {
1495 String keyPrefix = PropsKeys.DEFAULT_USER_PUBLIC_LAYOUT_PREFIX;
1496
1497 String portletIds = PropsUtil.get(keyPrefix.concat(columnId));
1498
1499 layoutTypePortlet.addPortletIds(
1500 0, StringUtil.split(portletIds), columnId, false);
1501 }
1502
1503 LayoutLocalServiceUtil.updateLayout(
1504 layout.getGroupId(), layout.isPrivateLayout(), layout.getLayoutId(),
1505 layout.getTypeSettings());
1506
1507 boolean updateLayoutSet = false;
1508
1509 LayoutSet layoutSet = layout.getLayoutSet();
1510
1511 if (Validator.isNotNull(
1512 PropsValues.DEFAULT_USER_PUBLIC_LAYOUT_REGULAR_THEME_ID)) {
1513
1514 layoutSet.setThemeId(
1515 PropsValues.DEFAULT_USER_PUBLIC_LAYOUT_REGULAR_THEME_ID);
1516
1517 updateLayoutSet = true;
1518 }
1519
1520 if (Validator.isNotNull(
1521 PropsValues.
1522 DEFAULT_USER_PUBLIC_LAYOUT_REGULAR_COLOR_SCHEME_ID)) {
1523
1524 layoutSet.setColorSchemeId(
1525 PropsValues.DEFAULT_USER_PUBLIC_LAYOUT_REGULAR_COLOR_SCHEME_ID);
1526
1527 updateLayoutSet = true;
1528 }
1529
1530 if (Validator.isNotNull(
1531 PropsValues.DEFAULT_USER_PUBLIC_LAYOUT_WAP_THEME_ID)) {
1532
1533 layoutSet.setWapThemeId(
1534 PropsValues.DEFAULT_USER_PUBLIC_LAYOUT_WAP_THEME_ID);
1535
1536 updateLayoutSet = true;
1537 }
1538
1539 if (Validator.isNotNull(
1540 PropsValues.DEFAULT_USER_PUBLIC_LAYOUT_WAP_COLOR_SCHEME_ID)) {
1541
1542 layoutSet.setWapColorSchemeId(
1543 PropsValues.DEFAULT_USER_PUBLIC_LAYOUT_WAP_COLOR_SCHEME_ID);
1544
1545 updateLayoutSet = true;
1546 }
1547
1548 if (updateLayoutSet) {
1549 LayoutSetLocalServiceUtil.updateLayoutSet(layoutSet);
1550 }
1551 }
1552
1553 protected void addDefaultUserPublicLayouts(User user)
1554 throws PortalException, SystemException {
1555
1556 Group userGroup = user.getGroup();
1557
1558 if (publicLARFile != null) {
1559 addDefaultLayoutsByLAR(
1560 user.getUserId(), userGroup.getGroupId(), false, publicLARFile);
1561 }
1562 else {
1563 addDefaultUserPublicLayoutByProperties(
1564 user.getUserId(), userGroup.getGroupId());
1565 }
1566 }
1567
1568 protected void deleteDefaultUserPrivateLayouts(User user)
1569 throws PortalException, SystemException {
1570
1571 Group userGroup = user.getGroup();
1572
1573 ServiceContext serviceContext = new ServiceContext();
1574
1575 LayoutLocalServiceUtil.deleteLayouts(
1576 userGroup.getGroupId(), true, serviceContext);
1577 }
1578
1579 protected void deleteDefaultUserPublicLayouts(User user)
1580 throws PortalException, SystemException {
1581
1582 Group userGroup = user.getGroup();
1583
1584 ServiceContext serviceContext = new ServiceContext();
1585
1586 LayoutLocalServiceUtil.deleteLayouts(
1587 userGroup.getGroupId(), false, serviceContext);
1588 }
1589
1590 protected Object[] getDefaultLayout(
1591 HttpServletRequest request, User user, boolean signedIn)
1592 throws PortalException, SystemException {
1593
1594 Layout layout = null;
1595 List<Layout> layouts = null;
1596
1597
1598
1599 LayoutSet layoutSet = (LayoutSet)request.getAttribute(
1600 WebKeys.VIRTUAL_HOST_LAYOUT_SET);
1601
1602 if (layoutSet != null) {
1603 layouts = LayoutLocalServiceUtil.getLayouts(
1604 layoutSet.getGroupId(), layoutSet.isPrivateLayout(),
1605 LayoutConstants.DEFAULT_PARENT_LAYOUT_ID);
1606
1607 Group group = null;
1608
1609 if (!layouts.isEmpty()) {
1610 layout = layouts.get(0);
1611
1612 group = layout.getGroup();
1613 }
1614
1615 if ((layout != null) && layout.isPrivateLayout()) {
1616 layouts = LayoutLocalServiceUtil.getLayouts(
1617 group.getGroupId(), false,
1618 LayoutConstants.DEFAULT_PARENT_LAYOUT_ID);
1619
1620 if (!layouts.isEmpty()) {
1621 layout = layouts.get(0);
1622 }
1623 else {
1624 group = null;
1625 layout = null;
1626 }
1627 }
1628
1629 if ((group != null) && group.isStagingGroup()) {
1630 Group liveGroup = group.getLiveGroup();
1631
1632 layouts = LayoutLocalServiceUtil.getLayouts(
1633 liveGroup.getGroupId(), false,
1634 LayoutConstants.DEFAULT_PARENT_LAYOUT_ID);
1635
1636 if (!layouts.isEmpty()) {
1637 layout = layouts.get(0);
1638 }
1639 else {
1640 layout = null;
1641 }
1642 }
1643 }
1644
1645 if ((layout == null) && signedIn) {
1646
1647
1648
1649 Group userGroup = user.getGroup();
1650
1651 layouts = LayoutLocalServiceUtil.getLayouts(
1652 userGroup.getGroupId(), true,
1653 LayoutConstants.DEFAULT_PARENT_LAYOUT_ID);
1654
1655 if (layouts.size() == 0) {
1656 layouts = LayoutLocalServiceUtil.getLayouts(
1657 userGroup.getGroupId(), false,
1658 LayoutConstants.DEFAULT_PARENT_LAYOUT_ID);
1659 }
1660
1661 if (layouts.size() > 0) {
1662 layout = layouts.get(0);
1663 }
1664
1665
1666
1667 if (layout == null) {
1668 LinkedHashMap<String, Object> groupParams =
1669 new LinkedHashMap<String, Object>();
1670
1671 groupParams.put("usersGroups", new Long(user.getUserId()));
1672
1673 List<Group> groups = GroupLocalServiceUtil.search(
1674 user.getCompanyId(), null, null, groupParams,
1675 QueryUtil.ALL_POS, QueryUtil.ALL_POS);
1676
1677 for (Group group : groups) {
1678 layouts = LayoutLocalServiceUtil.getLayouts(
1679 group.getGroupId(), true,
1680 LayoutConstants.DEFAULT_PARENT_LAYOUT_ID);
1681
1682 if (layouts.size() == 0) {
1683 layouts = LayoutLocalServiceUtil.getLayouts(
1684 group.getGroupId(), false,
1685 LayoutConstants.DEFAULT_PARENT_LAYOUT_ID);
1686 }
1687
1688 if (layouts.size() > 0) {
1689 layout = layouts.get(0);
1690
1691 break;
1692 }
1693 }
1694 }
1695 }
1696
1697 if (layout == null) {
1698
1699
1700
1701 Group guestGroup = GroupLocalServiceUtil.getGroup(
1702 user.getCompanyId(), GroupConstants.GUEST);
1703
1704 layouts = LayoutLocalServiceUtil.getLayouts(
1705 guestGroup.getGroupId(), false,
1706 LayoutConstants.DEFAULT_PARENT_LAYOUT_ID);
1707
1708 if (layouts.size() > 0) {
1709 layout = layouts.get(0);
1710 }
1711 }
1712
1713 return new Object[] {layout, layouts};
1714 }
1715
1716 protected String getFriendlyURL(String friendlyURL) {
1717 friendlyURL = GetterUtil.getString(friendlyURL);
1718
1719 return FriendlyURLNormalizerUtil.normalize(friendlyURL);
1720 }
1721
1722 protected Object[] getViewableLayouts(
1723 HttpServletRequest request, User user,
1724 PermissionChecker permissionChecker, Layout layout,
1725 List<Layout> layouts, long doAsGroupId, String controlPanelCategory)
1726 throws PortalException, SystemException {
1727
1728 if ((layouts == null) || layouts.isEmpty()) {
1729 return new Object[] {layout, layouts};
1730 }
1731
1732 Group group = layout.getGroup();
1733
1734 boolean hasViewLayoutPermission = false;
1735 boolean hasViewStagingPermission =
1736 (group.isStagingGroup() || group.isStagedRemotely()) &&
1737 !group.isControlPanel() &&
1738 GroupPermissionUtil.contains(
1739 permissionChecker, group.getGroupId(),
1740 ActionKeys.VIEW_STAGING);
1741
1742 if (hasAccessPermission(
1743 permissionChecker, layout, doAsGroupId, controlPanelCategory,
1744 false) ||
1745 hasViewStagingPermission) {
1746
1747 hasViewLayoutPermission = true;
1748 }
1749
1750 List<Layout> accessibleLayouts = new ArrayList<Layout>();
1751
1752 for (int i = 0; i < layouts.size(); i++) {
1753 Layout curLayout = layouts.get(i);
1754
1755 if (!curLayout.isHidden() &&
1756 (hasAccessPermission(
1757 permissionChecker, curLayout, doAsGroupId,
1758 controlPanelCategory, false) ||
1759 hasViewStagingPermission)) {
1760
1761 if (accessibleLayouts.isEmpty() && !hasViewLayoutPermission) {
1762 layout = curLayout;
1763 }
1764
1765 accessibleLayouts.add(curLayout);
1766 }
1767 }
1768
1769 if (accessibleLayouts.isEmpty()) {
1770 layouts = null;
1771
1772 if (!isLoginRequest(request) && !hasViewLayoutPermission) {
1773 if (user.isDefaultUser() &&
1774 PropsValues.AUTH_LOGIN_PROMPT_ENABLED) {
1775
1776 throw new PrincipalException("User is not authenticated");
1777 }
1778
1779 SessionErrors.add(
1780 request, LayoutPermissionException.class.getName());
1781 }
1782 }
1783 else {
1784 layouts = accessibleLayouts;
1785 }
1786
1787 return new Object[] {layout, layouts};
1788 }
1789
1790 protected boolean hasAccessPermission(
1791 PermissionChecker permissionChecker, Layout layout,
1792 long doAsGroupId, String controlPanelCategory,
1793 boolean checkViewableGroup)
1794 throws PortalException, SystemException {
1795
1796 if (layout.isTypeControlPanel()) {
1797 if (!permissionChecker.isSignedIn()) {
1798 return false;
1799 }
1800
1801 if (controlPanelCategory.startsWith(
1802 PortletCategoryKeys.CURRENT_SITE)) {
1803
1804 if (doAsGroupId <= 0) {
1805 return false;
1806 }
1807
1808 Group group = GroupLocalServiceUtil.getGroup(doAsGroupId);
1809
1810 if (group.isLayout()) {
1811 group = group.getParentGroup();
1812 }
1813
1814 if (GroupPermissionUtil.contains(
1815 permissionChecker, group.getGroupId(),
1816 ActionKeys.VIEW_SITE_ADMINISTRATION)) {
1817
1818 return true;
1819 }
1820 }
1821 else if (controlPanelCategory.equals(PortletCategoryKeys.MY) ||
1822 controlPanelCategory.equals(PortletCategoryKeys.PORTLET)) {
1823
1824 return true;
1825 }
1826
1827 return PortalPermissionUtil.contains(
1828 permissionChecker, ActionKeys.VIEW_CONTROL_PANEL);
1829 }
1830
1831 return LayoutPermissionUtil.contains(
1832 permissionChecker, layout, checkViewableGroup, ActionKeys.VIEW);
1833 }
1834
1835 protected Boolean hasPowerUserRole(User user) throws Exception {
1836 return RoleLocalServiceUtil.hasUserRole(
1837 user.getUserId(), user.getCompanyId(), RoleConstants.POWER_USER,
1838 true);
1839 }
1840
1841 protected void initImportLARFiles() {
1842 String privateLARFileName =
1843 PropsValues.DEFAULT_USER_PRIVATE_LAYOUTS_LAR;
1844
1845 if (_log.isDebugEnabled()) {
1846 _log.debug("Reading private LAR file " + privateLARFileName);
1847 }
1848
1849 if (Validator.isNotNull(privateLARFileName)) {
1850 privateLARFile = new File(privateLARFileName);
1851
1852 if (!privateLARFile.exists()) {
1853 _log.error(
1854 "Private LAR file " + privateLARFile + " does not exist");
1855
1856 privateLARFile = null;
1857 }
1858 else {
1859 if (_log.isDebugEnabled()) {
1860 _log.debug("Using private LAR file " + privateLARFileName);
1861 }
1862 }
1863 }
1864
1865 String publicLARFileName = PropsValues.DEFAULT_USER_PUBLIC_LAYOUTS_LAR;
1866
1867 if (_log.isDebugEnabled()) {
1868 _log.debug("Reading public LAR file " + publicLARFileName);
1869 }
1870
1871 if (Validator.isNotNull(publicLARFileName)) {
1872 publicLARFile = new File(publicLARFileName);
1873
1874 if (!publicLARFile.exists()) {
1875 _log.error(
1876 "Public LAR file " + publicLARFile + " does not exist");
1877
1878 publicLARFile = null;
1879 }
1880 else {
1881 if (_log.isDebugEnabled()) {
1882 _log.debug("Using public LAR file " + publicLARFileName);
1883 }
1884 }
1885 }
1886 }
1887
1888 protected boolean isLoginRequest(HttpServletRequest request) {
1889 String requestURI = request.getRequestURI();
1890
1891 String mainPath = PortalUtil.getPathMain();
1892
1893 if (requestURI.startsWith(mainPath.concat(_PATH_PORTAL_LOGIN))) {
1894 return true;
1895 }
1896 else {
1897 return false;
1898 }
1899 }
1900
1901
1904 protected boolean isViewableCommunity(
1905 User user, long groupId, boolean privateLayout,
1906 PermissionChecker permissionChecker)
1907 throws PortalException, SystemException {
1908
1909 return LayoutPermissionUtil.contains(
1910 permissionChecker, groupId, privateLayout, 0, ActionKeys.VIEW);
1911 }
1912
1913
1916 protected boolean isViewableGroup(
1917 User user, long groupId, boolean privateLayout, long layoutId,
1918 String controlPanelCategory, PermissionChecker permissionChecker)
1919 throws PortalException, SystemException {
1920
1921 return LayoutPermissionUtil.contains(
1922 permissionChecker, groupId, privateLayout, layoutId,
1923 ActionKeys.VIEW);
1924 }
1925
1926 protected List<Layout> mergeAdditionalLayouts(
1927 HttpServletRequest request, User user,
1928 PermissionChecker permissionChecker, Layout layout,
1929 List<Layout> layouts, long doAsGroupId, String controlPanelCategory)
1930 throws PortalException, SystemException {
1931
1932 if ((layout == null) || layout.isPrivateLayout()) {
1933 return layouts;
1934 }
1935
1936 long layoutGroupId = layout.getGroupId();
1937
1938 Group guestGroup = GroupLocalServiceUtil.getGroup(
1939 user.getCompanyId(), GroupConstants.GUEST);
1940
1941 if (layoutGroupId != guestGroup.getGroupId()) {
1942 Group layoutGroup = GroupLocalServiceUtil.getGroup(layoutGroupId);
1943
1944 UnicodeProperties typeSettingsProperties =
1945 layoutGroup.getTypeSettingsProperties();
1946
1947 boolean mergeGuestPublicPages = GetterUtil.getBoolean(
1948 typeSettingsProperties.getProperty("mergeGuestPublicPages"));
1949
1950 if (!mergeGuestPublicPages) {
1951 return layouts;
1952 }
1953
1954 List<Layout> guestLayouts = LayoutLocalServiceUtil.getLayouts(
1955 guestGroup.getGroupId(), false,
1956 LayoutConstants.DEFAULT_PARENT_LAYOUT_ID);
1957
1958 Object[] viewableLayouts = getViewableLayouts(
1959 request, user, permissionChecker, layout, guestLayouts,
1960 doAsGroupId, controlPanelCategory);
1961
1962 guestLayouts = (List<Layout>)viewableLayouts[1];
1963
1964 if (layouts == null) {
1965 return guestLayouts;
1966 }
1967
1968 layouts.addAll(0, guestLayouts);
1969 }
1970 else {
1971 HttpSession session = request.getSession();
1972
1973 Long previousGroupId = (Long)session.getAttribute(
1974 WebKeys.VISITED_GROUP_ID_PREVIOUS);
1975
1976 if ((previousGroupId != null) &&
1977 (previousGroupId.longValue() != layoutGroupId)) {
1978
1979 Group previousGroup = null;
1980
1981 try {
1982 previousGroup = GroupLocalServiceUtil.getGroup(
1983 previousGroupId.longValue());
1984 }
1985 catch (NoSuchGroupException nsge) {
1986 if (_log.isWarnEnabled()) {
1987 _log.warn(nsge);
1988 }
1989
1990 return layouts;
1991 }
1992
1993 UnicodeProperties typeSettingsProperties =
1994 previousGroup.getTypeSettingsProperties();
1995
1996 boolean mergeGuestPublicPages = GetterUtil.getBoolean(
1997 typeSettingsProperties.getProperty(
1998 "mergeGuestPublicPages"));
1999
2000 if (!mergeGuestPublicPages) {
2001 return layouts;
2002 }
2003
2004 List<Layout> previousLayouts =
2005 LayoutLocalServiceUtil.getLayouts(
2006 previousGroupId.longValue(), false,
2007 LayoutConstants.DEFAULT_PARENT_LAYOUT_ID);
2008
2009 Object[] viewableLayouts = getViewableLayouts(
2010 request, user, permissionChecker, layout, previousLayouts,
2011 doAsGroupId, controlPanelCategory);
2012
2013 previousLayouts = (List<Layout>)viewableLayouts[1];
2014
2015 if (previousLayouts != null) {
2016 layouts.addAll(previousLayouts);
2017 }
2018 }
2019 }
2020
2021 return layouts;
2022 }
2023
2024 protected void processControlPanelRedirects(
2025 HttpServletRequest request, HttpServletResponse response)
2026 throws Exception {
2027
2028 PermissionChecker permissionChecker =
2029 PermissionThreadLocal.getPermissionChecker();
2030
2031 ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
2032 WebKeys.THEME_DISPLAY);
2033
2034 Layout layout = themeDisplay.getLayout();
2035
2036 if ((layout == null) || !layout.isTypeControlPanel()) {
2037 return;
2038 }
2039
2040 String controlPanelCategory = themeDisplay.getControlPanelCategory();
2041 String currentURL = themeDisplay.getURLCurrent();
2042 String ppid = themeDisplay.getPpid();
2043 long scopeGroupId = themeDisplay.getScopeGroupId();
2044
2045 if (Validator.isNotNull(ppid)) {
2046 boolean switchGroup = ParamUtil.getBoolean(request, "switchGroup");
2047
2048 if (switchGroup &&
2049 !PortletPermissionUtil.hasControlPanelAccessPermission(
2050 permissionChecker, scopeGroupId, ppid)) {
2051
2052 String redirect = HttpUtil.removeParameter(
2053 currentURL, "p_p_id");
2054
2055 response.sendRedirect(redirect);
2056 }
2057 }
2058 else {
2059 if (Validator.isNull(controlPanelCategory)) {
2060 Map<String, List<Portlet>> categoriesMap =
2061 PortalUtil.getControlPanelCategoriesMap(request);
2062
2063 if (categoriesMap.size() == 1) {
2064 for (String curCategory : categoriesMap.keySet()) {
2065 List<Portlet> categoryPortlets = categoriesMap.get(
2066 curCategory);
2067
2068 if (categoryPortlets.size() == 1) {
2069 Portlet firstPortlet = categoryPortlets.get(0);
2070
2071 PortletURL redirectURL =
2072 PortalUtil.getSiteAdministrationURL(
2073 request, themeDisplay,
2074 firstPortlet.getPortletId());
2075
2076 response.sendRedirect(redirectURL.toString());
2077 }
2078 }
2079 }
2080 }
2081
2082 if (controlPanelCategory.startsWith(
2083 PortletCategoryKeys.CURRENT_SITE)) {
2084
2085 if (controlPanelCategory.indexOf(StringPool.PERIOD) == -1) {
2086 controlPanelCategory = StringUtil.replace(
2087 controlPanelCategory, PortletCategoryKeys.CURRENT_SITE,
2088 PortletCategoryKeys.SITE_ADMINISTRATION);
2089 }
2090 else {
2091 controlPanelCategory = StringUtil.replace(
2092 controlPanelCategory,
2093 PortletCategoryKeys.CURRENT_SITE + StringPool.PERIOD,
2094 PortletCategoryKeys.SITE_ADMINISTRATION);
2095 }
2096 }
2097
2098 if (controlPanelCategory.equals(
2099 PortletCategoryKeys.SITE_ADMINISTRATION)) {
2100
2101 Portlet firstPortlet =
2102 PortalUtil.getFirstSiteAdministrationPortlet(themeDisplay);
2103
2104 String redirect = HttpUtil.setParameter(
2105 currentURL, "p_p_id", firstPortlet.getPortletId());
2106
2107 response.sendRedirect(
2108 PortalUtil.getAbsoluteURL(request, redirect));
2109 }
2110 else {
2111 List<Portlet> portlets = PortalUtil.getControlPanelPortlets(
2112 controlPanelCategory, themeDisplay);
2113
2114 Portlet firstPortlet = null;
2115
2116 for (Portlet portlet : portlets) {
2117 if (PortletPermissionUtil.hasControlPanelAccessPermission(
2118 permissionChecker, scopeGroupId, portlet)) {
2119
2120 firstPortlet = portlet;
2121
2122 break;
2123 }
2124 }
2125
2126 if ((firstPortlet == null) &&
2127 controlPanelCategory.startsWith(
2128 PortletCategoryKeys.SITE_ADMINISTRATION)) {
2129
2130 firstPortlet = PortalUtil.getFirstSiteAdministrationPortlet(
2131 themeDisplay);
2132 }
2133
2134 if (firstPortlet != null) {
2135 String redirect = HttpUtil.setParameter(
2136 currentURL, "p_p_id", firstPortlet.getPortletId());
2137
2138 response.sendRedirect(
2139 PortalUtil.getAbsoluteURL(request, redirect));
2140 }
2141 }
2142 }
2143 }
2144
2145 protected void rememberVisitedGroupIds(
2146 HttpServletRequest request, long currentGroupId) {
2147
2148 String requestURI = GetterUtil.getString(request.getRequestURI());
2149
2150 if (!requestURI.endsWith(_PATH_PORTAL_LAYOUT)) {
2151 return;
2152 }
2153
2154 HttpSession session = request.getSession();
2155
2156 Long recentGroupId = (Long)session.getAttribute(
2157 WebKeys.VISITED_GROUP_ID_RECENT);
2158
2159 Long previousGroupId = (Long)session.getAttribute(
2160 WebKeys.VISITED_GROUP_ID_PREVIOUS);
2161
2162 if (recentGroupId == null) {
2163 recentGroupId = new Long(currentGroupId);
2164
2165 session.setAttribute(
2166 WebKeys.VISITED_GROUP_ID_RECENT, recentGroupId);
2167 }
2168 else if (recentGroupId.longValue() != currentGroupId) {
2169 previousGroupId = new Long(recentGroupId.longValue());
2170
2171 recentGroupId = new Long(currentGroupId);
2172
2173 session.setAttribute(
2174 WebKeys.VISITED_GROUP_ID_RECENT, recentGroupId);
2175
2176 session.setAttribute(
2177 WebKeys.VISITED_GROUP_ID_PREVIOUS, previousGroupId);
2178 }
2179
2180 if (_log.isDebugEnabled()) {
2181 _log.debug("Current group id " + currentGroupId);
2182 _log.debug("Recent group id " + recentGroupId);
2183 _log.debug("Previous group id " + previousGroupId);
2184 }
2185 }
2186
2187 protected void servicePre(
2188 HttpServletRequest request, HttpServletResponse response)
2189 throws Exception {
2190
2191 ThemeDisplay themeDisplay = initThemeDisplay(request, response);
2192
2193 if (themeDisplay == null) {
2194 return;
2195 }
2196
2197 request.setAttribute(WebKeys.THEME_DISPLAY, themeDisplay);
2198
2199
2200
2201 processControlPanelRedirects(request, response);
2202
2203
2204
2205 ServiceContext serviceContext = ServiceContextFactory.getInstance(
2206 request);
2207
2208 ServiceContextThreadLocal.pushServiceContext(serviceContext);
2209
2210
2211
2212 if (PropsValues.LAYOUT_AJAX_RENDER_ENABLE) {
2213 boolean portletAjaxRender = ParamUtil.getBoolean(
2214 request, "p_p_ajax", true);
2215
2216 request.setAttribute(
2217 WebKeys.PORTLET_AJAX_RENDER, portletAjaxRender);
2218 }
2219
2220
2221
2222 if (PropsValues.LAYOUT_PARALLEL_RENDER_ENABLE &&
2223 ServerDetector.isTomcat() && !PropsValues.TCK_URL) {
2224
2225 boolean portletParallelRender = ParamUtil.getBoolean(
2226 request, "p_p_parallel", true);
2227
2228 request.setAttribute(
2229 WebKeys.PORTLET_PARALLEL_RENDER, portletParallelRender);
2230 }
2231
2232
2233
2234 String strutsAction = PortalUtil.getStrutsAction(request);
2235
2236 if (strutsAction.equals(_PATH_PORTAL_LAYOUT)) {
2237 long mainJournalArticleId = ParamUtil.getLong(request, "p_j_a_id");
2238
2239 if (mainJournalArticleId > 0) {
2240 try {
2241 JournalArticle mainJournalArticle =
2242 JournalArticleServiceUtil.getArticle(
2243 mainJournalArticleId);
2244
2245 AssetEntry layoutAssetEntry =
2246 AssetEntryLocalServiceUtil.getEntry(
2247 JournalArticle.class.getName(),
2248 mainJournalArticle.getResourcePrimKey());
2249
2250 request.setAttribute(
2251 WebKeys.LAYOUT_ASSET_ENTRY, layoutAssetEntry);
2252 }
2253 catch (NoSuchArticleException nsae) {
2254 if (_log.isWarnEnabled()) {
2255 _log.warn(nsae.getMessage());
2256 }
2257 }
2258 }
2259 }
2260 }
2261
2262 protected void updateUserLayouts(User user) throws Exception {
2263 Boolean hasPowerUserRole = null;
2264
2265
2266
2267 boolean addDefaultUserPrivateLayouts = false;
2268
2269 if (PropsValues.LAYOUT_USER_PRIVATE_LAYOUTS_ENABLED &&
2270 PropsValues.LAYOUT_USER_PRIVATE_LAYOUTS_AUTO_CREATE) {
2271
2272 addDefaultUserPrivateLayouts = true;
2273
2274 if (PropsValues.LAYOUT_USER_PRIVATE_LAYOUTS_POWER_USER_REQUIRED) {
2275 if (hasPowerUserRole == null) {
2276 hasPowerUserRole = hasPowerUserRole(user);
2277 }
2278
2279 if (!hasPowerUserRole.booleanValue()) {
2280 addDefaultUserPrivateLayouts = false;
2281 }
2282 }
2283 }
2284
2285 Boolean hasPrivateLayouts = null;
2286
2287 if (addDefaultUserPrivateLayouts) {
2288 hasPrivateLayouts = LayoutLocalServiceUtil.hasLayouts(
2289 user, true, false);
2290
2291 if (!hasPrivateLayouts) {
2292 addDefaultUserPrivateLayouts(user);
2293 }
2294 }
2295
2296 boolean deleteDefaultUserPrivateLayouts = false;
2297
2298 if (!PropsValues.LAYOUT_USER_PRIVATE_LAYOUTS_ENABLED) {
2299 deleteDefaultUserPrivateLayouts = true;
2300 }
2301 else if (PropsValues.LAYOUT_USER_PRIVATE_LAYOUTS_POWER_USER_REQUIRED) {
2302 if (hasPowerUserRole == null) {
2303 hasPowerUserRole = hasPowerUserRole(user);
2304 }
2305
2306 if (!hasPowerUserRole.booleanValue()) {
2307 deleteDefaultUserPrivateLayouts = true;
2308 }
2309 }
2310
2311 if (deleteDefaultUserPrivateLayouts) {
2312 if (hasPrivateLayouts == null) {
2313 hasPrivateLayouts = LayoutLocalServiceUtil.hasLayouts(
2314 user, true, false);
2315 }
2316
2317 if (hasPrivateLayouts) {
2318 deleteDefaultUserPrivateLayouts(user);
2319 }
2320 }
2321
2322
2323
2324 boolean addDefaultUserPublicLayouts = false;
2325
2326 if (PropsValues.LAYOUT_USER_PUBLIC_LAYOUTS_ENABLED &&
2327 PropsValues.LAYOUT_USER_PUBLIC_LAYOUTS_AUTO_CREATE) {
2328
2329 addDefaultUserPublicLayouts = true;
2330
2331 if (PropsValues.LAYOUT_USER_PUBLIC_LAYOUTS_POWER_USER_REQUIRED) {
2332 if (hasPowerUserRole == null) {
2333 hasPowerUserRole = hasPowerUserRole(user);
2334 }
2335
2336 if (!hasPowerUserRole.booleanValue()) {
2337 addDefaultUserPublicLayouts = false;
2338 }
2339 }
2340 }
2341
2342 Boolean hasPublicLayouts = null;
2343
2344 if (addDefaultUserPublicLayouts) {
2345 hasPublicLayouts = LayoutLocalServiceUtil.hasLayouts(
2346 user, false, false);
2347
2348 if (!hasPublicLayouts) {
2349 addDefaultUserPublicLayouts(user);
2350 }
2351 }
2352
2353 boolean deleteDefaultUserPublicLayouts = false;
2354
2355 if (!PropsValues.LAYOUT_USER_PUBLIC_LAYOUTS_ENABLED) {
2356 deleteDefaultUserPublicLayouts = true;
2357 }
2358 else if (PropsValues.LAYOUT_USER_PUBLIC_LAYOUTS_POWER_USER_REQUIRED) {
2359 if (hasPowerUserRole == null) {
2360 hasPowerUserRole = hasPowerUserRole(user);
2361 }
2362
2363 if (!hasPowerUserRole.booleanValue()) {
2364 deleteDefaultUserPublicLayouts = true;
2365 }
2366 }
2367
2368 if (deleteDefaultUserPublicLayouts) {
2369 if (hasPublicLayouts == null) {
2370 hasPublicLayouts = LayoutLocalServiceUtil.hasLayouts(
2371 user, false, false);
2372 }
2373
2374 if (hasPublicLayouts) {
2375 deleteDefaultUserPublicLayouts(user);
2376 }
2377 }
2378 }
2379
2380 protected File privateLARFile;
2381 protected File publicLARFile;
2382
2383 private static final String _PATH_PORTAL_LAYOUT = "/portal/layout";
2384
2385 private static final String _PATH_PORTAL_LOGIN = "/portal/login";
2386
2387 private static final String _PATH_PORTAL_LOGOUT = "/portal/logout";
2388
2389 private static Log _log = LogFactoryUtil.getLog(ServicePreAction.class);
2390
2391 }