List of usage examples for com.liferay.portal.kernel.servlet SessionErrors add
public static void add(PortletRequest portletRequest, String key, Object value)
From source file:com.liferay.portlet.myplaces.action.ViewAction.java
License:Open Source License
@Override public ActionForward strutsExecute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); long groupId = ParamUtil.getLong(request, "groupId"); String privateLayoutParam = request.getParameter("privateLayout"); List<Layout> layouts = getLayouts(groupId, privateLayoutParam); if (layouts.isEmpty()) { SessionErrors.add(request, NoSuchLayoutSetException.class.getName(), new NoSuchLayoutSetException( "{groupId=" + groupId + ",privateLayout=" + privateLayoutParam + "}")); }/*from w w w . jav a 2 s . c om*/ String redirect = getRedirect(themeDisplay, layouts, groupId, privateLayoutParam); if (Validator.isNull(redirect)) { redirect = ParamUtil.getString(request, "redirect"); } response.sendRedirect(redirect); return null; }
From source file:com.liferay.portlet.myplaces.action.ViewAction.java
License:Open Source License
@Override public void processAction(ActionMapping mapping, ActionForm form, PortletConfig portletConfig, ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); long groupId = ParamUtil.getLong(actionRequest, "groupId"); String privateLayoutParam = actionRequest.getParameter("privateLayout"); List<Layout> layouts = getLayouts(groupId, privateLayoutParam); if (layouts.isEmpty()) { SessionErrors.add(actionRequest, NoSuchLayoutSetException.class.getName(), new NoSuchLayoutSetException( "{groupId=" + groupId + ",privateLayout=" + privateLayoutParam + "}")); }//from w w w. j a va 2s . c om String redirect = getRedirect(themeDisplay, layouts, groupId, privateLayoutParam); if (Validator.isNull(redirect)) { redirect = PortalUtil.escapeRedirect(ParamUtil.getString(actionRequest, "redirect")); } if (Validator.isNotNull(redirect)) { actionResponse.sendRedirect(redirect); } }
From source file:com.liferay.portlet.plugininstaller.action.InstallPluginAction.java
License:Open Source License
protected void remoteDeploy(ActionRequest actionRequest) throws Exception { try {/*from w ww. ja v a 2 s . c o m*/ String url = ParamUtil.getString(actionRequest, "url"); URL urlObj = new URL(url); String host = urlObj.getHost(); if (host.endsWith(".sf.net") || host.endsWith(".sourceforge.net")) { remoteDeploySourceForge(urlObj.getPath(), actionRequest); } else { remoteDeploy(url, urlObj, actionRequest, true); } } catch (MalformedURLException murle) { SessionErrors.add(actionRequest, "invalidUrl", murle); } }
From source file:com.liferay.portlet.plugininstaller.action.InstallPluginAction.java
License:Open Source License
protected int remoteDeploy(String url, URL urlObj, ActionRequest actionRequest, boolean failOnError) throws Exception { int responseCode = HttpServletResponse.SC_OK; GetMethod getMethod = null;/*from w w w. j a va 2 s . c o m*/ String deploymentContext = ParamUtil.getString(actionRequest, "deploymentContext"); try { HttpImpl httpImpl = (HttpImpl) HttpUtil.getHttp(); HostConfiguration hostConfiguration = httpImpl.getHostConfiguration(url); HttpClient httpClient = httpImpl.getClient(hostConfiguration); getMethod = new GetMethod(url); String fileName = null; if (Validator.isNotNull(deploymentContext)) { fileName = BaseDeployer.DEPLOY_TO_PREFIX + deploymentContext + ".war"; } else { fileName = url.substring(url.lastIndexOf(CharPool.SLASH) + 1); int pos = fileName.lastIndexOf(CharPool.PERIOD); if (pos != -1) { deploymentContext = fileName.substring(0, pos); } } PluginPackageUtil.registerPluginPackageInstallation(deploymentContext); responseCode = httpClient.executeMethod(hostConfiguration, getMethod); if (responseCode != HttpServletResponse.SC_OK) { if (failOnError) { SessionErrors.add(actionRequest, "errorConnectingToUrl", new Object[] { String.valueOf(responseCode) }); } return responseCode; } long contentLength = getMethod.getResponseContentLength(); String progressId = ParamUtil.getString(actionRequest, Constants.PROGRESS_ID); ProgressInputStream pis = new ProgressInputStream(actionRequest, getMethod.getResponseBodyAsStream(), contentLength, progressId); String deployDir = PrefsPropsUtil.getString(PropsKeys.AUTO_DEPLOY_DEPLOY_DIR, PropsValues.AUTO_DEPLOY_DEPLOY_DIR); String tmpFilePath = deployDir + StringPool.SLASH + _DOWNLOAD_DIR + StringPool.SLASH + fileName; File tmpFile = new File(tmpFilePath); if (!tmpFile.getParentFile().exists()) { tmpFile.getParentFile().mkdirs(); } FileOutputStream fos = new FileOutputStream(tmpFile); try { pis.readAll(fos); if (_log.isInfoEnabled()) { _log.info("Downloaded plugin from " + urlObj + " has " + pis.getTotalRead() + " bytes"); } } finally { pis.clearProgress(); } getMethod.releaseConnection(); if (pis.getTotalRead() > 0) { String destination = deployDir + StringPool.SLASH + fileName; File destinationFile = new File(destination); boolean moved = FileUtil.move(tmpFile, destinationFile); if (!moved) { FileUtil.copyFile(tmpFile, destinationFile); FileUtil.delete(tmpFile); } SessionMessages.add(actionRequest, "pluginDownloaded"); } else { if (failOnError) { SessionErrors.add(actionRequest, UploadException.class.getName()); } responseCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR; } } catch (MalformedURLException murle) { SessionErrors.add(actionRequest, "invalidUrl", murle); } catch (IOException ioe) { SessionErrors.add(actionRequest, "errorConnectingToUrl", ioe); } finally { if (getMethod != null) { getMethod.releaseConnection(); } PluginPackageUtil.endPluginPackageInstallation(deploymentContext); } return responseCode; }
From source file:com.liferay.portlet.plugininstaller.action.InstallPluginAction.java
License:Open Source License
protected void remoteDeploySourceForge(String path, ActionRequest actionRequest) throws Exception { String[] sourceForgeMirrors = getSourceForgeMirrors(); for (int i = 0; i < sourceForgeMirrors.length; i++) { try {// w w w . j a v a 2s . com String url = sourceForgeMirrors[i] + path; if (_log.isDebugEnabled()) { _log.debug("Downloading from SourceForge mirror " + url); } URL urlObj = new URL(url); boolean failOnError = false; if ((i + 1) == sourceForgeMirrors.length) { failOnError = true; } int responseCode = remoteDeploy(url, urlObj, actionRequest, failOnError); if (responseCode == HttpServletResponse.SC_OK) { return; } } catch (MalformedURLException murle) { SessionErrors.add(actionRequest, "invalidUrl", murle); } } }
From source file:com.liferay.portlet.rss.action.ConfigurationActionImpl.java
License:Open Source License
@Override public void processAction(PortletConfig portletConfig, ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { String cmd = ParamUtil.getString(actionRequest, Constants.CMD); if (cmd.equals(Constants.UPDATE)) { updateSubscriptions(actionRequest); super.processAction(portletConfig, actionRequest, actionResponse); return;//from w w w .j a v a 2s .c o m } String portletResource = ParamUtil.getString(actionRequest, "portletResource"); PortletPreferences preferences = PortletPreferencesFactoryUtil.getPortletSetup(actionRequest, portletResource); if (cmd.equals("remove-footer-article")) { removeFooterArticle(actionRequest, preferences); } else if (cmd.equals("remove-header-article")) { removeHeaderArticle(actionRequest, preferences); } else if (cmd.equals("set-footer-article")) { setFooterArticle(actionRequest, preferences); } else if (cmd.equals("set-header-article")) { setHeaderArticle(actionRequest, preferences); } if (SessionErrors.isEmpty(actionRequest)) { try { preferences.store(); } catch (ValidatorException ve) { SessionErrors.add(actionRequest, ValidatorException.class.getName(), ve); return; } SessionMessages.add(actionRequest, portletConfig.getPortletName() + SessionMessages.KEY_SUFFIX_REFRESH_PORTLET, portletResource); SessionMessages.add(actionRequest, portletConfig.getPortletName() + SessionMessages.KEY_SUFFIX_UPDATED_CONFIGURATION); } }
From source file:com.liferay.portlet.stagingbar.action.EditLayoutBranchAction.java
License:Open Source License
@Override public void processAction(ActionMapping mapping, ActionForm form, PortletConfig portletConfig, ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { try {//from w w w .j a v a2 s . com checkPermissions(actionRequest); } catch (PrincipalException pe) { return; } String cmd = ParamUtil.getString(actionRequest, Constants.CMD); try { if (cmd.equals(Constants.ADD) || cmd.equals(Constants.UPDATE)) { updateLayoutBranch(actionRequest); } else if (cmd.equals(Constants.DELETE)) { deleteLayoutBranch(actionRequest, portletConfig); } if (SessionErrors.isEmpty(actionRequest)) { SessionMessages.add(actionRequest, portletConfig.getPortletName() + SessionMessages.KEY_SUFFIX_REFRESH_PORTLET, PortletKeys.STAGING_BAR); Map<String, String> data = new HashMap<String, String>(); data.put("preventNotification", Boolean.TRUE.toString()); SessionMessages.add(actionRequest, portletConfig.getPortletName() + SessionMessages.KEY_SUFFIX_REFRESH_PORTLET_DATA, data); } sendRedirect(actionRequest, actionResponse); } catch (Exception e) { if (e instanceof LayoutBranchNameException) { SessionErrors.add(actionRequest, e.getClass().getName(), e); sendRedirect(actionRequest, actionResponse); } else if (e instanceof PrincipalException || e instanceof SystemException) { SessionErrors.add(actionRequest, e.getClass().getName()); setForward(actionRequest, "portlet.staging_bar.error"); } else { throw e; } } }
From source file:com.liferay.portlet.stagingbar.action.EditLayoutSetBranchAction.java
License:Open Source License
@Override public void processAction(ActionMapping mapping, ActionForm form, PortletConfig portletConfig, ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { try {//from w w w. j ava 2s . c o m checkPermissions(actionRequest); } catch (PrincipalException pe) { return; } String cmd = ParamUtil.getString(actionRequest, Constants.CMD); try { if (cmd.equals(Constants.ADD) || cmd.equals(Constants.UPDATE)) { updateLayoutSetBranch(actionRequest); } else if (cmd.equals(Constants.DELETE)) { deleteLayoutSetBranch(actionRequest, portletConfig); } else if (cmd.equals("merge_layout_set_branch")) { mergeLayoutSetBranch(actionRequest); } if (SessionErrors.isEmpty(actionRequest)) { SessionMessages.add(actionRequest, portletConfig.getPortletName() + SessionMessages.KEY_SUFFIX_REFRESH_PORTLET, PortletKeys.STAGING_BAR); Map<String, String> data = new HashMap<String, String>(); data.put("preventNotification", Boolean.TRUE.toString()); SessionMessages.add(actionRequest, portletConfig.getPortletName() + SessionMessages.KEY_SUFFIX_REFRESH_PORTLET_DATA, data); } sendRedirect(actionRequest, actionResponse); } catch (Exception e) { if (e instanceof LayoutSetBranchNameException) { SessionErrors.add(actionRequest, e.getClass().getName(), e); sendRedirect(actionRequest, actionResponse); } else if (e instanceof PrincipalException || e instanceof SystemException) { SessionErrors.add(actionRequest, e.getClass().getName()); setForward(actionRequest, "portlet.staging_bar.error"); } else { throw e; } } }
From source file:com.liferay.server.admin.web.internal.portlet.action.EditServerMVCActionCommand.java
License:Open Source License
protected String convertProcess(ActionRequest actionRequest, ActionResponse actionResponse, String cmd) throws Exception { ActionResponseImpl actionResponseImpl = (ActionResponseImpl) actionResponse; PortletSession portletSession = actionRequest.getPortletSession(); String className = StringUtil.replaceFirst(cmd, "convertProcess.", StringPool.BLANK); ConvertProcess convertProcess = (ConvertProcess) InstancePool.get(className); String[] parameters = convertProcess.getParameterNames(); if (parameters != null) { String[] values = new String[parameters.length]; for (int i = 0; i < parameters.length; i++) { String parameter = className + StringPool.PERIOD + parameters[i]; if (parameters[i].contains(StringPool.EQUAL)) { String[] parameterPair = StringUtil.split(parameters[i], CharPool.EQUAL); parameter = className + StringPool.PERIOD + parameterPair[0]; }//from w ww.ja va 2 s.c om values[i] = ParamUtil.getString(actionRequest, parameter); } convertProcess.setParameterValues(values); } try { convertProcess.validate(); } catch (ConvertException ce) { SessionErrors.add(actionRequest, ce.getClass(), ce); return null; } String path = convertProcess.getPath(); if (path != null) { PortletURL portletURL = actionResponseImpl.createRenderURL(); portletURL.setParameter("mvcRenderCommandName", path); portletURL.setWindowState(WindowState.MAXIMIZED); return portletURL.toString(); } MaintenanceUtil.maintain(portletSession.getId(), className); MessageBusUtil.sendMessage(DestinationNames.CONVERT_PROCESS, className); return null; }
From source file:com.liferay.server.admin.web.internal.portlet.action.EditServerMVCActionCommand.java
License:Open Source License
protected void runScript(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { String language = ParamUtil.getString(actionRequest, "language"); String script = ParamUtil.getString(actionRequest, "script"); PortletConfig portletConfig = getPortletConfig(actionRequest); PortletContext portletContext = portletConfig.getPortletContext(); Map<String, Object> portletObjects = ScriptingHelperUtil.getPortletObjects(portletConfig, portletContext, actionRequest, actionResponse); UnsyncByteArrayOutputStream unsyncByteArrayOutputStream = new UnsyncByteArrayOutputStream(); UnsyncPrintWriter unsyncPrintWriter = UnsyncPrintWriterPool.borrow(unsyncByteArrayOutputStream); portletObjects.put("out", unsyncPrintWriter); try {// w w w.ja v a 2 s .c o m SessionMessages.add(actionRequest, "language", language); SessionMessages.add(actionRequest, "script", script); _scripting.exec(null, portletObjects, language, script); unsyncPrintWriter.flush(); SessionMessages.add(actionRequest, "scriptOutput", unsyncByteArrayOutputStream.toString()); } catch (ScriptingException se) { SessionErrors.add(actionRequest, ScriptingException.class.getName(), se); Log log = SanitizerLogWrapper.allowCRLF(_log); log.error(se.getMessage()); } }