001: package org.claros.intouch.preferences.services;
002:
003: import java.io.IOException;
004: import java.io.PrintWriter;
005:
006: import javax.servlet.ServletException;
007: import javax.servlet.http.HttpServletRequest;
008: import javax.servlet.http.HttpServletResponse;
009:
010: import org.apache.commons.configuration.ConfigurationException;
011: import org.claros.commons.auth.models.AuthProfile;
012: import org.claros.commons.configuration.PropertyFile;
013: import org.claros.intouch.common.services.BaseService;
014: import org.claros.intouch.preferences.controllers.UserPrefsController;
015:
016: public class SavePreferencesService extends BaseService {
017:
018: /**
019: *
020: */
021: private static final long serialVersionUID = 3758680271955404513L;
022:
023: /**
024: * The doPost method of the servlet. <br>
025: *
026: * This method is called when a form has its tag value method equals to post.
027: *
028: * @param request the request send by the client to the server
029: * @param response the response send by the server to the client
030: * @throws ServletException if an error occurred
031: * @throws IOException if an error occurred
032: */
033: public void doPost(HttpServletRequest request,
034: HttpServletResponse response) throws ServletException,
035: IOException {
036:
037: response.setHeader("Expires", "-1");
038: response.setHeader("Pragma", "no-cache");
039: response.setHeader("Cache-control", "no-cache");
040: response.setHeader("Content-Type", "text/html; charset=utf-8");
041:
042: PrintWriter out = response.getWriter();
043: // String charset = Constants.charset;
044:
045: // String fullName = new String(request.getParameter("fullName").getBytes(charset), "utf-8");
046: String fullName = request.getParameter("fullName");
047: String emailAddress = request.getParameter("emailAddress");
048: String replyTo = request.getParameter("replyTo");
049: String mailSound = request.getParameter("mailSound");
050: String spamAnalysis = request.getParameter("spamAnalysis");
051: String saveSent = request.getParameter("saveSent");
052: // String signature = new String(request.getParameter("signature").getBytes(charset), "utf-8");
053: String signature = request.getParameter("signature");
054: String signaturePos = request.getParameter("signaturePos");
055: String sendReadReceipt = request
056: .getParameter("sendReadReceipt");
057: String safeContacts = request.getParameter("safeContacts");
058: String saveSentContacts = request
059: .getParameter("saveSentContacts");
060: String displayType = request.getParameter("displayType");
061: String chatAwayMins = request.getParameter("chatAwayMins");
062: String chatSound = request.getParameter("chatSound");
063: String newsUrl = request.getParameter("newsUrl");
064:
065: if (mailSound == null || mailSound.trim().equals("")) {
066: mailSound = "yes";
067: }
068: if (spamAnalysis == null || spamAnalysis.trim().equals("")) {
069: spamAnalysis = "-1";
070: }
071: if (saveSent == null || saveSent.trim().equals("")) {
072: saveSent = "yes";
073: }
074: if (signaturePos == null || signaturePos.trim().equals("")) {
075: signaturePos = "top";
076: }
077: if (sendReadReceipt == null
078: || sendReadReceipt.trim().equals("")) {
079: sendReadReceipt = "prompt";
080: }
081: if (safeContacts == null || safeContacts.trim().equals("")) {
082: safeContacts = "yes";
083: }
084: if (saveSentContacts == null
085: || saveSentContacts.trim().equals("")) {
086: saveSentContacts = "yes";
087: }
088: if (displayType == null || displayType.trim().equals("")) {
089: displayType = "nameFirst";
090: }
091: if (chatAwayMins == null || chatAwayMins.trim().equals("")) {
092: chatAwayMins = "15";
093: } else {
094: try {
095: // check if it is a valid integer number
096: chatAwayMins = Integer.parseInt(chatAwayMins) + "";
097: } catch (Exception e) {
098: chatAwayMins = "15";
099: }
100: }
101: if (chatSound == null || chatSound.trim().equals("")) {
102: chatSound = "yes";
103: }
104: if (newsUrl == null || newsUrl.trim().equals("")) {
105: try {
106: newsUrl = PropertyFile.getConfiguration(
107: "/config/config.xml").getString(
108: "common-params.rss-feed");
109: } catch (ConfigurationException e) {
110: }
111: }
112:
113: AuthProfile auth = getAuthProfile(request);
114: try {
115: UserPrefsController.saveItem(auth, "fullName", fullName);
116: UserPrefsController.saveItem(auth, "emailAddress",
117: emailAddress);
118: UserPrefsController.saveItem(auth, "replyTo", replyTo);
119: UserPrefsController.saveItem(auth, "mailSound", mailSound);
120: UserPrefsController.saveItem(auth, "spamAnalysis",
121: spamAnalysis);
122: UserPrefsController.saveItem(auth, "saveSent", saveSent);
123: UserPrefsController.saveItem(auth, "signature", signature);
124: UserPrefsController.saveItem(auth, "signaturePos",
125: signaturePos);
126: UserPrefsController.saveItem(auth, "sendReadReceipt",
127: sendReadReceipt);
128: UserPrefsController.saveItem(auth, "safeContacts",
129: safeContacts);
130: UserPrefsController.saveItem(auth, "saveSentContacts",
131: saveSentContacts);
132: UserPrefsController.saveItem(auth, "displayType",
133: displayType);
134: UserPrefsController.saveItem(auth, "chatAwayMins",
135: chatAwayMins);
136: UserPrefsController.saveItem(auth, "chatSound", chatSound);
137: UserPrefsController.saveItem(auth, "newsUrl", newsUrl);
138: out.print("ok");
139: } catch (Exception e) {
140: out.print("fail");
141: }
142: }
143: }
|