public PortletURL getURLEdit(
      LiferayPortletRequest liferayPortletRequest, LiferayPortletResponse liferayPortletResponse) {

    PortletURL editPortletURL = liferayPortletResponse.createRenderURL(PortletKeys.BLOGS);

    editPortletURL.setParameter("struts_action", "/blogs/edit_entry");
    editPortletURL.setParameter("entryId", String.valueOf(_entry.getEntryId()));

    return editPortletURL;
  }
  public PortletURL getURLEdit(
      LiferayPortletRequest liferayPortletRequest, LiferayPortletResponse liferayPortletResponse) {

    PortletURL editPortletURL = liferayPortletResponse.createRenderURL(PortletKeys.IMAGE_GALLERY);

    editPortletURL.setParameter("struts_action", "/image_gallery/edit_image");
    editPortletURL.setParameter("folderId", String.valueOf(_image.getFolderId()));
    editPortletURL.setParameter("imageId", String.valueOf(_image.getImageId()));

    return editPortletURL;
  }
  public void saveEntry(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

    try {
      doSaveEntry(actionRequest, actionResponse);

      long entryId = ParamUtil.getLong(actionRequest, "entryId");

      if (entryId <= 0) {
        SessionMessages.add(actionRequest, "announcementAdded");
      } else {
        SessionMessages.add(actionRequest, "announcementUpdated");
      }

      LiferayPortletResponse liferayPortletResponse = (LiferayPortletResponse) actionResponse;

      PortletURL portletURL = liferayPortletResponse.createRenderURL();

      portletURL.setParameter("mvcPath", "/manage_entries.jsp");
      portletURL.setParameter(
          "distributionScope", ParamUtil.getString(actionRequest, "distributionScope"));

      jsonObject.put("redirect", portletURL.toString());

      jsonObject.put("success", true);
    } catch (Exception e) {
      String message = null;

      if (e instanceof EntryContentException) {
        message = "please-enter-valid-content";
      } else if (e instanceof EntryDisplayDateException) {
        message = "please-enter-a-valid-display-date";
      } else if (e instanceof EntryExpirationDateException) {
        message = "please-enter-a-valid-expiration-date";
      } else if (e instanceof EntryTitleException) {
        message = "please-enter-a-valid-title";
      } else if (e instanceof EntryURLException) {
        message = "please-enter-a-valid-url";
      } else {
        throw new PortletException(e);
      }

      SessionErrors.clear(actionRequest);

      jsonObject.put("message", translate(actionRequest, message));
      jsonObject.put("success", false);
    }

    writeJSON(actionRequest, actionResponse, jsonObject);
  }
