List of usage examples for com.liferay.portal.kernel.servlet SessionErrors add
public static void add(PortletRequest portletRequest, String key)
From source file:com.liferay.image.editor.hook.action.EditFileEntryAction.java
License:Open Source License
@Override public void processAction(StrutsPortletAction originalStrutsPortletAction, PortletConfig portletConfig, ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { String cmd = ParamUtil.getString(actionRequest, Constants.CMD); try {/*w ww .j a va2 s . co m*/ if (cmd.equals(Constants.EDIT)) { updateImage(actionRequest); } else { originalStrutsPortletAction.processAction(originalStrutsPortletAction, portletConfig, actionRequest, actionResponse); } } catch (Exception e) { SessionErrors.add(actionRequest, e.getClass()); } finally { String redirect = ParamUtil.getString(actionRequest, "redirect"); actionResponse.sendRedirect(redirect); } }
From source file:com.liferay.image.uploader.web.internal.portlet.action.UploadImageMVCActionCommand.java
License:Open Source License
protected void handleUploadException(ActionRequest actionRequest, ActionResponse actionResponse, String cmd, long maxFileSize, Exception e) throws Exception { if (e instanceof PrincipalException) { SessionErrors.add(actionRequest, e.getClass()); actionResponse.setRenderParameter("mvcPath", "/error.jsp"); } else if (e instanceof AntivirusScannerException || e instanceof FileExtensionException || e instanceof FileSizeException || e instanceof ImageTypeException || e instanceof NoSuchFileException || e instanceof UploadException || e instanceof UploadRequestSizeException) { if (cmd.equals(Constants.ADD_TEMP)) { hideDefaultErrorMessage(actionRequest); ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); String errorMessage = StringPool.BLANK; if (e instanceof AntivirusScannerException) { AntivirusScannerException ase = (AntivirusScannerException) e; errorMessage = themeDisplay.translate(ase.getMessageKey()); } else if (e instanceof FileExtensionException) { errorMessage = themeDisplay.translate("please-enter-a-file-with-a-valid-extension-x", StringUtil.merge(_dlConfiguration.fileExtensions())); } else if (e instanceof FileSizeException) { if (maxFileSize == 0) { maxFileSize = _uploadServletRequestConfigurationHelper.getMaxSize(); }/*from w w w. j a v a 2 s . com*/ errorMessage = themeDisplay.translate( "please-enter-a-file-with-a-valid-file-size-no-" + "larger-than-x", TextFormatter.formatStorageSize(maxFileSize, themeDisplay.getLocale())); } else if (e instanceof ImageTypeException) { errorMessage = themeDisplay.translate("please-enter-a-file-with-a-valid-file-type"); } else if (e instanceof NoSuchFileException || e instanceof UploadException) { errorMessage = themeDisplay .translate("an-unexpected-error-occurred-while-uploading-your-" + "file"); } JSONObject jsonObject = JSONFactoryUtil.createJSONObject(); jsonObject.put("errorMessage", errorMessage); JSONPortletResponseUtil.writeJSON(actionRequest, actionResponse, jsonObject); } else { SessionErrors.add(actionRequest, e.getClass(), e); } } else { throw e; } }
From source file:com.liferay.journal.web.internal.portlet.action.CopyArticleMVCActionCommand.java
License:Open Source License
@Override protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { try {//from w w w. j av a2s. com copyArticle(actionRequest); } catch (Exception e) { if (e instanceof NoSuchArticleException || e instanceof PrincipalException) { SessionErrors.add(actionRequest, e.getClass()); PortletSession portletSession = actionRequest.getPortletSession(); PortletContext portletContext = portletSession.getPortletContext(); PortletRequestDispatcher portletRequestDispatcher = portletContext .getRequestDispatcher("/error.jsp"); portletRequestDispatcher.include(actionRequest, actionResponse); } else if (e instanceof ArticleIdException || e instanceof DuplicateArticleIdException) { SessionErrors.add(actionRequest, e.getClass()); } else { throw e; } } }
From source file:com.liferay.knowledgebase.admin.action.ConfigurationActionImpl.java
License:Open Source License
@Override protected void validateEmailFrom(ActionRequest actionRequest) { String emailFromName = getParameter(actionRequest, "emailFromName"); String emailFromAddress = getParameter(actionRequest, "emailFromAddress"); if (Validator.isNull(emailFromName)) { SessionErrors.add(actionRequest, "emailFromName"); } else if (!Validator.isEmailAddress(emailFromAddress) && !isVariableTerm(emailFromAddress)) { SessionErrors.add(actionRequest, "emailFromAddress"); }/*from ww w . j ava 2 s. com*/ }
From source file:com.liferay.knowledgebase.admin.action.ConfigurationActionImpl.java
License:Open Source License
protected void validateEmailKBArticleAdded(ActionRequest actionRequest) { String emailKBArticleAddedSubject = getParameter(actionRequest, "emailKBArticleAddedSubject"); String emailKBArticleAddedBody = getParameter(actionRequest, "emailKBArticleAddedBody"); if (Validator.isNull(emailKBArticleAddedSubject)) { SessionErrors.add(actionRequest, "emailKBArticleAddedSubject"); } else if (Validator.isNull(emailKBArticleAddedBody)) { SessionErrors.add(actionRequest, "emailKBArticleAddedBody"); }/*ww w . ja v a2 s . c o m*/ }
From source file:com.liferay.knowledgebase.admin.action.ConfigurationActionImpl.java
License:Open Source License
protected void validateEmailKBArticleUpdated(ActionRequest actionRequest) { String emailKBArticleUpdatedSubject = getParameter(actionRequest, "emailKBArticleUpdatedSubject"); String emailKBArticleUpdatedBody = getParameter(actionRequest, "emailKBArticleUpdatedBody"); if (Validator.isNull(emailKBArticleUpdatedSubject)) { SessionErrors.add(actionRequest, "emailKBArticleUpdatedSubject"); } else if (Validator.isNull(emailKBArticleUpdatedBody)) { SessionErrors.add(actionRequest, "emailKBArticleUpdatedBody"); }/*from w w w . ja v a 2s . c o m*/ }
From source file:com.liferay.knowledgebase.admin.portlet.AdminPortlet.java
License:Open Source License
@Override public void render(RenderRequest renderRequest, RenderResponse renderResponse) throws IOException, PortletException { try {// w w w . j a v a 2s. c o m int status = WorkflowConstants.STATUS_ANY; renderRequest.setAttribute(WebKeys.KNOWLEDGE_BASE_STATUS, status); KBArticle kbArticle = null; long kbArticleClassNameId = PortalUtil.getClassNameId(KBArticleConstants.getClassName()); long resourceClassNameId = ParamUtil.getLong(renderRequest, "resourceClassNameId", kbArticleClassNameId); long resourcePrimKey = ParamUtil.getLong(renderRequest, "resourcePrimKey"); if ((resourcePrimKey > 0) && (resourceClassNameId == kbArticleClassNameId)) { kbArticle = KBArticleServiceUtil.getLatestKBArticle(resourcePrimKey, status); } renderRequest.setAttribute(WebKeys.KNOWLEDGE_BASE_KB_ARTICLE, kbArticle); KBTemplate kbTemplate = null; long kbTemplateId = ParamUtil.getLong(renderRequest, "kbTemplateId"); if (kbTemplateId > 0) { kbTemplate = KBTemplateServiceUtil.getKBTemplate(kbTemplateId); } renderRequest.setAttribute(WebKeys.KNOWLEDGE_BASE_KB_TEMPLATE, kbTemplate); } catch (Exception e) { if (e instanceof NoSuchArticleException || e instanceof NoSuchTemplateException || e instanceof PrincipalException) { SessionErrors.add(renderRequest, e.getClass()); } else { throw new PortletException(e); } } super.render(renderRequest, renderResponse); }
From source file:com.liferay.knowledgebase.article.portlet.ArticlePortlet.java
License:Open Source License
@Override public void render(RenderRequest renderRequest, RenderResponse renderResponse) throws IOException, PortletException { try {/*w ww . j a va2 s . c om*/ int status = getStatus(renderRequest); renderRequest.setAttribute(WebKeys.KNOWLEDGE_BASE_STATUS, status); KBArticle kbArticle = null; long resourcePrimKey = getResourcePrimKey(renderRequest); if (resourcePrimKey > 0) { kbArticle = KBArticleServiceUtil.getLatestKBArticle(resourcePrimKey, status); } renderRequest.setAttribute(WebKeys.KNOWLEDGE_BASE_KB_ARTICLE, kbArticle); } catch (Exception e) { if (e instanceof NoSuchArticleException || e instanceof PrincipalException) { SessionErrors.add(renderRequest, e.getClass()); SessionMessages.add(renderRequest, PortalUtil.getPortletId(renderRequest) + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_ERROR_MESSAGE); } else { throw new PortletException(e); } } super.render(renderRequest, renderResponse); }
From source file:com.liferay.knowledgebase.display.portlet.DisplayPortlet.java
License:Open Source License
@Override public void render(RenderRequest renderRequest, RenderResponse renderResponse) throws IOException, PortletException { try {/*from w w w . j a va 2 s. co m*/ ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY); int status = getStatus(renderRequest); renderRequest.setAttribute(WebKeys.KNOWLEDGE_BASE_STATUS, status); KBArticle kbArticle = null; Tuple resourceTuple = getResourceTuple(renderRequest); long resourcePrimKey = (Long) resourceTuple.getObject(1); if (resourcePrimKey != KBFolderConstants.DEFAULT_PARENT_FOLDER_ID) { long resourceClassNameId = (Long) resourceTuple.getObject(0); long kbFolderClassNameId = PortalUtil.getClassNameId(KBFolderConstants.getClassName()); if (resourceClassNameId == kbFolderClassNameId) { PortalPreferences portalPreferences = PortletPreferencesFactoryUtil .getPortalPreferences(renderRequest); String preferredKBFolderUrlTitle = portalPreferences .getValue(PortletKeys.KNOWLEDGE_BASE_DISPLAY, "preferredKBFolderUrlTitle"); kbArticle = getKBFolderKBArticle(themeDisplay.getScopeGroupId(), resourcePrimKey, preferredKBFolderUrlTitle); } else { kbArticle = KBArticleServiceUtil.fetchLatestKBArticle(resourcePrimKey, status); } } else { long parentResourcePrimKey = ParamUtil.getLong(renderRequest, "parentResourcePrimKey", KBFolderConstants.DEFAULT_PARENT_FOLDER_ID); if (parentResourcePrimKey == KBFolderConstants.DEFAULT_PARENT_FOLDER_ID) { List<KBArticle> kbArticles = KBArticleLocalServiceUtil.getGroupKBArticles( themeDisplay.getScopeGroupId(), status, 0, 1, new KBArticlePriorityComparator(true)); if (!kbArticles.isEmpty()) { kbArticle = kbArticles.get(0); } } } renderRequest.setAttribute(WebKeys.KNOWLEDGE_BASE_KB_ARTICLE, kbArticle); } catch (Exception e) { if (e instanceof NoSuchArticleException || e instanceof PrincipalException) { SessionErrors.add(renderRequest, e.getClass()); SessionMessages.add(renderRequest, PortalUtil.getPortletId(renderRequest) + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_ERROR_MESSAGE); } else { throw new PortletException(e); } } super.render(renderRequest, renderResponse); }
From source file:com.liferay.knowledgebase.search.portlet.SearchPortlet.java
License:Open Source License
@Override public void render(RenderRequest renderRequest, RenderResponse renderResponse) throws IOException, PortletException { try {/*from www .j a va 2 s .c o m*/ int status = getStatus(renderRequest); renderRequest.setAttribute(WebKeys.KNOWLEDGE_BASE_STATUS, status); KBArticle kbArticle = null; long resourcePrimKey = ParamUtil.getLong(renderRequest, "resourcePrimKey"); if (resourcePrimKey > 0) { kbArticle = KBArticleServiceUtil.getLatestKBArticle(resourcePrimKey, status); } renderRequest.setAttribute(WebKeys.KNOWLEDGE_BASE_KB_ARTICLE, kbArticle); } catch (Exception e) { if (e instanceof NoSuchArticleException || e instanceof PrincipalException) { SessionErrors.add(renderRequest, e.getClass()); } else { throw new PortletException(e); } } super.render(renderRequest, renderResponse); }