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: }
086: if (folderNameLang == null
087: || folderNameLang.length() == 0) {
088: folderNameLang = folderName;
089: }
090:
091: folderNameLang = org.claros.intouch.common.utility.Utility
092: .htmlCheck(folderNameLang);
093: if (profile.getProtocol().equals(Constants.IMAP)) {
094: out
095: .print("<li "
096: + ((folderName.equals(sFolder)) ? "class=\"active\""
097: : "")
098: + " folderType=\""
099: + tmp.getFolderType()
100: + "\" folderId=\""
101: + folderNameEnc
102: + "\" folderName=\""
103: + folderNameLang
104: + "\" id=\"mailFolder"
105: + folderNameEnc
106: + "\" onclick=\"selectMailFolder('"
107: + folderNameEnc + "')\"><div>");
108: } else {
109: out
110: .print("<li "
111: + ((tmp.getId().toString()
112: .equals(sFolder)) ? "class=\"active\""
113: : "")
114: + " folderType=\""
115: + tmp.getFolderType()
116: + "\" folderId=\""
117: + tmp.getId()
118: + "\" folderName=\""
119: + folderNameLang
120: + "\" id=\"mailFolder"
121: + tmp.getId()
122: + "\" onclick=\"selectMailFolder('"
123: + tmp.getId() + "')\"><div>");
124: }
125: if (tmp.getUnreadItemCount().intValue() > 0) {
126: out
127: .print("<em><i class='left'> </i><b id=\"folderUnreadCount\">"
128: + tmp.getUnreadItemCount()
129: + "</b><i class=\"right\"> </i></em>");
130: }
131:
132: String tmpF = folderNameLang;
133: if (folderNameLang.length() > 15) {
134: tmpF = folderNameLang.substring(0, 13) + "...";
135: }
136: out
137: .print("<span><img alt=\"\" src=\"images/blue-folder.gif\"/></span>"
138: + tmpF);
139: out.print("</div></li>");
140: }
141: }
142: out.print("</ul>");
143: } catch (Exception e) {
144: out.print("");
145: }
146: }
147:
148: /**
149: * The doPost method of the servlet. <br>
150: *
151: * This method is called when a form has its tag value method equals to post.
152: *
153: * @param request the request send by the client to the server
154: * @param response the response send by the server to the client
155: * @throws ServletException if an error occurred
156: * @throws IOException if an error occurred
157: */
158: public void doPost(HttpServletRequest request,
159: HttpServletResponse response) throws ServletException,
160: IOException {
161: doGet(request, response);
162: }
163:
164: }
|