public void editConfiguration(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    Portlet portlet = ActionUtil.getPortlet(actionRequest);

    PortletConfig portletConfig =
        (PortletConfig) actionRequest.getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG);

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    String settingsScope = ParamUtil.getString(actionRequest, "settingsScope");

    PortletPreferences portletPreferences =
        getPortletPreferences(themeDisplay, portlet.getPortletId(), settingsScope);

    actionRequest = ActionUtil.getWrappedActionRequest(actionRequest, portletPreferences);

    ConfigurationAction configurationAction = getConfigurationAction(portlet);

    if (configurationAction == null) {
      return;
    }

    configurationAction.processAction(portletConfig, actionRequest, actionResponse);

    Layout layout = themeDisplay.getLayout();

    PortletLayoutListener portletLayoutListener = portlet.getPortletLayoutListenerInstance();

    if (portletLayoutListener != null) {
      portletLayoutListener.onSetup(portlet.getPortletId(), layout.getPlid());
    }
  }
  protected String getOldScopeName(ActionRequest actionRequest, Portlet portlet) throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    Layout layout = themeDisplay.getLayout();

    PortletPreferences portletPreferences = actionRequest.getPreferences();

    String scopeType = GetterUtil.getString(portletPreferences.getValue("lfrScopeType", null));

    if (Validator.isNull(scopeType)) {
      return null;
    }

    String scopeName = null;

    if (scopeType.equals("company")) {
      scopeName = themeDisplay.translate("global");
    } else if (scopeType.equals("layout")) {
      String scopeLayoutUuid =
          GetterUtil.getString(portletPreferences.getValue("lfrScopeLayoutUuid", null));

      Layout scopeLayout =
          _layoutLocalService.fetchLayoutByUuidAndGroupId(
              scopeLayoutUuid, layout.getGroupId(), layout.isPrivateLayout());

      if (scopeLayout != null) {
        scopeName = scopeLayout.getName(themeDisplay.getLocale());
      }
    } else {
      throw new IllegalArgumentException("Scope type " + scopeType + " is invalid");
    }

    return scopeName;
  }
  public boolean isShowIconsActions() throws PortalException {
    if (isSpreadsheet()) {
      return false;
    }

    if (_hasShowIconsActionPermission != null) {
      return _hasShowIconsActionPermission;
    }

    _hasShowIconsActionPermission = Boolean.FALSE;

    ThemeDisplay themeDisplay = getThemeDisplay();

    if (!themeDisplay.isSignedIn()) {
      return _hasShowIconsActionPermission;
    }

    Layout layout = themeDisplay.getLayout();

    if (layout.isLayoutPrototypeLinkActive()) {
      return _hasShowIconsActionPermission;
    }

    if (isShowConfigurationIcon()
        || isShowAddDDMDisplayTemplateIcon()
        || isShowAddDDMFormTemplateIcon()
        || isShowEditDisplayDDMTemplateIcon()
        || isShowEditFormDDMTemplateIcon()) {

      _hasShowIconsActionPermission = Boolean.TRUE;
    }

    return _hasShowIconsActionPermission;
  }
  protected PortletPreferences getPortletPreferences(
      ThemeDisplay themeDisplay, String portletId, String settingsScope) {

    Layout layout = themeDisplay.getLayout();

    if (!layout.isSupportsEmbeddedPortlets()) {
      return null;
    }

    LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) layout.getLayoutType();

    if (!layoutTypePortlet.isPortletEmbedded(portletId)) {
      return null;
    }

    PortletPreferencesIds portletPreferencesIds =
        new PortletPreferencesIds(
            themeDisplay.getCompanyId(),
            layout.getGroupId(),
            PortletKeys.PREFS_OWNER_TYPE_LAYOUT,
            PortletKeys.PREFS_PLID_SHARED,
            portletId);

    return _portletPreferencesLocalService.getPreferences(portletPreferencesIds);
  }
  public void restoreArchivedSetup(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    Portlet portlet = ActionUtil.getPortlet(actionRequest);

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    Settings portletInstanceSettings =
        SettingsFactoryUtil.getSettings(
            new PortletInstanceSettingsLocator(themeDisplay.getLayout(), portlet.getPortletId()));

    ModifiableSettings portletInstanceModifiableSettings =
        portletInstanceSettings.getModifiableSettings();

    String name = ParamUtil.getString(actionRequest, "name");

    ArchivedSettings archivedSettings =
        SettingsFactoryUtil.getPortletInstanceArchivedSettings(
            themeDisplay.getSiteGroupId(), portlet.getRootPortletId(), name);

    portletInstanceModifiableSettings.reset();

    portletInstanceModifiableSettings.setValues(archivedSettings);

    portletInstanceModifiableSettings.store();

    String portletResource = ParamUtil.getString(actionRequest, "portletResource");

    SessionMessages.add(
        actionRequest,
        PortalUtil.getPortletId(actionRequest) + SessionMessages.KEY_SUFFIX_REFRESH_PORTLET,
        portletResource);
  }
