BrightSide Workbench Full Report + Source Code
ContactAction.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2013 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 
19 package org.turro.contacts.action;
20 
21 import java.io.PrintWriter;
22 import org.turro.string.Strings;
23 import org.turro.auth.Authentication;
24 import org.turro.commentit.CommentItUtil;
25 import org.turro.contacts.SignUp;
26 import org.turro.contacts.zul.register.RegisterControl;
27 import org.turro.elephant.context.ElephantContext;
28 import org.turro.elephant.context.IAction;
29 import org.turro.elephant.impl.abstracts.AbstractAction;
30 import org.turro.plugin.contacts.IContact;
31 import org.turro.plugin.contacts.SoftContact;
32 import org.turro.starit.StarItUtil;
33 import org.turro.voteit.VoteItUtil;
34 import org.turro.www.commentit.CommentItCtrl;
35 import org.turro.www.starit.StarItCtrl;
36 import org.turro.www.voteit.VoteItCtrl;
37 
42 public class ContactAction extends AbstractAction implements IAction {
43 
45  public ContactAction() {
46  }
47 
48  @Override
49  public int execute() throws Exception {
50  String ctx = getParameter("context"),
51  action = getActionParameter();
52 
53  boolean isAJAX = false;
54 
55  if ("vote-it".equals(action)) {
56  isAJAX = true;
58  constructor.getResponse().setContentType("text/html");
59  constructor.getResponse().setCharacterEncoding(ElephantContext.getEncoding());
60  String path = getParameter("path");
61  String allowedString = getParameter("allowed");
62  int vote = getIntParameter("vote", 0);
63  VoteItUtil.addVote(path, vote, contact);
65  vic.setEntityPath(path);
66  vic.setForbiden(false);
67  vic.setAllowedString(allowedString == null ? null : allowedString.replaceAll("-", "'"));
68  vic.renderVotes(false);
69  } else if ("star-it".equals(action)) {
70  isAJAX = true;
72  constructor.getResponse().setContentType("text/html");
73  constructor.getResponse().setCharacterEncoding(ElephantContext.getEncoding());
74  String path = getParameter("path");
75  int stars = getIntParameter("stars", 0);
76  SoftContact scontact = new SoftContact();
77  scontact.contact = contact;
78  scontact.author_ip = constructor.getRequest().getRemoteAddr();
79  StarItUtil.addStars(path, stars, scontact);
81  sic.setEntityPath(path);
82  sic.renderStars(false);
83  } else if ("comment-it".equals(action)) {
84  isAJAX = true;
86  constructor.getResponse().setContentType("text/html");
87  constructor.getResponse().setCharacterEncoding(ElephantContext.getEncoding());
88  String path = getParameter("path"),
89  body = getParameter("body"),
90  remove = getParameter("remove");
91  if("true".equals(remove)) {
93  } else if(!Strings.isBlank(body)) {
94  SoftContact scontact = new SoftContact();
95  scontact.contact = contact;
96  scontact.author = getParameter("author");
97  scontact.author_email = getParameter("author_email");
98  scontact.author_web = getParameter("author_web");
99  scontact.author_ip = constructor.getRequest().getRemoteAddr();
100  if(scontact.isValid()) {
101  CommentItUtil.addComment(path, body, scontact);
102  }
104  sic.setEntityPath(path);
105  sic.renderComments(false);
106  }
107  } else if ("confirm".equals(action)) {
108  isAJAX = true;
109  constructor.getResponse().setContentType("text/html");
110  constructor.getResponse().setCharacterEncoding(ElephantContext.getEncoding());
111  PrintWriter out = constructor.getOut();
114  }
115 
116  if (!isAJAX) {
117  constructor.redirect(ctx);
118  }
119 
120  return IAction.DONE;
121  }
122 
123 }
static void addComment(Object entity, String comment, SoftContact contact)
static void writeResultConfirmAction(IConstructor constructor, SignUp signUp)
static void addStars(Object entity, int stars, SoftContact contact)
Definition: StarItUtil.java:39
static void addVote(Object entity, int vote, IContact contact)
Definition: VoteItUtil.java:41
void setEntityPath(String entityPath)
void renderComments(boolean container)
void setEntityPath(String entityPath)
Definition: StarItCtrl.java:46
void renderStars(boolean container)
Definition: StarItCtrl.java:66
void setAllowedString(String allowedString)
String getParameter(String param)