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