Source Code Cross Referenced for MailUtils.java in  » Portal » Open-Portal » com » sun » portal » wireless » taglibs » mail » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Portal » Open Portal » com.sun.portal.wireless.taglibs.mail 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // Copyright 04/11/01 Sun Microsystems, Inc. All Rights Reserved.
002:        // "@(#)MailContext.java        1.12 01/04/11 Sun Microsystems"
003:
004:        package com.sun.portal.wireless.taglibs.mail;
005:
006:        import javax.mail.*;
007:        import javax.mail.internet.*;
008:        import javax.mail.search.*;
009:        import javax.servlet.jsp.PageContext;
010:
011:        import java.util.*;
012:        import java.text.*;
013:
014:        class MailUtils {
015:
016:            private static int direction = 1;
017:
018:            public static void setSortDirection(String sd) {
019:                direction = 1;
020:
021:                if (sd != null && sd.equals("down")) {
022:                    direction = -1;
023:                }
024:            }
025:
026:            public static MsgBean[] toBeanArray(Message[] msgs, String from,
027:                    TimeZone tz, PageContext pageContext) {
028:
029:                MsgBean[] tmp = new MsgBean[msgs.length];
030:
031:                for (int i = 0; i < msgs.length; i++) {
032:                    tmp[i] = new MsgBean(msgs[i], from, tz);
033:                    tmp[i].setPageContext(pageContext);
034:                }
035:
036:                return tmp;
037:            }
038:
039:            public static FolderBean[] toFolderBeanArray(Folder[] folders) {
040:
041:                FolderBean[] tmp = new FolderBean[folders.length];
042:
043:                for (int i = 0; i < folders.length; i++) {
044:                    tmp[i] = new FolderBean(folders[i]);
045:                }
046:
047:                return tmp;
048:            }
049:
050:            public static Object[] inboxOrder(Object[] in) {
051:                if (direction < 0) {
052:                    Object tmp;
053:                    int len = in.length - 1;
054:                    int hlen = (in.length / 2);
055:                    for (int i = 0; i < hlen; i++) {
056:                        tmp = in[i];
057:                        in[i] = in[len - i];
058:                        in[len - i] = tmp;
059:                    }
060:                }
061:                return in;
062:            }
063:
064:            public static void prefetch(MsgBean[] msgs, String field) {
065:                FetchProfile fp = new FetchProfile();
066:                fp.add(field);
067:                prefetch(msgs, fp);
068:            }
069:
070:            public static void prefetch(MsgBean[] msgs, FetchProfile fp) {
071:                try {
072:                    Message[] m = new Message[msgs.length];
073:
074:                    for (int i = 0; i < msgs.length; i++) {
075:                        m[i] = msgs[i].getObject();
076:                    }
077:
078:                    m[0].getFolder().fetch(m, fp);
079:                } catch (Exception e) {
080:                    // Dont really care what the error was
081:                }
082:            }
083:
084:            public static class FolderComparator implements  Comparator {
085:                Collator collate = null;
086:
087:                public FolderComparator(Collator c) {
088:                    collate = c;
089:                }
090:
091:                public int compare(Object a, Object b) {
092:                    Folder f1 = ((FolderBean) a).getFolder();
093:                    Folder f2 = ((FolderBean) b).getFolder();
094:
095:                    String tmp1 = f1.getName();
096:                    String tmp2 = f2.getName();
097:
098:                    return direction * (collate.compare(tmp1, tmp2));
099:                }
100:            }
101:
102:            public static class MsgFromComparator implements  Comparator {
103:                Collator collate = null;
104:
105:                public MsgFromComparator(Collator c) {
106:                    collate = c;
107:                }
108:
109:                public int compare(Object a, Object b) {
110:                    MsgBean b1 = (MsgBean) a;
111:                    MsgBean b2 = (MsgBean) b;
112:                    String tmp1 = "";
113:                    String tmp2 = "";
114:
115:                    try {
116:                        tmp1 = b1.getFrom();
117:                    } catch (MessagingException ex) {
118:                    }
119:
120:                    try {
121:                        tmp2 = b2.getFrom();
122:                    } catch (MessagingException ex) {
123:                    }
124:
125:                    return direction * (collate.compare(tmp1, tmp2));
126:                }
127:            }
128:
129:            public static class MsgSubjectComparator implements  Comparator {
130:                Collator collate = null;
131:
132:                public MsgSubjectComparator(Collator c) {
133:                    collate = c;
134:                }
135:
136:                public int compare(Object a, Object b) {
137:                    MsgBean b1 = (MsgBean) a;
138:                    MsgBean b2 = (MsgBean) b;
139:                    String tmp1 = "";
140:                    String tmp2 = "";
141:
142:                    try {
143:                        tmp1 = b1.getSubject();
144:                    } catch (MessagingException ex) {
145:                    }
146:
147:                    try {
148:                        tmp2 = b2.getSubject();
149:                    } catch (MessagingException ex) {
150:                    }
151:
152:                    return direction * (collate.compare(tmp1, tmp2));
153:                }
154:            }
155:
156:            public static class MsgDateComparator implements  Comparator {
157:                public int compare(Object a, Object b) {
158:                    MsgBean b1 = (MsgBean) a;
159:                    MsgBean b2 = (MsgBean) b;
160:                    Message m1 = b1.getObject();
161:                    Message m2 = b2.getObject();
162:                    Date d1;
163:                    Date d2;
164:                    try {
165:                        d1 = m1.getReceivedDate();
166:                    } catch (MessagingException ex) {
167:                        return direction * 1;
168:                    }
169:
170:                    try {
171:                        d2 = m2.getReceivedDate();
172:                    } catch (MessagingException ex) {
173:                        return direction * (-1);
174:                    }
175:
176:                    return direction * (d1.compareTo(d2));
177:                }
178:            }
179:
180:            public static class MsgIdComparator implements  Comparator {
181:                public int compare(Object a, Object b) {
182:                    MsgBean b1 = (MsgBean) a;
183:                    MsgBean b2 = (MsgBean) b;
184:                    int i = b1.getMsgid();
185:                    int j = b2.getMsgid();
186:
187:                    return direction * (i - j);
188:                }
189:            }
190:
191:            public static class MsgSeenComparator implements  Comparator {
192:                public int compare(Object a, Object b) {
193:                    MsgBean b1 = (MsgBean) a;
194:                    MsgBean b2 = (MsgBean) b;
195:
196:                    int i = b1.getMsgid();
197:                    int j = b2.getMsgid();
198:
199:                    boolean s1;
200:                    try {
201:                        s1 = b1.isSeen();
202:                    } catch (Exception e) {
203:                        s1 = false;
204:                    }
205:
206:                    boolean s2;
207:                    try {
208:                        s2 = b2.isSeen();
209:                    } catch (Exception e) {
210:                        s2 = false;
211:                    }
212:
213:                    if (s1 == s2) {
214:                        return direction * (i - j);
215:                    }
216:
217:                    if (s1 == true) {
218:                        return direction;
219:                    }
220:
221:                    return -direction;
222:                }
223:            }
224:
225:            public static class MsgRecentComparator implements  Comparator {
226:                public int compare(Object a, Object b) {
227:                    MsgBean b1 = (MsgBean) a;
228:                    MsgBean b2 = (MsgBean) b;
229:
230:                    int i = b1.getMsgid();
231:                    int j = b2.getMsgid();
232:
233:                    boolean s1;
234:                    try {
235:                        s1 = b1.isRecent();
236:                    } catch (Exception e) {
237:                        s1 = false;
238:                    }
239:
240:                    boolean s2;
241:                    try {
242:                        s2 = b2.isRecent();
243:                    } catch (Exception e) {
244:                        s2 = false;
245:                    }
246:
247:                    if (s1 == s2) {
248:                        return direction * (i - j);
249:                    }
250:
251:                    if (s1 == true) {
252:                        return direction;
253:                    }
254:
255:                    return -direction;
256:                }
257:            }
258:
259:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.