Exemple #6
0
  public void setLayoutAssetEntry(AssetEntry assetEntry) throws PortalException {

    ThemeDisplay themeDisplay = (ThemeDisplay) _request.getAttribute(WebKeys.THEME_DISPLAY);

    String defaultAssetPublisherPortletId =
        AssetUtil.getDefaultAssetPublisherId(themeDisplay.getLayout());

    if (isDefaultAssetPublisher()
        || Validator.isNull(defaultAssetPublisherPortletId)
        || !PortletPermissionUtil.contains(
            themeDisplay.getPermissionChecker(),
            themeDisplay.getLayout(),
            defaultAssetPublisherPortletId,
            ActionKeys.VIEW)) {

      _request.setAttribute(WebKeys.LAYOUT_ASSET_ENTRY, assetEntry);
    }
  }
  protected Tuple getNewScope(ActionRequest actionRequest) throws Exception {
    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    Layout layout = themeDisplay.getLayout();

    String[] scopes = StringUtil.split(ParamUtil.getString(actionRequest, "scope"));

    String scopeType = scopes[0];

    long scopeGroupId = 0;
    String scopeName = null;

    if (Validator.isNull(scopeType)) {
      scopeGroupId = layout.getGroupId();
    } else if (scopeType.equals("company")) {
      scopeGroupId = themeDisplay.getCompanyGroupId();
      scopeName = themeDisplay.translate("global");
    } else if (scopeType.equals("layout")) {
      String scopeLayoutUuid = scopes[1];

      Layout scopeLayout =
          _layoutLocalService.getLayoutByUuidAndGroupId(
              scopeLayoutUuid, layout.getGroupId(), layout.isPrivateLayout());

      if (!scopeLayout.hasScopeGroup()) {
        Map<Locale, String> nameMap = new HashMap<>();

        String name = String.valueOf(scopeLayout.getPlid());

        nameMap.put(LocaleUtil.getDefault(), name);

        _groupLocalService.addGroup(
            themeDisplay.getUserId(),
            GroupConstants.DEFAULT_PARENT_GROUP_ID,
            Layout.class.getName(),
            scopeLayout.getPlid(),
            GroupConstants.DEFAULT_LIVE_GROUP_ID,
            nameMap,
            null,
            0,
            true,
            GroupConstants.DEFAULT_MEMBERSHIP_RESTRICTION,
            null,
            false,
            true,
            null);
      }

      scopeGroupId = scopeLayout.getGroupId();
      scopeName = scopeLayout.getName(themeDisplay.getLocale());
    } else {
      throw new IllegalArgumentException("Scope type " + scopeType + " is invalid");
    }

    return new Tuple(scopeGroupId, scopeName);
  }
  public void resetPrototype(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    SitesUtil.resetPrototype(themeDisplay.getLayout());

    MultiSessionMessages.add(
        actionRequest, PortalUtil.getPortletId(actionRequest) + "requestProcessed");
  }
Exemple #9
0
  public long[] getGroupIds() {
    if (_groupIds == null) {
      ThemeDisplay themeDisplay = (ThemeDisplay) _request.getAttribute(WebKeys.THEME_DISPLAY);

      _groupIds =
          AssetPublisherUtil.getGroupIds(
              _portletPreferences, themeDisplay.getScopeGroupId(), themeDisplay.getLayout());
    }

    return _groupIds;
  }
Exemple #10
0
  public Layout getLayout() {
    if (_layout != null) {
      return _layout;
    }

    ThemeDisplay themeDisplay = (ThemeDisplay) _request.getAttribute(WebKeys.THEME_DISPLAY);

    _layout = themeDisplay.getLayout();

    return _layout;
  }
