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