001: package org.claros.intouch.webmail.services;
002:
003: import java.io.IOException;
004: import java.io.PrintWriter;
005: import java.util.List;
006:
007: import javax.servlet.ServletException;
008: import javax.servlet.http.HttpServletRequest;
009: import javax.servlet.http.HttpServletResponse;
010:
011: import org.claros.commons.mail.models.ConnectionMetaHandler;
012: import org.claros.commons.mail.models.ConnectionProfile;
013: import org.claros.commons.mail.utility.Constants;
014: import org.claros.intouch.common.services.BaseService;
015: import org.claros.intouch.webmail.controllers.FolderController;
016: import org.claros.intouch.webmail.factory.FolderControllerFactory;
017: import org.claros.intouch.webmail.models.FolderDbObject;
018: import org.claros.intouch.webmail.models.FolderDbObjectWrapper;
019:
020: public class GetFoldersService extends BaseService {
021:
022: /**
023: *
024: */
025: private static final long serialVersionUID = 7348820385681559438L;
026:
027: /**
028: * The doGet method of the servlet. <br>
029: *
030: * This method is called when a form has its tag value method equals to get.
031: *
032: * @param request the request send by the client to the server
033: * @param response the response send by the server to the client
034: * @throws ServletException if an error occurred
035: * @throws IOException if an error occurred
036: */
037: public void doGet(HttpServletRequest request,
038: HttpServletResponse response) throws ServletException,
039: IOException {
040:
041: response.setHeader("Expires", "-1");
042: response.setHeader("Pragma", "no-cache");
043: response.setHeader("Cache-control", "no-cache");
044: response.setHeader("Content-Type", "text/html; charset=utf-8");
045:
046: PrintWriter out = response.getWriter();
047: ConnectionMetaHandler handler = (ConnectionMetaHandler) request
048: .getSession().getAttribute("handler");
049: ConnectionProfile profile = getConnectionProfile(request);
050:
051: String sFolder = (String) getVariable(request, "folder");
052: if (sFolder == null || sFolder.equals("")) {
053: sFolder = org.claros.commons.mail.utility.Constants
054: .FOLDER_INBOX(profile);
055: }
056:
057: try {
058: FolderControllerFactory foldFact = new FolderControllerFactory(
059: getAuthProfile(request), profile, handler);
060: FolderController folderCont = foldFact
061: .getFolderController();
062: if (profile.getProtocol().equals(Constants.POP3)) {
063: if (sFolder == null || sFolder.equals("INBOX")) {
064: FolderDbObject foldObj = folderCont
065: .getInboxFolder();
066: sFolder = foldObj.getId().toString();
067: }
068: }
069:
070: List folders = folderCont.getFolders();
071: out.print("<ul>");
072: if (folders != null) {
073: FolderDbObjectWrapper tmp = null;
074: String folderName = null;
075: String folderNameEnc = null;
076: String folderNameLang = null;
077: for (int i = 0; i < folders.size(); i++) {
078: tmp = (FolderDbObjectWrapper) folders.get(i);
079: folderName = folderNameLang = tmp.getFolderName();
080: folderNameEnc = java.net.URLEncoder.encode(
081: folderName, "utf-8");
082: if (tmp.getFolderType().intValue() < 6)
083: folderNameLang = getText(request, folderName
084: .replace(' ', '.'));
085: folderNameLang = org.claros.intouch.common.utility.Utility
086: .htmlCheck(folderNameLang);
087: if (profile.getProtocol().equals(Constants.IMAP)) {
088: out
089: .print("<li "
090: + ((folderName.equals(sFolder)) ? "class=\"active\""
091: : "")
092: + " folderType=\""
093: + tmp.getFolderType()
094: + "\" folderId=\""
095: + folderNameEnc
096: + "\" folderName=\""
097: + folderNameLang
098: + "\" id=\"mailFolder"
099: + folderNameEnc
100: + "\" onclick=\"selectMailFolder('"
101: + folderNameEnc + "')\"><div>");
102: } else {
103: out
104: .print("<li "
105: + ((tmp.getId().toString()
106: .equals(sFolder)) ? "class=\"active\""
107: : "")
108: + " folderType=\""
109: + tmp.getFolderType()
110: + "\" folderId=\""
111: + tmp.getId()
112: + "\" folderName=\""
113: + folderNameLang
114: + "\" id=\"mailFolder"
115: + tmp.getId()
116: + "\" onclick=\"selectMailFolder('"
117: + tmp.getId() + "')\"><div>");
118: }
119: if (tmp.getUnreadItemCount().intValue() > 0) {
120: out
121: .print("<em><i class='left'> </i><b id=\"folderUnreadCount\">"
122: + tmp.getUnreadItemCount()
123: + "</b><i class=\"right\"> </i></em>");
124: }
125: out
126: .print("<span><img alt=\"\" src=\"images/blue-folder.gif\"/></span>"
127: + folderNameLang);
128: out.print("</div></li>");
129: }
130: }
131: out.print("</ul>");
132: } catch (Exception e) {
133: out.print("");
134: }
135: }
136:
137: /**
138: * The doPost method of the servlet. <br>
139: *
140: * This method is called when a form has its tag value method equals to post.
141: *
142: * @param request the request send by the client to the server
143: * @param response the response send by the server to the client
144: * @throws ServletException if an error occurred
145: * @throws IOException if an error occurred
146: */
147: public void doPost(HttpServletRequest request,
148: HttpServletResponse response) throws ServletException,
149: IOException {
150: doGet(request, response);
151: }
152:
153: }
|