Example usage for com.liferay.portal.kernel.servlet SessionErrors add

List of usage examples for com.liferay.portal.kernel.servlet SessionErrors add

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.servlet SessionErrors add.

Prototype

public static void add(PortletRequest portletRequest, String key) 

Source Link

Usage

From source file:com.liferay.portlet.blogs.action.ConfigurationActionImpl.java

License:Open Source License

protected void validateEmailEntryUpdated(ActionRequest actionRequest) throws Exception {

    String emailEntryUpdatedSubject = getLocalizedParameter(actionRequest, "emailEntryUpdatedSubject");
    String emailEntryUpdatedBody = getLocalizedParameter(actionRequest, "emailEntryUpdatedBody");

    if (Validator.isNull(emailEntryUpdatedSubject)) {
        SessionErrors.add(actionRequest, "emailEntryUpdatedSubject");
    } else if (Validator.isNull(emailEntryUpdatedBody)) {
        SessionErrors.add(actionRequest, "emailEntryUpdatedBody");
    }/* w w  w  .j  a v a 2 s  .c om*/
}

From source file:com.liferay.portlet.blogs.action.EditEntryAction.java

License:Open Source License

public void processAction(ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
        ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

    String cmd = ParamUtil.getString(actionRequest, Constants.CMD);

    try {//from w  w w  .  ja va 2  s  . com
        BlogsEntry entry = null;
        String oldUrlTitle = StringPool.BLANK;

        if (cmd.equals(Constants.ADD) || cmd.equals(Constants.UPDATE)) {
            Object[] returnValue = updateEntry(actionRequest);

            entry = (BlogsEntry) returnValue[0];
            oldUrlTitle = ((String) returnValue[1]);
        } else if (cmd.equals(Constants.DELETE)) {
            deleteEntry(actionRequest);
        }

        String redirect = ParamUtil.getString(actionRequest, "redirect");
        boolean updateRedirect = false;

        if (redirect.indexOf("/blogs/" + oldUrlTitle + "/maximized") != -1) {

            oldUrlTitle += "/maximized";
        }

        if ((entry != null) && (Validator.isNotNull(oldUrlTitle)) && (redirect.endsWith("/blogs/" + oldUrlTitle)
                || redirect.indexOf("/blogs/" + oldUrlTitle + "?") != -1)) {

            int pos = redirect.indexOf("?");

            if (pos == -1) {
                pos = redirect.length();
            }

            String newRedirect = redirect.substring(0, pos - oldUrlTitle.length());

            newRedirect += entry.getUrlTitle();

            if (oldUrlTitle.indexOf("/maximized") != -1) {
                newRedirect += "/maximized";
            }

            if (pos < redirect.length()) {
                newRedirect += "?" + redirect.substring(pos + 1, redirect.length());
            }

            redirect = newRedirect;
            updateRedirect = true;
        }

        if ((entry != null) && entry.isDraft()) {
            JSONObject jsonObj = JSONFactoryUtil.createJSONObject();

            jsonObj.put("entryId", entry.getEntryId());
            jsonObj.put("redirect", redirect);
            jsonObj.put("updateRedirect", updateRedirect);

            HttpServletResponse response = PortalUtil.getHttpServletResponse(actionResponse);
            InputStream is = new ByteArrayInputStream(jsonObj.toString().getBytes());
            String contentType = ContentTypes.TEXT_JAVASCRIPT;

            ServletResponseUtil.sendFile(response, null, is, contentType);

            setForward(actionRequest, ActionConstants.COMMON_NULL);
        } else {
            ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

            LayoutTypePortlet layoutTypePortlet = themeDisplay.getLayoutTypePortlet();

            if (layoutTypePortlet.hasPortletId(portletConfig.getPortletName())) {

                sendRedirect(actionRequest, actionResponse, redirect);
            } else {
                actionResponse.sendRedirect(redirect);
            }
        }
    } catch (Exception e) {
        if (e instanceof NoSuchEntryException || e instanceof PrincipalException) {

            SessionErrors.add(actionRequest, e.getClass().getName());

            setForward(actionRequest, "portlet.blogs.error");
        } else if (e instanceof EntryContentException || e instanceof EntryDisplayDateException
                || e instanceof EntryTitleException) {

            SessionErrors.add(actionRequest, e.getClass().getName());
        } else if (e instanceof TagsEntryException) {
            SessionErrors.add(actionRequest, e.getClass().getName(), e);
        } else {
            throw e;
        }
    }
}

From source file:com.liferay.portlet.blogs.action.EditEntryAction.java

License:Open Source License

public ActionForward render(ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
        RenderRequest renderRequest, RenderResponse renderResponse) throws Exception {

    try {/*w  w w. j  av  a  2  s.  co m*/
        ActionUtil.getEntry(renderRequest);
    } catch (Exception e) {
        if (e instanceof NoSuchEntryException || e instanceof PrincipalException) {

            SessionErrors.add(renderRequest, e.getClass().getName());

            return mapping.findForward("portlet.blogs.error");
        } else {
            throw e;
        }
    }

    return mapping.findForward(getForward(renderRequest, "portlet.blogs.edit_entry"));
}

From source file:com.liferay.portlet.bookmarks.action.ConfigurationActionImpl.java

License:Open Source License

