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