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