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.plugininstaller.action.InstallPluginAction.java

License:Open Source License

protected void localDeploy(ActionRequest actionRequest) throws Exception {
    UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(actionRequest);

    String fileName = null;/*from   w ww  . ja  va 2s. c o m*/

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

    if (Validator.isNotNull(deploymentContext)) {
        fileName = BaseDeployer.DEPLOY_TO_PREFIX + deploymentContext + ".war";
    } else {
        fileName = GetterUtil.getString(uploadPortletRequest.getFileName("file"));

        int pos = fileName.lastIndexOf(CharPool.PERIOD);

        if (pos != -1) {
            deploymentContext = fileName.substring(0, pos);
        }
    }

    File file = uploadPortletRequest.getFile("file");

    byte[] bytes = FileUtil.getBytes(file);

    if ((bytes == null) || (bytes.length == 0)) {
        SessionErrors.add(actionRequest, UploadException.class.getName());

        return;
    }

    try {
        PluginPackageUtil.registerPluginPackageInstallation(deploymentContext);

        String source = file.toString();

        String deployDir = PrefsPropsUtil.getString(PropsKeys.AUTO_DEPLOY_DEPLOY_DIR,
                PropsValues.AUTO_DEPLOY_DEPLOY_DIR);

        String destination = deployDir + StringPool.SLASH + fileName;

        FileUtil.copyFile(source, destination);

        SessionMessages.add(actionRequest, "pluginUploaded");
    } finally {
        PluginPackageUtil.endPluginPackageInstallation(deploymentContext);
    }
}

From source file:com.liferay.portlet.pluginsadmin.action.EditPluginAction.java

License:Open Source License

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

    try {/* w  w w .  java2s.  co  m*/
        updatePluginSetting(actionRequest);

        sendRedirect(actionRequest, actionResponse);
    } catch (Exception e) {
        if (e instanceof PrincipalException) {
            SessionErrors.add(actionRequest, e.getClass().getName());

            setForward(actionRequest, "portlet.plugins_admin.error");
        } else {
            throw e;
        }
    }
}

From source file:com.liferay.portlet.portalsettings.action.EditCompanyAction.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 {//www.  j  a  va  2  s . c  om
        if (cmd.equals(Constants.ADD) || cmd.equals(Constants.UPDATE)) {
            validateCAS(actionRequest);

            if (!SessionErrors.isEmpty(actionRequest)) {
                setForward(actionRequest, "portlet.portal_settings.edit_company");
            } else {
                updateCompany(actionRequest);
                updateDisplay(actionRequest);

                sendRedirect(actionRequest, actionResponse);
            }
        }
    } catch (Exception e) {
        if (e instanceof PrincipalException) {
            SessionErrors.add(actionRequest, e.getClass().getName());

            setForward(actionRequest, "portlet.portal_settings.error");
        } else if (e instanceof AddressCityException || e instanceof AccountNameException
                || e instanceof AddressStreetException || e instanceof AddressZipException
                || e instanceof CompanyMxException || e instanceof CompanyVirtualHostException
                || e instanceof CompanyWebIdException || e instanceof EmailAddressException
                || e instanceof LocaleException || e instanceof NoSuchCountryException
                || e instanceof NoSuchListTypeException || e instanceof NoSuchRegionException
                || e instanceof PhoneNumberException || e instanceof WebsiteURLException) {

            if (e instanceof NoSuchListTypeException) {
                NoSuchListTypeException nslte = (NoSuchListTypeException) e;

                SessionErrors.add(actionRequest, e.getClass().getName() + nslte.getType());
            } else {
                SessionErrors.add(actionRequest, e.getClass().getName(), e);
            }

            setForward(actionRequest, "portlet.portal_settings.edit_company");
        } else {
            throw e;
        }
    }
}

From source file:com.liferay.portlet.portalsettings.action.EditCompanyAction.java

License:Open Source License

