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