Exemple #11
0
  public static void doTag(
      String portletProviderClassName,
      PortletProvider.Action portletProviderAction,
      String instanceId,
      String queryString,
      String defaultPreferences,
      boolean persistSettings,
      PageContext pageContext,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    String portletId =
        PortletProviderUtil.getPortletId(portletProviderClassName, portletProviderAction);

    if (Validator.isNotNull(portletId)) {
      doTag(
          portletId,
          instanceId,
          queryString,
          _SETTINGS_SCOPE_DEFAULT,
          defaultPreferences,
          persistSettings,
          pageContext,
          request,
          response);
    } else {
      ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

      Layout layout = themeDisplay.getLayout();

      if (!layout.isTypeControlPanel()
          && !LayoutPermissionUtil.contains(
              themeDisplay.getPermissionChecker(), layout, ActionKeys.UPDATE)) {

        return;
      }

      String errorMessage =
          LanguageUtil.format(
              request,
              "an-app-that-can-x-x-belongs-here",
              new Object[] {portletProviderAction.name(), portletProviderClassName},
              false);

      request.setAttribute("liferay-portlet:runtime:errorMessage", errorMessage);

      PortalIncludeUtil.include(pageContext, _ERROR_PAGE);
    }
  }
  public static BreadcrumbEntry getScopeGroupBreadcrumbEntry(ThemeDisplay themeDisplay)
      throws Exception {

    List<BreadcrumbEntry> breadcrumbEntries = new ArrayList<>();

    Layout layout = themeDisplay.getLayout();

    _addGroupsBreadcrumbEntries(breadcrumbEntries, themeDisplay, layout.getLayoutSet(), false);

    if (breadcrumbEntries.isEmpty()) {
      return null;
    }

    return breadcrumbEntries.get(0);
  }
  public static List<BreadcrumbEntry> getParentGroupBreadcrumbEntries(ThemeDisplay themeDisplay)
      throws Exception {

    List<BreadcrumbEntry> breadcrumbEntries = new ArrayList<>();

    Layout layout = themeDisplay.getLayout();

    LayoutSet parentLayoutSet = _getParentLayoutSet(layout.getLayoutSet());

    if (parentLayoutSet != null) {
      _addGroupsBreadcrumbEntries(breadcrumbEntries, themeDisplay, parentLayoutSet, true);
    }

    return breadcrumbEntries;
  }
  public static List<BreadcrumbEntry> getLayoutBreadcrumbEntries(ThemeDisplay themeDisplay)
      throws Exception {

    List<BreadcrumbEntry> breadcrumbEntries = new ArrayList<>();

    Layout layout = themeDisplay.getLayout();

    Group group = layout.getGroup();

    if (!group.isLayoutPrototype()) {
      _addLayoutBreadcrumbEntries(breadcrumbEntries, themeDisplay, layout);
    }

    return breadcrumbEntries;
  }
Exemple #15
0
  public boolean isDefaultAssetPublisher() {
    if (_defaultAssetPublisher != null) {
      return _defaultAssetPublisher;
    }

    ThemeDisplay themeDisplay = (ThemeDisplay) _request.getAttribute(WebKeys.THEME_DISPLAY);

    PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();

    _defaultAssetPublisher =
        AssetUtil.isDefaultAssetPublisher(
            themeDisplay.getLayout(), portletDisplay.getId(), getPortletResource());

    return _defaultAssetPublisher;
  }