protected void validateCAS(ActionRequest actionRequest) throws Exception {
    boolean casEnabled = ParamUtil.getBoolean(actionRequest, "settings--" + PropsKeys.CAS_AUTH_ENABLED + "--");

    if (!casEnabled) {
        return;/*  ww  w.  j  a v  a 2s  .  c om*/
    }

    String casLoginURL = ParamUtil.getString(actionRequest, "settings--" + PropsKeys.CAS_LOGIN_URL + "--");
    String casLogoutURL = ParamUtil.getString(actionRequest, "settings--" + PropsKeys.CAS_LOGOUT_URL + "--");
    String casServerName = ParamUtil.getString(actionRequest, "settings--" + PropsKeys.CAS_SERVER_NAME + "--");
    String casServerURL = ParamUtil.getString(actionRequest, "settings--" + PropsKeys.CAS_SERVER_URL + "--");
    String casServiceURL = ParamUtil.getString(actionRequest, "settings--" + PropsKeys.CAS_SERVICE_URL + "--");
    String casNoSuchUserRedirectURL = ParamUtil.getString(actionRequest,
            "settings--" + PropsKeys.CAS_NO_SUCH_USER_REDIRECT_URL + "--");

    if (!Validator.isUrl(casLoginURL)) {
        SessionErrors.add(actionRequest, "casLoginURLInvalid");
    }

    if (!Validator.isUrl(casLogoutURL)) {
        SessionErrors.add(actionRequest, "casLogoutURLInvalid");
    }

    if (Validator.isNull(casServerName)) {
        SessionErrors.add(actionRequest, "casServerNameInvalid");
    }

    if (Validator.isNotNull(casServerURL) && Validator.isNotNull(casServiceURL)) {

        SessionErrors.add(actionRequest, "casServerURLAndServiceURLConflict");
    } else if (Validator.isNull(casServerURL) && Validator.isNull(casServiceURL)) {

        SessionErrors.add(actionRequest, "casServerURLAndServiceURLNotSet");
    } else {
        if (Validator.isNotNull(casServerURL) && !Validator.isUrl(casServerURL)) {

            SessionErrors.add(actionRequest, "casServerURLInvalid");
        }

        if (Validator.isNotNull(casServiceURL) && !Validator.isUrl(casServiceURL)) {

            SessionErrors.add(actionRequest, "casServiceURLInvalid");
        }
    }

    if (Validator.isNotNull(casNoSuchUserRedirectURL) && !Validator.isUrl(casNoSuchUserRedirectURL)) {

        SessionErrors.add(actionRequest, "casNoSuchUserURLInvalid");
    }
}

From source file:com.liferay.portlet.portalsettings.action.EditCompanyLogoAction.java

License:Open Source License

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

    try {//from   ww  w  . j a  v a  2 s  . c  o  m
        updateLogo(actionRequest);

        sendRedirect(actionRequest, actionResponse);
    } catch (Exception e) {
        if (e instanceof PrincipalException) {
            SessionErrors.add(actionRequest, e.getClass().getName());

            setForward(actionRequest, "portlet.portal_settings.error");
        } else if (e instanceof ImageTypeException || e instanceof UploadException) {

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

From source file:com.liferay.portlet.portalsettings.action.EditLDAPServerAction.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 ww. j  a  v a2s . c o m
        if (cmd.equals(Constants.ADD) || cmd.equals(Constants.UPDATE)) {
            updateLDAPServer(actionRequest);
        } else if (cmd.equals(Constants.DELETE)) {
            deleteLDAPServer(actionRequest);
        }

        sendRedirect(actionRequest, actionResponse);
    } catch (Exception e) {
        if (e instanceof PrincipalException) {
            SessionErrors.add(actionRequest, e.getClass().getName());

            setForward(actionRequest, "portlet.portal_settings.error");
        } else {
            throw e;
        }
    }
}

From source file:com.liferay.portlet.portletconfiguration.action.EditArchivedSetupsAction.java

