Source Code Cross Referenced for GoogleMailBoxPacket.java in  » Net » openfire » org » jivesoftware » openfire » gateway » protocols » xmpp » packet » 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 » Net » openfire » org.jivesoftware.openfire.gateway.protocols.xmpp.packet 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * $Revision$
003:         * $Date$
004:         *
005:         * Copyright (C) 2006-2007 Jive Software. All rights reserved.
006:         *
007:         * This software is published under the terms of the GNU Public License (GPL),
008:         * a copy of which is included in this distribution.
009:         */package org.jivesoftware.openfire.gateway.protocols.xmpp.packet;
010:
011:        import org.jivesoftware.smack.packet.IQ;
012:        import org.jivesoftware.smack.packet.PacketExtension;
013:        import org.jivesoftware.smack.provider.IQProvider;
014:        import org.xmlpull.v1.XmlPullParser;
015:        import org.xmlpull.v1.XmlPullParserException;
016:        import org.apache.log4j.Logger;
017:
018:        import java.util.Vector;
019:        import java.util.Date;
020:        import java.util.ArrayList;
021:        import java.util.Arrays;
022:        import java.io.IOException;
023:
024:        /**
025:         * See: http://code.google.com/apis/talk/jep_extensions/gmail.html
026:         * 
027:         * @author mecevit
028:         * @author Daniel Henninger
029:         */
030:        public class GoogleMailBoxPacket extends IQ {
031:
032:            static Logger Log = Logger.getLogger(GoogleMailBoxPacket.class);
033:
034:            public static String MAILBOX_ELEMENT = "mailbox";
035:            public static String MAILBOX_NAMESPACE = "google:mail:notify";
036:
037:            private Date resultTime;
038:            private Integer totalMatched;
039:            private Boolean totalIsEstimate;
040:            private String url;
041:            private Vector<GoogleMailThread> mailThreads = new Vector<GoogleMailThread>();
042:
043:            public GoogleMailBoxPacket() {
044:            }
045:
046:            public void addExtension(PacketExtension extension) {
047:            }
048:
049:            public void addMailThread(GoogleMailThread thread) {
050:                mailThreads.add(thread);
051:            }
052:
053:            public Vector<GoogleMailThread> getMailThreads() {
054:                return mailThreads;
055:            }
056:
057:            public Date getResultTime() {
058:                return resultTime;
059:            }
060:
061:            public void setResultTime(Date resultTime) {
062:                this .resultTime = resultTime;
063:            }
064:
065:            public Integer getTotalMatched() {
066:                return totalMatched;
067:            }
068:
069:            public void setTotalMatched(Integer totalMatched) {
070:                this .totalMatched = totalMatched;
071:            }
072:
073:            public Boolean getTotalIsEstimate() {
074:                return totalIsEstimate;
075:            }
076:
077:            public void setTotalIsEstimate(Boolean totalIsEstimate) {
078:                this .totalIsEstimate = totalIsEstimate;
079:            }
080:
081:            public String getUrl() {
082:                return url;
083:            }
084:
085:            public void setUrl(String url) {
086:                this .url = url;
087:            }
088:
089:            public String getChildElementXML() {
090:                StringBuffer buf = new StringBuffer();
091:                buf.append("<mailbox xmlns=\"").append(MAILBOX_NAMESPACE)
092:                        .append("\"");
093:                if (resultTime != null) {
094:                    buf.append(" result-time=\"").append(resultTime.getTime())
095:                            .append("\"");
096:                }
097:                if (totalMatched != null) {
098:                    buf.append(" total-matched=\"").append(totalMatched)
099:                            .append("\"");
100:                }
101:                if (totalIsEstimate != null && totalIsEstimate) {
102:                    buf.append(" total-estimate=\"1\"");
103:                }
104:                if (url != null) {
105:                    buf.append(" url=\"").append(url).append("\"");
106:                }
107:                buf.append(">");
108:                for (GoogleMailThread thread : mailThreads) {
109:                    buf.append(thread.toXML());
110:                }
111:                buf.append("</mailbox>");
112:                return buf.toString();
113:            }
114:
115:            public static class Provider implements  IQProvider {
116:
117:                public Provider() {
118:                    super ();
119:                }
120:
121:                public IQ parseIQ(XmlPullParser parser) throws Exception {
122:                    GoogleMailBoxPacket mailPacket = new GoogleMailBoxPacket();
123:                    try {
124:                        GoogleMailThread thread = null;
125:
126:                        boolean done = false;
127:                        int eventType = parser.getEventType();
128:                        while (!done) {
129:                            if (eventType == XmlPullParser.START_TAG) {
130:                                if (parser.getName().equals("mailbox")) {
131:                                    String dateString = parser
132:                                            .getAttributeValue("",
133:                                                    "result-time");
134:                                    try {
135:                                        mailPacket.setResultTime(new Date(Long
136:                                                .valueOf(dateString)));
137:                                    } catch (Exception ex) {
138:                                        // Well crap, ok then, ignore it.
139:                                    }
140:                                    try {
141:                                        mailPacket
142:                                                .setTotalMatched(Integer
143:                                                        .valueOf(
144:                                                                parser
145:                                                                        .getAttributeValue(
146:                                                                                "",
147:                                                                                "total-matched"),
148:                                                                0));
149:                                    } catch (NumberFormatException ex) {
150:                                        // Well crap, ok then, ignore it.
151:                                    }
152:                                    String estimateString = parser
153:                                            .getAttributeValue("",
154:                                                    "total-estimate");
155:                                    mailPacket
156:                                            .setTotalIsEstimate(estimateString != null
157:                                                    && estimateString
158:                                                            .equals("1"));
159:                                    mailPacket.setUrl(parser.getAttributeValue(
160:                                            "", "url"));
161:                                } else if (parser.getName().equals(
162:                                        "mail-thread-info")) {
163:                                    Long tid = Long.valueOf(parser
164:                                            .getAttributeValue("", "tid"));
165:                                    Integer numParts = null;
166:                                    try {
167:                                        numParts = Integer.valueOf(parser
168:                                                .getAttributeValue("",
169:                                                        "participation"), 0);
170:                                    } catch (NumberFormatException ex) {
171:                                        // Well crap, ok then, ignore it.
172:                                    }
173:                                    Integer numMsgs = null;
174:                                    try {
175:                                        numMsgs = Integer.valueOf(parser
176:                                                .getAttributeValue("",
177:                                                        "messages"), 0);
178:                                    } catch (NumberFormatException ex) {
179:                                        // Well crap, ok then, ignore it.
180:                                    }
181:                                    String url = parser.getAttributeValue("",
182:                                            "url");
183:                                    String dateString = parser
184:                                            .getAttributeValue("", "date");
185:                                    Date date = null;
186:                                    try {
187:                                        date = new Date(Long
188:                                                .valueOf(dateString));
189:                                    } catch (Exception ex) {
190:                                        // Well crap, ok then, ignore it.
191:                                    }
192:                                    thread = new GoogleMailThread(tid,
193:                                            numParts, numMsgs, date, url,
194:                                            new ArrayList<GoogleMailSender>(),
195:                                            null, null, null);
196:                                } else if (parser.getName().equals("sender")) {
197:                                    String address = parser.getAttributeValue(
198:                                            "", "address");
199:                                    String name = parser.getAttributeValue("",
200:                                            "name");
201:                                    String origString = parser
202:                                            .getAttributeValue("", "originator");
203:                                    String unreadString = parser
204:                                            .getAttributeValue("", "unread");
205:                                    thread
206:                                            .getSenders()
207:                                            .add(
208:                                                    new GoogleMailSender(
209:                                                            address,
210:                                                            name,
211:                                                            origString != null
212:                                                                    && origString
213:                                                                            .equals("1"),
214:                                                            unreadString != null
215:                                                                    && unreadString
216:                                                                            .equals("1")));
217:                                } else if (parser.getName().equals("labels")) {
218:                                    thread.setLabels(Arrays.asList(parser
219:                                            .nextText().split("|")));
220:                                } else if (parser.getName().equals("subject")) {
221:                                    thread.setSubject(parser.nextText());
222:                                } else if (parser.getName().equals("snippet")) {
223:                                    thread.setSnippit(parser.nextText());
224:                                }
225:
226:                            } else if (eventType == XmlPullParser.END_TAG) {
227:                                if (parser.getName().equals("mail-thread-info")) {
228:                                    mailPacket.addMailThread(thread);
229:                                    thread = null;
230:                                } else if (parser.getName().equals("iq")) {
231:                                    done = true;
232:                                }
233:                            }
234:                            eventType = parser.next();
235:                        }
236:                    } catch (IOException ex) {
237:                        Log
238:                                .debug(
239:                                        "XMPP: IO exception while parsing mailbox packet:",
240:                                        ex);
241:                    } catch (XmlPullParserException ex) {
242:                        Log
243:                                .debug(
244:                                        "XMPP: XML pull exception while parsing mailbox packet:",
245:                                        ex);
246:                    } catch (Exception ex) {
247:                        Log
248:                                .debug(
249:                                        "XMPP: Unknown exception while parsing mailbox packet:",
250:                                        ex);
251:                    }
252:
253:                    return mailPacket;
254:                }
255:            }
256:
257:        }
w__w_w__.___ja_v__a2_s._co_m__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.