Exemple #16
0
  public AssetEntryQuery getAssetEntryQuery() throws Exception {
    if (_assetEntryQuery != null) {
      return _assetEntryQuery;
    }

    ThemeDisplay themeDisplay = (ThemeDisplay) _request.getAttribute(WebKeys.THEME_DISPLAY);

    _assetEntryQuery =
        AssetPublisherUtil.getAssetEntryQuery(
            _portletPreferences, getGroupIds(), getAllAssetCategoryIds(), getAllAssetTagNames());

    String portletName = getPortletName();

    if (!portletName.equals(AssetPublisherPortletKeys.RELATED_ASSETS)) {
      _assetEntryQuery.setGroupIds(getGroupIds());
    }

    _assetEntryQuery.setClassTypeIds(getClassTypeIds());
    _assetEntryQuery.setEnablePermissions(isEnablePermissions());
    _assetEntryQuery.setExcludeZeroViewCount(isExcludeZeroViewCount());

    configureSubtypeFieldFilter(_assetEntryQuery, themeDisplay.getLocale());

    if (isShowOnlyLayoutAssets()) {
      _assetEntryQuery.setLayout(themeDisplay.getLayout());
    }

    if (portletName.equals(AssetPublisherPortletKeys.RELATED_ASSETS)) {
      AssetEntry layoutAssetEntry = (AssetEntry) _request.getAttribute(WebKeys.LAYOUT_ASSET_ENTRY);

      if (layoutAssetEntry != null) {
        _assetEntryQuery.setLinkedAssetEntryId(layoutAssetEntry.getEntryId());
      }
    }

    _assetEntryQuery.setPaginationType(getPaginationType());
    _assetEntryQuery.setOrderByCol1(getOrderByColumn1());
    _assetEntryQuery.setOrderByCol2(getOrderByColumn2());
    _assetEntryQuery.setOrderByType1(getOrderByType1());
    _assetEntryQuery.setOrderByType2(getOrderByType2());

    AssetPublisherUtil.processAssetEntryQuery(
        themeDisplay.getUser(), _portletPreferences, _assetEntryQuery);

    return _assetEntryQuery;
  }
  @Override
  public boolean isShow(HttpServletRequest request) throws PortalException {
    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    Layout layout = themeDisplay.getLayout();

    if (!layout.isTypeControlPanel()) {
      return false;
    }

    PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();

    if (portletDisplay == null) {
      return false;
    }

    return super.isShow(request);
  }
  protected List<NavItem> getBranchNavItems(HttpServletRequest request) throws PortalException {

    List<NavItem> navItems = new ArrayList<>();

    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    Layout layout = themeDisplay.getLayout();

    NavItem navItem = new NavItem(request, layout, null);

    navItems.add(navItem);

    for (Layout ancestorLayout : layout.getAncestors()) {
      navItems.add(0, new NavItem(request, ancestorLayout, null));
    }

    return navItems;
  }
  protected List<NavItem> getNavItems(List<NavItem> branchNavItems) throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    List<NavItem> navItems = new ArrayList<>();

    NavItem rootNavItem = null;

    if (_rootLayoutType.equals("relative")) {
      if ((_rootLayoutLevel >= 0) && (_rootLayoutLevel < branchNavItems.size())) {

        rootNavItem = branchNavItems.get(_rootLayoutLevel);
      }
    } else if (_rootLayoutType.equals("absolute")) {
      int ancestorIndex = branchNavItems.size() - _rootLayoutLevel;

      if ((ancestorIndex >= 0) && (ancestorIndex < branchNavItems.size())) {

        rootNavItem = branchNavItems.get(ancestorIndex);
      } else if (ancestorIndex == branchNavItems.size()) {
        navItems = NavItem.fromLayouts(request, themeDisplay.getLayouts(), null);
      }
    } else if (_rootLayoutType.equals("select")) {
      Layout layout = themeDisplay.getLayout();

      if (Validator.isNotNull(_rootLayoutUuid)) {
        Layout rootLayout =
            LayoutLocalServiceUtil.getLayoutByUuidAndGroupId(
                _rootLayoutUuid, layout.getGroupId(), layout.isPrivateLayout());

        rootNavItem = new NavItem(request, rootLayout, null);
      } else {
        navItems = NavItem.fromLayouts(request, themeDisplay.getLayouts(), null);
      }
    }

    if (rootNavItem != null) {
      navItems = rootNavItem.getChildren();
    }

    return navItems;
  }
  public boolean isShowConfigurationIcon() throws PortalException {
    if (_showConfigurationIcon != null) {
      return _showConfigurationIcon;
    }

    if (isPreview() || (isSharedURL() && isFormShared())) {
      _showConfigurationIcon = false;

      return _showConfigurationIcon;
    }

    ThemeDisplay themeDisplay = getThemeDisplay();

    _showConfigurationIcon =
        PortletPermissionUtil.contains(
            themeDisplay.getPermissionChecker(),
            themeDisplay.getLayout(),
            getPortletId(),
            ActionKeys.CONFIGURATION);

    return _showConfigurationIcon;
  }
  public void resetCustomizationView(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    if (!LayoutPermissionUtil.contains(
        themeDisplay.getPermissionChecker(), themeDisplay.getLayout(), ActionKeys.CUSTOMIZE)) {

      throw new PrincipalException();
    }

    LayoutTypePortlet layoutTypePortlet = themeDisplay.getLayoutTypePortlet();

    if ((layoutTypePortlet != null)
        && layoutTypePortlet.isCustomizable()
        && layoutTypePortlet.isCustomizedView()) {

      layoutTypePortlet.resetUserPreferences();
    }

    MultiSessionMessages.add(
        actionRequest, PortalUtil.getPortletId(actionRequest) + "requestProcessed");
  }
  public void updateArchivedSetup(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    Portlet portlet = ActionUtil.getPortlet(actionRequest);

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    String name = ParamUtil.getString(actionRequest, "name");

    ArchivedSettings archivedSettings =
        SettingsFactoryUtil.getPortletInstanceArchivedSettings(
            themeDisplay.getSiteGroupId(), portlet.getRootPortletId(), name);

    Settings portletInstanceSettings =
        SettingsFactoryUtil.getSettings(
            new PortletInstanceSettingsLocator(themeDisplay.getLayout(), portlet.getPortletId()));

    ModifiableSettings portletInstanceModifiableSettings =
        portletInstanceSettings.getModifiableSettings();

    archivedSettings.setValues(portletInstanceModifiableSettings);

    archivedSettings.store();
  }
