List of usage examples for com.liferay.portal.kernel.servlet SessionMessages add
public static void add(PortletRequest portletRequest, String key)
From source file:it.gebhard.qa.QAPortlet.java
License:Open Source License
@ProcessAction(name = "updateQuestion") public void updateQuestion(ActionRequest actionRequest, ActionResponse actionResponse) throws IOException, PortletException { try {//from ww w . ja v a 2 s .c o m // Get user input and read the Question instance long id = Long.valueOf(actionRequest.getParameter("questionId")); String title = actionRequest.getParameter("qa-question-title"); String tags = actionRequest.getParameter("qa-question-tags"); String message = actionRequest.getParameter("qa-question-detail"); Question question = QuestionLocalServiceUtil.getQuestion(id); // Check user permissions if (isGuest(actionRequest) || question.getUserId() != getUser(actionRequest).getUserId()) { SessionErrors.add(actionRequest, "guest-not-allowed"); actionResponse.setRenderParameter("questionId", actionRequest.getParameter("questionId")); actionResponse.setRenderParameter("jspPage", "/html/qa/view_question.jsp"); return; } // Update question object question.setTitle(title); question.setMessage(message); question.setModified(new Date(System.currentTimeMillis())); question.persist(); // Update tags QuestionLocalServiceUtil.deleteTags(question); updateTags(question, tags); SessionMessages.add(actionRequest, "success"); } catch (Exception e) { e.printStackTrace(); SessionErrors.add(actionRequest, "error"); } actionResponse.setRenderParameter("questionId", actionRequest.getParameter("questionId")); actionResponse.setRenderParameter("jspPage", "/html/qa/view_question.jsp"); }
From source file:it.gebhard.qa.QAPortlet.java
License:Open Source License
@ProcessAction(name = "deleteQuestion") public void deleteQuestion(ActionRequest actionRequest, ActionResponse actionResponse) throws IOException, PortletException { try {/* w ww . ja v a 2 s . com*/ // Read the question instance long questionId = Long.valueOf(actionRequest.getParameter("questionId")); Question question = QuestionLocalServiceUtil.getQuestion(questionId); // Check user permissions if (isGuest(actionRequest) || question.getUserId() != getUser(actionRequest).getUserId()) { SessionErrors.add(actionRequest, "guest-not-allowed"); actionResponse.setRenderParameter("questionId", actionRequest.getParameter("questionId")); actionResponse.setRenderParameter("jspPage", "/html/qa/view_question.jsp"); return; } // Delete question QuestionLocalServiceUtil.deleteQuestion(questionId); SessionMessages.add(actionRequest, "success"); } catch (Exception e) { e.printStackTrace(); SessionErrors.add(actionRequest, "error"); } actionResponse.setRenderParameter("jspPage", "/html/qa/view.jsp"); actionResponse.setRenderParameter("qa-sort-value", "newest"); actionResponse.setRenderParameter("qa-search-input", ""); }
From source file:it.gebhard.qa.QAPortlet.java
License:Open Source License
@ProcessAction(name = "commitAnswer") public void commitAnswer(ActionRequest actionRequest, ActionResponse actionResponse) throws IOException, PortletException { try {// w w w . ja va2 s . c o m // Check user input String guestName = actionRequest.getParameter("qa-guest-name"); String guestEmail = actionRequest.getParameter("qa-guest-email"); String message = actionRequest.getParameter("qa-answer"); if (!validateCommitAnswerData(actionRequest, actionResponse, guestName, guestEmail, message)) return; // Create and commit the answer and notification instances Question question = QuestionLocalServiceUtil .getQuestion(Long.valueOf(actionRequest.getParameter("questionId"))); Answer answer = createNewAnswer(actionRequest, question, guestName, guestEmail, message); createNotification(question, answer); SessionMessages.add(actionRequest, "success"); } catch (Exception e) { e.printStackTrace(); SessionErrors.add(actionRequest, "error"); } actionResponse.setRenderParameter("questionId", actionRequest.getParameter("questionId")); actionResponse.setRenderParameter("jspPage", "/html/qa/view_question.jsp"); }
From source file:it.gebhard.qa.QAPortlet.java
License:Open Source License
@ProcessAction(name = "updateAnswer") public void updateAnswer(ActionRequest actionRequest, ActionResponse actionResponse) throws IOException, PortletException { try {/*from w w w . j a va 2 s . c o m*/ // Read Answer instance long answerId = Long.valueOf(actionRequest.getParameter("answerId")); Answer answer = AnswerLocalServiceUtil.getAnswer(answerId); // Check user permissions if (isGuest(actionRequest) || answer.getUserId() != getUser(actionRequest).getUserId()) { SessionErrors.add(actionRequest, "guest-not-allowed"); actionResponse.setRenderParameter("questionId", actionRequest.getParameter("questionId")); actionResponse.setRenderParameter("jspPage", "/html/qa/view_question.jsp"); return; } // Update the answer String message = actionRequest.getParameter("qa-answer"); answer.setMessage(message); answer.setModified(new Date(System.currentTimeMillis())); answer.persist(); SessionMessages.add(actionRequest, "success"); } catch (Exception e) { e.printStackTrace(); SessionErrors.add(actionRequest, "error"); } actionResponse.setRenderParameter("questionId", actionRequest.getParameter("questionId")); actionResponse.setRenderParameter("jspPage", "/html/qa/view_question.jsp"); }
From source file:it.gebhard.qa.QAPortlet.java
License:Open Source License
@ProcessAction(name = "commitComment") public void commitComment(ActionRequest actionRequest, ActionResponse actionResponse) throws IOException, PortletException { // Check if user is logged in if (isGuest(actionRequest)) { SessionErrors.add(actionRequest, "guest-not-allowed"); actionResponse.setRenderParameter("questionId", actionRequest.getParameter("questionId")); actionResponse.setRenderParameter("jspPage", "/html/qa/view_question.jsp"); return;/*from w w w. j av a2 s . c o m*/ } try { Long questionId = Long.valueOf(actionRequest.getParameter("questionId")); String answerId = actionRequest.getParameter("answerId"); String message = actionRequest.getParameter("comment"); Comment comment = CommentLocalServiceUtil .createComment(CounterLocalServiceUtil.increment(Comment.class.getName())); // Determine if comment is intended for a question or answer if (answerId != null) { Answer answer = AnswerLocalServiceUtil.getAnswer(Long.valueOf(answerId)); comment.setAnswerId(answer.getAnswerId()); } else { Question question = QuestionLocalServiceUtil.getQuestion(questionId); comment.setQuestionId(question.getQuestionId()); } comment.setMessage(message); comment.setCreated(new Date(System.currentTimeMillis())); comment.setUserId(getUser(actionRequest).getUserId()); comment.persist(); SessionMessages.add(actionRequest, "success"); } catch (Exception e) { e.printStackTrace(); SessionErrors.add(actionRequest, "error"); } actionResponse.setRenderParameter("questionId", actionRequest.getParameter("questionId")); actionResponse.setRenderParameter("jspPage", "/html/qa/view_question.jsp"); }
From source file:it.gebhard.qa.QAPortlet.java
License:Open Source License
private void createVote(ActionRequest actionRequest, ActionResponse actionResponse, boolean plusOne) throws IOException, PortletException { try {//from ww w . java 2s .c o m Long questionId = Long.valueOf(actionRequest.getParameter("questionId")); String answerId = actionRequest.getParameter("answerId"); Vote vote = null; User user = getUser(actionRequest); if (answerId != null) { Answer answer = AnswerLocalServiceUtil.getAnswer(Long.valueOf(answerId)); if (userHasAlreadyVoted(null, answer, user) || answer.getUserId() == user.getUserId()) { actionResponse.setRenderParameter("questionId", actionRequest.getParameter("questionId")); actionResponse.setRenderParameter("jspPage", "/html/qa/view_question.jsp"); SessionErrors.add(actionRequest, "qa-already-voted"); return; } vote = VoteLocalServiceUtil.createVote(CounterLocalServiceUtil.increment(Vote.class.getName())); vote.setAnswerId(answer.getAnswerId()); } else { Question question = QuestionLocalServiceUtil.getQuestion(questionId); if (userHasAlreadyVoted(question, null, user) || question.getUserId() == user.getUserId()) { actionResponse.setRenderParameter("questionId", actionRequest.getParameter("questionId")); actionResponse.setRenderParameter("jspPage", "/html/qa/view_question.jsp"); SessionErrors.add(actionRequest, "qa-already-voted"); return; } vote = VoteLocalServiceUtil.createVote(CounterLocalServiceUtil.increment(Vote.class.getName())); vote.setQuestionId(question.getQuestionId()); } vote.setUserId(user.getUserId()); vote.setPlusOne(plusOne); vote.persist(); SessionMessages.add(actionRequest, "success"); } catch (Exception e) { e.printStackTrace(); SessionErrors.add(actionRequest, "error"); } actionResponse.setRenderParameter("questionId", actionRequest.getParameter("questionId")); actionResponse.setRenderParameter("jspPage", "/html/qa/view_question.jsp"); }
From source file:it.infn.ct.chipster.Chipster.java
License:Apache License
@Override public void processAction(ActionRequest request, ActionResponse response) throws PortletException, IOException { PortletRequestDispatcher dispatcher = null; try {//from ww w.j a v a2s . c o m String action = ""; File temp = null; File credfile = null; // Getting the action to be processed from the request action = request.getParameter("ActionEvent"); // Determine the username and the email address ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); User user = themeDisplay.getUser(); String username = user.getScreenName(); String user_emailAddress = user.getDisplayEmailAddress(); Company company = PortalUtil.getCompany(request); String gateway = company.getName(); PortletPreferences portletPreferences = (PortletPreferences) request.getPreferences(); if (action.equals("CONFIG_CHIPSTER_PORTLET")) { log.info("\nPROCESS ACTION => " + action); // Getting the CHIPSTER APPID from the portlet request String chipster_EXPIRATION = request.getParameter("chipster_EXPIRATION"); // Getting the LOGLEVEL from the portlet request String chipster_LOGLEVEL = request.getParameter("chipster_LOGLEVEL"); // Getting the CHIPSTER_METADATA_HOST from the portlet request String chipster_HOST = request.getParameter("chipster_HOST"); // Getting the CHIPSTER OUTPUT_PATH from the portlet request String chipster_ACCOUNT_FILE = request.getParameter("chipster_ACCOUNT_FILE"); // Getting the SMTP_HOST from the portlet request String SMTP_HOST = request.getParameter("SMTP_HOST"); // Getting the SENDER_MAIL from the portlet request String SENDER_MAIL = request.getParameter("SENDER_MAIL"); // Getting the SENDER_ADMIN from the portlet request String SENDER_ADMIN = request.getParameter("SENDER_ADMIN"); //String[] infras = new String[6]; log.info("\n\nPROCESS ACTION => " + action + "\nchipster_EXPIRATION: " + chipster_EXPIRATION + "\nchipster_LOGLEVEL: " + chipster_LOGLEVEL + "\nchipster_HOST: " + chipster_HOST + "\nchipster_ACCOUNT_FILE: " + chipster_ACCOUNT_FILE + "\nSMTP_HOST: " + SMTP_HOST + "\nSENDER_MAIL: " + SENDER_MAIL + "\nSENDER_ADMIN: " + SENDER_ADMIN); portletPreferences.setValue("chipster_EXPIRATION", chipster_EXPIRATION.trim()); portletPreferences.setValue("chipster_LOGLEVEL", chipster_LOGLEVEL.trim()); portletPreferences.setValue("chipster_ACCOUNT_FILE", chipster_ACCOUNT_FILE.trim()); portletPreferences.setValue("chipster_HOST", chipster_HOST.trim()); portletPreferences.setValue("SMTP_HOST", SMTP_HOST.trim()); portletPreferences.setValue("SENDER_MAIL", SENDER_MAIL.trim()); portletPreferences.setValue("SENDER_ADMIN", SENDER_ADMIN.trim()); portletPreferences.store(); response.setPortletMode(PortletMode.VIEW); } // end PROCESS ACTION [ CONFIG_CHIPSTER_PORTLET ] if (action.equals("SUBMIT_CHIPSTER_PORTLET")) { log.info("\nPROCESS ACTION => " + action); // Getting the CHIPSTER APPID from the portlet preferences String chipster_EXPIRATION = portletPreferences.getValue("chipster_EXPIRATION", "30"); // Getting the LOGLEVEL from the portlet preferences String chipster_LOGLEVEL = portletPreferences.getValue("chipster_LOGLEVEL", "INFO"); // Getting the CHIPSTER_METADATA_HOST from the portlet preferences String chipster_HOST = portletPreferences.getValue("chipster_HOST", "INFO"); // Getting the CHIPSTER OUTPUT_PATH from the portlet preferences String chipster_ACCOUNT_FILE = portletPreferences.getValue("chipster_ACCOUNT_FILE", "N/A"); // Getting the SMTP_HOST from the portlet request String SMTP_HOST = portletPreferences.getValue("SMTP_HOST", "N/A"); // Getting the SENDER_MAIL from the portlet request String SENDER_MAIL = portletPreferences.getValue("SENDER_MAIL", "N/A"); // Getting the SENDER_ADMIN from the portlet request String SENDER_ADMIN = portletPreferences.getValue("SENDER_ADMIN", "N/A"); log.info("\n\nPROCESS ACTION => " + action + "\nchipster_EXPIRATION: " + chipster_EXPIRATION + "\nchipster_LOGLEVEL: " + chipster_LOGLEVEL + "\nchipster_HOST: " + chipster_HOST + "\nchipster_ACCOUNT_FILE: " + chipster_ACCOUNT_FILE + "\nSMTP_HOST: " + SMTP_HOST + "\nSENDER_MAIL: " + SENDER_MAIL + "\nSENDER_ADMIN: " + SENDER_ADMIN); String[] CHIPSTER_Parameters = new String[4]; // Upload the input settings for the application CHIPSTER_Parameters = uploadChipsterSettings(request, response, username); //Set the public key for SSH connections String PublicKey = System.getProperty("user.home") + System.getProperty("file.separator") + ".ssh/id_rsa.pub"; //Set the private key for SSH connections String PrivateKey = System.getProperty("user.home") + System.getProperty("file.separator") + ".ssh/id_rsa"; log.info("\n\n [ Settings ]"); log.info("\n- Input Parameters: "); //log.info("\n- UserID = " + CHIPSTER_Parameters[0]); log.info("\n- Alias = " + CHIPSTER_Parameters[3]); //log.info("\n- Password = " + CHIPSTER_Parameters[1]); log.info("\n- Chipster Front node server = " + chipster_HOST); log.info("\n- Chipster accounting file = " + chipster_ACCOUNT_FILE); log.info("\n- Expiration date = " + chipster_EXPIRATION); log.info("\n- SSH Public Key file = " + PublicKey); log.info("\n- SSH Private Key file = " + PrivateKey); log.info("\n- Admin e-mail address = " + SENDER_ADMIN); log.info("\n- Enable Notification = " + CHIPSTER_Parameters[2]); Date date = new Date(); SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd"); Calendar c = Calendar.getInstance(); c.setTime(new Date()); // Now use today date. c.add(Calendar.DATE, Integer.parseInt(chipster_EXPIRATION)); String output = ft.format(c.getTime()); log.info("Date = " + output); /*String credential = CHIPSTER_Parameters[0] + ":" + CHIPSTER_Parameters[1];*/ /*String credential = CHIPSTER_Parameters[0] + ":" + CHIPSTER_Parameters[3] + ":" + CHIPSTER_Parameters[1];*/ String credential = CHIPSTER_Parameters[3] + ":" + CHIPSTER_Parameters[1]; try { temp = File.createTempFile("file_", ".chipster"); log.info("\n- Creating a temporary file = " + temp); // Getting a copy of the remote file doSFTP(CHIPSTER_Parameters, "get", chipster_HOST, chipster_ACCOUNT_FILE, null, temp); // Checking if the credential is already available //if (checkChipsterCredential(temp, CHIPSTER_Parameters[0])) if (checkChipsterCredential(temp, CHIPSTER_Parameters[3], CHIPSTER_Parameters[1])) { log.info( "\n- The user's credentials [ " + CHIPSTER_Parameters[3] + " ] does already exist"); SessionErrors.add(request, "user-found"); } else { log.info("\n- No credentials have been found!"); try { credential += ":" + output; credfile = File.createTempFile("cred_", ".chipster"); BufferedWriter writer = new BufferedWriter(new FileWriter(credfile)); writer.write(credential + "\n"); writer.close(); // Register the credential doSFTP(CHIPSTER_Parameters, "put-append", chipster_HOST, chipster_ACCOUNT_FILE, credfile, temp); // Send a notification email to the user if enabled. if (CHIPSTER_Parameters[2] != null) if ((SMTP_HOST == null) || (SMTP_HOST.trim().equals("")) || (SMTP_HOST.trim().equals("N/A")) || (SENDER_MAIL == null) || (SENDER_MAIL.trim().equals("")) || (SENDER_MAIL.trim().equals("N/A"))) log.info("\nThe Notification Service is not properly configured!!"); else sendHTMLEmail(username, SENDER_ADMIN, SENDER_MAIL, SMTP_HOST, "Chipster Account Generator", user_emailAddress, CHIPSTER_Parameters[3] + ":" + CHIPSTER_Parameters[1], chipster_HOST); credfile.deleteOnExit(); } catch (IOException ex) { log.error(ex); } finally { credfile.delete(); } SessionMessages.add(request, "user-not-found"); } temp.deleteOnExit(); } catch (IOException ex) { log.error(ex); } finally { temp.delete(); } } // end PROCESS ACTION [ SUBMIT_CHIPSTER_PORTLET ] // Hide default Liferay success/error messages /*PortletConfig portletConfig = (PortletConfig) request .getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG); LiferayPortletConfig liferayPortletConfig = (LiferayPortletConfig) portletConfig; SessionMessages.add(request, liferayPortletConfig.getPortletName() + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_ERROR_MESSAGE);*/ } catch (PortalException ex) { Logger.getLogger(Chipster.class.getName()).log(Level.SEVERE, null, ex); } catch (SystemException ex) { Logger.getLogger(Chipster.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:it.webscience.kpeople.web.portlet.report.action.ConfigurationActionImpl.java
License:Open Source License
public void processAction(PortletConfig portletConfig, ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { String cmd = ParamUtil.getString(actionRequest, Constants.CMD); if (!cmd.equals(Constants.UPDATE)) { return;//from w w w . j av a 2 s . c o m } // String src = ParamUtil.getString(actionRequest, "src"); // if (!src.startsWith("/") && !StringUtil.startsWith(src, "http://") // && !StringUtil.startsWith(src, "https://") // && !StringUtil.startsWith(src, "mhtml://")) { // // src = HttpUtil.getProtocol(actionRequest) + "://" + src; // } String showFilter = ParamUtil.getString(actionRequest, ReportBrowserConstants.SHOW_FILTER); String reportType = ParamUtil.getString(actionRequest, "reportType"); String style = ParamUtil.getString(actionRequest, "style"); String widthChart = ParamUtil.getString(actionRequest, "widthChart"); String heightChart = ParamUtil.getString(actionRequest, "heightChart"); boolean relative = ParamUtil.getBoolean(actionRequest, "relative"); boolean auth = ParamUtil.getBoolean(actionRequest, "auth"); String authType = ParamUtil.getString(actionRequest, "authType"); String formMethod = ParamUtil.getString(actionRequest, "formMethod"); String userName = ParamUtil.getString(actionRequest, "userName"); String userNameField = ParamUtil.getString(actionRequest, "userNameField"); String password = ParamUtil.getString(actionRequest, "password"); String passwordField = ParamUtil.getString(actionRequest, "passwordField"); String hiddenVariables = ParamUtil.getString(actionRequest, "hiddenVariables"); String[] htmlAttributes = StringUtil.split(ParamUtil.getString(actionRequest, "htmlAttributes"), StringPool.NEW_LINE); String portletResource = ParamUtil.getString(actionRequest, "portletResource"); PortletPreferences preferences = PortletPreferencesFactoryUtil.getPortletSetup(actionRequest, portletResource); // preferences.setValue("src", src); preferences.setValue("relative", String.valueOf(relative)); preferences.setValue("auth", String.valueOf(auth)); preferences.setValue("auth-type", authType); preferences.setValue("form-method", formMethod); preferences.setValue("user-name", userName); preferences.setValue("user-name-field", userNameField); preferences.setValue("password", password); preferences.setValue("password-field", passwordField); preferences.setValue("hidden-variables", hiddenVariables); preferences.setValue("reportType", reportType); preferences.setValue("widthChart", widthChart); preferences.setValue("heightChart", heightChart); preferences.setValue("style", style); preferences.setValue(ReportBrowserConstants.SHOW_FILTER, showFilter); for (String htmlAttribute : htmlAttributes) { int pos = htmlAttribute.indexOf(StringPool.EQUAL); if (pos == -1) { continue; } String key = htmlAttribute.substring(0, pos); String value = htmlAttribute.substring(pos + 1, htmlAttribute.length()); preferences.setValue(key, value); } preferences.store(); SessionMessages.add(actionRequest, portletConfig.getPortletName() + ".doConfigure"); }
From source file:m.omarh.liferay.resources.importer.generator.SitemapGeneratorPortlet.java
License:Open Source License
@Override public void doView(RenderRequest renderRequest, RenderResponse renderResponse) throws IOException, PortletException { ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY); Group scopeGroup = themeDisplay.getScopeGroup(); if (scopeGroup.getGroupId() == themeDisplay.getCompanyGroupId()) { SessionMessages.add(renderRequest, PortalUtil.getPortletId(renderRequest) + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_ERROR_MESSAGE); SessionErrors.add(renderRequest, "company-group-exception"); super.doView(renderRequest, renderResponse); } else {/*from w ww. j a va 2 s . co m*/ JSONObject sitemapJsonObject = SiteMapUtil.generateJSONSitemap(scopeGroup); renderRequest.setAttribute("autoDeployDestDir", AutoDeployUtil.getAutoDeployDestDir() + StringPool.SLASH); renderRequest.setAttribute("sitemap", JSONUtil.beautify(sitemapJsonObject.toString())); super.doView(renderRequest, renderResponse); } }
From source file:org.dihedron.demo.portlets.portlet1.actions.Portlet1ValidationHandler.java
License:Open Source License
/** * @see org.dihedron.strutlets.validation.ValidationHandler#onParametersViolations(java.util.Set) *///from w ww.ja v a 2 s . co m @Override public String onParametersViolations(String action, String method, Set<ConstraintViolation<?>> violations) { SessionMessages.add(ActionContext.getPortletRequest(), ActionContext.getPortletName() + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_ERROR_MESSAGE); for (ConstraintViolation<?> violation : violations) { logger.warn("{}!{}: violation on parameter value '{}' will show error message with key '{}'", action, method, violation.getInvalidValue(), violation.getMessage()); SessionErrors.add(ActionContext.getPortletRequest(), violation.getMessage()); } return "invalid_input"; }