Posted By

kiran8049 on 10/05/12


Tagged

hook liferay


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

kiran8049


Override servicePreaction using hook


 / Published in: Java
 

overriding servicePreAction class using hooks in liferay

  1. package com.ssdg.portal.events;
  2.  
  3. import com.liferay.portal.LayoutPermissionException;
  4. import com.liferay.portal.NoSuchGroupException;
  5. import com.liferay.portal.NoSuchLayoutException;
  6. import com.liferay.portal.NoSuchUserException;
  7. import com.liferay.portal.kernel.dao.orm.QueryUtil;
  8. import com.liferay.portal.kernel.events.Action;
  9. import com.liferay.portal.kernel.events.ActionException;
  10. import com.liferay.portal.kernel.exception.PortalException;
  11. import com.liferay.portal.kernel.exception.SystemException;
  12. import com.liferay.portal.kernel.language.LanguageUtil;
  13. import com.liferay.portal.kernel.lar.PortletDataHandlerKeys;
  14. import com.liferay.portal.kernel.log.Log;
  15. import com.liferay.portal.kernel.log.LogFactoryUtil;
  16. import com.liferay.portal.kernel.portlet.LiferayPortletURL;
  17. import com.liferay.portal.kernel.portlet.LiferayWindowState;
  18. import com.liferay.portal.kernel.servlet.BrowserSnifferUtil;
  19. import com.liferay.portal.kernel.servlet.HttpHeaders;
  20. import com.liferay.portal.kernel.servlet.SessionErrors;
  21. import com.liferay.portal.kernel.util.FriendlyURLNormalizerUtil;
  22. import com.liferay.portal.kernel.util.GetterUtil;
  23. import com.liferay.portal.kernel.util.HttpUtil;
  24. import com.liferay.portal.kernel.util.LocaleUtil;
  25. import com.liferay.portal.kernel.util.ParamUtil;
  26. import com.liferay.portal.kernel.util.PropsKeys;
  27. import com.liferay.portal.kernel.util.SessionParamUtil;
  28. import com.liferay.portal.kernel.util.StringBundler;
  29. import com.liferay.portal.kernel.util.StringPool;
  30. import com.liferay.portal.kernel.util.StringUtil;
  31. import com.liferay.portal.kernel.util.UnicodeProperties;
  32. import com.liferay.portal.kernel.util.Validator;
  33. import com.liferay.portal.model.ColorScheme;
  34. import com.liferay.portal.model.Company;
  35. import com.liferay.portal.model.Group;
  36. import com.liferay.portal.model.GroupConstants;
  37. import com.liferay.portal.model.Image;
  38. import com.liferay.portal.model.Layout;
  39. import com.liferay.portal.model.LayoutConstants;
  40. import com.liferay.portal.model.LayoutSet;
  41. import com.liferay.portal.model.LayoutTypePortlet;
  42. import com.liferay.portal.model.LayoutTypePortletConstants;
  43. import com.liferay.portal.model.Portlet;
  44. import com.liferay.portal.model.RoleConstants;
  45. import com.liferay.portal.model.Theme;
  46. import com.liferay.portal.model.User;
  47. import com.liferay.portal.model.impl.ColorSchemeImpl;
  48. import com.liferay.portal.model.impl.VirtualLayout;
  49. import com.liferay.portal.security.auth.PrincipalException;
  50. import com.liferay.portal.security.permission.ActionKeys;
  51. import com.liferay.portal.security.permission.PermissionChecker;
  52. import com.liferay.portal.security.permission.PermissionCheckerFactoryUtil;
  53. import com.liferay.portal.security.permission.PermissionThreadLocal;
  54. import com.liferay.portal.service.GroupLocalServiceUtil;
  55. import com.liferay.portal.service.ImageLocalServiceUtil;
  56. import com.liferay.portal.service.LayoutLocalServiceUtil;
  57. import com.liferay.portal.service.LayoutSetLocalServiceUtil;
  58. import com.liferay.portal.service.PortletLocalServiceUtil;
  59. import com.liferay.portal.service.RoleLocalServiceUtil;
  60. import com.liferay.portal.service.ServiceContext;
  61. import com.liferay.portal.service.ServiceContextFactory;
  62. import com.liferay.portal.service.ServiceContextThreadLocal;
  63. import com.liferay.portal.service.ThemeLocalServiceUtil;
  64. import com.liferay.portal.service.UserLocalServiceUtil;
  65. import com.liferay.portal.service.permission.GroupPermissionUtil;
  66. import com.liferay.portal.service.permission.LayoutPermissionUtil;
  67. import com.liferay.portal.service.permission.PortletPermissionUtil;
  68. import com.liferay.portal.theme.ThemeDisplay;
  69. import com.liferay.portal.theme.ThemeDisplayFactory;
  70. import com.liferay.portal.util.CookieKeys;
  71. import com.liferay.portal.util.LayoutClone;
  72. import com.liferay.portal.util.LayoutCloneFactory;
  73. import com.liferay.portal.util.PortalUtil;
  74. import com.liferay.portal.util.PortletCategoryKeys;
  75. import com.liferay.portal.util.PortletKeys;
  76. import com.liferay.portal.util.PrefsPropsUtil;
  77. import com.liferay.portal.util.PropsUtil;
  78. import com.liferay.portal.util.PropsValues;
  79. import com.liferay.portal.util.WebKeys;
  80. import com.liferay.portal.webserver.WebServerServletTokenUtil;
  81. import com.liferay.portlet.PortalPreferences;
  82. import com.liferay.portlet.PortletPreferencesFactoryUtil;
  83. import com.liferay.portlet.PortletURLImpl;
  84. import com.liferay.portlet.asset.model.AssetEntry;
  85. import com.liferay.portlet.asset.service.AssetEntryLocalServiceUtil;
  86. import com.liferay.portlet.journal.NoSuchArticleException;
  87. import com.liferay.portlet.journal.model.JournalArticle;
  88. import com.liferay.portlet.journal.service.JournalArticleServiceUtil;
  89. import com.liferay.portlet.sites.util.SitesUtil;
  90.  
  91. import java.io.File;
  92.  
  93. import java.util.ArrayList;
  94. import java.util.HashMap;
  95. import java.util.LinkedHashMap;
  96. import java.util.List;
  97. import java.util.Locale;
  98. import java.util.Map;
  99. import java.util.TimeZone;
  100.  
  101. import javax.portlet.PortletMode;
  102. import javax.portlet.PortletRequest;
  103. import javax.portlet.PortletURL;
  104. import javax.portlet.WindowState;
  105.  
  106. import javax.servlet.http.HttpServletRequest;
  107. import javax.servlet.http.HttpServletResponse;
  108. import javax.servlet.http.HttpSession;
  109.  
  110. import org.apache.commons.lang3.time.StopWatch;
  111. import org.apache.struts.Globals;
  112.  
  113. public class ServicePreAction extends Action {
  114.  
  115. public ServicePreAction() {
  116. initImportLARFiles();
  117. }
  118.  
  119. public ThemeDisplay initThemeDisplay(
  120. HttpServletRequest request, HttpServletResponse response)
  121. throws Exception {
  122.  
  123. HttpSession session = request.getSession();
  124.  
  125. // Company
  126.  
  127. Company company = PortalUtil.getCompany(request);
  128.  
  129. long companyId = company.getCompanyId();
  130.  
  131. // CDN host
  132.  
  133. String cdnHost = PortalUtil.getCDNHost(request);
  134.  
  135. // Portal URL
  136.  
  137. String portalURL = PortalUtil.getPortalURL(request);
  138.  
  139. // Paths
  140.  
  141. String contextPath = PortalUtil.getPathContext();
  142. String friendlyURLPrivateGroupPath =
  143. PortalUtil.getPathFriendlyURLPrivateGroup();
  144. String friendlyURLPrivateUserPath =
  145. PortalUtil.getPathFriendlyURLPrivateUser();
  146. String friendlyURLPublicPath = PortalUtil.getPathFriendlyURLPublic();
  147. String imagePath = cdnHost.concat(PortalUtil.getPathImage());
  148. String mainPath = PortalUtil.getPathMain();
  149.  
  150. String i18nPath = (String)request.getAttribute(WebKeys.I18N_PATH);
  151.  
  152. if (Validator.isNotNull(i18nPath)) {
  153. if (Validator.isNotNull(contextPath)) {
  154. String i18nContextPath = contextPath.concat(i18nPath);
  155.  
  156. friendlyURLPrivateGroupPath = StringUtil.replaceFirst(
  157. friendlyURLPrivateGroupPath, contextPath, i18nContextPath);
  158. friendlyURLPrivateUserPath = StringUtil.replaceFirst(
  159. friendlyURLPrivateUserPath, contextPath, i18nContextPath);
  160. friendlyURLPublicPath = StringUtil.replaceFirst(
  161. friendlyURLPublicPath, contextPath, i18nContextPath);
  162. mainPath = StringUtil.replaceFirst(
  163. mainPath, contextPath, i18nContextPath);
  164. }
  165. else {
  166. friendlyURLPrivateGroupPath = i18nPath.concat(
  167. friendlyURLPrivateGroupPath);
  168. friendlyURLPrivateUserPath = i18nPath.concat(
  169. friendlyURLPrivateUserPath);
  170. friendlyURLPublicPath = i18nPath.concat(friendlyURLPublicPath);
  171. mainPath = i18nPath.concat(mainPath);
  172. }
  173. }
  174.  
  175. // Company logo
  176.  
  177. StringBundler sb = new StringBundler(5);
  178.  
  179. sb.append(imagePath);
  180. sb.append("/company_logo?img_id=");
  181. sb.append(company.getLogoId());
  182. sb.append("&t=");
  183. sb.append(WebServerServletTokenUtil.getToken(company.getLogoId()));
  184.  
  185. String companyLogo = sb.toString();
  186.  
  187. int companyLogoHeight = 0;
  188. int companyLogoWidth = 0;
  189.  
  190. Image companyLogoImage = ImageLocalServiceUtil.getCompanyLogo(
  191. company.getLogoId());
  192.  
  193. if (companyLogoImage != null) {
  194. companyLogoHeight = companyLogoImage.getHeight();
  195. companyLogoWidth = companyLogoImage.getWidth();
  196. }
  197.  
  198. String realCompanyLogo = companyLogo;
  199. int realCompanyLogoHeight = companyLogoHeight;
  200. int realCompanyLogoWidth = companyLogoWidth;
  201.  
  202. // User
  203.  
  204. User user = null;
  205.  
  206. try {
  207. user = PortalUtil.getUser(request);
  208. }
  209. catch (NoSuchUserException nsue) {
  210. if (_log.isWarnEnabled()) {
  211. _log.warn(nsue.getMessage());
  212. }
  213.  
  214. long userId = PortalUtil.getUserId(request);
  215.  
  216. if (userId > 0) {
  217. session.invalidate();
  218. }
  219.  
  220. return null;
  221. }
  222.  
  223. boolean signedIn = false;
  224.  
  225. if (user == null) {
  226. user = company.getDefaultUser();
  227. }
  228. else if (!user.isDefaultUser()) {
  229. signedIn = true;
  230. }
  231.  
  232. if (PropsValues.BROWSER_CACHE_DISABLED ||
  233. (PropsValues.BROWSER_CACHE_SIGNED_IN_DISABLED && signedIn)) {
  234.  
  235. response.setDateHeader(HttpHeaders.EXPIRES, 0);
  236. response.setHeader(
  237. HttpHeaders.CACHE_CONTROL,
  238. HttpHeaders.CACHE_CONTROL_NO_CACHE_VALUE);
  239. response.setHeader(
  240. HttpHeaders.PRAGMA, HttpHeaders.PRAGMA_NO_CACHE_VALUE);
  241. }
  242.  
  243. User realUser = user;
  244.  
  245. Long realUserId = (Long)session.getAttribute(WebKeys.USER_ID);
  246.  
  247. if (realUserId != null) {
  248. if (user.getUserId() != realUserId.longValue()) {
  249. realUser = UserLocalServiceUtil.getUserById(
  250. realUserId.longValue());
  251. }
  252. }
  253.  
  254. String doAsUserId = ParamUtil.getString(request, "doAsUserId");
  255. String doAsUserLanguageId = ParamUtil.getString(
  256. request, "doAsUserLanguageId");
  257. long doAsGroupId = ParamUtil.getLong(request, "doAsGroupId");
  258.  
  259. long refererPlid = ParamUtil.getLong(request, "refererPlid");
  260.  
  261. if (LayoutLocalServiceUtil.fetchLayout(refererPlid) == null) {
  262. refererPlid = 0;
  263. }
  264.  
  265. String controlPanelCategory = ParamUtil.getString(
  266. request, "controlPanelCategory");
  267.  
  268. // Permission checker
  269.  
  270. PermissionChecker permissionChecker =
  271. PermissionCheckerFactoryUtil.create(user, true);
  272.  
  273. PermissionThreadLocal.setPermissionChecker(permissionChecker);
  274.  
  275. // Locale
  276.  
  277. Locale locale = (Locale)session.getAttribute(Globals.LOCALE_KEY);
  278.  
  279. if (Validator.isNotNull(doAsUserLanguageId)) {
  280. locale = LocaleUtil.fromLanguageId(doAsUserLanguageId);
  281. }
  282.  
  283. String i18nLanguageId = (String)request.getAttribute(
  284. WebKeys.I18N_LANGUAGE_ID);
  285.  
  286. if (Validator.isNotNull(i18nLanguageId)) {
  287. locale = LocaleUtil.fromLanguageId(i18nLanguageId);
  288. }
  289. else if (locale == null) {
  290. if (signedIn) {
  291. locale = user.getLocale();
  292. }
  293. else {
  294.  
  295. // User previously set their preferred language
  296.  
  297. String languageId = CookieKeys.getCookie(
  298. request, CookieKeys.GUEST_LANGUAGE_ID, false);
  299.  
  300. if (Validator.isNotNull(languageId)) {
  301. locale = LocaleUtil.fromLanguageId(languageId);
  302. }
  303.  
  304. // Get locale from the request
  305.  
  306. if ((locale == null) && PropsValues.LOCALE_DEFAULT_REQUEST) {
  307. locale = request.getLocale();
  308. }
  309.  
  310. // Get locale from the default user
  311.  
  312. if (locale == null) {
  313. locale = user.getLocale();
  314. }
  315.  
  316. if (Validator.isNull(locale.getCountry())) {
  317.  
  318. // Locales must contain a country code
  319.  
  320. locale = LanguageUtil.getLocale(locale.getLanguage());
  321. }
  322.  
  323. if (!LanguageUtil.isAvailableLocale(locale)) {
  324. locale = user.getLocale();
  325. }
  326. }
  327.  
  328. session.setAttribute(Globals.LOCALE_KEY, locale);
  329.  
  330. LanguageUtil.updateCookie(request, response, locale);
  331. }
  332.  
  333. // Cookie support
  334.  
  335. try {
  336.  
  337. // LEP-4069
  338.  
  339. CookieKeys.validateSupportCookie(request);
  340. }
  341. catch (Exception e) {
  342. CookieKeys.addSupportCookie(request, response);
  343. }
  344.  
  345. // Time zone
  346.  
  347. TimeZone timeZone = user.getTimeZone();
  348.  
  349. if (timeZone == null) {
  350. timeZone = company.getTimeZone();
  351. }
  352.  
  353. // Layouts
  354.  
  355. if (signedIn) {
  356. updateUserLayouts(user);
  357. }
  358.  
  359. Layout layout = null;
  360. List<Layout> layouts = null;
  361.  
  362. long plid = ParamUtil.getLong(request, "p_l_id");
  363.  
  364. if (plid > 0) {
  365. layout = LayoutLocalServiceUtil.getLayout(plid);
  366.  
  367. long sourceGroupId = ParamUtil.getLong(request, "p_v_l_s_g_id");
  368.  
  369. if ((sourceGroupId > 0) && (sourceGroupId != layout.getGroupId())) {
  370. Group sourceGroup = GroupLocalServiceUtil.getGroup(
  371. sourceGroupId);
  372.  
  373. if (SitesUtil.isUserGroupLayoutSetViewable(
  374. permissionChecker, layout.getGroup())) {
  375.  
  376. layout = new VirtualLayout(layout, sourceGroup);
  377. }
  378. else {
  379. layout = null;
  380. }
  381. }
  382. }
  383. else {
  384. long groupId = ParamUtil.getLong(request, "groupId");
  385. boolean privateLayout = ParamUtil.getBoolean(
  386. request, "privateLayout");
  387. long layoutId = ParamUtil.getLong(request, "layoutId");
  388.  
  389. if ((groupId > 0) && (layoutId > 0)) {
  390. layout = LayoutLocalServiceUtil.getLayout(
  391. groupId, privateLayout, layoutId);
  392. }
  393. }
  394.  
  395. Boolean redirectToDefaultLayout = (Boolean)request.getAttribute(
  396. WebKeys.REDIRECT_TO_DEFAULT_LAYOUT);
  397.  
  398. if (redirectToDefaultLayout == null) {
  399. redirectToDefaultLayout = Boolean.FALSE;
  400. }
  401.  
  402. if (layout != null) {
  403. Group group = layout.getGroup();
  404.  
  405. if (!signedIn && PropsValues.AUTH_FORWARD_BY_REDIRECT) {
  406. request.setAttribute(WebKeys.REQUESTED_LAYOUT, layout);
  407. }
  408.  
  409. boolean isViewableGroup = LayoutPermissionUtil.contains(
  410. permissionChecker, layout, controlPanelCategory, true,
  411. ActionKeys.VIEW);
  412. boolean isViewableStaging = GroupPermissionUtil.contains(
  413. permissionChecker, group.getGroupId(),
  414. ActionKeys.VIEW_STAGING);
  415.  
  416. if (isViewableStaging) {
  417. layouts = LayoutLocalServiceUtil.getLayouts(
  418. layout.getGroupId(), layout.isPrivateLayout(),
  419. LayoutConstants.DEFAULT_PARENT_LAYOUT_ID);
  420. }
  421. else if (!isViewableGroup && group.isStagingGroup()) {
  422. layout = null;
  423. }
  424. else if (!isLoginRequest(request) &&
  425. (!isViewableGroup ||
  426. (!redirectToDefaultLayout &&
  427. !LayoutPermissionUtil.contains(
  428. permissionChecker, layout, false,
  429. ActionKeys.VIEW)))) {
  430.  
  431. if (user.isDefaultUser()) {
  432. throw new PrincipalException("User is not authenticated");
  433. }
  434.  
  435. sb = new StringBundler(6);
  436.  
  437. sb.append("User ");
  438. sb.append(user.getUserId());
  439. sb.append(" is not allowed to access the ");
  440. sb.append(layout.isPrivateLayout() ? "private": "public");
  441. sb.append(" pages of group ");
  442. sb.append(layout.getGroupId());
  443.  
  444. if (_log.isWarnEnabled()) {
  445. _log.warn(sb.toString());
  446. }
  447.  
  448. throw new NoSuchLayoutException(sb.toString());
  449. }
  450. else if (group.isLayoutPrototype()) {
  451. layouts = new ArrayList<Layout>();
  452. }
  453. else {
  454. layouts = LayoutLocalServiceUtil.getLayouts(
  455. layout.getGroupId(), layout.isPrivateLayout(),
  456. LayoutConstants.DEFAULT_PARENT_LAYOUT_ID);
  457.  
  458. if (!group.isControlPanel()) {
  459. doAsGroupId = 0;
  460. }
  461. }
  462. }
  463.  
  464. List<Layout> unfilteredLayouts = layouts;
  465.  
  466. if (layout == null) {
  467. Object[] defaultLayout = getDefaultLayout(request, user, signedIn);
  468.  
  469. layout = (Layout)defaultLayout[0];
  470. layouts = (List<Layout>)defaultLayout[1];
  471.  
  472. request.setAttribute(WebKeys.LAYOUT_DEFAULT, Boolean.TRUE);
  473. }
  474.  
  475. Object[] viewableLayouts = getViewableLayouts(
  476. request, user, permissionChecker, layout, layouts);
  477.  
  478. String layoutSetLogo = null;
  479.  
  480. layout = (Layout)viewableLayouts[0];
  481. layouts = (List<Layout>)viewableLayouts[1];
  482.  
  483. Group group = null;
  484.  
  485. if (layout != null) {
  486. group = layout.getGroup();
  487.  
  488. if (!group.isControlPanel()) {
  489. rememberVisitedGroupIds(request, group.getGroupId());
  490. }
  491. }
  492.  
  493. LayoutTypePortlet layoutTypePortlet = null;
  494.  
  495. layouts = mergeAdditionalLayouts(
  496. request, user, permissionChecker, layout, layouts);
  497.  
  498. LayoutSet layoutSet = null;
  499.  
  500. boolean hasCustomizeLayoutPermission = false;
  501. boolean hasUpdateLayoutPermission = false;
  502.  
  503. boolean customizedView = SessionParamUtil.getBoolean(
  504. request, "customized_view", true);
  505.  
  506. if (layout != null) {
  507. hasCustomizeLayoutPermission = LayoutPermissionUtil.contains(
  508. permissionChecker, layout, ActionKeys.CUSTOMIZE);
  509. hasUpdateLayoutPermission = LayoutPermissionUtil.contains(
  510. permissionChecker, layout, ActionKeys.UPDATE);
  511.  
  512. layoutSet = layout.getLayoutSet();
  513.  
  514. if (company.isSiteLogo()) {
  515. long logoId = 0;
  516.  
  517. if (layoutSet.isLogo()) {
  518. logoId = layoutSet.getLogoId();
  519. }
  520. else {
  521. LayoutSet siblingLayoutSet =
  522. LayoutSetLocalServiceUtil.getLayoutSet(
  523. layout.getGroupId(), !layout.isPrivateLayout());
  524.  
  525. if (siblingLayoutSet.isLogo()) {
  526. logoId = siblingLayoutSet.getLogoId();
  527. }
  528. }
  529.  
  530. if (logoId > 0) {
  531. sb = new StringBundler(5);
  532.  
  533. sb.append(imagePath);
  534. sb.append("/layout_set_logo?img_id=");
  535. sb.append(logoId);
  536. sb.append("&t=");
  537. sb.append(WebServerServletTokenUtil.getToken(logoId));
  538.  
  539. layoutSetLogo = sb.toString();
  540.  
  541. Image layoutSetLogoImage =
  542. ImageLocalServiceUtil.getCompanyLogo(logoId);
  543.  
  544. companyLogo = layoutSetLogo;
  545. companyLogoHeight = layoutSetLogoImage.getHeight();
  546. companyLogoWidth = layoutSetLogoImage.getWidth();
  547. }
  548. }
  549.  
  550. plid = layout.getPlid();
  551.  
  552. // Updates to shared layouts are not reflected until the next time
  553. // the user logs in because group layouts are cached in the session
  554.  
  555. layout = (Layout)layout.clone();
  556.  
  557. layoutTypePortlet = (LayoutTypePortlet)layout.getLayoutType();
  558.  
  559. boolean customizable = layoutTypePortlet.isCustomizable();
  560.  
  561. if (!customizable ||
  562. (group.isLayoutPrototype() || group.isLayoutSetPrototype())) {
  563.  
  564. customizedView = false;
  565. }
  566.  
  567. layoutTypePortlet.setCustomizedView(customizedView);
  568. layoutTypePortlet.setUpdatePermission(hasUpdateLayoutPermission);
  569.  
  570. if (signedIn && customizable && customizedView &&
  571. hasCustomizeLayoutPermission) {
  572.  
  573. PortalPreferences portalPreferences =
  574. PortletPreferencesFactoryUtil.getPortalPreferences(
  575. companyId, user.getUserId(), true);
  576.  
  577. layoutTypePortlet.setPortalPreferences(portalPreferences);
  578. }
  579.  
  580. LayoutClone layoutClone = LayoutCloneFactory.getInstance();
  581.  
  582. if (layoutClone != null) {
  583. String typeSettings = layoutClone.get(request, plid);
  584.  
  585. if (typeSettings != null) {
  586. UnicodeProperties typeSettingsProperties =
  587. new UnicodeProperties(true);
  588.  
  589. typeSettingsProperties.load(typeSettings);
  590.  
  591. String stateMax = typeSettingsProperties.getProperty(
  592. LayoutTypePortletConstants.STATE_MAX);
  593. String stateMin = typeSettingsProperties.getProperty(
  594. LayoutTypePortletConstants.STATE_MIN);
  595. String modeAbout = typeSettingsProperties.getProperty(
  596. LayoutTypePortletConstants.MODE_ABOUT);
  597. String modeConfig = typeSettingsProperties.getProperty(
  598. LayoutTypePortletConstants.MODE_CONFIG);
  599. String modeEdit = typeSettingsProperties.getProperty(
  600. LayoutTypePortletConstants.MODE_EDIT);
  601. String modeEditDefaults =
  602. typeSettingsProperties.getProperty(
  603. LayoutTypePortletConstants.MODE_EDIT_DEFAULTS);
  604. String modeEditGuest = typeSettingsProperties.getProperty(
  605. LayoutTypePortletConstants.MODE_EDIT_GUEST);
  606. String modeHelp = typeSettingsProperties.getProperty(
  607. LayoutTypePortletConstants.MODE_HELP);
  608. String modePreview = typeSettingsProperties.getProperty(
  609. LayoutTypePortletConstants.MODE_PREVIEW);
  610. String modePrint = typeSettingsProperties.getProperty(
  611. LayoutTypePortletConstants.MODE_PRINT);
  612.  
  613. layoutTypePortlet.setStateMax(stateMax);
  614. layoutTypePortlet.setStateMin(stateMin);
  615. layoutTypePortlet.setModeAbout(modeAbout);
  616. layoutTypePortlet.setModeConfig(modeConfig);
  617. layoutTypePortlet.setModeEdit(modeEdit);
  618. layoutTypePortlet.setModeEditDefaults(modeEditDefaults);
  619. layoutTypePortlet.setModeEditGuest(modeEditGuest);
  620. layoutTypePortlet.setModeHelp(modeHelp);
  621. layoutTypePortlet.setModePreview(modePreview);
  622. layoutTypePortlet.setModePrint(modePrint);
  623. }
  624. }
  625.  
  626. request.setAttribute(WebKeys.LAYOUT, layout);
  627. request.setAttribute(WebKeys.LAYOUTS, layouts);
  628.  
  629. if (layout.isPrivateLayout()) {
  630. permissionChecker.setCheckGuest(false);
  631. }
  632. }
  633.  
  634. // Scope
  635.  
  636. long scopeGroupId = PortalUtil.getScopeGroupId(request);
  637. long parentGroupId = PortalUtil.getParentGroupId(scopeGroupId);
  638.  
  639. // Theme and color scheme
  640.  
  641. Theme theme = null;
  642. ColorScheme colorScheme = null;
  643.  
  644. boolean wapTheme = BrowserSnifferUtil.isWap(request);
  645. System.out.println("isWap()"+wapTheme);
  646. //uses WAP theme as a mobile theme
  647. boolean mobileTheme = BrowserSnifferUtil.isMobile(request);
  648. System.out.println("isMobile()"+mobileTheme);
  649. if ((layout != null) && group.isControlPanel()) {
  650. String themeId = PrefsPropsUtil.getString(
  651. companyId, PropsKeys.CONTROL_PANEL_LAYOUT_REGULAR_THEME_ID);
  652. String colorSchemeId =
  653. ColorSchemeImpl.getDefaultRegularColorSchemeId();
  654.  
  655. theme = ThemeLocalServiceUtil.getTheme(
  656. companyId, themeId, wapTheme);
  657. colorScheme = ThemeLocalServiceUtil.getColorScheme(
  658. companyId, theme.getThemeId(), colorSchemeId, wapTheme);
  659.  
  660. if (!wapTheme && theme.isWapTheme()) {
  661. theme = ThemeLocalServiceUtil.getTheme(
  662. companyId,
  663. PropsValues.CONTROL_PANEL_LAYOUT_REGULAR_THEME_ID, false);
  664. colorScheme = ThemeLocalServiceUtil.getColorScheme(
  665. companyId, theme.getThemeId(), colorSchemeId, false);
  666. }
  667.  
  668. request.setAttribute(WebKeys.THEME, theme);
  669. request.setAttribute(WebKeys.COLOR_SCHEME, colorScheme);
  670. }
  671.  
  672. boolean themeCssFastLoad = SessionParamUtil.getBoolean(
  673. request, "css_fast_load", PropsValues.THEME_CSS_FAST_LOAD);
  674. boolean themeImagesFastLoad = SessionParamUtil.getBoolean(
  675. request, "images_fast_load", PropsValues.THEME_IMAGES_FAST_LOAD);
  676.  
  677. boolean themeJsBarebone = PropsValues.JAVASCRIPT_BAREBONE_ENABLED;
  678.  
  679. if (themeJsBarebone) {
  680. if (signedIn) {
  681. themeJsBarebone = false;
  682. }
  683. }
  684.  
  685. boolean themeJsFastLoad = SessionParamUtil.getBoolean(
  686. request, "js_fast_load", PropsValues.JAVASCRIPT_FAST_LOAD);
  687.  
  688. String lifecycle = ParamUtil.getString(request, "p_p_lifecycle", "0");
  689.  
  690. lifecycle = ParamUtil.getString(request, "p_t_lifecycle", lifecycle);
  691.  
  692. boolean isolated = ParamUtil.getBoolean(request, "p_p_isolated");
  693.  
  694. String facebookCanvasPageURL = (String)request.getAttribute(
  695. WebKeys.FACEBOOK_CANVAS_PAGE_URL);
  696.  
  697. boolean widget = false;
  698.  
  699. Boolean widgetObj = (Boolean)request.getAttribute(WebKeys.WIDGET);
  700.  
  701. if (widgetObj != null) {
  702. widget = widgetObj.booleanValue();
  703. }
  704.  
  705. // Theme display
  706.  
  707. ThemeDisplay themeDisplay = ThemeDisplayFactory.create();
  708.  
  709. // Set the CDN host, portal URL, and Facebook application ID first
  710. // because other methods (setLookAndFeel) depend on them being set
  711.  
  712. themeDisplay.setCDNHost(cdnHost);
  713. themeDisplay.setPortalURL(portalURL);
  714. themeDisplay.setFacebookCanvasPageURL(facebookCanvasPageURL);
  715. themeDisplay.setWidget(widget);
  716.  
  717. themeDisplay.setCompany(company);
  718. themeDisplay.setCompanyLogo(companyLogo);
  719. themeDisplay.setCompanyLogoHeight(companyLogoHeight);
  720. themeDisplay.setCompanyLogoWidth(companyLogoWidth);
  721. themeDisplay.setRealCompanyLogo(realCompanyLogo);
  722. themeDisplay.setRealCompanyLogoHeight(realCompanyLogoHeight);
  723. themeDisplay.setRealCompanyLogoWidth(realCompanyLogoWidth);
  724. themeDisplay.setUser(user);
  725. themeDisplay.setRealUser(realUser);
  726. themeDisplay.setDoAsUserId(doAsUserId);
  727. themeDisplay.setDoAsUserLanguageId(doAsUserLanguageId);
  728. themeDisplay.setDoAsGroupId(doAsGroupId);
  729. themeDisplay.setRefererPlid(refererPlid);
  730. themeDisplay.setControlPanelCategory(controlPanelCategory);
  731. themeDisplay.setLayoutSet(layoutSet);
  732. themeDisplay.setLayoutSetLogo(layoutSetLogo);
  733. themeDisplay.setLayout(layout);
  734. themeDisplay.setLayouts(layouts);
  735. themeDisplay.setUnfilteredLayouts(unfilteredLayouts);
  736. themeDisplay.setPlid(plid);
  737. themeDisplay.setLayoutTypePortlet(layoutTypePortlet);
  738. themeDisplay.setScopeGroupId(scopeGroupId);
  739. themeDisplay.setParentGroupId(parentGroupId);
  740. themeDisplay.setSignedIn(signedIn);
  741. themeDisplay.setPermissionChecker(permissionChecker);
  742. themeDisplay.setLocale(locale);
  743. themeDisplay.setLanguageId(LocaleUtil.toLanguageId(locale));
  744. themeDisplay.setI18nLanguageId(i18nLanguageId);
  745. themeDisplay.setI18nPath(i18nPath);
  746. themeDisplay.setTimeZone(timeZone);
  747. themeDisplay.setLookAndFeel(theme, colorScheme);
  748. themeDisplay.setThemeCssFastLoad(themeCssFastLoad);
  749. themeDisplay.setThemeImagesFastLoad(themeImagesFastLoad);
  750. themeDisplay.setThemeJsBarebone(themeJsBarebone);
  751. themeDisplay.setThemeJsFastLoad(themeJsFastLoad);
  752. themeDisplay.setServerName(request.getServerName());
  753. themeDisplay.setServerPort(request.getServerPort());
  754. themeDisplay.setSecure(PortalUtil.isSecure(request));
  755. themeDisplay.setLifecycle(lifecycle);
  756. themeDisplay.setLifecycleAction(lifecycle.equals("1"));
  757. themeDisplay.setLifecycleRender(lifecycle.equals("0"));
  758. themeDisplay.setLifecycleResource(lifecycle.equals("2"));
  759. themeDisplay.setStateExclusive(LiferayWindowState.isExclusive(request));
  760. themeDisplay.setStateMaximized(LiferayWindowState.isMaximized(request));
  761. themeDisplay.setStatePopUp(LiferayWindowState.isPopUp(request));
  762. themeDisplay.setIsolated(isolated);
  763. themeDisplay.setPathApplet(contextPath.concat("/applets"));
  764. themeDisplay.setPathCms(contextPath.concat("/cms"));
  765. themeDisplay.setPathContext(contextPath);
  766. themeDisplay.setPathFlash(contextPath.concat("/flash"));
  767. themeDisplay.setPathFriendlyURLPrivateGroup(
  768. friendlyURLPrivateGroupPath);
  769. themeDisplay.setPathFriendlyURLPrivateUser(friendlyURLPrivateUserPath);
  770. themeDisplay.setPathFriendlyURLPublic(friendlyURLPublicPath);
  771. themeDisplay.setPathImage(imagePath);
  772. themeDisplay.setPathJavaScript(
  773. cdnHost.concat(contextPath).concat("/html/js"));
  774. themeDisplay.setPathMain(mainPath);
  775. themeDisplay.setPathSound(contextPath.concat("/html/sound"));
  776.  
  777. // Icons
  778.  
  779. themeDisplay.setShowAddContentIcon(false);
  780. themeDisplay.setShowControlPanelIcon(signedIn);
  781. themeDisplay.setShowHomeIcon(true);
  782. themeDisplay.setShowMyAccountIcon(signedIn);
  783. themeDisplay.setShowPageSettingsIcon(false);
  784. themeDisplay.setShowPortalIcon(true);
  785. themeDisplay.setShowSignInIcon(!signedIn);
  786. themeDisplay.setShowSignOutIcon(signedIn);
  787.  
  788. boolean showSiteContentIcon = false;
  789.  
  790. long controlPanelPlid = 0;
  791.  
  792. if (signedIn) {
  793. Group controlPanelGroup = GroupLocalServiceUtil.getGroup(
  794. companyId, GroupConstants.CONTROL_PANEL);
  795.  
  796. controlPanelPlid = LayoutLocalServiceUtil.getDefaultPlid(
  797. controlPanelGroup.getGroupId(), true);
  798.  
  799. List<Portlet> siteContentPortlets =
  800. PortalUtil.getControlPanelPortlets(
  801. PortletCategoryKeys.CONTENT, themeDisplay);
  802.  
  803. Portlet groupPagesPortlet = PortletLocalServiceUtil.getPortletById(
  804. PortletKeys.GROUP_PAGES);
  805.  
  806. siteContentPortlets.remove(groupPagesPortlet);
  807.  
  808. Portlet siteMembershipsAdminPortlet =
  809. PortletLocalServiceUtil.getPortletById(
  810. PortletKeys.SITE_MEMBERSHIPS_ADMIN);
  811.  
  812. siteContentPortlets.remove(siteMembershipsAdminPortlet);
  813.  
  814. Portlet siteSettingsPortlet =
  815. PortletLocalServiceUtil.getPortletById(
  816. PortletKeys.SITE_SETTINGS);
  817.  
  818. siteContentPortlets.remove(siteSettingsPortlet);
  819.  
  820. showSiteContentIcon = PortletPermissionUtil.contains(
  821. permissionChecker, scopeGroupId, controlPanelPlid,
  822. siteContentPortlets, ActionKeys.VIEW);
  823. }
  824.  
  825. themeDisplay.setShowSiteContentIcon(showSiteContentIcon);
  826.  
  827. themeDisplay.setShowStagingIcon(false);
  828.  
  829. // Session
  830.  
  831. if (PropsValues.SESSION_ENABLE_URL_WITH_SESSION_ID &&
  832. !CookieKeys.hasSessionId(request)) {
  833.  
  834. themeDisplay.setAddSessionIdToURL(true);
  835. themeDisplay.setSessionId(session.getId());
  836. }
  837.  
  838. // URLs
  839.  
  840. String urlControlPanel = friendlyURLPrivateGroupPath.concat(
  841. GroupConstants.CONTROL_PANEL_FRIENDLY_URL);
  842.  
  843. if (Validator.isNotNull(doAsUserId)) {
  844. urlControlPanel = HttpUtil.addParameter(
  845. urlControlPanel, "doAsUserId", doAsUserId);
  846. }
  847.  
  848. if (scopeGroupId > 0) {
  849. urlControlPanel = HttpUtil.addParameter(
  850. urlControlPanel, "doAsGroupId", scopeGroupId);
  851. }
  852.  
  853. if (refererPlid > 0) {
  854. urlControlPanel = HttpUtil.addParameter(
  855. urlControlPanel, "refererPlid", refererPlid);
  856. }
  857. else if (plid > 0) {
  858. urlControlPanel = HttpUtil.addParameter(
  859. urlControlPanel, "refererPlid", plid);
  860. }
  861.  
  862. if (themeDisplay.isAddSessionIdToURL()) {
  863. urlControlPanel = PortalUtil.getURLWithSessionId(
  864. urlControlPanel, session.getId());
  865. }
  866.  
  867. themeDisplay.setURLControlPanel(urlControlPanel);
  868.  
  869. String siteContentURL = urlControlPanel;
  870.  
  871. siteContentURL = HttpUtil.addParameter(
  872. siteContentURL, "controlPanelCategory",
  873. PortletCategoryKeys.CONTENT);
  874.  
  875. themeDisplay.setURLSiteContent(siteContentURL);
  876.  
  877. String currentURL = PortalUtil.getCurrentURL(request);
  878.  
  879. themeDisplay.setURLCurrent(currentURL);
  880.  
  881. String urlHome = PortalUtil.getHomeURL(request);
  882.  
  883. themeDisplay.setURLHome(urlHome);
  884.  
  885. if (layout != null) {
  886. if (layout.isTypePortlet()) {
  887. boolean freeformLayout =
  888. layoutTypePortlet.getLayoutTemplateId().equals("freeform");
  889.  
  890. themeDisplay.setFreeformLayout(freeformLayout);
  891.  
  892. if (hasUpdateLayoutPermission) {
  893. themeDisplay.setShowAddContentIconPermission(true);
  894.  
  895. if (!LiferayWindowState.isMaximized(request)) {
  896. themeDisplay.setShowAddContentIcon(true);
  897. }
  898.  
  899. themeDisplay.setShowLayoutTemplatesIcon(true);
  900.  
  901. if (!group.isUser()) {
  902. themeDisplay.setShowPageCustomizationIcon(true);
  903. }
  904.  
  905. themeDisplay.setURLAddContent(
  906. "Liferay.LayoutConfiguration.toggle('".concat(
  907. PortletKeys.LAYOUT_CONFIGURATION).concat("');"));
  908.  
  909. themeDisplay.setURLLayoutTemplates(
  910. "Liferay.LayoutConfiguration.showTemplates();");
  911. }
  912.  
  913. if (hasCustomizeLayoutPermission && customizedView) {
  914. themeDisplay.setShowAddContentIconPermission(true);
  915.  
  916. if (!LiferayWindowState.isMaximized(request)) {
  917. themeDisplay.setShowAddContentIcon(true);
  918. }
  919.  
  920. themeDisplay.setURLAddContent(
  921. "Liferay.LayoutConfiguration.toggle('".concat(
  922. PortletKeys.LAYOUT_CONFIGURATION).concat("');"));
  923. }
  924. }
  925.  
  926. if (signedIn) {
  927. if (group.isUser()) {
  928. if ((layout.isPrivateLayout() &&
  929. !PropsValues.LAYOUT_USER_PRIVATE_LAYOUTS_MODIFIABLE) ||
  930. (layout.isPublicLayout() &&
  931. !PropsValues.LAYOUT_USER_PUBLIC_LAYOUTS_MODIFIABLE)) {
  932.  
  933. hasUpdateLayoutPermission = false;
  934. }
  935. }
  936. }
  937.  
  938. if (hasUpdateLayoutPermission) {
  939. themeDisplay.setShowPageSettingsIcon(true);
  940.  
  941. LiferayPortletURL pageSettingsURL = new PortletURLImpl(
  942. request, PortletKeys.LAYOUTS_ADMIN, controlPanelPlid,
  943. PortletRequest.RENDER_PHASE);
  944.  
  945. pageSettingsURL.setControlPanelCategory(
  946. _CONTROL_PANEL_CATEGORY_PORTLET_PREFIX +
  947. PortletKeys.LAYOUTS_ADMIN);
  948. pageSettingsURL.setParameter(
  949. "struts_action", "/layouts_admin/edit_layouts");
  950.  
  951. if (layout.isPrivateLayout()) {
  952. pageSettingsURL.setParameter("tabs1", "private-pages");
  953. }
  954. else {
  955. pageSettingsURL.setParameter("tabs1", "public-pages");
  956. }
  957.  
  958. pageSettingsURL.setParameter("closeRedirect", currentURL);
  959. pageSettingsURL.setParameter(
  960. "groupId", String.valueOf(scopeGroupId));
  961. pageSettingsURL.setParameter("selPlid", String.valueOf(plid));
  962. pageSettingsURL.setPortletMode(PortletMode.VIEW);
  963. pageSettingsURL.setWindowState(LiferayWindowState.POP_UP);
  964.  
  965. themeDisplay.setURLPageSettings(pageSettingsURL);
  966.  
  967. boolean site = group.isSite();
  968.  
  969. if (!site && group.isStagingGroup()) {
  970. Group liveGroup = group.getLiveGroup();
  971.  
  972. site = liveGroup.isSite();
  973. }
  974.  
  975. if (site &&
  976. GroupPermissionUtil.contains(
  977. permissionChecker, scopeGroupId,
  978. ActionKeys.ASSIGN_MEMBERS)) {
  979.  
  980. themeDisplay.setShowManageSiteMembershipsIcon(true);
  981.  
  982. LiferayPortletURL manageSiteMembershipsURL =
  983. new PortletURLImpl(
  984. request, PortletKeys.SITE_MEMBERSHIPS_ADMIN,
  985. controlPanelPlid, PortletRequest.RENDER_PHASE);
  986.  
  987. manageSiteMembershipsURL.setControlPanelCategory(
  988. _CONTROL_PANEL_CATEGORY_PORTLET_PREFIX +
  989. PortletKeys.SITE_MEMBERSHIPS_ADMIN);
  990. manageSiteMembershipsURL.setParameter(
  991. "struts_action", "/sites_admin/edit_site_assignments");
  992. manageSiteMembershipsURL.setParameter(
  993. "groupId", String.valueOf(scopeGroupId));
  994. manageSiteMembershipsURL.setParameter(
  995. "selPlid", String.valueOf(plid));
  996. manageSiteMembershipsURL.setPortletMode(PortletMode.VIEW);
  997. manageSiteMembershipsURL.setWindowState(
  998. LiferayWindowState.POP_UP);
  999.  
  1000. themeDisplay.setURLManageSiteMemberships(
  1001. manageSiteMembershipsURL);
  1002. }
  1003. else {
  1004. themeDisplay.setShowManageSiteMembershipsIcon(false);
  1005. }
  1006. }
  1007.  
  1008. boolean hasAddLayoutGroupPermission =
  1009. GroupPermissionUtil.contains(
  1010. permissionChecker, scopeGroupId, ActionKeys.ADD_LAYOUT);
  1011. boolean hasAddLayoutLayoutPermission =
  1012. LayoutPermissionUtil.contains(
  1013. permissionChecker, layout, ActionKeys.ADD_LAYOUT);
  1014. boolean hasManageLayoutsGroupPermission =
  1015. GroupPermissionUtil.contains(
  1016. permissionChecker, scopeGroupId, ActionKeys.MANAGE_LAYOUTS);
  1017. boolean hasManageStagingPermission = GroupPermissionUtil.contains(
  1018. permissionChecker, scopeGroupId, ActionKeys.MANAGE_STAGING);
  1019. boolean hasPublishStagingPermission = GroupPermissionUtil.contains(
  1020. permissionChecker, scopeGroupId, ActionKeys.PUBLISH_STAGING);
  1021. boolean hasUpdateGroupPermission = GroupPermissionUtil.contains(
  1022. permissionChecker, scopeGroupId, ActionKeys.UPDATE);
  1023. boolean hasViewStagingPermission = GroupPermissionUtil.contains(
  1024. permissionChecker, scopeGroupId, ActionKeys.VIEW_STAGING);
  1025.  
  1026. if (!group.isControlPanel() && !group.isUser() &&
  1027. !group.isUserGroup() && hasUpdateGroupPermission) {
  1028.  
  1029. themeDisplay.setShowSiteSettingsIcon(true);
  1030.  
  1031. LiferayPortletURL siteSettingsURL = new PortletURLImpl(
  1032. request, PortletKeys.SITE_SETTINGS, controlPanelPlid,
  1033. PortletRequest.RENDER_PHASE);
  1034.  
  1035. siteSettingsURL.setControlPanelCategory(
  1036. _CONTROL_PANEL_CATEGORY_PORTLET_PREFIX +
  1037. PortletKeys.SITE_SETTINGS);
  1038. siteSettingsURL.setParameter(
  1039. "struts_action", "/sites_admin/edit_site");
  1040. siteSettingsURL.setParameter("closeRedirect", currentURL);
  1041. siteSettingsURL.setParameter(
  1042. "groupId", String.valueOf(scopeGroupId));
  1043. siteSettingsURL.setPortletMode(PortletMode.VIEW);
  1044. siteSettingsURL.setWindowState(LiferayWindowState.POP_UP);
  1045.  
  1046. themeDisplay.setURLSiteSettings(siteSettingsURL);
  1047. }
  1048.  
  1049. if (!group.isLayoutPrototype() &&
  1050. (hasAddLayoutGroupPermission || hasAddLayoutLayoutPermission ||
  1051. hasManageLayoutsGroupPermission || hasUpdateGroupPermission)) {
  1052.  
  1053. themeDisplay.setShowSiteMapSettingsIcon(true);
  1054.  
  1055. LiferayPortletURL siteMapSettingsURL = new PortletURLImpl(
  1056. request, PortletKeys.LAYOUTS_ADMIN, controlPanelPlid,
  1057. PortletRequest.RENDER_PHASE);
  1058.  
  1059. siteMapSettingsURL.setControlPanelCategory(
  1060. _CONTROL_PANEL_CATEGORY_PORTLET_PREFIX +
  1061. PortletKeys.LAYOUTS_ADMIN);
  1062. siteMapSettingsURL.setParameter(
  1063. "struts_action", "/layouts_admin/edit_layouts");
  1064.  
  1065. if (layout.isPrivateLayout()) {
  1066. siteMapSettingsURL.setParameter("tabs1", "private-pages");
  1067. }
  1068. else {
  1069. siteMapSettingsURL.setParameter("tabs1", "public-pages");
  1070. }
  1071.  
  1072. siteMapSettingsURL.setParameter("closeRedirect", currentURL);
  1073. siteMapSettingsURL.setParameter(
  1074. "groupId", String.valueOf(scopeGroupId));
  1075. siteMapSettingsURL.setPortletMode(PortletMode.VIEW);
  1076. siteMapSettingsURL.setWindowState(LiferayWindowState.POP_UP);
  1077.  
  1078. themeDisplay.setURLSiteMapSettings(siteMapSettingsURL);
  1079. }
  1080.  
  1081. if (group.hasStagingGroup() && !group.isStagingGroup()) {
  1082. themeDisplay.setShowAddContentIcon(false);
  1083. themeDisplay.setShowLayoutTemplatesIcon(false);
  1084. themeDisplay.setShowPageSettingsIcon(false);
  1085. themeDisplay.setURLPublishToLive(null);
  1086. }
  1087.  
  1088. if (group.isControlPanel()) {
  1089. themeDisplay.setShowPageSettingsIcon(false);
  1090. themeDisplay.setURLPublishToLive(null);
  1091. }
  1092.  
  1093. // LEP-4987
  1094.  
  1095. if (group.isStaged() || group.isStagingGroup()) {
  1096. if (hasManageStagingPermission || hasPublishStagingPermission ||
  1097. hasUpdateLayoutPermission || hasViewStagingPermission) {
  1098.  
  1099. themeDisplay.setShowStagingIcon(true);
  1100. }
  1101.  
  1102. if (hasPublishStagingPermission) {
  1103. PortletURL publishToLiveURL = new PortletURLImpl(
  1104. request, PortletKeys.LAYOUTS_ADMIN, plid,
  1105. PortletRequest.RENDER_PHASE);
  1106.  
  1107. publishToLiveURL.setParameter(
  1108. "struts_action", "/layouts_admin/publish_layouts");
  1109.  
  1110. if (layout.isPrivateLayout()) {
  1111. publishToLiveURL.setParameter("tabs1", "private-pages");
  1112. }
  1113. else {
  1114. publishToLiveURL.setParameter("tabs1", "public-pages");
  1115. }
  1116.  
  1117. publishToLiveURL.setParameter("pagesRedirect", currentURL);
  1118. publishToLiveURL.setParameter(
  1119. "groupId", String.valueOf(scopeGroupId));
  1120. publishToLiveURL.setParameter(
  1121. "selPlid", String.valueOf(plid));
  1122. publishToLiveURL.setPortletMode(PortletMode.VIEW);
  1123. publishToLiveURL.setWindowState(
  1124. LiferayWindowState.EXCLUSIVE);
  1125.  
  1126. themeDisplay.setURLPublishToLive(publishToLiveURL);
  1127. }
  1128. }
  1129.  
  1130. PortletURLImpl myAccountURL = new PortletURLImpl(
  1131. request, PortletKeys.MY_ACCOUNT, controlPanelPlid,
  1132. PortletRequest.RENDER_PHASE);
  1133.  
  1134. if (scopeGroupId > 0) {
  1135. myAccountURL.setDoAsGroupId(scopeGroupId);
  1136. }
  1137.  
  1138. myAccountURL.setParameter("struts_action", "/my_account/edit_user");
  1139. myAccountURL.setPortletMode(PortletMode.VIEW);
  1140.  
  1141. if (refererPlid > 0) {
  1142. myAccountURL.setRefererPlid(refererPlid);
  1143. }
  1144. else {
  1145. myAccountURL.setRefererPlid(plid);
  1146. }
  1147.  
  1148. myAccountURL.setWindowState(WindowState.MAXIMIZED);
  1149.  
  1150. themeDisplay.setURLMyAccount(myAccountURL);
  1151. }
  1152.  
  1153. if ((!user.isActive()) ||
  1154. (PrefsPropsUtil.getBoolean(
  1155. companyId, PropsKeys.TERMS_OF_USE_REQUIRED) &&
  1156. !user.isAgreedToTermsOfUse())) {
  1157.  
  1158. themeDisplay.setShowAddContentIcon(false);
  1159. themeDisplay.setShowMyAccountIcon(false);
  1160. themeDisplay.setShowPageSettingsIcon(false);
  1161. }
  1162.  
  1163. if (group.isLayoutPrototype()) {
  1164. themeDisplay.setShowControlPanelIcon(false);
  1165. themeDisplay.setShowHomeIcon(false);
  1166. themeDisplay.setShowManageSiteMembershipsIcon(false);
  1167. themeDisplay.setShowMyAccountIcon(false);
  1168. themeDisplay.setShowPageCustomizationIcon(false);
  1169. themeDisplay.setShowPageSettingsIcon(true);
  1170. themeDisplay.setShowPortalIcon(false);
  1171. themeDisplay.setShowSignInIcon(false);
  1172. themeDisplay.setShowSignOutIcon(false);
  1173. themeDisplay.setShowSiteContentIcon(false);
  1174. themeDisplay.setShowSiteSettingsIcon(false);
  1175. themeDisplay.setShowStagingIcon(false);
  1176. }
  1177.  
  1178. if (group.isLayoutSetPrototype()) {
  1179. themeDisplay.setShowPageCustomizationIcon(false);
  1180. themeDisplay.setShowSiteSettingsIcon(false);
  1181. }
  1182.  
  1183. if (group.hasStagingGroup() && !group.isStagingGroup()) {
  1184. themeDisplay.setShowLayoutTemplatesIcon(false);
  1185. themeDisplay.setShowPageCustomizationIcon(false);
  1186. themeDisplay.setShowPageSettingsIcon(false);
  1187. themeDisplay.setShowSiteContentIcon(false);
  1188. themeDisplay.setShowSiteMapSettingsIcon(false);
  1189. themeDisplay.setShowSiteSettingsIcon(false);
  1190. }
  1191.  
  1192. themeDisplay.setURLPortal(portalURL.concat(contextPath));
  1193.  
  1194. String urlSignIn = mainPath.concat("/portal/login");
  1195.  
  1196. if (layout != null) {
  1197. urlSignIn = HttpUtil.addParameter(
  1198. urlSignIn, "p_l_id", layout.getPlid());
  1199. }
  1200.  
  1201. themeDisplay.setURLSignIn(urlSignIn);
  1202.  
  1203. themeDisplay.setURLSignOut(mainPath.concat("/portal/logout"));
  1204.  
  1205. PortletURL updateManagerURL = new PortletURLImpl(
  1206. request, PortletKeys.UPDATE_MANAGER, plid,
  1207. PortletRequest.RENDER_PHASE);
  1208.  
  1209. updateManagerURL.setParameter("struts_action", "/update_manager/view");
  1210. updateManagerURL.setPortletMode(PortletMode.VIEW);
  1211. updateManagerURL.setWindowState(WindowState.MAXIMIZED);
  1212.  
  1213. themeDisplay.setURLUpdateManager(updateManagerURL);
  1214.  
  1215. return themeDisplay;
  1216. }
  1217.  
  1218. @Override
  1219. public void run(HttpServletRequest request, HttpServletResponse response)
  1220. throws ActionException {
  1221.  
  1222. StopWatch stopWatch = null;
  1223.  
  1224. if (_log.isDebugEnabled()) {
  1225. stopWatch = new StopWatch();
  1226.  
  1227. stopWatch.start();
  1228. }
  1229.  
  1230. try {
  1231. servicePre(request, response);
  1232. }
  1233. catch (Exception e) {
  1234. throw new ActionException(e);
  1235. }
  1236.  
  1237. if (_log.isDebugEnabled()) {
  1238. _log.debug("Running takes " + stopWatch.getTime() + " ms");
  1239. }
  1240. }
  1241.  
  1242. protected void addDefaultLayoutsByLAR(
  1243. long userId, long groupId, boolean privateLayout, File larFile)
  1244. throws PortalException, SystemException {
  1245.  
  1246. Map<String, String[]> parameterMap = new HashMap<String, String[]>();
  1247.  
  1248. parameterMap.put(
  1249. PortletDataHandlerKeys.PERMISSIONS,
  1250. new String[] {Boolean.TRUE.toString()});
  1251. parameterMap.put(
  1252. PortletDataHandlerKeys.PORTLET_DATA,
  1253. new String[] {Boolean.TRUE.toString()});
  1254. parameterMap.put(
  1255. PortletDataHandlerKeys.PORTLET_DATA_CONTROL_DEFAULT,
  1256. new String[] {Boolean.TRUE.toString()});
  1257. parameterMap.put(
  1258. PortletDataHandlerKeys.PORTLET_SETUP,
  1259. new String[] {Boolean.TRUE.toString()});
  1260. parameterMap.put(
  1261. PortletDataHandlerKeys.USER_PERMISSIONS,
  1262. new String[] {Boolean.FALSE.toString()});
  1263.  
  1264. LayoutLocalServiceUtil.importLayouts(
  1265. userId, groupId, privateLayout, parameterMap, larFile);
  1266. }
  1267.  
  1268. protected void addDefaultUserPrivateLayoutByProperties(
  1269. long userId, long groupId)
  1270. throws PortalException, SystemException {
  1271.  
  1272. String friendlyURL = getFriendlyURL(
  1273. PropsValues.DEFAULT_USER_PRIVATE_LAYOUT_FRIENDLY_URL);
  1274.  
  1275. ServiceContext serviceContext = new ServiceContext();
  1276.  
  1277. Layout layout = LayoutLocalServiceUtil.addLayout(
  1278. userId, groupId, true, LayoutConstants.DEFAULT_PARENT_LAYOUT_ID,
  1279. PropsValues.DEFAULT_USER_PRIVATE_LAYOUT_NAME, StringPool.BLANK,
  1280. StringPool.BLANK, LayoutConstants.TYPE_PORTLET, false, friendlyURL,
  1281. serviceContext);
  1282.  
  1283. LayoutTypePortlet layoutTypePortlet =
  1284. (LayoutTypePortlet)layout.getLayoutType();
  1285.  
  1286. layoutTypePortlet.setLayoutTemplateId(
  1287. 0, PropsValues.DEFAULT_USER_PRIVATE_LAYOUT_TEMPLATE_ID, false);
  1288.  
  1289. for (int i = 0; i < 10; i++) {
  1290. String columnId = "column-" + i;
  1291. String portletIds = PropsUtil.get(
  1292. PropsKeys.DEFAULT_USER_PRIVATE_LAYOUT_COLUMN + i);
  1293.  
  1294. String[] portletIdsArray = StringUtil.split(portletIds);
  1295.  
  1296. layoutTypePortlet.addPortletIds(
  1297. 0, portletIdsArray, columnId, false);
  1298. }
  1299.  
  1300. LayoutLocalServiceUtil.updateLayout(
  1301. layout.getGroupId(), layout.isPrivateLayout(), layout.getLayoutId(),
  1302. layout.getTypeSettings());
  1303.  
  1304. boolean updateLayoutSet = false;
  1305.  
  1306. LayoutSet layoutSet = layout.getLayoutSet();
  1307.  
  1308. if (Validator.isNotNull(
  1309. PropsValues.DEFAULT_USER_PRIVATE_LAYOUT_REGULAR_THEME_ID)) {
  1310.  
  1311. layoutSet.setThemeId(
  1312. PropsValues.DEFAULT_USER_PRIVATE_LAYOUT_REGULAR_THEME_ID);
  1313.  
  1314. updateLayoutSet = true;
  1315. }
  1316.  
  1317. if (Validator.isNotNull(
  1318. PropsValues.
  1319. DEFAULT_USER_PRIVATE_LAYOUT_REGULAR_COLOR_SCHEME_ID)) {
  1320.  
  1321. layoutSet.setColorSchemeId(
  1322. PropsValues.
  1323. DEFAULT_USER_PRIVATE_LAYOUT_REGULAR_COLOR_SCHEME_ID);
  1324.  
  1325. updateLayoutSet = true;
  1326. }
  1327.  
  1328. if (Validator.isNotNull(
  1329. PropsValues.DEFAULT_USER_PRIVATE_LAYOUT_WAP_THEME_ID)) {
  1330.  
  1331. layoutSet.setWapThemeId(
  1332. PropsValues.DEFAULT_USER_PRIVATE_LAYOUT_WAP_THEME_ID);
  1333.  
  1334. updateLayoutSet = true;
  1335. }
  1336.  
  1337. if (Validator.isNotNull(
  1338. PropsValues.DEFAULT_USER_PRIVATE_LAYOUT_WAP_COLOR_SCHEME_ID)) {
  1339.  
  1340. layoutSet.setWapColorSchemeId(
  1341. PropsValues.DEFAULT_USER_PRIVATE_LAYOUT_WAP_COLOR_SCHEME_ID);
  1342.  
  1343. updateLayoutSet = true;
  1344. }
  1345.  
  1346. if (updateLayoutSet) {
  1347. LayoutSetLocalServiceUtil.updateLayoutSet(layoutSet);
  1348. }
  1349. }
  1350.  
  1351. protected void addDefaultUserPrivateLayouts(User user)
  1352. throws PortalException, SystemException {
  1353.  
  1354. Group userGroup = user.getGroup();
  1355.  
  1356. if (privateLARFile != null) {
  1357. addDefaultLayoutsByLAR(
  1358. user.getUserId(), userGroup.getGroupId(), true, privateLARFile);
  1359. }
  1360. else {
  1361. addDefaultUserPrivateLayoutByProperties(
  1362. user.getUserId(), userGroup.getGroupId());
  1363. }
  1364. }
  1365.  
  1366. protected void addDefaultUserPublicLayoutByProperties(
  1367. long userId, long groupId)
  1368. throws PortalException, SystemException {
  1369.  
  1370. String friendlyURL = getFriendlyURL(
  1371. PropsValues.DEFAULT_USER_PUBLIC_LAYOUT_FRIENDLY_URL);
  1372.  
  1373. ServiceContext serviceContext = new ServiceContext();
  1374.  
  1375. Layout layout = LayoutLocalServiceUtil.addLayout(
  1376. userId, groupId, false, LayoutConstants.DEFAULT_PARENT_LAYOUT_ID,
  1377. PropsValues.DEFAULT_USER_PUBLIC_LAYOUT_NAME, StringPool.BLANK,
  1378. StringPool.BLANK, LayoutConstants.TYPE_PORTLET, false, friendlyURL,
  1379. serviceContext);
  1380.  
  1381. LayoutTypePortlet layoutTypePortlet =
  1382. (LayoutTypePortlet)layout.getLayoutType();
  1383.  
  1384. layoutTypePortlet.setLayoutTemplateId(
  1385. 0, PropsValues.DEFAULT_USER_PUBLIC_LAYOUT_TEMPLATE_ID, false);
  1386.  
  1387. for (int i = 0; i < 10; i++) {
  1388. String columnId = "column-" + i;
  1389. String portletIds = PropsUtil.get(
  1390. PropsKeys.DEFAULT_USER_PUBLIC_LAYOUT_COLUMN + i);
  1391.  
  1392. String[] portletIdsArray = StringUtil.split(portletIds);
  1393.  
  1394. layoutTypePortlet.addPortletIds(
  1395. 0, portletIdsArray, columnId, false);
  1396. }
  1397.  
  1398. LayoutLocalServiceUtil.updateLayout(
  1399. layout.getGroupId(), layout.isPrivateLayout(), layout.getLayoutId(),
  1400. layout.getTypeSettings());
  1401.  
  1402. boolean updateLayoutSet = false;
  1403.  
  1404. LayoutSet layoutSet = layout.getLayoutSet();
  1405.  
  1406. if (Validator.isNotNull(
  1407. PropsValues.DEFAULT_USER_PUBLIC_LAYOUT_REGULAR_THEME_ID)) {
  1408.  
  1409. layoutSet.setThemeId(
  1410. PropsValues.DEFAULT_USER_PUBLIC_LAYOUT_REGULAR_THEME_ID);
  1411.  
  1412. updateLayoutSet = true;
  1413. }
  1414.  
  1415. if (Validator.isNotNull(
  1416. PropsValues.
  1417. DEFAULT_USER_PUBLIC_LAYOUT_REGULAR_COLOR_SCHEME_ID)) {
  1418.  
  1419. layoutSet.setColorSchemeId(
  1420. PropsValues.DEFAULT_USER_PUBLIC_LAYOUT_REGULAR_COLOR_SCHEME_ID);
  1421.  
  1422. updateLayoutSet = true;
  1423. }
  1424.  
  1425. if (Validator.isNotNull(
  1426. PropsValues.DEFAULT_USER_PUBLIC_LAYOUT_WAP_THEME_ID)) {
  1427.  
  1428. layoutSet.setWapThemeId(
  1429. PropsValues.DEFAULT_USER_PUBLIC_LAYOUT_WAP_THEME_ID);
  1430.  
  1431. updateLayoutSet = true;
  1432. }
  1433.  
  1434. if (Validator.isNotNull(
  1435. PropsValues.DEFAULT_USER_PUBLIC_LAYOUT_WAP_COLOR_SCHEME_ID)) {
  1436.  
  1437. layoutSet.setWapColorSchemeId(
  1438. PropsValues.DEFAULT_USER_PUBLIC_LAYOUT_WAP_COLOR_SCHEME_ID);
  1439.  
  1440. updateLayoutSet = true;
  1441. }
  1442.  
  1443. if (updateLayoutSet) {
  1444. LayoutSetLocalServiceUtil.updateLayoutSet(layoutSet);
  1445. }
  1446. }
  1447.  
  1448. protected void addDefaultUserPublicLayouts(User user)
  1449. throws PortalException, SystemException {
  1450.  
  1451. Group userGroup = user.getGroup();
  1452.  
  1453. if (publicLARFile != null) {
  1454. addDefaultLayoutsByLAR(
  1455. user.getUserId(), userGroup.getGroupId(), false, publicLARFile);
  1456. }
  1457. else {
  1458. addDefaultUserPublicLayoutByProperties(
  1459. user.getUserId(), userGroup.getGroupId());
  1460. }
  1461. }
  1462.  
  1463. protected void deleteDefaultUserPrivateLayouts(User user)
  1464. throws PortalException, SystemException {
  1465.  
  1466. Group userGroup = user.getGroup();
  1467.  
  1468. ServiceContext serviceContext = new ServiceContext();
  1469.  
  1470. LayoutLocalServiceUtil.deleteLayouts(
  1471. userGroup.getGroupId(), true, serviceContext);
  1472. }
  1473.  
  1474. protected void deleteDefaultUserPublicLayouts(User user)
  1475. throws PortalException, SystemException {
  1476.  
  1477. Group userGroup = user.getGroup();
  1478.  
  1479. ServiceContext serviceContext = new ServiceContext();
  1480.  
  1481. LayoutLocalServiceUtil.deleteLayouts(
  1482. userGroup.getGroupId(), false, serviceContext);
  1483. }
  1484.  
  1485. protected Object[] getDefaultLayout(
  1486. HttpServletRequest request, User user, boolean signedIn)
  1487. throws PortalException, SystemException {
  1488.  
  1489. // Check the virtual host
  1490.  
  1491. LayoutSet layoutSet = (LayoutSet)request.getAttribute(
  1492. WebKeys.VIRTUAL_HOST_LAYOUT_SET);
  1493.  
  1494. if (layoutSet != null) {
  1495. List<Layout> layouts = LayoutLocalServiceUtil.getLayouts(
  1496. layoutSet.getGroupId(), layoutSet.isPrivateLayout(),
  1497. LayoutConstants.DEFAULT_PARENT_LAYOUT_ID);
  1498.  
  1499. if (layouts.size() > 0) {
  1500. Layout layout = layouts.get(0);
  1501.  
  1502. return new Object[] {layout, layouts};
  1503. }
  1504. }
  1505.  
  1506. Layout layout = null;
  1507. List<Layout> layouts = null;
  1508.  
  1509. if (signedIn) {
  1510.  
  1511. // Check the user's personal layouts
  1512.  
  1513. Group userGroup = user.getGroup();
  1514.  
  1515. layouts = LayoutLocalServiceUtil.getLayouts(
  1516. userGroup.getGroupId(), true,
  1517. LayoutConstants.DEFAULT_PARENT_LAYOUT_ID);
  1518.  
  1519. if (layouts.size() == 0) {
  1520. layouts = LayoutLocalServiceUtil.getLayouts(
  1521. userGroup.getGroupId(), false,
  1522. LayoutConstants.DEFAULT_PARENT_LAYOUT_ID);
  1523. }
  1524.  
  1525. if (layouts.size() > 0) {
  1526. layout = layouts.get(0);
  1527. }
  1528.  
  1529. // Check the user's sites
  1530.  
  1531. if (layout == null) {
  1532. LinkedHashMap<String, Object> groupParams =
  1533. new LinkedHashMap<String, Object>();
  1534.  
  1535. groupParams.put("usersGroups", new Long(user.getUserId()));
  1536.  
  1537. List<Group> groups = GroupLocalServiceUtil.search(
  1538. user.getCompanyId(), null, null, groupParams,
  1539. QueryUtil.ALL_POS, QueryUtil.ALL_POS);
  1540.  
  1541. for (Group group : groups) {
  1542. layouts = LayoutLocalServiceUtil.getLayouts(
  1543. group.getGroupId(), true,
  1544. LayoutConstants.DEFAULT_PARENT_LAYOUT_ID);
  1545.  
  1546. if (layouts.size() == 0) {
  1547. layouts = LayoutLocalServiceUtil.getLayouts(
  1548. group.getGroupId(), false,
  1549. LayoutConstants.DEFAULT_PARENT_LAYOUT_ID);
  1550. }
  1551.  
  1552. if (layouts.size() > 0) {
  1553. layout = layouts.get(0);
  1554.  
  1555. break;
  1556. }
  1557. }
  1558. }
  1559. }
  1560.  
  1561. if (layout == null) {
  1562.  
  1563. // Check the Guest site
  1564.  
  1565. Group guestGroup = GroupLocalServiceUtil.getGroup(
  1566. user.getCompanyId(), GroupConstants.GUEST);
  1567.  
  1568. layouts = LayoutLocalServiceUtil.getLayouts(
  1569. guestGroup.getGroupId(), false,
  1570. LayoutConstants.DEFAULT_PARENT_LAYOUT_ID);
  1571.  
  1572. if (layouts.size() > 0) {
  1573. layout = layouts.get(0);
  1574. }
  1575. }
  1576.  
  1577. return new Object[] {layout, layouts};
  1578. }
  1579.  
  1580. protected String getFriendlyURL(String friendlyURL) {
  1581. friendlyURL = GetterUtil.getString(friendlyURL);
  1582.  
  1583. return FriendlyURLNormalizerUtil.normalize(friendlyURL);
  1584. }
  1585.  
  1586. protected Object[] getViewableLayouts(
  1587. HttpServletRequest request, User user,
  1588. PermissionChecker permissionChecker, Layout layout,
  1589. List<Layout> layouts)
  1590. throws PortalException, SystemException {
  1591.  
  1592. if ((layouts == null) || layouts.isEmpty()) {
  1593. return new Object[] {layout, layouts};
  1594. }
  1595.  
  1596. Group group = layout.getGroup();
  1597.  
  1598. boolean hasViewLayoutPermission = false;
  1599. boolean hasViewStagingPermission =
  1600. (group.isStagingGroup() || group.isStagedRemotely()) &&
  1601. GroupPermissionUtil.contains(
  1602. permissionChecker, group.getGroupId(),
  1603. ActionKeys.VIEW_STAGING);
  1604.  
  1605. if (LayoutPermissionUtil.contains(
  1606. permissionChecker, layout, false, ActionKeys.VIEW) ||
  1607. hasViewStagingPermission) {
  1608.  
  1609. hasViewLayoutPermission = true;
  1610. }
  1611.  
  1612. List<Layout> accessibleLayouts = new ArrayList<Layout>();
  1613.  
  1614. for (int i = 0; i < layouts.size(); i++) {
  1615. Layout curLayout = layouts.get(i);
  1616.  
  1617. if (!curLayout.isHidden() &&
  1618. (LayoutPermissionUtil.contains(
  1619. permissionChecker, curLayout, false, ActionKeys.VIEW) ||
  1620. hasViewStagingPermission)) {
  1621.  
  1622. if (accessibleLayouts.isEmpty() && !hasViewLayoutPermission) {
  1623. layout = curLayout;
  1624. }
  1625.  
  1626. accessibleLayouts.add(curLayout);
  1627. }
  1628. }
  1629.  
  1630. if (accessibleLayouts.isEmpty()) {
  1631. layouts = null;
  1632.  
  1633. if (!hasViewLayoutPermission) {
  1634. SessionErrors.add(
  1635. request, LayoutPermissionException.class.getName());
  1636. }
  1637. }
  1638. else {
  1639. layouts = accessibleLayouts;
  1640. }
  1641.  
  1642. return new Object[] {layout, layouts};
  1643. }
  1644.  
  1645. protected Boolean hasPowerUserRole(User user) throws Exception {
  1646. return RoleLocalServiceUtil.hasUserRole(
  1647. user.getUserId(), user.getCompanyId(), RoleConstants.POWER_USER,
  1648. true);
  1649. }
  1650.  
  1651. protected void initImportLARFiles() {
  1652. String privateLARFileName =
  1653. PropsValues.DEFAULT_USER_PRIVATE_LAYOUTS_LAR;
  1654.  
  1655. if (_log.isDebugEnabled()) {
  1656. _log.debug("Reading private LAR file " + privateLARFileName);
  1657. }
  1658.  
  1659. if (Validator.isNotNull(privateLARFileName)) {
  1660. privateLARFile = new File(privateLARFileName);
  1661.  
  1662. if (!privateLARFile.exists()) {
  1663. _log.error(
  1664. "Private LAR file " + privateLARFile + " does not exist");
  1665.  
  1666. privateLARFile = null;
  1667. }
  1668. else {
  1669. if (_log.isDebugEnabled()) {
  1670. _log.debug("Using private LAR file " + privateLARFileName);
  1671. }
  1672. }
  1673. }
  1674.  
  1675. String publicLARFileName = PropsValues.DEFAULT_USER_PUBLIC_LAYOUTS_LAR;
  1676.  
  1677. if (_log.isDebugEnabled()) {
  1678. _log.debug("Reading public LAR file " + publicLARFileName);
  1679. }
  1680.  
  1681. if (Validator.isNotNull(publicLARFileName)) {
  1682. publicLARFile = new File(publicLARFileName);
  1683.  
  1684. if (!publicLARFile.exists()) {
  1685. _log.error(
  1686. "Public LAR file " + publicLARFile + " does not exist");
  1687.  
  1688. publicLARFile = null;
  1689. }
  1690. else {
  1691. if (_log.isDebugEnabled()) {
  1692. _log.debug("Using public LAR file " + publicLARFileName);
  1693. }
  1694. }
  1695. }
  1696. }
  1697.  
  1698. protected boolean isLoginRequest(HttpServletRequest request) {
  1699. String requestURI = request.getRequestURI();
  1700.  
  1701. String mainPath = PortalUtil.getPathMain();
  1702.  
  1703. if (requestURI.startsWith(mainPath.concat("/portal/login"))) {
  1704. return true;
  1705. }
  1706. else {
  1707. return false;
  1708. }
  1709. }
  1710.  
  1711. /**
  1712. * @deprecated
  1713. */
  1714. protected boolean isViewableCommunity(
  1715. User user, long groupId, boolean privateLayout,
  1716. PermissionChecker permissionChecker)
  1717. throws PortalException, SystemException {
  1718.  
  1719. return LayoutPermissionUtil.contains(
  1720. permissionChecker, groupId, privateLayout, 0, ActionKeys.VIEW);
  1721. }
  1722.  
  1723. /**
  1724. * @deprecated
  1725. */
  1726. protected boolean isViewableGroup(
  1727. User user, long groupId, boolean privateLayout, long layoutId,
  1728. String controlPanelCategory, PermissionChecker permissionChecker)
  1729. throws PortalException, SystemException {
  1730.  
  1731. return LayoutPermissionUtil.contains(
  1732. permissionChecker, groupId, privateLayout, layoutId,
  1733. controlPanelCategory, ActionKeys.VIEW);
  1734. }
  1735.  
  1736. protected List<Layout> mergeAdditionalLayouts(
  1737. HttpServletRequest request, User user,
  1738. PermissionChecker permissionChecker, Layout layout,
  1739. List<Layout> layouts)
  1740. throws PortalException, SystemException {
  1741.  
  1742. if ((layout == null) || layout.isPrivateLayout()) {
  1743. return layouts;
  1744. }
  1745.  
  1746. long layoutGroupId = layout.getGroupId();
  1747.  
  1748. Group guestGroup = GroupLocalServiceUtil.getGroup(
  1749. user.getCompanyId(), GroupConstants.GUEST);
  1750.  
  1751. if (layoutGroupId != guestGroup.getGroupId()) {
  1752. Group layoutGroup = GroupLocalServiceUtil.getGroup(layoutGroupId);
  1753.  
  1754. UnicodeProperties typeSettingsProperties =
  1755. layoutGroup.getTypeSettingsProperties();
  1756.  
  1757. boolean mergeGuestPublicPages = GetterUtil.getBoolean(
  1758. typeSettingsProperties.getProperty("mergeGuestPublicPages"));
  1759.  
  1760. if (!mergeGuestPublicPages) {
  1761. return layouts;
  1762. }
  1763.  
  1764. List<Layout> guestLayouts = LayoutLocalServiceUtil.getLayouts(
  1765. guestGroup.getGroupId(), false,
  1766. LayoutConstants.DEFAULT_PARENT_LAYOUT_ID);
  1767.  
  1768. Object[] viewableLayouts = getViewableLayouts(
  1769. request, user, permissionChecker, layout, guestLayouts);
  1770.  
  1771. guestLayouts = (List<Layout>)viewableLayouts[1];
  1772.  
  1773. if (layouts == null) {
  1774. return guestLayouts;
  1775. }
  1776.  
  1777. layouts.addAll(0, guestLayouts);
  1778. }
  1779. else {
  1780. HttpSession session = request.getSession();
  1781.  
  1782. Long previousGroupId = (Long)session.getAttribute(
  1783. WebKeys.VISITED_GROUP_ID_PREVIOUS);
  1784.  
  1785. if ((previousGroupId != null) &&
  1786. (previousGroupId.longValue() != layoutGroupId)) {
  1787.  
  1788. Group previousGroup = null;
  1789.  
  1790. try {
  1791. previousGroup = GroupLocalServiceUtil.getGroup(
  1792. previousGroupId.longValue());
  1793. }
  1794. catch (NoSuchGroupException nsge) {
  1795. if (_log.isWarnEnabled()) {
  1796. _log.warn(nsge);
  1797. }
  1798.  
  1799. return layouts;
  1800. }
  1801.  
  1802. UnicodeProperties typeSettingsProperties =
  1803. previousGroup.getTypeSettingsProperties();
  1804.  
  1805. boolean mergeGuestPublicPages = GetterUtil.getBoolean(
  1806. typeSettingsProperties.getProperty(
  1807. "mergeGuestPublicPages"));
  1808.  
  1809. if (!mergeGuestPublicPages) {
  1810. return layouts;
  1811. }
  1812.  
  1813. List<Layout> previousLayouts =
  1814. LayoutLocalServiceUtil.getLayouts(
  1815. previousGroupId.longValue(), false,
  1816. LayoutConstants.DEFAULT_PARENT_LAYOUT_ID);
  1817.  
  1818. Object[] viewableLayouts = getViewableLayouts(
  1819. request, user, permissionChecker, layout, previousLayouts);
  1820.  
  1821. previousLayouts = (List<Layout>)viewableLayouts[1];
  1822.  
  1823. if (previousLayouts != null) {
  1824. layouts.addAll(previousLayouts);
  1825. }
  1826. }
  1827. }
  1828.  
  1829. return layouts;
  1830. }
  1831.  
  1832. protected void rememberVisitedGroupIds(
  1833. HttpServletRequest request, long currentGroupId) {
  1834.  
  1835. String requestURI = GetterUtil.getString(request.getRequestURI());
  1836.  
  1837. if (!requestURI.endsWith(_PATH_PORTAL_LAYOUT)) {
  1838. return;
  1839. }
  1840.  
  1841. HttpSession session = request.getSession();
  1842.  
  1843. Long recentGroupId = (Long)session.getAttribute(
  1844. WebKeys.VISITED_GROUP_ID_RECENT);
  1845.  
  1846. Long previousGroupId = (Long)session.getAttribute(
  1847. WebKeys.VISITED_GROUP_ID_PREVIOUS);
  1848.  
  1849. if (recentGroupId == null) {
  1850. recentGroupId = new Long(currentGroupId);
  1851.  
  1852. session.setAttribute(
  1853. WebKeys.VISITED_GROUP_ID_RECENT, recentGroupId);
  1854. }
  1855. else if (recentGroupId.longValue() != currentGroupId) {
  1856. previousGroupId = new Long(recentGroupId.longValue());
  1857.  
  1858. recentGroupId = new Long(currentGroupId);
  1859.  
  1860. session.setAttribute(
  1861. WebKeys.VISITED_GROUP_ID_RECENT, recentGroupId);
  1862.  
  1863. session.setAttribute(
  1864. WebKeys.VISITED_GROUP_ID_PREVIOUS, previousGroupId);
  1865. }
  1866.  
  1867. if (_log.isDebugEnabled()) {
  1868. _log.debug("Current group id " + currentGroupId);
  1869. _log.debug("Recent group id " + recentGroupId);
  1870. _log.debug("Previous group id " + previousGroupId);
  1871. }
  1872. }
  1873.  
  1874. protected void servicePre(
  1875. HttpServletRequest request, HttpServletResponse response)
  1876. throws Exception {
  1877. System.out.println("In ServicePreAction-Mobile class-servicePre method");
  1878. ThemeDisplay themeDisplay = initThemeDisplay(request, response);
  1879.  
  1880. if (themeDisplay == null) {
  1881. return;
  1882. }
  1883.  
  1884. request.setAttribute(WebKeys.THEME_DISPLAY, themeDisplay);
  1885.  
  1886. // Service context
  1887.  
  1888. ServiceContext serviceContext = ServiceContextFactory.getInstance(
  1889. request);
  1890.  
  1891. ServiceContextThreadLocal.pushServiceContext(serviceContext);
  1892.  
  1893. // Parallel render
  1894.  
  1895. boolean parallelRenderEnable = true;
  1896.  
  1897. Layout layout = themeDisplay.getLayout();
  1898.  
  1899. if (layout != null) {
  1900. LayoutTypePortlet layoutTypePortlet =
  1901. themeDisplay.getLayoutTypePortlet();
  1902.  
  1903. List<String> portletIds = layoutTypePortlet.getPortletIds();
  1904.  
  1905. if (portletIds.size() == 1) {
  1906. String portletId = portletIds.get(0);
  1907.  
  1908. Portlet portlet = PortletLocalServiceUtil.getPortletById(
  1909. portletId);
  1910.  
  1911. if ((portlet != null) && !portlet.isAjaxable()) {
  1912. parallelRenderEnable = false;
  1913. }
  1914. }
  1915. }
  1916.  
  1917. Boolean parallelRenderEnableObj = Boolean.valueOf(ParamUtil.getBoolean(
  1918. request, "p_p_parallel", parallelRenderEnable));
  1919.  
  1920. request.setAttribute(
  1921. WebKeys.PORTLET_PARALLEL_RENDER, parallelRenderEnableObj);
  1922.  
  1923. // Main Journal article
  1924.  
  1925. long mainJournalArticleId = ParamUtil.getLong(request, "p_j_a_id");
  1926.  
  1927. if (mainJournalArticleId > 0) {
  1928. try{
  1929. JournalArticle mainJournalArticle =
  1930. JournalArticleServiceUtil.getArticle(mainJournalArticleId);
  1931.  
  1932. AssetEntry layoutAssetEntry =
  1933. AssetEntryLocalServiceUtil.getEntry(
  1934. JournalArticle.class.getName(),
  1935. mainJournalArticle.getResourcePrimKey());
  1936.  
  1937. request.setAttribute(
  1938. WebKeys.LAYOUT_ASSET_ENTRY, layoutAssetEntry);
  1939. }
  1940. catch (NoSuchArticleException nsae) {
  1941. if (_log.isWarnEnabled()) {
  1942. _log.warn(nsae.getMessage());
  1943. }
  1944. }
  1945. }
  1946. }
  1947.  
  1948. protected void updateUserLayouts(User user) throws Exception {
  1949. Boolean hasPowerUserRole = null;
  1950.  
  1951. // Private layouts
  1952.  
  1953. boolean addDefaultUserPrivateLayouts = false;
  1954.  
  1955. if (PropsValues.LAYOUT_USER_PRIVATE_LAYOUTS_ENABLED &&
  1956. PropsValues.LAYOUT_USER_PRIVATE_LAYOUTS_AUTO_CREATE) {
  1957.  
  1958. addDefaultUserPrivateLayouts = true;
  1959.  
  1960. if (PropsValues.LAYOUT_USER_PRIVATE_LAYOUTS_POWER_USER_REQUIRED) {
  1961. if (hasPowerUserRole == null) {
  1962. hasPowerUserRole = hasPowerUserRole(user);
  1963. }
  1964.  
  1965. if (!hasPowerUserRole.booleanValue()) {
  1966. addDefaultUserPrivateLayouts = false;
  1967. }
  1968. }
  1969. }
  1970.  
  1971. Boolean hasPrivateLayouts = null;
  1972.  
  1973. if (addDefaultUserPrivateLayouts) {
  1974. hasPrivateLayouts = LayoutLocalServiceUtil.hasLayouts(user, true);
  1975.  
  1976. if (!hasPrivateLayouts) {
  1977. addDefaultUserPrivateLayouts(user);
  1978. }
  1979. }
  1980.  
  1981. boolean deleteDefaultUserPrivateLayouts = false;
  1982.  
  1983. if (!PropsValues.LAYOUT_USER_PRIVATE_LAYOUTS_ENABLED) {
  1984. deleteDefaultUserPrivateLayouts = true;
  1985. }
  1986. else if (PropsValues.LAYOUT_USER_PRIVATE_LAYOUTS_POWER_USER_REQUIRED) {
  1987. if (hasPowerUserRole == null) {
  1988. hasPowerUserRole = hasPowerUserRole(user);
  1989. }
  1990.  
  1991. if (!hasPowerUserRole.booleanValue()) {
  1992. deleteDefaultUserPrivateLayouts = true;
  1993. }
  1994. }
  1995.  
  1996. if (deleteDefaultUserPrivateLayouts) {
  1997. if (hasPrivateLayouts == null) {
  1998. hasPrivateLayouts = LayoutLocalServiceUtil.hasLayouts(
  1999. user, true);
  2000. }
  2001.  
  2002. if (hasPrivateLayouts) {
  2003. deleteDefaultUserPrivateLayouts(user);
  2004. }
  2005. }
  2006.  
  2007. // Public pages
  2008.  
  2009. boolean addDefaultUserPublicLayouts = false;
  2010.  
  2011. if (PropsValues.LAYOUT_USER_PUBLIC_LAYOUTS_ENABLED &&
  2012. PropsValues.LAYOUT_USER_PUBLIC_LAYOUTS_AUTO_CREATE) {
  2013.  
  2014. addDefaultUserPublicLayouts = true;
  2015.  
  2016. if (PropsValues.LAYOUT_USER_PUBLIC_LAYOUTS_POWER_USER_REQUIRED) {
  2017. if (hasPowerUserRole == null) {
  2018. hasPowerUserRole = hasPowerUserRole(user);
  2019. }
  2020.  
  2021. if (!hasPowerUserRole.booleanValue()) {
  2022. addDefaultUserPublicLayouts = false;
  2023. }
  2024. }
  2025. }
  2026.  
  2027. Boolean hasPublicLayouts = null;
  2028.  
  2029. if (addDefaultUserPublicLayouts) {
  2030. hasPublicLayouts = LayoutLocalServiceUtil.hasLayouts(user, false);
  2031.  
  2032. if (!hasPublicLayouts) {
  2033. addDefaultUserPublicLayouts(user);
  2034. }
  2035. }
  2036.  
  2037. boolean deleteDefaultUserPublicLayouts = false;
  2038.  
  2039. if (!PropsValues.LAYOUT_USER_PUBLIC_LAYOUTS_ENABLED) {
  2040. deleteDefaultUserPublicLayouts = true;
  2041. }
  2042. else if (PropsValues.LAYOUT_USER_PUBLIC_LAYOUTS_POWER_USER_REQUIRED) {
  2043. if (hasPowerUserRole == null) {
  2044. hasPowerUserRole = hasPowerUserRole(user);
  2045. }
  2046.  
  2047. if (!hasPowerUserRole.booleanValue()) {
  2048. deleteDefaultUserPublicLayouts = true;
  2049. }
  2050. }
  2051.  
  2052. if (deleteDefaultUserPublicLayouts) {
  2053. if (hasPublicLayouts == null) {
  2054. hasPublicLayouts = LayoutLocalServiceUtil.hasLayouts(
  2055. user, false);
  2056. }
  2057.  
  2058. if (hasPublicLayouts) {
  2059. deleteDefaultUserPublicLayouts(user);
  2060. }
  2061. }
  2062. }
  2063.  
  2064. protected File privateLARFile;
  2065. protected File publicLARFile;
  2066.  
  2067. private static final String _CONTROL_PANEL_CATEGORY_PORTLET_PREFIX =
  2068. "portlet_";
  2069.  
  2070. private static final String _PATH_PORTAL_LAYOUT = "/portal/layout";
  2071.  
  2072. private static Log _log = LogFactoryUtil.getLog(ServicePreAction.class);
  2073.  
  2074. }

Report this snippet  

You need to login to post a comment.