Exemple #23
0
  public static void doTag(
      String portletName,
      String instanceId,
      String queryString,
      String settingsScope,
      String defaultPreferences,
      boolean persistSettings,
      PageContext pageContext,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    if (pageContext != null) {
      response = new PipingServletResponse(response, pageContext.getOut());
    }

    PortletInstance portletInstance = PortletInstance.fromPortletInstanceKey(portletName);

    if (Validator.isNotNull(instanceId)) {
      portletInstance =
          new PortletInstance(
              portletInstance.getPortletName(), portletInstance.getUserId(), instanceId);
    }

    RestrictPortletServletRequest restrictPortletServletRequest =
        new RestrictPortletServletRequest(PortalUtil.getOriginalServletRequest(request));

    queryString =
        PortletParameterUtil.addNamespace(portletInstance.getPortletInstanceKey(), queryString);

    Map<String, String[]> parameterMap = request.getParameterMap();

    if (!Objects.equals(portletInstance.getPortletInstanceKey(), request.getParameter("p_p_id"))) {

      parameterMap = MapUtil.filterByKeys(parameterMap, (key) -> !key.startsWith("p_p_"));
    }

    request =
        DynamicServletRequest.addQueryString(
            restrictPortletServletRequest, parameterMap, queryString, false);

    try {
      request.setAttribute(WebKeys.RENDER_PORTLET_RESOURCE, Boolean.TRUE);

      ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

      Portlet portlet =
          getPortlet(themeDisplay.getCompanyId(), portletInstance.getPortletInstanceKey());

      Stack<String> embeddedPortletIds = _embeddedPortletIds.get();

      if (embeddedPortletIds == null) {
        embeddedPortletIds = new Stack<>();

        _embeddedPortletIds.set(embeddedPortletIds);
      }

      if (embeddedPortletIds.search(portlet.getPortletId()) > -1) {
        String errorMessage = LanguageUtil.get(request, "the-application-cannot-include-itself");

        request.setAttribute("liferay-portlet:runtime:errorMessage", errorMessage);

        PortalIncludeUtil.include(pageContext, _ERROR_PAGE);

        return;
      }

      if (themeDisplay.isStateMaximized()) {
        LayoutTypePortlet layoutTypePortlet = themeDisplay.getLayoutTypePortlet();

        if (layoutTypePortlet.hasStateMaxPortletId(portletInstance.getPortletInstanceKey())) {

          // A portlet in the maximized state has already been
          // processed

          return;
        }
      }

      Layout layout = themeDisplay.getLayout();

      request.setAttribute(WebKeys.SETTINGS_SCOPE, settingsScope);

      JSONObject jsonObject = null;

      boolean writeJSONObject = false;

      LayoutTypePortlet layoutTypePortlet = themeDisplay.getLayoutTypePortlet();

      if (persistSettings && !layoutTypePortlet.isPortletEmbedded(portlet.getPortletId())) {

        PortletPreferencesFactoryUtil.getLayoutPortletSetup(
            themeDisplay.getCompanyId(),
            themeDisplay.getScopeGroupId(),
            PortletKeys.PREFS_OWNER_TYPE_LAYOUT,
            PortletKeys.PREFS_PLID_SHARED,
            portletInstance.getPortletInstanceKey(),
            defaultPreferences);

        writeJSONObject = true;
      }

      if (PortletPreferencesLocalServiceUtil.getPortletPreferencesCount(
              PortletKeys.PREFS_OWNER_TYPE_LAYOUT,
              themeDisplay.getPlid(),
              portletInstance.getPortletInstanceKey())
          < 1) {

        PortletPreferencesFactoryUtil.getLayoutPortletSetup(
            layout, portletInstance.getPortletInstanceKey(), defaultPreferences);
        PortletPreferencesFactoryUtil.getPortletSetup(
            request, portletInstance.getPortletInstanceKey(), defaultPreferences);

        PortletLayoutListener portletLayoutListener = portlet.getPortletLayoutListenerInstance();

        if (portletLayoutListener != null) {
          portletLayoutListener.onAddToLayout(
              portletInstance.getPortletInstanceKey(), themeDisplay.getPlid());
        }

        writeJSONObject = true;
      }

      if (writeJSONObject) {
        jsonObject = JSONFactoryUtil.createJSONObject();

        PortletJSONUtil.populatePortletJSONObject(request, StringPool.BLANK, portlet, jsonObject);
      }

      if (jsonObject != null) {
        PortletJSONUtil.writeHeaderPaths(response, jsonObject);
      }

      embeddedPortletIds.push(portletInstance.getPortletInstanceKey());

      PortletContainerUtil.render(request, response, portlet);

      embeddedPortletIds.pop();

      if (jsonObject != null) {
        PortletJSONUtil.writeFooterPaths(response, jsonObject);
      }
    } finally {
      restrictPortletServletRequest.mergeSharedAttributes();
    }
  }
  @Override
  protected byte[] getRSS(HttpServletRequest request) throws Exception {
    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    Layout layout = themeDisplay.getLayout();

    long plid = ParamUtil.getLong(request, "p_l_id");

    if (plid == LayoutConstants.DEFAULT_PLID) {
      plid = themeDisplay.getPlid();
    }

    long companyId = ParamUtil.getLong(request, "companyId");
    long groupId = ParamUtil.getLong(request, "groupId");
    long organizationId = ParamUtil.getLong(request, "organizationId");
    int status = WorkflowConstants.STATUS_APPROVED;
    int max = ParamUtil.getInteger(request, "max", SearchContainer.DEFAULT_DELTA);
    String type = ParamUtil.getString(request, "type", RSSUtil.FORMAT_DEFAULT);
    double version = ParamUtil.getDouble(request, "version", RSSUtil.VERSION_DEFAULT);
    String displayStyle =
        ParamUtil.getString(request, "displayStyle", RSSUtil.DISPLAY_STYLE_DEFAULT);

    String feedURL =
        themeDisplay.getPortalURL() + themeDisplay.getPathMain() + "/blogs/find_entry?";

    String entryURL = feedURL;

    String rss = StringPool.BLANK;

    if (companyId > 0) {
      feedURL = StringPool.BLANK;

      rss =
          _blogsEntryService.getCompanyEntriesRSS(
              companyId,
              new Date(),
              status,
              max,
              type,
              version,
              displayStyle,
              feedURL,
              entryURL,
              themeDisplay);
    } else if (groupId > 0) {
      feedURL += "p_l_id=" + plid;

      entryURL = feedURL;

      rss =
          _blogsEntryService.getGroupEntriesRSS(
              groupId,
              new Date(),
              status,
              max,
              type,
              version,
              displayStyle,
              feedURL,
              entryURL,
              themeDisplay);
    } else if (organizationId > 0) {
      feedURL = StringPool.BLANK;

      rss =
          _blogsEntryService.getOrganizationEntriesRSS(
              organizationId,
              new Date(),
              status,
              max,
              type,
              version,
              displayStyle,
              feedURL,
              entryURL,
              themeDisplay);
    } else if (layout != null) {
      groupId = themeDisplay.getScopeGroupId();

      feedURL = themeDisplay.getPathMain() + "/blogs/rss";

      entryURL = feedURL;

      rss =
          _blogsEntryService.getGroupEntriesRSS(
              groupId,
              new Date(),
              status,
              max,
              type,
              version,
              displayStyle,
              feedURL,
              entryURL,
              themeDisplay);
    }

    return rss.getBytes(StringPool.UTF8);
  }
  @Override
  public ActionForward execute(
      ActionMapping actionMapping,
      ActionForm actionForm,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    HttpSession session = request.getSession();

    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    String languageId = ParamUtil.getString(request, "languageId");

    Locale locale = LocaleUtil.fromLanguageId(languageId);

    if (LanguageUtil.isAvailableLocale(themeDisplay.getSiteGroupId(), locale)) {

      boolean persistState = ParamUtil.getBoolean(request, "persistState", true);

      if (themeDisplay.isSignedIn() && persistState) {
        User user = themeDisplay.getUser();

        Contact contact = user.getContact();

        AdminUtil.updateUser(
            request,
            user.getUserId(),
            user.getScreenName(),
            user.getEmailAddress(),
            user.getFacebookId(),
            user.getOpenId(),
            languageId,
            user.getTimeZoneId(),
            user.getGreeting(),
            user.getComments(),
            contact.getSmsSn(),
            contact.getFacebookSn(),
            contact.getJabberSn(),
            contact.getSkypeSn(),
            contact.getTwitterSn());
      }

      session.setAttribute(Globals.LOCALE_KEY, locale);

      LanguageUtil.updateCookie(request, response, locale);
    }

    // Send redirect

    String redirect = ParamUtil.getString(request, "redirect");

    String layoutURL = StringPool.BLANK;
    String queryString = StringPool.BLANK;

    int pos = redirect.indexOf(Portal.FRIENDLY_URL_SEPARATOR);

    if (pos == -1) {
      pos = redirect.indexOf(StringPool.QUESTION);
    }

    if (pos != -1) {
      layoutURL = redirect.substring(0, pos);
      queryString = redirect.substring(pos);
    } else {
      layoutURL = redirect;
    }

    Layout layout = themeDisplay.getLayout();

    if (isGroupFriendlyURL(layout.getGroup(), layout, layoutURL, locale)) {
      if (PropsValues.LOCALE_PREPEND_FRIENDLY_URL_STYLE == 0) {
        redirect = layoutURL;
      } else {
        redirect = PortalUtil.getGroupFriendlyURL(layout.getLayoutSet(), themeDisplay, locale);
      }
    } else {
      if (PropsValues.LOCALE_PREPEND_FRIENDLY_URL_STYLE == 0) {
        if (themeDisplay.isI18n()) {
          redirect = layout.getFriendlyURL(locale);
        } else {
          redirect = PortalUtil.getLayoutURL(layout, themeDisplay, locale);
        }
      } else {
        redirect = PortalUtil.getLayoutFriendlyURL(layout, themeDisplay, locale);
      }
    }

    if (layout.isTypeControlPanel()) {
      redirect = redirect + queryString;
    }

    response.sendRedirect(redirect);

    return null;
  }
  @Override
  public void run(HttpServletRequest request, HttpServletResponse response) throws ActionException {

    try {

      // Do not randomize look and feel unless the user is logged in

      ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

      if (!themeDisplay.isSignedIn()) {
        return;
      }

      // Do not randomize look and feel unless the user is accessing the
      // portal

      String requestURI = GetterUtil.getString(request.getRequestURI());

      if (!requestURI.endsWith("/portal/layout")) {
        return;
      }

      // Do not randomize look and feel unless the user is accessing a
      // personal layout

      Layout layout = themeDisplay.getLayout();

      if (layout == null) {
        return;
      }

      boolean wapTheme = BrowserSnifferUtil.isWap(request);

      List<Theme> themes =
          ThemeLocalServiceUtil.getPageThemes(
              themeDisplay.getCompanyId(),
              themeDisplay.getScopeGroupId(),
              themeDisplay.getUserId(),
              wapTheme);

      if (!themes.isEmpty()) {
        Theme theme = themes.get(RandomUtil.nextInt(themes.size()));

        List<ColorScheme> colorSchemes = theme.getColorSchemes();

        ColorScheme colorScheme = colorSchemes.get(RandomUtil.nextInt(colorSchemes.size()));

        LayoutServiceUtil.updateLookAndFeel(
            layout.getGroupId(),
            layout.isPrivateLayout(),
            layout.getPlid(),
            theme.getThemeId(),
            colorScheme.getColorSchemeId(),
            layout.getCss(),
            wapTheme);

        themeDisplay.setLookAndFeel(theme, colorScheme);

        request.setAttribute(WebKeys.THEME, theme);
        request.setAttribute(WebKeys.COLOR_SCHEME, colorScheme);
      }
    } catch (Exception e) {
      _log.error(e, e);

      throw new ActionException(e);
    }
  }