BrightSide Workbench Full Report + Source Code
FeedbackAction.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2011 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 package org.turro.elephant.impl.feedback;
19 
20 import java.io.File;
21 import java.util.Date;
22 import org.turro.action.MailSenders;
23 import org.turro.string.ObjectString;
24 import org.turro.string.Strings;
25 import org.turro.elephant.context.ElephantContext;
26 import org.turro.elephant.context.IAction;
27 import org.turro.elephant.impl.abstracts.AbstractAction;
28 import org.turro.elephant.impl.util.FileUtil;
29 import org.turro.elephant.impl.util.StringParser;
30 
35 public class FeedbackAction extends AbstractAction implements IAction {
36 
38  public FeedbackAction() {
39  }
40 
41  @Override
42  public int execute() throws Exception {
43  String fbquery = getParameter("fbquery"),
44  comment = getParameter("comment"),
45  action = getActionParameter(),
46  ctx = getParameter("context");
47 
48  if("post".equals(action)) {
49  if(!Strings.isBlank(comment)) {
50  String feedback = ctx + "|" + fbquery + "|" + comment + "|" +
51  constructor.getRequest().getRemoteAddr() + "|" +
52  "|*EOL*|" + "\n";
55  "/WEB-INF/elephant/feedback/data/" +
56  ObjectString.formatObject(new Date(), "yyyyMMdd", false) +
57  ".txt"
58  )),
59  feedback
60  );
61 
62  String mailBody =
63  "Context: " + ctx + "\n" +
64  "Opinion:" + fbquery + "\n" +
65  "Comment:" + "\n" + comment + "\n\n" +
66  "RemoteADR:" + constructor.getRequest().getRemoteAddr();
67  String subject = "Feedback on " + ElephantContext.getSiteName();
70  .send(subject, StringParser.toHTML(mailBody));
71  }
72  }
73  return IAction.DONE;
74  }
75 
76 }
static IMailSender getPool()
static void appendContent(File file, String value)
Definition: FileUtil.java:282
static String toHTML(String value)
String getParameter(String param)