Source Code Cross Referenced for EmailEndPointFactory.java in  » Workflow-Engines » Dalma » dalma » endpoints » email » spi » 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 » Workflow Engines » Dalma » dalma.endpoints.email.spi 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package dalma.endpoints.email.spi;
002:
003:        import dalma.EndPoint;
004:        import dalma.endpoints.email.EmailEndPoint;
005:        import dalma.endpoints.email.Listener;
006:        import dalma.endpoints.email.MailDirListener;
007:        import dalma.endpoints.email.POP3Listener;
008:        import dalma.endpoints.email.TCPListener;
009:        import dalma.spi.EndPointFactory;
010:        import dalma.spi.UrlQueryParser;
011:
012:        import javax.mail.Session;
013:        import javax.mail.internet.InternetAddress;
014:        import java.io.File;
015:        import java.io.UnsupportedEncodingException;
016:        import java.net.URI;
017:        import java.net.URISyntaxException;
018:        import java.net.InetSocketAddress;
019:        import java.text.ParseException;
020:        import java.util.Properties;
021:
022:        /**
023:         * {@link EndPointFactory} for the e-mail port.
024:         *
025:         * @author Kohsuke Kawaguchi
026:         */
027:        public class EmailEndPointFactory implements  EndPointFactory {
028:            public EndPoint create(String endPointName, String endpointURL)
029:                    throws ParseException {
030:                // split into the SMTP part and listener part
031:                int idx = endpointURL.indexOf('!');
032:                if (idx < 0)
033:                    throw new ParseException(
034:                            "the smtp protocol string needs to contain '!'", -1);
035:
036:                try {
037:                    URI smtp = new URI(endpointURL.substring(0, idx));
038:                    String listener = endpointURL.substring(idx + 1);
039:
040:                    Listener listenerObject;
041:
042:                    if (listener.startsWith("pop3://"))
043:                        listenerObject = createPop3Listener(listener, idx + 1);
044:                    else if (listener.startsWith("imap4://"))
045:                        listenerObject = createImap4Listener(listener, idx + 1);
046:                    else if (listener.startsWith("maildir://"))
047:                        listenerObject = createMailDirListener(listener,
048:                                idx + 1);
049:                    else if (listener.startsWith("tcp://"))
050:                        listenerObject = createTcpListener(listener, idx + 1);
051:                    else
052:                        throw new ParseException("Unsupported scheme: "
053:                                + listener, idx + 1);
054:
055:                    if (smtp.getUserInfo() == null)
056:                        throw new ParseException("user name is missing", -1);
057:                    UrlQueryParser smtpQuery = new UrlQueryParser(smtp);
058:
059:                    Properties props = new Properties(System.getProperties());
060:                    smtpQuery.addTo(props);
061:
062:                    // translate known query parameters
063:                    if (smtpQuery.getValue("host") != null)
064:                        props.put("mail.smtp.host", smtpQuery.getValue("host"));
065:
066:                    return new EmailEndPoint(endPointName, new InternetAddress(
067:                            smtp.getUserInfo() + '@' + smtp.getHost(),
068:                            smtpQuery.getValue("personal")), listenerObject,
069:                            Session.getInstance(props));
070:
071:                } catch (URISyntaxException e) {
072:                    throw new ParseException(e.getMessage(), e.getIndex());
073:                } catch (UnsupportedEncodingException e) {
074:                    throw new ParseException("Unsupported encoding: "
075:                            + e.getMessage(), -1);
076:                }
077:            }
078:
079:            private Listener createImap4Listener(String listener, int startIndex)
080:                    throws URISyntaxException, ParseException {
081:                try {
082:                    URI uri = new URI(listener);
083:                    UrlQueryParser query = new UrlQueryParser(uri);
084:
085:                    String userInfo = uri.getUserInfo();
086:                    if (userInfo == null)
087:                        throw new ParseException("imap4 needs a user name",
088:                                startIndex);
089:                    int idx = userInfo.indexOf(':');
090:                    if (idx < 0)
091:                        throw new ParseException("imap4 needs a password",
092:                                startIndex);
093:
094:                    return new POP3Listener(uri.getHost(), userInfo.substring(
095:                            0, idx), userInfo.substring(idx + 1), query
096:                            .getValue("interval", 3000));
097:                } catch (URISyntaxException e) {
098:                    throw new URISyntaxException(e.getInput(), e.getReason(), e
099:                            .getIndex()
100:                            + startIndex);
101:                }
102:            }
103:
104:            private Listener createPop3Listener(String listener, int startIndex)
105:                    throws URISyntaxException, ParseException {
106:                try {
107:                    URI uri = new URI(listener);
108:                    UrlQueryParser query = new UrlQueryParser(uri);
109:
110:                    String userInfo = uri.getUserInfo();
111:                    if (userInfo == null)
112:                        throw new ParseException("pop3 needs a user name",
113:                                startIndex);
114:                    int idx = userInfo.indexOf(':');
115:                    if (idx < 0)
116:                        throw new ParseException("pop3 needs a password",
117:                                startIndex);
118:
119:                    return new POP3Listener(uri.getHost(), userInfo.substring(
120:                            0, idx), userInfo.substring(idx + 1), query
121:                            .getValue("interval", 3000));
122:                } catch (URISyntaxException e) {
123:                    throw new URISyntaxException(e.getInput(), e.getReason(), e
124:                            .getIndex()
125:                            + startIndex);
126:                }
127:            }
128:
129:            private Listener createMailDirListener(String listener,
130:                    int startIndex) throws ParseException {
131:                listener = listener.substring("maildir://".length());
132:                int questionMark = listener.indexOf('?');
133:                // parse the query parameter
134:                UrlQueryParser query = new UrlQueryParser(
135:                        questionMark < 0 ? null : listener
136:                                .substring(questionMark + 1));
137:
138:                // extract the file name portion
139:                String filePath = questionMark < 0 ? listener : listener
140:                        .substring(0, questionMark);
141:
142:                File dir = new File(filePath);
143:                if (!dir.isDirectory())
144:                    throw new ParseException("no such directory exists: "
145:                            + filePath, -1);
146:
147:                int interval = query.getValue("interval", 3000);
148:
149:                return new MailDirListener(dir, interval);
150:            }
151:
152:            private Listener createTcpListener(String listener, int startIndex)
153:                    throws URISyntaxException, ParseException {
154:                try {
155:                    URI uri = new URI(listener);
156:                    if (uri.getPort() == -1)
157:                        throw new ParseException(
158:                                "tcp protocol requres a port number", -1);
159:                    return new TCPListener(new InetSocketAddress(uri.getHost(),
160:                            uri.getPort()));
161:                } catch (URISyntaxException e) {
162:                    throw new URISyntaxException(e.getInput(), e.getReason(), e
163:                            .getIndex()
164:                            + startIndex);
165:                }
166:            }
167:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.