Source Code Cross Referenced for IdentityMailServiceImpl.java in  » Portal » jboss-portal-2.6.4 » org » jboss » portal » core » identity » services » impl » 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 » jboss portal 2.6.4 » org.jboss.portal.core.identity.services.impl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /******************************************************************************
002:         * JBoss, a division of Red Hat                                               *
003:         * Copyright 2006, Red Hat Middleware, LLC, and individual                    *
004:         * contributors as indicated by the @authors tag. See the                     *
005:         * copyright.txt in the distribution for a full listing of                    *
006:         * individual contributors.                                                   *
007:         *                                                                            *
008:         * This is free software; you can redistribute it and/or modify it            *
009:         * under the terms of the GNU Lesser General Public License as                *
010:         * published by the Free Software Foundation; either version 2.1 of           *
011:         * the License, or (at your option) any later version.                        *
012:         *                                                                            *
013:         * This software is distributed in the hope that it will be useful,           *
014:         * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
015:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU           *
016:         * Lesser General Public License for more details.                            *
017:         *                                                                            *
018:         * You should have received a copy of the GNU Lesser General Public           *
019:         * License along with this software; if not, write to the Free                *
020:         * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA         *
021:         * 02110-1301 USA, or see the FSF site: http://www.fsf.org.                   *
022:         ******************************************************************************/package org.jboss.portal.core.identity.services.impl;
023:
024:        import java.io.FileNotFoundException;
025:        import java.io.IOException;
026:        import java.io.InputStream;
027:        import java.io.InputStreamReader;
028:        import java.io.StringWriter;
029:        import java.net.URL;
030:        import java.util.HashMap;
031:        import java.util.Locale;
032:        import java.util.Map;
033:        import java.util.ResourceBundle;
034:
035:        import org.jboss.logging.Logger;
036:        import org.jboss.portal.core.identity.services.IdentityConstants;
037:        import org.jboss.portal.core.identity.services.IdentityMailService;
038:        import org.jboss.portal.core.identity.services.metadata.IdentityUIConfiguration;
039:        import org.jboss.portal.core.identity.services.metadata.IdentityUIConfigurationService;
040:        import org.jboss.portal.core.modules.MailModule;
041:        import org.jboss.portal.jems.as.JNDI;
042:        import org.jboss.portal.jems.as.system.AbstractJBossService;
043:
044:        import freemarker.template.Configuration;
045:        import freemarker.template.Template;
046:        import freemarker.template.TemplateException;
047:
048:        /**
049:         * @author <a href="mailto:emuckenh@redhat.com">Emanuel Muckenhuber</a>
050:         * @version $Revision$
051:         */
052:        public class IdentityMailServiceImpl extends AbstractJBossService
053:                implements  IdentityMailService {
054:
055:            /** Template mail data */
056:            private Map mailData = new HashMap();
057:
058:            /** Requested locale */
059:            private Locale locale;
060:
061:            /** The e-mail text */
062:            private String emailText = null;
063:
064:            /** The e-mail domain */
065:            private String emailDomain = null;
066:
067:            /** E-Mail from */
068:            private String emailFrom = null;
069:
070:            /** Template location */
071:            private String templateLocation;
072:
073:            /** The mail module */
074:            private MailModule mailModule;
075:
076:            /** The core-identity configuration service */
077:            private IdentityUIConfigurationService identityUIConfigurationService;
078:
079:            /** . */
080:            private static final Logger log = Logger
081:                    .getLogger(IdentityMailServiceImpl.class);
082:
083:            /** . */
084:            private JNDI.Binding jndiBinding;
085:
086:            /** . */
087:            private String jndiName = null;
088:
089:            public void startService() throws Exception {
090:                super .startService();
091:
092:                IdentityUIConfiguration cf = this .identityUIConfigurationService
093:                        .getConfiguration();
094:                this .emailDomain = cf.getEmailDomain();
095:                this .emailFrom = cf.getEmailFrom();
096:
097:                if (this .jndiName != null) {
098:                    jndiBinding = new JNDI.Binding(jndiName, this );
099:                    jndiBinding.bind();
100:                }
101:            }
102:
103:            public void stopService() throws Exception {
104:                super .stopService();
105:
106:                if (jndiBinding != null) {
107:                    jndiBinding.unbind();
108:                    jndiBinding = null;
109:                }
110:            }
111:
112:            public String getEmailDomain() {
113:                return emailDomain;
114:            }
115:
116:            public void setEmailDomain(String emailDomain) {
117:                this .emailDomain = emailDomain;
118:            }
119:
120:            public String getEmailFrom() {
121:                return emailFrom;
122:            }
123:
124:            public void setEmailFrom(String emailFrom) {
125:                this .emailFrom = emailFrom;
126:            }
127:
128:            public MailModule getMailModule() {
129:                return mailModule;
130:            }
131:
132:            public void setMailModule(MailModule mailModule) {
133:                this .mailModule = mailModule;
134:            }
135:
136:            public IdentityUIConfigurationService getIdentityUIConfigurationService() {
137:                return identityUIConfigurationService;
138:            }
139:
140:            public void setIdentityUIConfigurationService(
141:                    IdentityUIConfigurationService identityUIConfigurationService) {
142:                this .identityUIConfigurationService = identityUIConfigurationService;
143:            }
144:
145:            public String getJNDIName() {
146:                return this .jndiName;
147:            }
148:
149:            public void setJNDIName(String jndiName) {
150:                this .jndiName = jndiName;
151:            }
152:
153:            public void sendMail(String templateLocation, Map mailData,
154:                    Locale locale) throws IOException, TemplateException {
155:                this .templateLocation = templateLocation;
156:                this .mailData = mailData;
157:                this .locale = locale;
158:                this .mailData.put(IdentityConstants.EMAIL_DOMAIN, emailDomain);
159:
160:                ResourceBundle bundle = ResourceBundle.getBundle(
161:                        "conf.bundles.Identity", locale);
162:
163:                String subject = null;
164:                String to = (String) mailData.get(IdentityConstants.EMAIL_TO);
165:
166:                if (IdentityConstants.ACTION_REGISTER_USER
167:                        .equals(templateLocation)) {
168:                    subject = bundle
169:                            .getString("IDENTITY_MAIL_SUBJECT_REGISTER");
170:                } else if (IdentityConstants.ACTION_CHANGE_EMAIL
171:                        .equals(templateLocation)) {
172:                    subject = bundle
173:                            .getString("IDENTITY_MAIL_SUBJECT_CHANGE_EMAIL");
174:                } else if (IdentityConstants.ACTION_LOST_PASSWORD
175:                        .equals(templateLocation)) {
176:                    subject = bundle
177:                            .getString("IDENTITY_MAIL_SUBJECT_LOST_PASSWORD");
178:                } else {
179:                    throw new IllegalArgumentException("unknown template.");
180:                }
181:
182:                // Generating message
183:                this .generateEmailText();
184:                // log.debug(this.emailText);
185:
186:                // Sending mail
187:                this .getMailModule().send(emailFrom, to, subject, emailText);
188:
189:            }
190:
191:            private void generateEmailText() throws IOException,
192:                    TemplateException {
193:                ClassLoader tcl = Thread.currentThread()
194:                        .getContextClassLoader();
195:                URL config = tcl.getResource("conf/templates/"
196:                        + this .templateLocation + "/emailTemplate_"
197:                        + locale.getLanguage() + "_" + locale.getCountry()
198:                        + ".tpl");
199:                if (config == null) {
200:                    config = tcl.getResource("conf/templates/"
201:                            + this .templateLocation + "/emailTemplate_"
202:                            + locale.getLanguage() + ".tpl");
203:                }
204:                if (config == null) {
205:                    config = tcl.getResource("conf/templates/"
206:                            + this .templateLocation + "/emailTemplate.tpl");
207:                }
208:                if (config == null) {
209:                    throw new FileNotFoundException(
210:                            "Cannot load a suitable emailTemplate.tpl in conf/templates/"
211:                                    + this .templateLocation);
212:                }
213:                InputStream in = config.openStream();
214:                Template tpl = new Template("emailTemplate",
215:                        new InputStreamReader(in), new Configuration());
216:                StringWriter out = new StringWriter();
217:                tpl.process(this.mailData, out);
218:                out.close();
219:
220:                this.emailText = out.toString();
221:            }
222:        }
w__w_w_.__j___a_va2__s__.__c_o___m | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.