KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > raptus > owxv3 > modules > base > EABaseAction


1 /*
2  * eAdmin/OWX
3  * Copyright (C) 1996-2003 OWX-Project Team <owx-team@gmx.net>
4  */

5
6 package com.raptus.owxv3.modules.base;
7
8 import javax.servlet.http.HttpServletRequest JavaDoc;
9
10 import org.apache.struts.util.MessageResources;
11
12 import com.raptus.owxv3.*;
13 import com.raptus.owxv3.api.VModuleRoleAction;
14
15
16 /**
17  *
18  * <hr>
19  * <table width="100%" border="0">
20  * <tr>
21  * <td width="24%"><b>Filename</b></td><td width="76%">EABaseAction.java</td>
22  * </tr>
23  * <tr>
24  * <td width="24%"><b>Author</b></td><td width="76%">Guy Z�rcher (gzuercher@raptus.com)</td>
25  * </tr>
26  * <tr>
27  * <td width="24%"><b>Date</b></td><td width="76%">20th of April 2001</td>
28  * </tr>
29  * </table>
30  * <hr>
31  * <table width="100%" border="0">
32  * <tr>
33  * <td width="24%"><b>Date / Author</b></td><td width="76%"><b>Changes</b></td>
34  * </tr>
35  * </table>
36  * <hr>
37  */

38 //public class EABaseAction extends VModuleAuthAction
39
public class EABaseAction extends VModuleRoleAction
40 {
41     /**
42      *
43      */

44     public String JavaDoc dispatchVModuleElement(HttpServletRequest JavaDoc request,
45                                          String JavaDoc element,
46                                          org.apache.struts.action.ActionForm form,
47                                          VModule vm,
48                                          com.raptus.owxv3.api.usermgr.User user)
49     {
50         if(element.compareToIgnoreCase(BaseConstants.ELEMENT_INDEX) == 0)
51         {
52
53            BaseObject newsObj=new BaseObject( vm,user.getLocale() );
54            EABaseBean newsBean= (EABaseBean) form;
55            newsBean.setPropertiesDisabled(! newsObj.arePropertiesEnabled());
56            newsBean.setFilesDisabled(! newsObj.areFilesEnabled());
57            newsBean.setPicturesDisabled(! newsObj.arePicturesEnabled());
58            newsBean.setLinksDisabled(! newsObj.areLinksEnabled());
59
60            String JavaDoc action=request.getParameter(BaseConstants.HTTPGET_PARAM_ACTION);
61            if(action!=null)
62            {
63                boolean success = sendEmail(vm.getStringProperty(BaseConstants.VMODULE_PROPERTY_MAILHOST),
64                                            vm.getStringProperty(BaseConstants.VMODULE_PROPERTY_ADMINEMAIL),
65                                            user.getName()+"("+user.getEmail()+")",action);
66
67                MessageResources mr=MessageResources.getMessageResources(Constants.OWXRESOURCES);
68                if(success)
69                {
70                  newsBean.setMessage( mr.getMessage(user.getLocale(),BaseConstants.INDEX_MESSAGE_EMAILSENT)) ;
71                }
72                else
73                {
74                  newsBean.setMessage( mr.getMessage(user.getLocale(),BaseConstants.INDEX_ERROR_SENDINGEMAIL) );
75                }
76            } // end if
77

78         } // end if
79
else
80             return null; // display unknown element screen
81

82         return Constants.SECTION_EADMIN + Constants.DEFAULT_SPACER + element;
83     }
84
85
86     private boolean sendEmail(String JavaDoc mailhost,String JavaDoc to,String JavaDoc fromname,String JavaDoc requesttype)
87     {
88         try
89         {
90             sun.net.smtp.SmtpClient smtp=new sun.net.smtp.SmtpClient(mailhost);
91             smtp.from(to);
92             smtp.to(to);
93             java.io.PrintStream JavaDoc msg = smtp.startMessage();
94
95            //Write the message header in the output stream.
96
msg.print("From: ");
97             msg.println(to);
98             msg.print("To: ");
99             msg.println(to);
100             msg.print("Subject: Request from eadmin client: ");
101             msg.println(fromname);
102             msg.println();
103
104             msg.println("The client is requesting the activation of ");
105
106             boolean validrequest=false;
107             if(requesttype.equals(BaseConstants.VMODULE_ACTION_ENABLEFILES))
108             {
109                 msg.print("Files");
110                 validrequest=true;
111
112             }
113             else if(requesttype.equals(BaseConstants.VMODULE_ACTION_ENABLELINKS))
114             {
115                 msg.print("Links");
116                 validrequest=true;
117
118             }
119             if(requesttype.equals(BaseConstants.VMODULE_ACTION_ENABLEPICTURES))
120             {
121                 msg.print("Pictures");
122                 validrequest=true;
123
124             }
125             if(requesttype.equals(BaseConstants.VMODULE_ACTION_ENABLEPROPERTIES))
126             {
127                 msg.print("Properties");
128                 validrequest=true;
129             }
130
131             if(!validrequest) return true;
132
133             msg.println(".");
134
135             msg.close();
136             smtp.closeServer();
137         }
138         catch(Exception JavaDoc e)
139         {
140             LoggingManager.log("Unable to send email to administrator. Error:"+e,this);
141             return false;
142         }
143
144             return true;
145
146     }
147
148 }
149
150 // eof
151
Popular Tags