Example usage for com.liferay.portal.kernel.util PortalUtil sendError

List of usage examples for com.liferay.portal.kernel.util PortalUtil sendError

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util PortalUtil sendError.

Prototype

public static void sendError(Exception e, HttpServletRequest httpServletRequest,
            HttpServletResponse httpServletResponse) throws IOException, ServletException 

Source Link

Usage

From source file:com.liferay.akismet.hook.action.AkismetEditDiscussionAction.java

License:Open Source License

@Override
public String execute(HttpServletRequest request, HttpServletResponse response) throws Exception {

    try {//ww  w.  j  a v  a  2s  .  c o  m
        checkPermission(request);

        updateStatus(request, response);

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

        response.sendRedirect(redirect);
    } catch (Exception e) {
        PortalUtil.sendError(e, request, response);
    }

    return null;
}

From source file:com.liferay.bookmarks.web.internal.portlet.action.OpenEntryAction.java

License:Open Source License

@Override
public String execute(HttpServletRequest request, HttpServletResponse response) throws Exception {

    try {/* w ww.  j a  va2s .  c  o m*/
        long entryId = ParamUtil.getLong(request, "entryId");

        BookmarksEntry entry = _bookmarksEntryService.getEntry(entryId);

        if (entry.isInTrash()) {
            int status = ParamUtil.getInteger(request, "status", WorkflowConstants.STATUS_APPROVED);

            if (status != WorkflowConstants.STATUS_IN_TRASH) {
                throw new NoSuchEntryException("{entryId=" + entryId + "}");
            }
        }

        entry = _bookmarksEntryService.openEntry(entry);

        response.sendRedirect(entry.getUrl());

        return null;
    } catch (Exception e) {
        PortalUtil.sendError(e, request, response);

        return null;
    }
}

From source file:com.liferay.message.boards.web.internal.portlet.action.FindRecentPostsAction.java

License:Open Source License

@Override
public String execute(HttpServletRequest request, HttpServletResponse response) throws Exception {

    try {/*from  w w  w  . ja  va2s . co m*/
        long plid = ParamUtil.getLong(request, "p_l_id");

        PortletURL portletURL = PortletURLFactoryUtil.create(request, MBPortletKeys.MESSAGE_BOARDS, plid,
                PortletRequest.RENDER_PHASE);

        portletURL.setParameter("mvcRenderCommandName", "/message_boards/view_recent_posts");
        portletURL.setPortletMode(PortletMode.VIEW);
        portletURL.setWindowState(WindowState.NORMAL);

        response.sendRedirect(portletURL.toString());

        return null;
    } catch (Exception e) {
        PortalUtil.sendError(e, request, response);

        return null;
    }
}

From source file:com.liferay.wiki.web.internal.portlet.action.ExportPageMVCActionCommand.java

License:Open Source License

@Override
protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

    PortletConfig portletConfig = getPortletConfig(actionRequest);

    try {//www.j  ava  2s  .  c o m
        long nodeId = ParamUtil.getLong(actionRequest, "nodeId");
        String nodeName = ParamUtil.getString(actionRequest, "nodeName");
        String title = ParamUtil.getString(actionRequest, "title");
        double version = ParamUtil.getDouble(actionRequest, "version");

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

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

        PortletURL viewPageURL = PortletURLFactoryUtil.create(actionRequest, portletConfig.getPortletName(),
                PortletRequest.RENDER_PHASE);

        viewPageURL.setParameter("mvcRenderCommandName", "/wiki/view");
        viewPageURL.setParameter("nodeName", nodeName);
        viewPageURL.setParameter("title", title);
        viewPageURL.setPortletMode(PortletMode.VIEW);
        viewPageURL.setWindowState(WindowState.MAXIMIZED);

        PortletURL editPageURL = PortletURLFactoryUtil.create(actionRequest, portletConfig.getPortletName(),
                PortletRequest.RENDER_PHASE);

        editPageURL.setParameter("mvcRenderCommandName", "/wiki/edit_page");
        editPageURL.setParameter("nodeId", String.valueOf(nodeId));
        editPageURL.setParameter("title", title);
        editPageURL.setPortletMode(PortletMode.VIEW);
        editPageURL.setWindowState(WindowState.MAXIMIZED);

        HttpServletRequest request = PortalUtil.getHttpServletRequest(actionRequest);
        HttpServletResponse response = PortalUtil.getHttpServletResponse(actionResponse);

        getFile(nodeId, title, version, targetExtension, viewPageURL, editPageURL, themeDisplay, request,
                response);

        actionResponse.setRenderParameter("mvcPath", "/null.jsp");
    } catch (Exception e) {
        String host = PrefsPropsUtil.getString(PropsKeys.OPENOFFICE_SERVER_HOST);

        if (Validator.isNotNull(host) && !host.equals(_LOCALHOST_IP) && !host.startsWith(_LOCALHOST)) {

            StringBundler sb = new StringBundler(3);

            sb.append("Conversion using a remote OpenOffice instance is ");
            sb.append("not fully supported. Please use a local instance ");
            sb.append("to prevent any limitations and problems.");

            _log.error(sb.toString());
        }

        PortalUtil.sendError(e, actionRequest, actionResponse);
    }
}

From source file:com.liferay.wiki.web.internal.portlet.action.GetPageAttachmentAction.java

License:Open Source License

@Override
public String execute(HttpServletRequest request, HttpServletResponse response) throws Exception {

    try {/*from  w ww  . j  a  v a 2  s.  c o m*/
        long nodeId = ParamUtil.getLong(request, "nodeId");
        String title = ParamUtil.getString(request, "title");
        String fileName = ParamUtil.getString(request, "fileName");

        if (fileName.startsWith(MediaWikiImporter.SHARED_IMAGES_TITLE + StringPool.SLASH)) {

            String[] fileNameParts = fileName.split(MediaWikiImporter.SHARED_IMAGES_TITLE + StringPool.SLASH);

            fileName = fileNameParts[1];

            title = MediaWikiImporter.SHARED_IMAGES_TITLE;
        }

        int status = ParamUtil.getInteger(request, "status", WorkflowConstants.STATUS_APPROVED);

        getFile(nodeId, title, fileName, status, request, response);

        return null;
    } catch (Exception e) {
        if ((e instanceof NoSuchPageException) || (e instanceof NoSuchFileException)) {

            if (_log.isWarnEnabled()) {
                _log.warn(e);
            }
        } else {
            PortalUtil.sendError(e, request, response);
        }

        return null;
    }
}