License:Open Source License

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

    Portlet portlet = null;/*www . j av  a  2  s  . c o m*/

    try {
        portlet = getPortlet(actionRequest);
    } catch (PrincipalException pe) {
        SessionErrors.add(actionRequest, PrincipalException.class.getName());

        setForward(actionRequest, "portlet.portlet_configuration.error");
    }

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

    try {
        if (cmd.equals(Constants.SAVE)) {
            updateSetup(actionRequest, portlet);
        } else if (cmd.equals(Constants.RESTORE)) {
            restoreSetup(actionRequest, portlet);
        } else if (cmd.equals(Constants.DELETE)) {
            deleteSetup(actionRequest);
        }
    } catch (Exception e) {
        if (e instanceof NoSuchPortletItemException || e instanceof PortletItemNameException) {

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

            sendRedirect(actionRequest, actionResponse);
        } else if (e instanceof PrincipalException) {
            SessionErrors.add(actionRequest, e.getClass().getName());

            setForward(actionRequest, "portlet.portlet_configuration.error");
        } else {
            throw e;
        }
    }

    if (SessionErrors.isEmpty(actionRequest)) {
        String portletResource = ParamUtil.getString(actionRequest, "portletResource");

        SessionMessages.add(actionRequest,
                portletConfig.getPortletName() + SessionMessages.KEY_SUFFIX_REFRESH_PORTLET, portletResource);

        SessionMessages.add(actionRequest,
                portletConfig.getPortletName() + SessionMessages.KEY_SUFFIX_UPDATED_CONFIGURATION);

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

        if (Validator.isNotNull(redirect)) {
            actionResponse.sendRedirect(redirect);
        }
    }
}

From source file:com.liferay.portlet.portletconfiguration.action.EditArchivedSetupsAction.java

License:Open Source License

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

    Portlet portlet = null;/*from w  ww  .ja  v a2s .  c o m*/

    try {
        portlet = getPortlet(renderRequest);
    } catch (PrincipalException pe) {
        SessionErrors.add(renderRequest, PrincipalException.class.getName());

        return mapping.findForward("portlet.portlet_configuration.error");
    }

    renderResponse.setTitle(getTitle(portlet, renderRequest));

    return mapping.findForward(getForward(renderRequest, "portlet.portlet_configuration.edit_archived_setups"));
}

From source file:com.liferay.portlet.portletconfiguration.action.EditConfigurationAction.java

License:Open Source License

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

    Portlet portlet = null;/*from w ww . ja va2 s .c o m*/

    try {
        portlet = ActionUtil.getPortlet(actionRequest);
    } catch (PrincipalException pe) {
        SessionErrors.add(actionRequest, PrincipalException.class.getName());

        setForward(actionRequest, "portlet.portlet_configuration.error");

        return;
    }

    actionRequest = ActionUtil.getWrappedActionRequest(actionRequest, null);

    ConfigurationAction configurationAction = getConfigurationAction(portlet);

    if (configurationAction == null) {
        return;
    }

    configurationAction.processAction(portletConfig, actionRequest, actionResponse);
}

From source file:com.liferay.portlet.portletconfiguration.action.EditConfigurationAction.java

License:Open Source License

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

    Portlet portlet = null;//ww  w.  j av a 2  s .  c o  m

    try {
        portlet = ActionUtil.getPortlet(renderRequest);
    } catch (PrincipalException pe) {
        SessionErrors.add(renderRequest, PrincipalException.class.getName());

        return actionMapping.findForward("portlet.portlet_configuration.error");
    }

    renderRequest = ActionUtil.getWrappedRenderRequest(renderRequest, null);

    renderResponse.setTitle(ActionUtil.getTitle(portlet, renderRequest));

    ConfigurationAction configurationAction = getConfigurationAction(portlet);

    if (configurationAction != null) {
        String path = configurationAction.render(portletConfig, renderRequest, renderResponse);

        if (_log.isDebugEnabled()) {
            _log.debug("Configuration action returned render path " + path);
        }

        if (Validator.isNotNull(path)) {
            renderRequest.setAttribute(WebKeys.CONFIGURATION_ACTION_PATH, path);
        } else {
            _log.error("Configuration action returned a null path");
        }
    }

    return actionMapping
            .findForward(getForward(renderRequest, "portlet.portlet_configuration.edit_configuration"));
}