Beispiel #4
0
  public Map<Long, Map<String, PortletURL>> getScopeAddPortletURLs(int max) throws Exception {

    long[] groupIds = getGroupIds();

    if (groupIds.length == 0) {
      return Collections.emptyMap();
    }

    Map<Long, Map<String, PortletURL>> scopeAddPortletURLs = new HashMap();

    LiferayPortletResponse liferayPortletResponse = (LiferayPortletResponse) _portletResponse;

    PortletURL redirectURL = liferayPortletResponse.createRenderURL();

    redirectURL.setParameter("hideDefaultSuccessMessage", Boolean.TRUE.toString());
    redirectURL.setParameter("mvcPath", "/add_asset_redirect.jsp");

    LiferayPortletRequest liferayPortletRequest = (LiferayPortletRequest) _portletRequest;

    PortletURL currentURLObj =
        PortletURLUtil.getCurrent(liferayPortletRequest, liferayPortletResponse);

    redirectURL.setParameter("redirect", currentURLObj.toString());

    redirectURL.setWindowState(LiferayWindowState.POP_UP);

    String redirect = redirectURL.toString();

    for (long groupId : groupIds) {
      Map<String, PortletURL> addPortletURLs =
          AssetUtil.getAddPortletURLs(
              liferayPortletRequest,
              liferayPortletResponse,
              groupId,
              getClassNameIds(),
              getClassTypeIds(),
              getAllAssetCategoryIds(),
              getAllAssetTagNames(),
              redirect);

      if (MapUtil.isNotEmpty(addPortletURLs)) {
        scopeAddPortletURLs.put(groupId, addPortletURLs);
      }

      if (scopeAddPortletURLs.size() > max) {
        break;
      }
    }

    return scopeAddPortletURLs;
  }
  @Override
  public PortletURL getURLAdd(
      LiferayPortletRequest liferayPortletRequest, LiferayPortletResponse liferayPortletResponse) {

    PortletURL portletURL = liferayPortletResponse.createRenderURL(PortletKeys.DOCUMENT_LIBRARY);

    portletURL.setParameter("struts_action", "/document_library/edit_file_entry");
    portletURL.setParameter(
        "folderId",
        String.valueOf(
            AssetPublisherUtil.getRecentFolderId(liferayPortletRequest, getClassName())));

    return portletURL;
  }
  @Override
  public PortletURL getURLAdd(
      LiferayPortletRequest liferayPortletRequest,
      LiferayPortletResponse liferayPortletResponse,
      long classTypeId) {

    PortletURL portletURL = liferayPortletResponse.createRenderURL(BookmarksPortletKeys.BOOKMARKS);

    portletURL.setParameter("struts_action", "/bookmarks/edit_entry");
    portletURL.setParameter(
        "folderId", String.valueOf(BookmarksFolderConstants.DEFAULT_PARENT_FOLDER_ID));

    return portletURL;
  }
  public void deauthorize(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

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

    oAuthManager.deleteAccessToken(themeDisplay.getUser());

    LiferayPortletResponse liferayPortletResponse = (LiferayPortletResponse) actionResponse;

    PortletURL portletURL = liferayPortletResponse.createRenderURL();

    portletURL.setParameter("mvcPath", "/view.jsp");

    actionResponse.sendRedirect(portletURL.toString());
  }
  public String getURLViewInContext(
      LiferayPortletRequest liferayPortletRequest,
      LiferayPortletResponse liferayPortletResponse,
      String noSuchEntryRedirect)
      throws Exception {

    PortletURL viewPortletURL = liferayPortletResponse.createRenderURL(PortletKeys.IMAGE_GALLERY);

    viewPortletURL.setWindowState(WindowState.MAXIMIZED);

    viewPortletURL.setParameter("struts_action", "/image_gallery/view");
    viewPortletURL.setParameter("groupId", String.valueOf(_image.getGroupId()));
    viewPortletURL.setParameter("folderId", String.valueOf(_image.getFolderId()));

    return viewPortletURL.toString();
  }
  @Override
  public PortletURL getURLAdd(
      LiferayPortletRequest liferayPortletRequest,
      LiferayPortletResponse liferayPortletResponse,
      long classTypeId) {

    PortletURL portletURL =
        liferayPortletResponse.createRenderURL(DDLPortletKeys.DYNAMIC_DATA_LISTS);

    portletURL.setParameter("mvcPath", "/edit_record.jsp");

    if (classTypeId > 0) {
      portletURL.setParameter("recordSetId", String.valueOf(classTypeId));
    }

    return portletURL;
  }
  public static void addPortletBreadcrumbEntries(
      Folder folder, HttpServletRequest request, LiferayPortletResponse liferayPortletResponse)
      throws Exception {

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

    PortletURL portletURL = liferayPortletResponse.createRenderURL();

    portletURL.setParameter("struts_action", "/document_library/view");
    portletURL.setParameter("viewEntries", Boolean.TRUE.toString());
    portletURL.setParameter("viewFolders", Boolean.TRUE.toString());

    Map<String, Object> data = new HashMap<String, Object>();

    data.put("folder-id", _getDefaultFolderId(request));

    PortalUtil.addPortletBreadcrumbEntry(
        request, themeDisplay.translate("home"), portletURL.toString(), data);

    addPortletBreadcrumbEntries(folder, request, portletURL);
  }
  @Override
  protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

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

    if (PropsValues.AUTH_LOGIN_DISABLED) {
      actionResponse.sendRedirect(
          themeDisplay.getPathMain() + PropsValues.AUTH_LOGIN_DISABLED_PATH);

      return;
    }

    /*if (actionRequest.getRemoteUser() != null) {
    	actionResponse.sendRedirect(themeDisplay.getPathMain());

    	return;
    }*/

    try {
      login(themeDisplay, actionRequest, actionResponse);

      boolean doActionAfterLogin = ParamUtil.getBoolean(actionRequest, "doActionAfterLogin");

      if (doActionAfterLogin) {
        LiferayPortletResponse liferayPortletResponse = (LiferayPortletResponse) actionResponse;

        PortletURL renderURL = liferayPortletResponse.createRenderURL();

        renderURL.setParameter("mvcRenderCommandName", "/login/login_redirect");

        actionRequest.setAttribute(WebKeys.REDIRECT, renderURL.toString());
      }
    } catch (Exception e) {
      if (e instanceof AuthException) {
        Throwable cause = e.getCause();

        if (cause instanceof PasswordExpiredException || cause instanceof UserLockoutException) {

          SessionErrors.add(actionRequest, cause.getClass(), cause);
        } else {
          if (_log.isInfoEnabled()) {
            _log.info("Authentication failed");
          }

          SessionErrors.add(actionRequest, e.getClass());
        }
      } else if (e instanceof CompanyMaxUsersException
          || e instanceof CookieNotSupportedException
          || e instanceof NoSuchUserException
          || e instanceof PasswordExpiredException
          || e instanceof UserEmailAddressException
          || e instanceof UserIdException
          || e instanceof UserLockoutException
          || e instanceof UserPasswordException
          || e instanceof UserScreenNameException) {

        SessionErrors.add(actionRequest, e.getClass(), e);
      } else {
        _log.error(e, e);

        PortalUtil.sendError(e, actionRequest, actionResponse);

        return;
      }

      postProcessAuthFailure(actionRequest, actionResponse);
    }
  }