Source Code Cross Referenced for ServicePreAction.java in  » Portal » liferay-portal-4.4.2 » com » liferay » portal » events » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Portal » liferay portal 4.4.2 » com.liferay.portal.events 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /**
0002:         * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
0003:         *
0004:         * Permission is hereby granted, free of charge, to any person obtaining a copy
0005:         * of this software and associated documentation files (the "Software"), to deal
0006:         * in the Software without restriction, including without limitation the rights
0007:         * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
0008:         * copies of the Software, and to permit persons to whom the Software is
0009:         * furnished to do so, subject to the following conditions:
0010:         *
0011:         * The above copyright notice and this permission notice shall be included in
0012:         * all copies or substantial portions of the Software.
0013:         *
0014:         * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0015:         * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0016:         * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
0017:         * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
0018:         * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
0019:         * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
0020:         * SOFTWARE.
0021:         */package com.liferay.portal.events;
0022:
0023:        import com.liferay.portal.LayoutPermissionException;
0024:        import com.liferay.portal.NoSuchGroupException;
0025:        import com.liferay.portal.NoSuchLayoutException;
0026:        import com.liferay.portal.PortalException;
0027:        import com.liferay.portal.SystemException;
0028:        import com.liferay.portal.kernel.events.Action;
0029:        import com.liferay.portal.kernel.events.ActionException;
0030:        import com.liferay.portal.kernel.language.LanguageUtil;
0031:        import com.liferay.portal.kernel.lar.PortletDataHandlerKeys;
0032:        import com.liferay.portal.kernel.portlet.LiferayWindowState;
0033:        import com.liferay.portal.kernel.security.permission.ActionKeys;
0034:        import com.liferay.portal.kernel.security.permission.PermissionChecker;
0035:        import com.liferay.portal.kernel.servlet.BrowserSniffer;
0036:        import com.liferay.portal.kernel.servlet.ImageServletTokenUtil;
0037:        import com.liferay.portal.kernel.util.GetterUtil;
0038:        import com.liferay.portal.kernel.util.LocaleUtil;
0039:        import com.liferay.portal.kernel.util.NullSafeProperties;
0040:        import com.liferay.portal.kernel.util.ParamUtil;
0041:        import com.liferay.portal.kernel.util.PropertiesUtil;
0042:        import com.liferay.portal.kernel.util.StringPool;
0043:        import com.liferay.portal.kernel.util.StringUtil;
0044:        import com.liferay.portal.kernel.util.Validator;
0045:        import com.liferay.portal.model.ColorScheme;
0046:        import com.liferay.portal.model.Company;
0047:        import com.liferay.portal.model.Group;
0048:        import com.liferay.portal.model.Image;
0049:        import com.liferay.portal.model.Layout;
0050:        import com.liferay.portal.model.LayoutSet;
0051:        import com.liferay.portal.model.LayoutTypePortlet;
0052:        import com.liferay.portal.model.Theme;
0053:        import com.liferay.portal.model.User;
0054:        import com.liferay.portal.model.impl.ColorSchemeImpl;
0055:        import com.liferay.portal.model.impl.GroupImpl;
0056:        import com.liferay.portal.model.impl.LayoutImpl;
0057:        import com.liferay.portal.model.impl.LayoutTypePortletImpl;
0058:        import com.liferay.portal.model.impl.ThemeImpl;
0059:        import com.liferay.portal.security.permission.PermissionCheckerFactory;
0060:        import com.liferay.portal.security.permission.PermissionCheckerImpl;
0061:        import com.liferay.portal.security.permission.PermissionThreadLocal;
0062:        import com.liferay.portal.service.GroupLocalServiceUtil;
0063:        import com.liferay.portal.service.LayoutLocalServiceUtil;
0064:        import com.liferay.portal.service.OrganizationLocalServiceUtil;
0065:        import com.liferay.portal.service.UserLocalServiceUtil;
0066:        import com.liferay.portal.service.impl.ImageLocalUtil;
0067:        import com.liferay.portal.service.impl.ThemeLocalUtil;
0068:        import com.liferay.portal.service.permission.GroupPermissionUtil;
0069:        import com.liferay.portal.service.permission.LayoutPermissionUtil;
0070:        import com.liferay.portal.service.permission.OrganizationPermissionUtil;
0071:        import com.liferay.portal.service.permission.UserPermissionUtil;
0072:        import com.liferay.portal.theme.ThemeDisplay;
0073:        import com.liferay.portal.theme.ThemeDisplayFactory;
0074:        import com.liferay.portal.util.CookieKeys;
0075:        import com.liferay.portal.util.LayoutClone;
0076:        import com.liferay.portal.util.LayoutCloneFactory;
0077:        import com.liferay.portal.util.PortalUtil;
0078:        import com.liferay.portal.util.PortletKeys;
0079:        import com.liferay.portal.util.PropsUtil;
0080:        import com.liferay.portal.util.PropsValues;
0081:        import com.liferay.portal.util.WebKeys;
0082:        import com.liferay.portlet.PortletURLImpl;
0083:        import com.liferay.util.ListUtil;
0084:        import com.liferay.util.dao.hibernate.QueryUtil;
0085:        import com.liferay.util.servlet.SessionErrors;
0086:
0087:        import java.io.File;
0088:
0089:        import java.util.ArrayList;
0090:        import java.util.HashMap;
0091:        import java.util.LinkedHashMap;
0092:        import java.util.List;
0093:        import java.util.Locale;
0094:        import java.util.Map;
0095:        import java.util.Properties;
0096:        import java.util.TimeZone;
0097:
0098:        import javax.portlet.PortletMode;
0099:        import javax.portlet.PortletURL;
0100:        import javax.portlet.WindowState;
0101:
0102:        import javax.servlet.http.HttpServletRequest;
0103:        import javax.servlet.http.HttpServletResponse;
0104:        import javax.servlet.http.HttpSession;
0105:
0106:        import org.apache.commons.lang.time.StopWatch;
0107:        import org.apache.commons.logging.Log;
0108:        import org.apache.commons.logging.LogFactory;
0109:        import org.apache.struts.Globals;
0110:
0111:        /**
0112:         * <a href="ServicePreAction.java.html"><b><i>View Source</i></b></a>
0113:         *
0114:         * @author Brian Wing Shun Chan
0115:         * @author Felix Ventero
0116:         *
0117:         */
0118:        public class ServicePreAction extends Action {
0119:
0120:            public ServicePreAction() {
0121:                initImportLARFiles();
0122:            }
0123:
0124:            public void run(HttpServletRequest req, HttpServletResponse res)
0125:                    throws ActionException {
0126:
0127:                StopWatch stopWatch = null;
0128:
0129:                if (_log.isDebugEnabled()) {
0130:                    stopWatch = new StopWatch();
0131:
0132:                    stopWatch.start();
0133:                }
0134:
0135:                try {
0136:                    servicePre(req, res);
0137:                } catch (Exception e) {
0138:                    _log.error(e, e);
0139:
0140:                    throw new ActionException(e);
0141:                }
0142:
0143:                if (_log.isDebugEnabled()) {
0144:                    _log.debug("Running takes " + stopWatch.getTime() + " ms");
0145:                }
0146:            }
0147:
0148:            protected void addDefaultLayouts(User user) throws PortalException,
0149:                    SystemException {
0150:
0151:                if (user.hasPrivateLayouts()) {
0152:                    return;
0153:                }
0154:
0155:                Group userGroup = user.getGroup();
0156:
0157:                if (privateLARFile != null) {
0158:                    importLayoutsByLAR(user.getUserId(),
0159:                            userGroup.getGroupId(), true, privateLARFile);
0160:                } else {
0161:                    importLayoutsByProperties(user.getUserId(), userGroup
0162:                            .getGroupId());
0163:                }
0164:
0165:                if (publicLARFile != null) {
0166:                    importLayoutsByLAR(user.getUserId(),
0167:                            userGroup.getGroupId(), false, publicLARFile);
0168:                }
0169:            }
0170:
0171:            protected void deleteDefaultLayouts(User user)
0172:                    throws PortalException, SystemException {
0173:
0174:                if (user.hasPrivateLayouts()) {
0175:                    Group userGroup = user.getGroup();
0176:
0177:                    LayoutLocalServiceUtil.deleteLayouts(
0178:                            userGroup.getGroupId(), true);
0179:                }
0180:
0181:                if (user.hasPublicLayouts()) {
0182:                    Group userGroup = user.getGroup();
0183:
0184:                    LayoutLocalServiceUtil.deleteLayouts(
0185:                            userGroup.getGroupId(), false);
0186:                }
0187:            }
0188:
0189:            protected void fixState(HttpServletRequest req,
0190:                    ThemeDisplay themeDisplay) throws PortalException,
0191:                    SystemException {
0192:
0193:                String requestURI = GetterUtil.getString(req.getRequestURI());
0194:
0195:                if (!requestURI.endsWith("/portal/layout")) {
0196:                    return;
0197:                }
0198:
0199:                Layout layout = themeDisplay.getLayout();
0200:
0201:                if ((layout == null)
0202:                        || (!layout.getType().equals(LayoutImpl.TYPE_PORTLET))) {
0203:
0204:                    return;
0205:                }
0206:
0207:                LayoutTypePortlet layoutTypePortlet = themeDisplay
0208:                        .getLayoutTypePortlet();
0209:
0210:                // Fix pop up state
0211:
0212:                String stateMaxPrevious = layoutTypePortlet
0213:                        .getStateMaxPrevious();
0214:
0215:                if (stateMaxPrevious != null && !themeDisplay.isStatePopUp()) {
0216:                    layoutTypePortlet.removeStateMaxPrevious();
0217:
0218:                    if (stateMaxPrevious.equals(StringPool.BLANK)) {
0219:                        layoutTypePortlet.setStateMax(StringPool.BLANK);
0220:                    } else {
0221:                        layoutTypePortlet.setStateMax(stateMaxPrevious);
0222:                    }
0223:                }
0224:
0225:                // Fix maximized state
0226:
0227:                if (layoutTypePortlet.hasStateMax()) {
0228:                    String portletId = StringUtil.split(layoutTypePortlet
0229:                            .getStateMax())[0];
0230:
0231:                    boolean removeStateMax = false;
0232:
0233:                    if (!PropsValues.LAYOUT_REMEMBER_REQUEST_WINDOW_STATE_MAXIMIZED
0234:                            && Validator.isNotNull(portletId)) {
0235:
0236:                        removeStateMax = true;
0237:                    }
0238:
0239:                    // If a user accesses a maximized portlet that is not a part of the
0240:                    // layout, the maximized portlet should be removed the next time the
0241:                    // layout is accessed.
0242:
0243:                    if (!layoutTypePortlet.hasPortletId(portletId)) {
0244:                        removeStateMax = true;
0245:                    }
0246:
0247:                    if (removeStateMax) {
0248:                        String ppState = ParamUtil.getString(req, "p_p_state");
0249:
0250:                        if (Validator.isNull(ppState)
0251:                                || ppState
0252:                                        .equals(WindowState.NORMAL.toString())) {
0253:
0254:                            layoutTypePortlet
0255:                                    .removeStateMaxPortletId(portletId);
0256:                        }
0257:                    }
0258:                }
0259:            }
0260:
0261:            protected Object[] getDefaultLayout(HttpServletRequest req,
0262:                    User user, boolean signedIn) throws PortalException,
0263:                    SystemException {
0264:
0265:                // Check the virtual host
0266:
0267:                LayoutSet layoutSet = (LayoutSet) req
0268:                        .getAttribute(WebKeys.VIRTUAL_HOST_LAYOUT_SET);
0269:
0270:                if (layoutSet != null) {
0271:                    List layouts = LayoutLocalServiceUtil.getLayouts(layoutSet
0272:                            .getGroupId(), layoutSet.isPrivateLayout(),
0273:                            LayoutImpl.DEFAULT_PARENT_LAYOUT_ID);
0274:
0275:                    if (layouts.size() > 0) {
0276:                        Layout layout = (Layout) layouts.get(0);
0277:
0278:                        return new Object[] { layout, layouts };
0279:                    }
0280:                }
0281:
0282:                Layout layout = null;
0283:                List layouts = null;
0284:
0285:                if (signedIn) {
0286:
0287:                    // Check the user's personal layouts
0288:
0289:                    Group userGroup = user.getGroup();
0290:
0291:                    layouts = LayoutLocalServiceUtil.getLayouts(userGroup
0292:                            .getGroupId(), true,
0293:                            LayoutImpl.DEFAULT_PARENT_LAYOUT_ID);
0294:
0295:                    if (layouts.size() == 0) {
0296:                        layouts = LayoutLocalServiceUtil.getLayouts(userGroup
0297:                                .getGroupId(), false,
0298:                                LayoutImpl.DEFAULT_PARENT_LAYOUT_ID);
0299:                    }
0300:
0301:                    if (layouts.size() > 0) {
0302:                        layout = (Layout) layouts.get(0);
0303:                    }
0304:
0305:                    // Check the user's communities
0306:
0307:                    if (layout == null) {
0308:                        LinkedHashMap groupParams = new LinkedHashMap();
0309:
0310:                        groupParams.put("usersGroups", new Long(user
0311:                                .getUserId()));
0312:
0313:                        List groups = GroupLocalServiceUtil.search(user
0314:                                .getCompanyId(), null, null, groupParams,
0315:                                QueryUtil.ALL_POS, QueryUtil.ALL_POS);
0316:
0317:                        for (int i = 0; i < groups.size(); i++) {
0318:                            Group group = (Group) groups.get(i);
0319:
0320:                            layouts = LayoutLocalServiceUtil.getLayouts(group
0321:                                    .getGroupId(), true,
0322:                                    LayoutImpl.DEFAULT_PARENT_LAYOUT_ID);
0323:
0324:                            if (layouts.size() == 0) {
0325:                                layouts = LayoutLocalServiceUtil.getLayouts(
0326:                                        group.getGroupId(), false,
0327:                                        LayoutImpl.DEFAULT_PARENT_LAYOUT_ID);
0328:                            }
0329:
0330:                            if (layouts.size() > 0) {
0331:                                layout = (Layout) layouts.get(0);
0332:
0333:                                break;
0334:                            }
0335:                        }
0336:                    }
0337:                } else {
0338:
0339:                    // Check the guest community
0340:
0341:                    Group guestGroup = GroupLocalServiceUtil.getGroup(user
0342:                            .getCompanyId(), GroupImpl.GUEST);
0343:
0344:                    layouts = LayoutLocalServiceUtil.getLayouts(guestGroup
0345:                            .getGroupId(), false,
0346:                            LayoutImpl.DEFAULT_PARENT_LAYOUT_ID);
0347:
0348:                    if (layouts.size() > 0) {
0349:                        layout = (Layout) layouts.get(0);
0350:                    }
0351:                }
0352:
0353:                return new Object[] { layout, layouts };
0354:            }
0355:
0356:            protected void importLayoutsByLAR(long userId, long groupId,
0357:                    boolean privateLayout, File larFile)
0358:                    throws PortalException, SystemException {
0359:
0360:                Map parameterMap = new HashMap();
0361:
0362:                parameterMap.put(PortletDataHandlerKeys.PERMISSIONS,
0363:                        Boolean.TRUE.toString());
0364:                parameterMap.put(PortletDataHandlerKeys.USER_PERMISSIONS,
0365:                        Boolean.FALSE.toString());
0366:                parameterMap.put(PortletDataHandlerKeys.PORTLET_DATA,
0367:                        Boolean.TRUE.toString());
0368:                parameterMap.put(
0369:                        PortletDataHandlerKeys.PORTLET_DATA_CONTROL_DEFAULT,
0370:                        Boolean.TRUE.toString());
0371:                parameterMap.put(PortletDataHandlerKeys.PORTLET_SETUP,
0372:                        Boolean.TRUE.toString());
0373:
0374:                LayoutLocalServiceUtil.importLayouts(userId, groupId,
0375:                        privateLayout, parameterMap, larFile);
0376:            }
0377:
0378:            protected void importLayoutsByProperties(long userId, long groupId)
0379:                    throws PortalException, SystemException {
0380:
0381:                String name = PropsValues.DEFAULT_USER_LAYOUT_NAME;
0382:
0383:                Layout layout = LayoutLocalServiceUtil.addLayout(userId,
0384:                        groupId, true, LayoutImpl.DEFAULT_PARENT_LAYOUT_ID,
0385:                        name, StringPool.BLANK, StringPool.BLANK,
0386:                        LayoutImpl.TYPE_PORTLET, false, StringPool.BLANK);
0387:
0388:                LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) layout
0389:                        .getLayoutType();
0390:
0391:                String layoutTemplateId = PropsValues.DEFAULT_USER_LAYOUT_TEMPLATE_ID;
0392:
0393:                layoutTypePortlet.setLayoutTemplateId(0, layoutTemplateId,
0394:                        false);
0395:
0396:                for (int i = 0; i < 10; i++) {
0397:                    String columnId = "column-" + i;
0398:                    String portletIds = PropsUtil
0399:                            .get(PropsUtil.DEFAULT_USER_LAYOUT_COLUMN + i);
0400:
0401:                    String[] portletIdsArray = StringUtil.split(portletIds);
0402:
0403:                    layoutTypePortlet.addPortletIds(0, portletIdsArray,
0404:                            columnId, false);
0405:                }
0406:
0407:                LayoutLocalServiceUtil.updateLayout(layout.getGroupId(), layout
0408:                        .isPrivateLayout(), layout.getLayoutId(), layout
0409:                        .getTypeSettings());
0410:            }
0411:
0412:            protected Object[] getViewableLayouts(HttpServletRequest req,
0413:                    User user, PermissionChecker permissionChecker,
0414:                    Layout layout, List layouts) throws PortalException,
0415:                    SystemException {
0416:
0417:                if ((layouts != null) && (layouts.size() > 0)) {
0418:                    boolean replaceLayout = true;
0419:
0420:                    if (LayoutPermissionUtil.contains(permissionChecker,
0421:                            layout, ActionKeys.VIEW)) {
0422:
0423:                        replaceLayout = false;
0424:                    }
0425:
0426:                    List accessibleLayouts = new ArrayList();
0427:
0428:                    for (int i = 0; i < layouts.size(); i++) {
0429:                        Layout curLayout = (Layout) layouts.get(i);
0430:
0431:                        if (!curLayout.isHidden()
0432:                                && LayoutPermissionUtil.contains(
0433:                                        permissionChecker, curLayout,
0434:                                        ActionKeys.VIEW)) {
0435:
0436:                            if ((accessibleLayouts.size() == 0)
0437:                                    && replaceLayout) {
0438:                                layout = curLayout;
0439:                            }
0440:
0441:                            accessibleLayouts.add(curLayout);
0442:                        }
0443:                    }
0444:
0445:                    if (accessibleLayouts.size() == 0) {
0446:                        layouts = null;
0447:
0448:                        SessionErrors.add(req, LayoutPermissionException.class
0449:                                .getName());
0450:                    } else {
0451:                        layouts = accessibleLayouts;
0452:                    }
0453:                }
0454:
0455:                return new Object[] { layout, layouts };
0456:            }
0457:
0458:            protected void initImportLARFiles() {
0459:                String privateLARFileName = PropsValues.DEFAULT_USER_PRIVATE_LAYOUT_LAR;
0460:
0461:                if (_log.isDebugEnabled()) {
0462:                    _log
0463:                            .debug("Reading private LAR file "
0464:                                    + privateLARFileName);
0465:                }
0466:
0467:                if (Validator.isNotNull(privateLARFileName)) {
0468:                    privateLARFile = new File(privateLARFileName);
0469:
0470:                    if (!privateLARFile.exists()) {
0471:                        _log.error("Private LAR file " + privateLARFile
0472:                                + " does not exist");
0473:
0474:                        privateLARFile = null;
0475:                    } else {
0476:                        if (_log.isDebugEnabled()) {
0477:                            _log.debug("Using private LAR file "
0478:                                    + privateLARFileName);
0479:                        }
0480:                    }
0481:                }
0482:
0483:                String publicLARFileName = PropsValues.DEFAULT_USER_PUBLIC_LAYOUT_LAR;
0484:
0485:                if (_log.isDebugEnabled()) {
0486:                    _log.debug("Reading public LAR file " + publicLARFileName);
0487:                }
0488:
0489:                if (Validator.isNotNull(publicLARFileName)) {
0490:                    publicLARFile = new File(publicLARFileName);
0491:
0492:                    if (!publicLARFile.exists()) {
0493:                        _log.error("Public LAR file " + publicLARFile
0494:                                + " does not exist");
0495:
0496:                        publicLARFile = null;
0497:                    } else {
0498:                        if (_log.isDebugEnabled()) {
0499:                            _log.debug("Using public LAR file "
0500:                                    + publicLARFileName);
0501:                        }
0502:                    }
0503:                }
0504:            }
0505:
0506:            protected boolean isViewableCommunity(User user, long groupId,
0507:                    boolean privateLayout, PermissionChecker permissionChecker)
0508:                    throws PortalException, SystemException {
0509:
0510:                Group group = GroupLocalServiceUtil.getGroup(groupId);
0511:
0512:                // Inactive communities are not viewable
0513:
0514:                if (!group.isActive()) {
0515:                    return false;
0516:                } else if (group.isStagingGroup()) {
0517:                    Group liveGroup = group.getLiveGroup();
0518:
0519:                    if (!liveGroup.isActive()) {
0520:                        return false;
0521:                    }
0522:                }
0523:
0524:                // User private layouts are only viewable by the user and anyone who can
0525:                // update the user. The user must also be active.
0526:
0527:                if (group.isUser()) {
0528:                    long groupUserId = group.getClassPK();
0529:
0530:                    if (groupUserId == user.getUserId()) {
0531:                        return true;
0532:                    } else {
0533:                        User groupUser = UserLocalServiceUtil
0534:                                .getUserById(groupUserId);
0535:
0536:                        if (!groupUser.isActive()) {
0537:                            return false;
0538:                        }
0539:
0540:                        if (privateLayout) {
0541:                            if (UserPermissionUtil.contains(permissionChecker,
0542:                                    groupUserId,
0543:                                    groupUser.getOrganizationIds(),
0544:                                    ActionKeys.UPDATE)) {
0545:
0546:                                return true;
0547:                            } else {
0548:                                return false;
0549:                            }
0550:                        }
0551:                    }
0552:                }
0553:
0554:                // Most public layouts are viewable
0555:
0556:                if (!privateLayout) {
0557:                    return true;
0558:                }
0559:
0560:                // If the current group is staging, the live group should be checked
0561:                // for membership instead
0562:
0563:                if (group.isStagingGroup()) {
0564:                    groupId = group.getLiveGroupId();
0565:                }
0566:
0567:                // Community or organization layouts are only viewable by users who
0568:                // belong to the community or organization, or by users who can update
0569:                // the community or organization
0570:
0571:                if (group.isCommunity()) {
0572:                    if (GroupLocalServiceUtil.hasUserGroup(user.getUserId(),
0573:                            groupId)) {
0574:                        return true;
0575:                    } else if (GroupPermissionUtil.contains(permissionChecker,
0576:                            groupId, ActionKeys.UPDATE)) {
0577:
0578:                        return true;
0579:                    }
0580:                } else if (group.isOrganization()) {
0581:                    long organizationId = group.getClassPK();
0582:
0583:                    if (OrganizationLocalServiceUtil.hasUserOrganization(user
0584:                            .getUserId(), organizationId)) {
0585:
0586:                        return true;
0587:                    } else if (OrganizationPermissionUtil.contains(
0588:                            permissionChecker, organizationId,
0589:                            ActionKeys.UPDATE)) {
0590:
0591:                        return true;
0592:                    }
0593:                }
0594:
0595:                return false;
0596:            }
0597:
0598:            protected List mergeAdditionalLayouts(User user, Layout layout,
0599:                    List layouts, HttpServletRequest req)
0600:                    throws PortalException, SystemException {
0601:
0602:                if ((layout == null) || layout.isPrivateLayout()) {
0603:                    return layouts;
0604:                }
0605:
0606:                long layoutGroupId = layout.getGroupId();
0607:
0608:                Group guestGroup = GroupLocalServiceUtil.getGroup(user
0609:                        .getCompanyId(), GroupImpl.GUEST);
0610:
0611:                if (layoutGroupId != guestGroup.getGroupId()) {
0612:                    Group layoutGroup = GroupLocalServiceUtil
0613:                            .getGroup(layoutGroupId);
0614:
0615:                    Properties props = layoutGroup.getTypeSettingsProperties();
0616:
0617:                    boolean mergeGuestPublicPages = GetterUtil.getBoolean(props
0618:                            .getProperty("mergeGuestPublicPages"));
0619:
0620:                    if (!mergeGuestPublicPages) {
0621:                        return layouts;
0622:                    }
0623:
0624:                    List guestLayouts = LayoutLocalServiceUtil.getLayouts(
0625:                            guestGroup.getGroupId(), false,
0626:                            LayoutImpl.DEFAULT_PARENT_LAYOUT_ID);
0627:
0628:                    layouts.addAll(0, guestLayouts);
0629:                } else {
0630:                    HttpSession ses = req.getSession();
0631:
0632:                    Long previousGroupId = (Long) ses
0633:                            .getAttribute(WebKeys.LIFERAY_SHARED_VISITED_GROUP_ID_PREVIOUS);
0634:
0635:                    if ((previousGroupId != null)
0636:                            && (previousGroupId.longValue() != layoutGroupId)) {
0637:
0638:                        Group previousGroup = null;
0639:
0640:                        try {
0641:                            previousGroup = GroupLocalServiceUtil
0642:                                    .getGroup(previousGroupId.longValue());
0643:                        } catch (NoSuchGroupException nsge) {
0644:                            if (_log.isWarnEnabled()) {
0645:                                _log.warn(nsge);
0646:                            }
0647:
0648:                            return layouts;
0649:                        }
0650:
0651:                        Properties props = previousGroup
0652:                                .getTypeSettingsProperties();
0653:
0654:                        boolean mergeGuestPublicPages = GetterUtil
0655:                                .getBoolean(props
0656:                                        .getProperty("mergeGuestPublicPages"));
0657:
0658:                        if (!mergeGuestPublicPages) {
0659:                            return layouts;
0660:                        }
0661:
0662:                        List previousLayouts = LayoutLocalServiceUtil
0663:                                .getLayouts(previousGroupId.longValue(), false,
0664:                                        LayoutImpl.DEFAULT_PARENT_LAYOUT_ID);
0665:
0666:                        layouts.addAll(previousLayouts);
0667:                    }
0668:                }
0669:
0670:                return layouts;
0671:            }
0672:
0673:            protected void rememberVisitedGroupIds(long currentGroupId,
0674:                    HttpServletRequest req) {
0675:
0676:                String requestURI = GetterUtil.getString(req.getRequestURI());
0677:
0678:                if (!requestURI.endsWith(_PATH_PORTAL_LAYOUT)) {
0679:                    return;
0680:                }
0681:
0682:                HttpSession ses = req.getSession();
0683:
0684:                Long recentGroupId = (Long) ses
0685:                        .getAttribute(WebKeys.LIFERAY_SHARED_VISITED_GROUP_ID_RECENT);
0686:
0687:                Long previousGroupId = (Long) ses
0688:                        .getAttribute(WebKeys.LIFERAY_SHARED_VISITED_GROUP_ID_PREVIOUS);
0689:
0690:                if (recentGroupId == null) {
0691:                    recentGroupId = new Long(currentGroupId);
0692:
0693:                    ses.setAttribute(
0694:                            WebKeys.LIFERAY_SHARED_VISITED_GROUP_ID_RECENT,
0695:                            recentGroupId);
0696:                } else if (recentGroupId.longValue() != currentGroupId) {
0697:                    previousGroupId = new Long(recentGroupId.longValue());
0698:
0699:                    recentGroupId = new Long(currentGroupId);
0700:
0701:                    ses.setAttribute(
0702:                            WebKeys.LIFERAY_SHARED_VISITED_GROUP_ID_RECENT,
0703:                            recentGroupId);
0704:
0705:                    ses.setAttribute(
0706:                            WebKeys.LIFERAY_SHARED_VISITED_GROUP_ID_PREVIOUS,
0707:                            previousGroupId);
0708:                }
0709:
0710:                if (_log.isDebugEnabled()) {
0711:                    _log.debug("Current group id " + currentGroupId);
0712:                    _log.debug("Recent group id " + recentGroupId);
0713:                    _log.debug("Previous group id " + previousGroupId);
0714:                }
0715:            }
0716:
0717:            protected void servicePre(HttpServletRequest req,
0718:                    HttpServletResponse res) throws Exception {
0719:
0720:                HttpSession ses = req.getSession();
0721:
0722:                // Company
0723:
0724:                Company company = PortalUtil.getCompany(req);
0725:
0726:                long companyId = company.getCompanyId();
0727:
0728:                // CDN host
0729:
0730:                String cdnHost = ParamUtil.getString(req, "cdn_host",
0731:                        PortalUtil.getCDNHost());
0732:
0733:                // Paths
0734:
0735:                String contextPath = PortalUtil.getPathContext();
0736:                String friendlyURLPrivateGroupPath = PortalUtil
0737:                        .getPathFriendlyURLPrivateGroup();
0738:                String friendlyURLPrivateUserPath = PortalUtil
0739:                        .getPathFriendlyURLPrivateUser();
0740:                String friendlyURLPublicPath = PortalUtil
0741:                        .getPathFriendlyURLPublic();
0742:                String imagePath = PortalUtil.getPathImage();
0743:                String mainPath = PortalUtil.getPathMain();
0744:
0745:                // Company logo
0746:
0747:                String companyLogo = imagePath + "/company_logo?img_id="
0748:                        + company.getLogoId() + "&t="
0749:                        + ImageServletTokenUtil.getToken(company.getLogoId());
0750:
0751:                Image companyLogoImage = ImageLocalUtil.getCompanyLogo(company
0752:                        .getLogoId());
0753:
0754:                int companyLogoHeight = companyLogoImage.getHeight();
0755:                int companyLogoWidth = companyLogoImage.getWidth();
0756:
0757:                String realCompanyLogo = companyLogo;
0758:                int realCompanyLogoHeight = companyLogoHeight;
0759:                int realCompanyLogoWidth = companyLogoWidth;
0760:
0761:                // User
0762:
0763:                User user = PortalUtil.getUser(req);
0764:
0765:                boolean signedIn = false;
0766:
0767:                if (user == null) {
0768:                    user = company.getDefaultUser();
0769:                } else if (!user.isDefaultUser()) {
0770:                    signedIn = true;
0771:                }
0772:
0773:                User realUser = user;
0774:
0775:                Long realUserId = (Long) ses.getAttribute(WebKeys.USER_ID);
0776:
0777:                if (realUserId != null) {
0778:                    if (user.getUserId() != realUserId.longValue()) {
0779:                        realUser = UserLocalServiceUtil.getUserById(realUserId
0780:                                .longValue());
0781:                    }
0782:                }
0783:
0784:                String doAsUserId = ParamUtil.getString(req, "doAsUserId");
0785:
0786:                // Permission checker
0787:
0788:                PermissionCheckerImpl permissionChecker = PermissionCheckerFactory
0789:                        .create(user, true);
0790:
0791:                PermissionThreadLocal.setPermissionChecker(permissionChecker);
0792:
0793:                // Locale
0794:
0795:                Locale locale = (Locale) ses.getAttribute(Globals.LOCALE_KEY);
0796:
0797:                if (locale == null) {
0798:                    if (signedIn) {
0799:                        locale = user.getLocale();
0800:                    } else {
0801:
0802:                        // User previously set their preferred language
0803:
0804:                        String languageId = CookieKeys.getCookie(req,
0805:                                CookieKeys.GUEST_LANGUAGE_ID);
0806:
0807:                        if (Validator.isNotNull(languageId)) {
0808:                            locale = LocaleUtil.fromLanguageId(languageId);
0809:                        }
0810:
0811:                        // Get locale from the request
0812:
0813:                        if ((locale == null)
0814:                                && PropsValues.LOCALE_DEFAULT_REQUEST) {
0815:                            locale = req.getLocale();
0816:                        }
0817:
0818:                        // Get locale from the default user
0819:
0820:                        if (locale == null) {
0821:                            locale = user.getLocale();
0822:                        }
0823:
0824:                        if (Validator.isNull(locale.getCountry())) {
0825:
0826:                            // Locales must contain the country code
0827:
0828:                            locale = LanguageUtil.getLocale(locale
0829:                                    .getLanguage());
0830:                        }
0831:
0832:                        List availableLocales = ListUtil.fromArray(LanguageUtil
0833:                                .getAvailableLocales());
0834:
0835:                        if (!availableLocales.contains(locale)) {
0836:                            locale = user.getLocale();
0837:                        }
0838:                    }
0839:
0840:                    ses.setAttribute(Globals.LOCALE_KEY, locale);
0841:
0842:                    LanguageUtil.updateCookie(res, locale);
0843:                }
0844:
0845:                // Cookie support
0846:
0847:                try {
0848:
0849:                    // LEP-4069
0850:
0851:                    CookieKeys.validateSupportCookie(req);
0852:                } catch (Exception e) {
0853:                    CookieKeys.addSupportCookie(res);
0854:                }
0855:
0856:                // Time zone
0857:
0858:                TimeZone timeZone = user.getTimeZone();
0859:
0860:                if (timeZone == null) {
0861:                    timeZone = company.getTimeZone();
0862:                }
0863:
0864:                // Layouts
0865:
0866:                if (signedIn) {
0867:                    boolean layoutsRequired = user.isLayoutsRequired();
0868:
0869:                    if (layoutsRequired) {
0870:                        addDefaultLayouts(user);
0871:                    } else {
0872:                        deleteDefaultLayouts(user);
0873:                    }
0874:                }
0875:
0876:                Layout layout = null;
0877:                List layouts = null;
0878:
0879:                long plid = ParamUtil.getLong(req, "p_l_id");
0880:
0881:                if (plid > 0) {
0882:                    layout = LayoutLocalServiceUtil.getLayout(plid);
0883:                } else {
0884:                    long groupId = ParamUtil.getLong(req, "groupId");
0885:                    boolean privateLayout = ParamUtil.getBoolean(req,
0886:                            "privateLayout");
0887:                    long layoutId = ParamUtil.getLong(req, "layoutId");
0888:
0889:                    if ((groupId > 0) && layoutId > 0) {
0890:                        layout = LayoutLocalServiceUtil.getLayout(groupId,
0891:                                privateLayout, layoutId);
0892:                    }
0893:                }
0894:
0895:                if (layout != null) {
0896:                    try {
0897:                        if (!signedIn && PropsValues.AUTH_FORWARD_BY_REDIRECT) {
0898:                            req.setAttribute(WebKeys.REQUESTED_LAYOUT, layout);
0899:                        }
0900:
0901:                        boolean isViewableCommunity = isViewableCommunity(user,
0902:                                layout.getGroupId(), layout.isPrivateLayout(),
0903:                                permissionChecker);
0904:
0905:                        if (!isViewableCommunity) {
0906:                            layout = null;
0907:                        } else if (isViewableCommunity
0908:                                && !LayoutPermissionUtil.contains(
0909:                                        permissionChecker, layout,
0910:                                        ActionKeys.VIEW)) {
0911:
0912:                            layout = null;
0913:                        } else {
0914:                            layouts = LayoutLocalServiceUtil.getLayouts(layout
0915:                                    .getGroupId(), layout.isPrivateLayout(),
0916:                                    LayoutImpl.DEFAULT_PARENT_LAYOUT_ID);
0917:                        }
0918:                    } catch (NoSuchLayoutException nsle) {
0919:                    }
0920:                }
0921:
0922:                if (layout == null) {
0923:                    Object[] defaultLayout = getDefaultLayout(req, user,
0924:                            signedIn);
0925:
0926:                    layout = (Layout) defaultLayout[0];
0927:                    layouts = (List) defaultLayout[1];
0928:
0929:                    req.setAttribute(WebKeys.LAYOUT_DEFAULT, Boolean.TRUE);
0930:                }
0931:
0932:                Object[] viewableLayouts = getViewableLayouts(req, user,
0933:                        permissionChecker, layout, layouts);
0934:
0935:                String layoutSetLogo = null;
0936:
0937:                layout = (Layout) viewableLayouts[0];
0938:                layouts = (List) viewableLayouts[1];
0939:
0940:                long portletGroupId = PortalUtil.getPortletGroupId(layout);
0941:
0942:                rememberVisitedGroupIds(portletGroupId, req);
0943:
0944:                layouts = mergeAdditionalLayouts(user, layout, layouts, req);
0945:
0946:                if (layout != null) {
0947:                    if (company.isCommunityLogo()) {
0948:                        LayoutSet layoutSet = layout.getLayoutSet();
0949:
0950:                        if (layoutSet.isLogo()) {
0951:                            long logoId = layoutSet.getLogoId();
0952:
0953:                            layoutSetLogo = imagePath
0954:                                    + "/layout_set_logo?img_id=" + logoId
0955:                                    + "&t="
0956:                                    + ImageServletTokenUtil.getToken(logoId);
0957:
0958:                            Image layoutSetLogoImage = ImageLocalUtil
0959:                                    .getCompanyLogo(logoId);
0960:
0961:                            companyLogo = layoutSetLogo;
0962:                            companyLogoHeight = layoutSetLogoImage.getHeight();
0963:                            companyLogoWidth = layoutSetLogoImage.getWidth();
0964:                        }
0965:                    }
0966:
0967:                    plid = layout.getPlid();
0968:                }
0969:
0970:                if (layout != null) {
0971:
0972:                    // Updates to shared layouts are not reflected until the next time
0973:                    // the user logs in because group layouts are cached in the session
0974:
0975:                    layout = (Layout) ((LayoutImpl) layout).clone();
0976:
0977:                    LayoutClone layoutClone = LayoutCloneFactory.getInstance();
0978:
0979:                    if (layoutClone != null) {
0980:                        String typeSettings = layoutClone.get(req, layout
0981:                                .getPlid());
0982:
0983:                        if (typeSettings != null) {
0984:                            Properties props = new NullSafeProperties();
0985:
0986:                            PropertiesUtil.load(props, typeSettings);
0987:
0988:                            String stateMax = props
0989:                                    .getProperty(LayoutTypePortletImpl.STATE_MAX);
0990:                            String stateMaxPrevious = props
0991:                                    .getProperty(LayoutTypePortletImpl.STATE_MAX_PREVIOUS);
0992:                            String stateMin = props
0993:                                    .getProperty(LayoutTypePortletImpl.STATE_MIN);
0994:                            String modeAbout = props
0995:                                    .getProperty(LayoutTypePortletImpl.MODE_ABOUT);
0996:                            String modeConfig = props
0997:                                    .getProperty(LayoutTypePortletImpl.MODE_CONFIG);
0998:                            String modeEdit = props
0999:                                    .getProperty(LayoutTypePortletImpl.MODE_EDIT);
1000:                            String modeEditDefaults = props
1001:                                    .getProperty(LayoutTypePortletImpl.MODE_EDIT_DEFAULTS);
1002:                            String modeEditGuest = props
1003:                                    .getProperty(LayoutTypePortletImpl.MODE_EDIT_GUEST);
1004:                            String modeHelp = props
1005:                                    .getProperty(LayoutTypePortletImpl.MODE_HELP);
1006:                            String modePreview = props
1007:                                    .getProperty(LayoutTypePortletImpl.MODE_PREVIEW);
1008:                            String modePrint = props
1009:                                    .getProperty(LayoutTypePortletImpl.MODE_PRINT);
1010:
1011:                            LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) layout
1012:                                    .getLayoutType();
1013:
1014:                            layoutTypePortlet.setStateMax(stateMax);
1015:                            layoutTypePortlet
1016:                                    .setStateMaxPrevious(stateMaxPrevious);
1017:                            layoutTypePortlet.setStateMin(stateMin);
1018:                            layoutTypePortlet.setModeAbout(modeAbout);
1019:                            layoutTypePortlet.setModeConfig(modeConfig);
1020:                            layoutTypePortlet.setModeEdit(modeEdit);
1021:                            layoutTypePortlet
1022:                                    .setModeEditDefaults(modeEditDefaults);
1023:                            layoutTypePortlet.setModeEditGuest(modeEditGuest);
1024:                            layoutTypePortlet.setModeHelp(modeHelp);
1025:                            layoutTypePortlet.setModePreview(modePreview);
1026:                            layoutTypePortlet.setModePrint(modePrint);
1027:                        }
1028:                    }
1029:                }
1030:
1031:                LayoutTypePortlet layoutTypePortlet = null;
1032:
1033:                if (layout != null) {
1034:                    req.setAttribute(WebKeys.LAYOUT, layout);
1035:                    req.setAttribute(WebKeys.LAYOUTS, layouts);
1036:
1037:                    layoutTypePortlet = (LayoutTypePortlet) layout
1038:                            .getLayoutType();
1039:
1040:                    if (layout.isPrivateLayout()) {
1041:                        permissionChecker.setCheckGuest(false);
1042:                    }
1043:                }
1044:
1045:                // Theme and color scheme
1046:
1047:                Theme theme = null;
1048:                ColorScheme colorScheme = null;
1049:
1050:                boolean wapTheme = BrowserSniffer.is_wap_xhtml(req);
1051:
1052:                if (layout != null) {
1053:                    if (wapTheme) {
1054:                        theme = layout.getWapTheme();
1055:                        colorScheme = layout.getWapColorScheme();
1056:                    } else {
1057:                        theme = layout.getTheme();
1058:                        colorScheme = layout.getColorScheme();
1059:                    }
1060:                } else {
1061:                    String themeId = null;
1062:                    String colorSchemeId = null;
1063:
1064:                    if (wapTheme) {
1065:                        themeId = ThemeImpl.getDefaultWapThemeId();
1066:                        colorSchemeId = ColorSchemeImpl
1067:                                .getDefaultWapColorSchemeId();
1068:                    } else {
1069:                        themeId = ThemeImpl.getDefaultRegularThemeId();
1070:                        colorSchemeId = ColorSchemeImpl
1071:                                .getDefaultRegularColorSchemeId();
1072:                    }
1073:
1074:                    theme = ThemeLocalUtil.getTheme(companyId, themeId,
1075:                            wapTheme);
1076:                    colorScheme = ThemeLocalUtil.getColorScheme(companyId,
1077:                            theme.getThemeId(), colorSchemeId, wapTheme);
1078:                }
1079:
1080:                req.setAttribute(WebKeys.THEME, theme);
1081:                req.setAttribute(WebKeys.COLOR_SCHEME, colorScheme);
1082:
1083:                // Theme display
1084:
1085:                ThemeDisplay themeDisplay = ThemeDisplayFactory.create();
1086:
1087:                // Set the CDN host first because other methods (setLookAndFeel) depend
1088:                // on it being set
1089:
1090:                themeDisplay.setCDNHost(cdnHost);
1091:
1092:                themeDisplay.setCompany(company);
1093:                themeDisplay.setCompanyLogo(companyLogo);
1094:                themeDisplay.setCompanyLogoHeight(companyLogoHeight);
1095:                themeDisplay.setCompanyLogoWidth(companyLogoWidth);
1096:                themeDisplay.setRealCompanyLogo(realCompanyLogo);
1097:                themeDisplay.setRealCompanyLogoHeight(realCompanyLogoHeight);
1098:                themeDisplay.setRealCompanyLogoWidth(realCompanyLogoWidth);
1099:                themeDisplay.setUser(user);
1100:                themeDisplay.setRealUser(realUser);
1101:                themeDisplay.setDoAsUserId(doAsUserId);
1102:                themeDisplay.setLayoutSetLogo(layoutSetLogo);
1103:                themeDisplay.setLayout(layout);
1104:                themeDisplay.setLayouts(layouts);
1105:                themeDisplay.setPlid(plid);
1106:                themeDisplay.setLayoutTypePortlet(layoutTypePortlet);
1107:                themeDisplay.setPortletGroupId(portletGroupId);
1108:                themeDisplay.setSignedIn(signedIn);
1109:                themeDisplay.setPermissionChecker(permissionChecker);
1110:                themeDisplay.setLocale(locale);
1111:                themeDisplay.setLanguageId(LocaleUtil.toLanguageId(locale));
1112:                themeDisplay.setTimeZone(timeZone);
1113:                themeDisplay.setLookAndFeel(contextPath, theme, colorScheme);
1114:                themeDisplay
1115:                        .setThemeCssFastLoad(PropsValues.THEME_CSS_FAST_LOAD);
1116:                themeDisplay.setServerName(req.getServerName());
1117:                themeDisplay.setServerPort(req.getServerPort());
1118:                themeDisplay.setSecure(req.isSecure());
1119:                themeDisplay.setStateExclusive(LiferayWindowState
1120:                        .isExclusive(req));
1121:                themeDisplay.setStateMaximized(LiferayWindowState
1122:                        .isMaximized(req));
1123:                themeDisplay.setStatePopUp(LiferayWindowState.isPopUp(req));
1124:                themeDisplay.setPathApplet(contextPath + "/applets");
1125:                themeDisplay.setPathCms(contextPath + "/cms");
1126:                themeDisplay.setPathContext(contextPath);
1127:                themeDisplay.setPathFlash(contextPath + "/flash");
1128:                themeDisplay
1129:                        .setPathFriendlyURLPrivateGroup(friendlyURLPrivateGroupPath);
1130:                themeDisplay
1131:                        .setPathFriendlyURLPrivateUser(friendlyURLPrivateUserPath);
1132:                themeDisplay.setPathFriendlyURLPublic(friendlyURLPublicPath);
1133:                themeDisplay.setPathImage(imagePath);
1134:                themeDisplay.setPathJavaScript(cdnHost + contextPath
1135:                        + "/html/js");
1136:                themeDisplay.setPathMain(mainPath);
1137:                themeDisplay.setPathSound(contextPath + "/html/sound");
1138:
1139:                // URLs
1140:
1141:                themeDisplay.setShowAddContentIcon(false);
1142:                themeDisplay.setShowHomeIcon(true);
1143:                themeDisplay.setShowMyAccountIcon(signedIn);
1144:                themeDisplay.setShowPageSettingsIcon(false);
1145:                themeDisplay.setShowPortalIcon(true);
1146:                themeDisplay.setShowSignInIcon(!signedIn);
1147:                themeDisplay.setShowSignOutIcon(signedIn);
1148:
1149:                PortletURL createAccountURL = new PortletURLImpl(req,
1150:                        PortletKeys.MY_ACCOUNT, plid, true);
1151:
1152:                createAccountURL.setWindowState(WindowState.MAXIMIZED);
1153:                createAccountURL.setPortletMode(PortletMode.VIEW);
1154:
1155:                createAccountURL.setParameter("struts_action",
1156:                        "/my_account/create_account");
1157:
1158:                themeDisplay.setURLCreateAccount(createAccountURL);
1159:
1160:                String currentURL = PortalUtil.getCurrentURL(req);
1161:
1162:                themeDisplay.setURLCurrent(currentURL);
1163:
1164:                String urlHome = PortalUtil.getPortalURL(req) + contextPath;
1165:
1166:                if (!CookieKeys.hasSessionId(req)) {
1167:                    urlHome = PortalUtil.getURLWithSessionId(urlHome, ses
1168:                            .getId());
1169:                }
1170:
1171:                themeDisplay.setURLHome(urlHome);
1172:
1173:                if (layout != null) {
1174:                    if (layout.getType().equals(LayoutImpl.TYPE_PORTLET)) {
1175:                        boolean freeformLayout = layoutTypePortlet
1176:                                .getLayoutTemplateId().equals("freeform");
1177:
1178:                        themeDisplay.setFreeformLayout(freeformLayout);
1179:
1180:                        boolean hasUpdateLayoutPermission = LayoutPermissionUtil
1181:                                .contains(permissionChecker, layout,
1182:                                        ActionKeys.UPDATE);
1183:
1184:                        if (hasUpdateLayoutPermission) {
1185:                            if (!LiferayWindowState.isMaximized(req)) {
1186:                                themeDisplay.setShowAddContentIcon(true);
1187:                            }
1188:
1189:                            themeDisplay.setShowLayoutTemplatesIcon(true);
1190:
1191:                            themeDisplay
1192:                                    .setURLAddContent("LayoutConfiguration.toggle('"
1193:                                            + plid
1194:                                            + "', '"
1195:                                            + PortletKeys.LAYOUT_CONFIGURATION
1196:                                            + "', '" + doAsUserId + "');");
1197:
1198:                            themeDisplay
1199:                                    .setURLLayoutTemplates("showLayoutTemplates();");
1200:                        }
1201:                    }
1202:
1203:                    boolean hasManageLayoutsPermission = GroupPermissionUtil
1204:                            .contains(permissionChecker, portletGroupId,
1205:                                    ActionKeys.MANAGE_LAYOUTS);
1206:
1207:                    if (hasManageLayoutsPermission) {
1208:                        themeDisplay.setShowPageSettingsIcon(true);
1209:
1210:                        PortletURL pageSettingsURL = new PortletURLImpl(req,
1211:                                PortletKeys.LAYOUT_MANAGEMENT, plid, false);
1212:
1213:                        pageSettingsURL.setWindowState(WindowState.MAXIMIZED);
1214:                        pageSettingsURL.setPortletMode(PortletMode.VIEW);
1215:
1216:                        pageSettingsURL.setParameter("struts_action",
1217:                                "/layout_management/edit_pages");
1218:
1219:                        if (layout.isPrivateLayout()) {
1220:                            pageSettingsURL.setParameter("tabs2", "private");
1221:                        } else {
1222:                            pageSettingsURL.setParameter("tabs2", "public");
1223:                        }
1224:
1225:                        pageSettingsURL.setParameter("redirect", currentURL);
1226:                        pageSettingsURL.setParameter("groupId", String
1227:                                .valueOf(portletGroupId));
1228:                        pageSettingsURL.setParameter("selPlid", String
1229:                                .valueOf(plid));
1230:
1231:                        themeDisplay.setURLPageSettings(pageSettingsURL);
1232:
1233:                        // Publish To Live
1234:
1235:                        PortletURL publishToLiveURL = new PortletURLImpl(req,
1236:                                PortletKeys.LAYOUT_MANAGEMENT, plid, false);
1237:
1238:                        publishToLiveURL
1239:                                .setWindowState(LiferayWindowState.EXCLUSIVE);
1240:                        publishToLiveURL.setPortletMode(PortletMode.VIEW);
1241:
1242:                        publishToLiveURL.setParameter("struts_action",
1243:                                "/layout_management/export_pages");
1244:
1245:                        publishToLiveURL.setParameter("popupId",
1246:                                "publish-to-live");
1247:
1248:                        if (layout.isPrivateLayout()) {
1249:                            publishToLiveURL.setParameter("tabs2", "private");
1250:                        } else {
1251:                            publishToLiveURL.setParameter("tabs2", "public");
1252:                        }
1253:
1254:                        publishToLiveURL.setParameter("pagesRedirect",
1255:                                currentURL);
1256:                        publishToLiveURL.setParameter("groupId", String
1257:                                .valueOf(portletGroupId));
1258:                        publishToLiveURL.setParameter("selPlid", String
1259:                                .valueOf(plid));
1260:
1261:                        themeDisplay.setURLPublishToLive(publishToLiveURL);
1262:                    }
1263:
1264:                    String myAccountNamespace = PortalUtil
1265:                            .getPortletNamespace(PortletKeys.MY_ACCOUNT);
1266:
1267:                    String myAccountRedirect = ParamUtil.getString(req,
1268:                            myAccountNamespace + "backURL", currentURL);
1269:
1270:                    PortletURL myAccountURL = new PortletURLImpl(req,
1271:                            PortletKeys.MY_ACCOUNT, plid, false);
1272:
1273:                    myAccountURL.setWindowState(WindowState.MAXIMIZED);
1274:                    myAccountURL.setPortletMode(PortletMode.VIEW);
1275:
1276:                    myAccountURL.setParameter("struts_action",
1277:                            "/my_account/edit_user");
1278:                    myAccountURL.setParameter("backURL", myAccountRedirect);
1279:
1280:                    themeDisplay.setURLMyAccount(myAccountURL);
1281:                }
1282:
1283:                if ((!user.isActive())
1284:                        || (PropsValues.TERMS_OF_USE_REQUIRED && !user
1285:                                .isAgreedToTermsOfUse())) {
1286:
1287:                    themeDisplay.setShowAddContentIcon(false);
1288:                    themeDisplay.setShowMyAccountIcon(false);
1289:                    themeDisplay.setShowPageSettingsIcon(false);
1290:                }
1291:
1292:                themeDisplay.setURLPortal(themeDisplay.getURLHome());
1293:                themeDisplay.setURLSignIn(mainPath + "/portal/login");
1294:                themeDisplay.setURLSignOut(mainPath + "/portal/logout");
1295:
1296:                PortletURL updateManagerURL = new PortletURLImpl(req,
1297:                        PortletKeys.UPDATE_MANAGER, plid, false);
1298:
1299:                updateManagerURL.setWindowState(WindowState.MAXIMIZED);
1300:                updateManagerURL.setPortletMode(PortletMode.VIEW);
1301:
1302:                updateManagerURL.setParameter("struts_action",
1303:                        "/update_manager/view");
1304:
1305:                themeDisplay.setURLUpdateManager(updateManagerURL);
1306:
1307:                req.setAttribute(WebKeys.THEME_DISPLAY, themeDisplay);
1308:
1309:                // Parallel render
1310:
1311:                boolean parallelRenderEnable = true;
1312:
1313:                if (layout != null) {
1314:                    if (layoutTypePortlet.getPortletIds().size() == 1) {
1315:                        parallelRenderEnable = false;
1316:                    }
1317:                }
1318:
1319:                Boolean parallelRenderEnableObj = Boolean.valueOf(ParamUtil
1320:                        .getBoolean(req, "p_p_parallel", parallelRenderEnable));
1321:
1322:                req.setAttribute(WebKeys.PORTLET_PARALLEL_RENDER,
1323:                        parallelRenderEnableObj);
1324:
1325:                // Fix state
1326:
1327:                fixState(req, themeDisplay);
1328:            }
1329:
1330:            protected File privateLARFile;
1331:            protected File publicLARFile;
1332:
1333:            private static final String _PATH_PORTAL_LAYOUT = "/portal/layout";
1334:
1335:            private static Log _log = LogFactory.getLog(ServicePreAction.class);
1336:
1337:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.