KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > scioworks > imap > presentation > imapWeb > folder_list


1 /* -----------------------------------------------------------------------------
2  * Copyright (c) 2001, Low Kin Onn
3  * All rights reserved.
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  *
8  * Redistributions of source code must retain the above copyright notice, this
9  * list of conditions and the following disclaimer.
10  *
11  * Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * Neither name of the Scioworks Pte. Ltd. nor the names of its contributors
16  * may beused to endorse or promote products derived from this software without
17  * specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
23  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  *
30  * -----------------------------------------------------------------------------
31  */

32
33 package scioworks.imap.presentation.imapWeb;
34
35 import java.net.URLEncoder JavaDoc;
36 import java.util.Vector JavaDoc;
37
38 import javax.mail.*;
39 import javax.activation.*;
40
41 import org.w3c.dom.*;
42 import org.w3c.dom.html.*;
43
44 import com.lutris.appserver.server.httpPresentation.*;
45
46 import scioworks.imap.presentation.base.*;
47 import scioworks.imap.presentation.imapWeb.*;
48 import scioworks.imap.spec.ImapWebConstant;
49 import scioworks.imap.spec.beans.*;
50 import scioworks.imap.spec.ImapWebException;
51
52 public class folder_list extends BasePO {
53   // Override login requirement
54
protected boolean isLoginRequired() {
55     return false;
56   }
57
58   public String JavaDoc handleDefault()
59       throws HttpPresentationException {
60
61     folder_listHTML page = (folder_listHTML)m_comms.xmlcFactory.create(folder_listHTML.class);
62
63
64     try {
65
66       // Get reference to the row to be modified
67
HTMLTableRowElement folderListRow = page.getElementFolderListRow();
68       Node folderListTable = folderListRow.getParentNode();
69
70       // Get reference to the URL to be modified
71
HTMLAnchorElement mailListLink = page.getElementMailListLink();
72       /** @todo : complete the link */
73       String JavaDoc currLink = mailListLink.getHref() + "?" +
74                         PARAM_folder + "=";
75
76       // Get and set inbox folder
77

78       Folder folder = super.getImapWebSessionData().getImapStore().getFolder("INBOX");
79     
80       page.setTextInboxMessageCount(Integer.toString(folder.getMessageCount()));
81       page.setTextInboxUnreadMessageCount(Integer.toString(folder.getUnreadMessageCount()));
82
83       // Get and set Sent folder
84
folder = super.getImapWebSessionData().getImapStore().getFolder(ImapWebConstant.singleton().folderSent());
85       page.setTextSentName(ImapWebConstant.singleton().folderSent());
86       page.setTextSentMessageCount(Integer.toString(folder.getMessageCount()));
87       page.setTextSentUnreadMessageCount(Integer.toString(folder.getUnreadMessageCount()));
88       page.getElementSentLink().setHref(currLink + URLEncoder.encode(ImapWebConstant.singleton().folderSent()));
89
90       // Get and set Trash folder
91
folder = super.getImapWebSessionData().getImapStore().getFolder(ImapWebConstant.singleton().folderTrash());
92       page.setTextTrashName(ImapWebConstant.singleton().folderTrash());
93       page.setTextTrashMessageCount(Integer.toString(folder.getMessageCount()));
94       page.setTextTrashUnreadMessageCount(Integer.toString(folder.getUnreadMessageCount()));
95       page.getElementTrashLink().setHref(currLink + URLEncoder.encode(ImapWebConstant.singleton().folderTrash()));
96
97       // the rest of the folders
98
HTMLElement msgCountEle = page.getElementMessageCount();
99       HTMLElement unreadMsgCountEle = page.getElementUnreadMessageCount();
100
101       msgCountEle.removeAttribute("id");
102       unreadMsgCountEle.removeAttribute("id");
103
104       Folder[] folders = super.getImapWebSessionData().getImapStore().getDefaultFolder().list();
105
106       for (int i=0; i<folders.length; i++) {
107
108         folder = folders[i];
109
110         if (folder.getName().equalsIgnoreCase("INBOX")) {
111           continue;
112         } else if (folder.getName().equalsIgnoreCase(ImapWebConstant.singleton().folderSent())) {
113           continue;
114         } else if (folder.getName().equalsIgnoreCase(ImapWebConstant.singleton().folderTrash())) {
115           continue;
116         }
117
118         page.setTextFolderName(folder.getName());
119         page.setTextMessageCount(Integer.toString(folder.getMessageCount()));
120         page.setTextUnreadMessageCount(Integer.toString(folder.getUnreadMessageCount()));
121
122         mailListLink.setHref(currLink + URLEncoder.encode(folder.getName()));
123
124         folderListTable.appendChild(folderListRow.cloneNode(true));
125       }
126       folderListTable.removeChild(folderListRow);
127
128
129       // set the drop down list of target folders for Move
130
IWMessage iwMsg = IWMessageFactory.getIWMessage("scioworks.imap.business.beans.IWMessageImpl");
131      
132       try {
133         Vector JavaDoc targetFolders = iwMsg.getFolderNames(super.getImapWebSessionData().getImapStore(),
134                                                     "INBOX");
135         super.processSelectList(page, page.getElementFolder(),
136                                 targetFolders, targetFolders, "-1");
137       
138   
139       
140       } catch (ImapWebException e) {
141         return super.showErrorPage(MSG_OPERATION_FAILED, e.getMessage(), "", "");
142       }
143
144     }catch(NullPointerException JavaDoc ex) {
145     /*
146      * The response will be default HTML page
147      * We need to allow imapWeb_pres to be functional
148      */

149      return ((folder_listHTML)m_comms.xmlcFactory.create(folder_listHTML.class)).toDocument();
150     
151     } catch (MessagingException e) {
152       e.printStackTrace();
153       return super.showErrorPage("Error getting folders", e.getMessage(), "", "");
154     }
155
156
157     return page.toDocument();
158   }
159 }
Popular Tags