001: package org.claros.intouch.contacts.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.logging.Log;
011: import org.apache.commons.logging.LogFactory;
012: import org.claros.intouch.common.services.BaseService;
013: import org.claros.intouch.common.utility.Utility;
014: import org.claros.intouch.contacts.controllers.ContactsController;
015: import org.claros.intouch.contacts.models.Contact;
016:
017: public class GetContactDetailsService extends BaseService {
018:
019: /**
020: *
021: */
022: private static final long serialVersionUID = 5200489224050326230L;
023: private static Log log = LogFactory
024: .getLog(GetContactDetailsService.class);
025:
026: /**
027: * The doPost method of the servlet. <br>
028: *
029: * This method is called when a form has its tag value method equals to post.
030: *
031: * @param request the request send by the client to the server
032: * @param response the response send by the server to the client
033: * @throws ServletException if an error occurred
034: * @throws IOException if an error occurred
035: */
036: public void doPost(HttpServletRequest request,
037: HttpServletResponse response) throws ServletException,
038: IOException {
039:
040: response.setHeader("Expires", "-1");
041: response.setHeader("Pragma", "no-cache");
042: response.setHeader("Cache-control", "no-cache");
043: response.setHeader("Content-Type", "text/xml; charset=utf-8");
044:
045: PrintWriter out = response.getWriter();
046: out.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
047: out.write("<data>");
048:
049: String id = request.getParameter("id");
050: try {
051: Contact cont = ContactsController.getContactById(
052: getAuthProfile(request), new Long(id));
053:
054: out.print("<emailAlternate>"
055: + getInfo(cont.getEmailAlternate())
056: + "</emailAlternate>");
057: out.print("<emailPrimary>"
058: + getInfo(cont.getEmailPrimary())
059: + "</emailPrimary>");
060: out.print("<firstName>" + getInfo(cont.getFirstName())
061: + "</firstName>");
062: out.print("<gsmNoAlternate>"
063: + getInfo(cont.getGsmNoAlternate())
064: + "</gsmNoAlternate>");
065: out.print("<gsmNoPrimary>"
066: + getInfo(cont.getGsmNoPrimary())
067: + "</gsmNoPrimary>");
068: out.print("<homeAddress>" + getInfo(cont.getHomeAddress())
069: + "</homeAddress>");
070: out.print("<homeCity>" + getInfo(cont.getHomeCity())
071: + "</homeCity>");
072: out.print("<homeCountry>" + getInfo(cont.getHomeCountry())
073: + "</homeCountry>");
074: out.print("<homeFaks>" + getInfo(cont.getHomeFaks())
075: + "</homeFaks>");
076: out.print("<homePhone>" + getInfo(cont.getHomePhone())
077: + "</homePhone>");
078: out.print("<homeProvince>"
079: + getInfo(cont.getHomeProvince())
080: + "</homeProvince>");
081: out.print("<homeZip>" + getInfo(cont.getHomeZip())
082: + "</homeZip>");
083: out.print("<lastName>" + getInfo(cont.getLastName())
084: + "</lastName>");
085: out.print("<middleName>" + getInfo(cont.getMiddleName())
086: + "</middleName>");
087: out.print("<nickName>" + getInfo(cont.getNickName())
088: + "</nickName>");
089: out.print("<personalNote>"
090: + getInfo(cont.getPersonalNote())
091: + "</personalNote>");
092: out.print("<sex>" + getInfo(cont.getSex()) + "</sex>");
093: out.print("<spouseName>" + getInfo(cont.getSpouseName())
094: + "</spouseName>");
095: out
096: .print("<title>" + getInfo(cont.getTitle())
097: + "</title>");
098: out.print("<username>" + getInfo(cont.getUsername())
099: + "</username>");
100: out.print("<webPage>" + getInfo(cont.getWebPage())
101: + "</webPage>");
102: out.print("<workAddress>" + getInfo(cont.getWorkAddress())
103: + "</workAddress>");
104: out.print("<workAssistantName>"
105: + getInfo(cont.getWorkAssistantName())
106: + "</workAssistantName>");
107: out.print("<workCity>" + getInfo(cont.getWorkCity())
108: + "</workCity>");
109: out.print("<workCompany>" + getInfo(cont.getWorkCompany())
110: + "</workCompany>");
111: out.print("<workCountry>" + getInfo(cont.getWorkCountry())
112: + "</workCountry>");
113: out.print("<workDepartment>"
114: + getInfo(cont.getWorkDepartment())
115: + "</workDepartment>");
116: out.print("<workFaks>" + getInfo(cont.getWorkFaks())
117: + "</workFaks>");
118: out.print("<workJobTitle>"
119: + getInfo(cont.getWorkJobTitle())
120: + "</workJobTitle>");
121: out.print("<workManagerName>"
122: + getInfo(cont.getWorkManagerName())
123: + "</workManagerName>");
124: out.print("<workOffice>" + getInfo(cont.getWorkOffice())
125: + "</workOffice>");
126: out.print("<workPhone>" + getInfo(cont.getWorkPhone())
127: + "</workPhone>");
128: out.print("<workProfession>"
129: + getInfo(cont.getWorkProfession())
130: + "</workProfession>");
131: out.print("<workProvince>"
132: + getInfo(cont.getWorkProvince())
133: + "</workProvince>");
134: out.print("<workZip>" + getInfo(cont.getWorkZip())
135: + "</workZip>");
136: out.print("<anniversaryDay>"
137: + getInfo(cont.getAnniversaryDay())
138: + "</anniversaryDay>");
139: out.print("<anniversaryMonth>"
140: + getInfo(cont.getAnniversaryMonth())
141: + "</anniversaryMonth>");
142: out.print("<birthDay>" + getInfo(cont.getBirthDay())
143: + "</birthDay>");
144: out.print("<birthMonth>" + getInfo(cont.getBirthMonth())
145: + "</birthMonth>");
146: out.print("<id>" + cont.getId() + "</id>");
147: } catch (NumberFormatException e) {
148: log.error("not a valid id number", e);
149: } catch (Exception e) {
150: log.error("error getting info for contact", e);
151: }
152: out.write("</data>");
153: }
154:
155: /**
156: *
157: * @param str
158: * @return
159: */
160: private static String getInfo(String str) {
161: if (str == null)
162: return " ";
163: if (str.equals(""))
164: return " ";
165: return Utility.htmlCheck(str);
166: }
167: }
|