protected void validateRootFolder(ActionRequest actionRequest) throws Exception {

    long rootFolderId = GetterUtil.getLong(getParameter(actionRequest, "rootFolderId"));

    if (rootFolderId != BookmarksFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
        try {//from w  w  w . j  a v  a2  s. co m
            BookmarksFolderLocalServiceUtil.getFolder(rootFolderId);
        } catch (NoSuchFolderException nsfe) {
            SessionErrors.add(actionRequest, "rootFolderIdInvalid");
        }
    }
}

From source file:com.liferay.portlet.bookmarks.action.EditEntryAction.java

License:Open Source License

public void processAction(ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
        ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

    String cmd = ParamUtil.getString(actionRequest, Constants.CMD);

    try {/*w  ww .j  av a2  s  .com*/
        if (cmd.equals(Constants.ADD) || cmd.equals(Constants.UPDATE)) {
            updateEntry(actionRequest);
        } else if (cmd.equals(Constants.DELETE)) {
            deleteEntry(actionRequest);
        }

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

        LayoutTypePortlet layoutTypePortlet = themeDisplay.getLayoutTypePortlet();

        if (layoutTypePortlet.hasPortletId(portletConfig.getPortletName())) {

            sendRedirect(actionRequest, actionResponse);
        } else {
            String redirect = ParamUtil.getString(actionRequest, "redirect");

            actionResponse.sendRedirect(redirect);
        }
    } catch (Exception e) {
        if (e instanceof NoSuchEntryException || e instanceof PrincipalException) {

            SessionErrors.add(actionRequest, e.getClass().getName());

            setForward(actionRequest, "portlet.bookmarks.error");
        } else if (e instanceof EntryURLException || e instanceof NoSuchFolderException) {

            SessionErrors.add(actionRequest, e.getClass().getName());
        } else if (e instanceof TagsEntryException) {
            SessionErrors.add(actionRequest, e.getClass().getName(), e);
        } else {
            throw e;
        }
    }
}

From source file:com.liferay.portlet.bookmarks.action.EditEntryAction.java

License:Open Source License

public ActionForward render(ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
        RenderRequest renderRequest, RenderResponse renderResponse) throws Exception {

    try {/* w  w w. j a v  a2 s .c o  m*/
        ActionUtil.getEntry(renderRequest);
    } catch (Exception e) {
        if (e instanceof NoSuchEntryException || e instanceof PrincipalException) {

            SessionErrors.add(renderRequest, e.getClass().getName());

            return mapping.findForward("portlet.bookmarks.error");
        } else {
            throw e;
        }
    }

    return mapping.findForward(getForward(renderRequest, "portlet.bookmarks.edit_entry"));
}

From source file:com.liferay.portlet.bookmarks.action.EditFolderAction.java

License:Open Source License

@Override
public void processAction(ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
        ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

    String cmd = ParamUtil.getString(actionRequest, Constants.CMD);

    try {/*from  w  w w.  ja  va2 s .c o m*/
        if (cmd.equals(Constants.ADD) || cmd.equals(Constants.UPDATE)) {
            updateFolder(actionRequest);
        } else if (cmd.equals(Constants.DELETE)) {
            deleteFolder(actionRequest);
        }

        sendRedirect(actionRequest, actionResponse);
    } catch (Exception e) {
        if (e instanceof NoSuchFolderException || e instanceof PrincipalException) {

            SessionErrors.add(actionRequest, e.getClass().getName());

            setForward(actionRequest, "portlet.bookmarks.error");
        } else if (e instanceof FolderNameException) {
            SessionErrors.add(actionRequest, e.getClass().getName());
        } else {
            throw e;
        }
    }
}

From source file:com.liferay.portlet.bookmarks.action.EditFolderAction.java

License:Open Source License

@Override
public ActionForward render(ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
        RenderRequest renderRequest, RenderResponse renderResponse) throws Exception {

    try {//w  w  w. j  a v  a 2  s .c  om
        ActionUtil.getFolder(renderRequest);
    } catch (Exception e) {
        if (e instanceof NoSuchFolderException || e instanceof PrincipalException) {

            SessionErrors.add(renderRequest, e.getClass().getName());

            return mapping.findForward("portlet.bookmarks.error");
        } else {
            throw e;
        }
    }

    return mapping.findForward(getForward(renderRequest, "portlet.bookmarks.edit_folder"));
}

From source file:com.liferay.portlet.bookmarks.action.ViewAction.java

License:Open Source License

@Override
public ActionForward render(ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
        RenderRequest renderRequest, RenderResponse renderResponse) throws Exception {

    try {/*w ww. j  a  v  a 2 s .  co  m*/
        ActionUtil.getFolder(renderRequest);
    } catch (Exception e) {
        if (e instanceof NoSuchFolderException || e instanceof PrincipalException) {

            SessionErrors.add(renderRequest, e.getClass().getName());

            return mapping.findForward("portlet.bookmarks.error");
        } else {
            throw e;
        }
    }

    return mapping.findForward("portlet.bookmarks.view");
}

From source file:com.liferay.portlet.calendar.action.ConfigurationActionImpl.java

License:Open Source License

protected void validateEmailFrom(ActionRequest actionRequest) throws Exception {

    String emailFromName = getParameter(actionRequest, "emailFromName");
    String emailFromAddress = getParameter(actionRequest, "emailFromAddress");

    if (Validator.isNull(emailFromName)) {
        SessionErrors.add(actionRequest, "emailFromName");
    } else if (!Validator.isEmailAddress(emailFromAddress)) {
        SessionErrors.add(actionRequest, "emailFromAddress");
    }/*w ww  . j  a v  a 2s.  com*/
}