@Override
  public void removePortletId(long userId, String portletId, boolean cleanUp) {

    try {
      Portlet portlet = PortletLocalServiceUtil.getPortletById(getCompanyId(), portletId);

      if (portlet == null) {
        _log.error("Portlet " + portletId + " cannot be removed because it is not registered");

        return;
      }

      PermissionChecker permissionChecker = PermissionThreadLocal.getPermissionChecker();

      if (!LayoutPermissionUtil.contains(permissionChecker, getLayout(), ActionKeys.UPDATE)
          && !isCustomizable()) {

        return;
      }
    } catch (Exception e) {
      _log.error(e, e);

      return;
    }

    List<String> columns = getColumns();

    for (int i = 0; i < columns.size(); i++) {
      String columnId = columns.get(i);

      if (isCustomizable() && isColumnDisabled(columnId)) {
        continue;
      }

      String columnValue = StringPool.BLANK;

      if (hasUserPreferences()) {
        columnValue = getUserPreference(columnId);
      } else {
        columnValue = getTypeSettingsProperty(columnId);
      }

      columnValue = StringUtil.removeFromList(columnValue, portletId);

      if (hasUserPreferences()) {
        setUserPreference(columnId, columnValue);
      } else {
        setTypeSettingsProperty(columnId, columnValue);
      }
    }

    if (cleanUp) {
      try {
        onRemoveFromLayout(new String[] {portletId});
      } catch (Exception e) {
        _log.error(e, e);
      }
    }
  }
Beispiel #2
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 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");
  }