1/*2 * Copyright 2000-2004 The Apache Software Foundation.3 * 4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 * 8 * http://www.apache.org/licenses/LICENSE-2.09 * 10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */1617packageorg.apache.jetspeed.modules.actions;
1819// Java stuff20import java.io.StringWriter;
21import java.util.Properties;
22import java.util.Locale;
2324// Jetspeed Stuff25import org.apache.jetspeed.services.resources.JetspeedResources;
26import org.apache.jetspeed.services.TemplateLocator;
27import org.apache.jetspeed.services.JetspeedSecurity;
28import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
29import org.apache.jetspeed.services.logging.JetspeedLogger;
30import org.apache.jetspeed.om.security.JetspeedUser;
3132// Turbine Stuff33import org.apache.turbine.modules.Action;
34import org.apache.turbine.services.localization.Localization;
35import org.apache.turbine.services.velocity.TurbineVelocity;
36import org.apache.turbine.util.RunData;
37import org.apache.turbine.util.DynamicURI;
38import org.apache.turbine.util.mail.SimpleEmail;
3940// Velocity Stuff41import org.apache.velocity.context.Context;
4243/***44 This action will send a notification email to the notification user.4546TODO - does this apply to the notify emails?47 This class is used in two places, the first one is for new users.48 The second is where a user is updating their information after they49 have already created their account. If they are updating and they change50 their email address, then we want to re-confirm it to prevent people from51 screwing up their email address.52*/53publicclassSendNewUserNotificationEmailextends Action
54 {
55/***56 * Static initialization of the logger for this class57 */58privatestaticfinalJetspeedLogger logger = JetspeedLogFactoryService.getLogger(SendNewUserNotificationEmail.class.getName());
5960publicvoid doPerform( RunData data ) throws Exception
61 {
62JetspeedUser user = JetspeedSecurity.getUser(data.getParameters().getString("username", ""));
63 DynamicURI url = new DynamicURI(data)
64 .addPathInfo("pane0", "Security" )
65 .addPathInfo("select-panel2", "User")
66 .addPathInfo("entityid", user.getUserName() )
67 .addQueryData("mode","update");
68try69 {
70//build body via template71 StringWriter email_body = new StringWriter();
72 SimpleEmail se = new SimpleEmail();
73 Context emailContext = TurbineVelocity.getContext();
74 emailContext.put( "data", data );
75 emailContext.put( "user", user );
76 emailContext.put( "config",newJetspeedResources());
77 emailContext.put( "userurl",url);
78 emailContext.put( "email",se);
7980//determine the language to be used for the notification email81 String language = JetspeedResources.getString("newuser.notification.language","en");
82 String country = JetspeedResources.getString("newuser.notification.country","US");
83 Locale locale = new Locale(language,country);
8485 String templateFile = JetspeedResources.getString("newuser.notification.email.template");
86 String templatePath = TemplateLocator.locateEmailTemplate(data, templateFile, locale);
87 TurbineVelocity.handleRequest(emailContext, templatePath, email_body);
8889 se.setMsg(email_body.toString());
9091 Properties props = System.getProperties();
92 String mailServerMachine = JetspeedResources.getString( "mail.server" );
93 props.put ( "mail.host", mailServerMachine );
94 props.put("mail.smtp.host", mailServerMachine);
9596 se.send();
9798 data.setMessage (Localization.getString(data, "SENDCONFIRMATIONEMAIL_SENT"));
99 } catch ( Exception e )
100 {
101 String errorTitle = Localization.getString(data, "SENDCONFIRMATIONEMAIL_ERROR") ;
102 String errorMessage = errorTitle + e.getMessage();
103104 logger.error( errorMessage, e );
105 data.setMessage ( errorTitle + errorMessage );
106 }
107 }
108 }