Source Code Cross Referenced for EmailApp.java in  » Ajax » NextApp-Echo2 » echo2example » email » 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 » Ajax » NextApp Echo2 » echo2example.email 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* 
002:         * This file is part of the Echo Web Application Framework (hereinafter "Echo").
003:         * Copyright (C) 2002-2005 NextApp, Inc.
004:         *
005:         * Version: MPL 1.1/GPL 2.0/LGPL 2.1
006:         *
007:         * The contents of this file are subject to the Mozilla Public License Version
008:         * 1.1 (the "License"); you may not use this file except in compliance with
009:         * the License. You may obtain a copy of the License at
010:         * http://www.mozilla.org/MPL/
011:         *
012:         * Software distributed under the License is distributed on an "AS IS" basis,
013:         * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
014:         * for the specific language governing rights and limitations under the
015:         * License.
016:         *
017:         * Alternatively, the contents of this file may be used under the terms of
018:         * either the GNU General Public License Version 2 or later (the "GPL"), or
019:         * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
020:         * in which case the provisions of the GPL or the LGPL are applicable instead
021:         * of those above. If you wish to allow use of your version of this file only
022:         * under the terms of either the GPL or the LGPL, and not to allow others to
023:         * use your version of this file under the terms of the MPL, indicate your
024:         * decision by deleting the provisions above and replace them with the notice
025:         * and other provisions required by the GPL or the LGPL. If you do not delete
026:         * the provisions above, a recipient may use your version of this file under
027:         * the terms of any one of the MPL, the GPL or the LGPL.
028:         */
029:
030:        package echo2example.email;
031:
032:        import java.util.Properties;
033:        import java.util.ResourceBundle;
034:
035:        import javax.mail.AuthenticationFailedException;
036:        import javax.mail.MessagingException;
037:        import javax.mail.Session;
038:        import javax.mail.Store;
039:
040:        import nextapp.echo2.app.ApplicationInstance;
041:        import nextapp.echo2.app.Window;
042:
043:        /**
044:         * Email Application Instance.
045:         */
046:        public class EmailApp extends ApplicationInstance {
047:
048:            /**
049:             * Flag indicating whether we should use fake e-mail data.  Enabling this 
050:             * flag will cause the <code>FauxStore</code> e-mail store to be used and
051:             * will disable sending of messages. 
052:             */
053:            public static final boolean FAUX_MODE;
054:            public static final String MAIL_DOMAIN, RECEIVE_MAIL_SERVER,
055:                    RECEIVE_PROTOCOL, SEND_MAIL_SERVER, SEND_MAIL_PORT;
056:            public static final int MESSAGES_PER_PAGE;
057:
058:            static {
059:                // Static initializer to retrieve information from configuration properties file.
060:                ResourceBundle config = ResourceBundle
061:                        .getBundle("/echo2example/email/Configuration");
062:                FAUX_MODE = "true".equals(config.getString("FauxMode"));
063:                MAIL_DOMAIN = config.getString("MailDomain");
064:                RECEIVE_MAIL_SERVER = config.getString("ReceiveMailServer");
065:                RECEIVE_PROTOCOL = config.getString("ReceiveProtocol");
066:                SEND_MAIL_SERVER = config.getString("SendMailServer");
067:                SEND_MAIL_PORT = config.getString("SendMailPort");
068:                MESSAGES_PER_PAGE = Integer.parseInt(config
069:                        .getString("MessagesPerPage"));
070:            }
071:
072:            /**
073:             * The user name of the currently logged in user.  This property
074:             * will be null when no user is logged in.
075:             */
076:            private String emailAddress;
077:
078:            /**
079:             * The <code>javax.mail.Store</code> used to retrieve messages from the mail server.
080:             * See the Sun JavaMail API Specification for details.
081:             */
082:            private Store store;
083:
084:            /**
085:             * The <code>javax.mail.Session</code> used to connect to the mail server.
086:             * See the Sun JavaMail API Specification for details.
087:             */
088:            private Session mailSession;
089:
090:            /**
091:             * Convenience method to return the active email application as a
092:             * <code>EmailApp</code>.
093:             * 
094:             * @return the active <code>EmailApp</code>
095:             */
096:            public static EmailApp getApp() {
097:                return (EmailApp) getActive();
098:            }
099:
100:            /**
101:             * Connects to the mail server with the given e-mail address and
102:             * password.   Displays the <code>MailScreen</code> on success.
103:             *
104:             * @param emailAddress e-mail address 
105:             * @param password the password
106:             * @return true if the application was able to connect to the
107:             *         server using the specified information, false if not.
108:             */
109:            public boolean connect(String emailAddress, String password) {
110:                Properties properties = System.getProperties();
111:                if (!FAUX_MODE) {
112:                    properties.put("mail.smtp.host", SEND_MAIL_SERVER);
113:                    properties.put("mail.smtp.port", SEND_MAIL_PORT);
114:                }
115:                try {
116:                    mailSession = Session.getDefaultInstance(properties, null);
117:                    store = mailSession.getStore(RECEIVE_PROTOCOL);
118:                    store.connect(RECEIVE_MAIL_SERVER, emailAddress, password);
119:
120:                    // Store user name.
121:                    this .emailAddress = emailAddress;
122:
123:                    // Display MailScreen.
124:                    MailScreen mailScreen = new MailScreen();
125:                    mailScreen.setStore(store);
126:                    getDefaultWindow().setContent(mailScreen);
127:                } catch (AuthenticationFailedException ex) {
128:                    // Return false to indicate the user was not successfully authenticated.
129:                    return false;
130:                } catch (MessagingException ex) {
131:                    processFatalException(ex);
132:                }
133:
134:                // Return indicating that the user was successfully authenticated.
135:                return true;
136:            }
137:
138:            /**
139:             * Disconnects the session with the mail server and displays
140:             * the authentication screen.
141:             */
142:            public void disconnect() {
143:                if (store != null) {
144:                    try {
145:                        store.close();
146:                    } catch (MessagingException ex) {
147:                        // Do nothing.
148:                    }
149:                    store = null;
150:                }
151:
152:                emailAddress = null;
153:                getDefaultWindow().setContent(new LoginScreen());
154:            }
155:
156:            /**
157:             * Returns the email address of the active user, or null if none.
158:             * 
159:             * @return the email address
160:             */
161:            public String getEmailAddress() {
162:                return emailAddress;
163:            }
164:
165:            /**
166:             * Returns the active JavaMail <code>Session</code> object.
167:             * 
168:             * @return the <code>Session</code>
169:             */
170:            public Session getMailSession() {
171:                return mailSession;
172:            }
173:
174:            /**
175:             * @see nextapp.echo2.app.ApplicationInstance#init()
176:             */
177:            public Window init() {
178:                setStyleSheet(Styles.DEFAULT_STYLE_SHEET);
179:                Window window = new Window();
180:                window.setTitle(Messages.getString("Application.Title.Window"));
181:                window.setContent(new LoginScreen());
182:                return window;
183:            }
184:
185:            /**
186:             * Handles a fatal exception.
187:             * This method is invoked when a component of the application 
188:             * encounters a fatal error that can not be resolved.  This
189:             * method will log off any currently logged in user and 
190:             * display an error dialog screen.
191:             *
192:             * @param ex the fatal exception
193:             */
194:            public void processFatalException(Exception ex) {
195:                ex.printStackTrace();
196:                disconnect();
197:                MessageDialog messageDialog = new MessageDialog(Messages
198:                        .getString("FatalException.Title"), ex.toString(),
199:                        MessageDialog.TYPE_ERROR, MessageDialog.CONTROLS_OK);
200:                getDefaultWindow().getContent().add(messageDialog);
201:            }
202:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.