Source Code Cross Referenced for JwmaAdminController.java in  » Web-Mail » Jwma » dtw » webmail » 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 » Web Mail » Jwma » dtw.webmail 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /***
002:         * jwma Java WebMail
003:         * Copyright (c) 2000-2003 jwma team
004:         *
005:         * jwma is free software; you can distribute and use this source
006:         * under the terms of the BSD-style license received along with
007:         * the distribution.
008:         ***/package dtw.webmail;
009:
010:        import java.io.*;
011:        import javax.servlet.*;
012:        import javax.servlet.http.*;
013:
014:        import org.apache.log4j.Logger;
015:        import org.apache.log4j.NDC;
016:
017:        import dtw.webmail.util.*;
018:        import dtw.webmail.model.*;
019:        import dtw.webmail.admin.*;
020:
021:        /**
022:         * Class extending the <tt>HttpServlet</tt> to implement
023:         * the Admin controller of jwma.
024:         * <p>
025:         * Please see the related documentation for more detailed
026:         * information on process flow and functionality.
027:         *
028:         * @author Dieter Wimberger
029:         * @version 0.9.7 07/02/2003
030:         */
031:        public class JwmaAdminController extends HttpServlet {
032:
033:            //logging
034:            private static Logger log = Logger
035:                    .getLogger(JwmaAdminController.class);
036:
037:            /**
038:             * Initializes the servlet when it is loaded by the
039:             * servlet engine.
040:             * <p>This implementation just calls its superclass
041:             * implementation.
042:             *
043:             * @throws ServletException if initialization fails.
044:             */
045:            public void init(ServletConfig config) throws ServletException {
046:
047:                super .init(config);
048:            }//init
049:
050:            /**
051:             * Handles the incoming requests.
052:             * <p>
053:             *
054:             * @param req a reference to the actual <tt>HttpServletRequest</tt>
055:             *        instance.
056:             * @param res a reference to the actual <tt>HttpServletResponse</tt>
057:             *        instance.
058:             *
059:             * @throws ServletException if servlet related operations fail.
060:             * @throws IOException if i/o operations fail.
061:             */
062:            public void service(HttpServletRequest req, HttpServletResponse res)
063:                    throws ServletException, IOException {
064:
065:                try {
066:                    NDC.push(req.getRemoteHost());
067:                    //1. Handle Session
068:                    HttpSession websession = req.getSession(true);
069:                    Object o = websession.getValue("jwma.session");
070:                    String acton = req.getParameter("acton");
071:                    String dome = req.getParameter("todo");
072:
073:                    //2. Ensure valid jwma session
074:                    JwmaSession session = ((o == null) ? new JwmaSession(
075:                            websession) : ((JwmaSession) o));
076:                    session.setRequest(req);
077:                    session.setResponse(res);
078:                    session.setWebSession(websession);
079:
080:                    //3. Redirect invalid web sessions
081:                    if (!session.isValidWebSession()) {
082:                        session.redirect(JwmaKernel.LOGIN_VIEW);
083:                    } else {
084:
085:                        //dispatch all actions that need a valid action.
086:                        try {
087:                            if (acton == null || acton.equals("")) {
088:                                throw new JwmaException(
089:                                        "request.target.missing");
090:                            } else if (dome == null || dome.equals("")) {
091:                                throw new JwmaException(
092:                                        "request.action.missing");
093:                            } else if (acton.equals("system")) {
094:                                doDispatchSystemActions(session, dome);
095:                            } else {
096:                                //ensure authentication & administrator
097:                                session.ensureAuthenticated();
098:                                session.ensureAdministrator();
099:
100:                                if (acton.equals("session")) {
101:                                    //doDispatchSessionActions
102:                                } else if (acton.equals("preferences")) {
103:                                    //doDispatchPreferencesActions(session,dome);
104:                                } else if (acton.equals("settings")) {
105:                                    //doDispatchSettingsActions(session,dome);
106:                                } else {
107:                                    throw new JwmaException(
108:                                            "request.target.invalid");
109:                                }
110:                            }
111:                        } catch (JwmaException ex) {
112:                            //1. if not authenticated forward to login page
113:                            if (!session.isAuthenticated()) {
114:                                session.redirect(JwmaKernel.LOGIN_VIEW);
115:                            } else {
116:                                String message = ex.getMessage();
117:                                //oneliner resolving of key to message in
118:                                message = JwmaKernel.getReference()
119:                                        .getLogMessage("jwma.usererror")
120:                                        + JwmaKernel.getReference()
121:                                                .getErrorMessage(message);
122:
123:                                //log exception with description and trace if inlined exception
124:                                //available, else with stacktrace.
125:                                if (ex.hasException()) {
126:                                    log.error(message, ex.getException());
127:                                } else {
128:                                    log.error(message, ex);
129:                                }
130:                                //store error
131:                                session.storeBean("jwma.error", ex);
132:                                //redirect last view with inlined error or
133:                                //to error page.
134:                                if (ex.isInlineError()) {
135:                                    session.redirectToActual();
136:                                } else {
137:                                    session.redirect(JwmaKernel.ERROR_VIEW);
138:                                }
139:                            }
140:                        }
141:                    }
142:                } finally {
143:                    NDC.pop();
144:                }
145:            }//service
146:
147:            /*** Dispatchers ***************************************************/
148:
149:            /**
150:             * Dispatches actions targeting a <tt>session</tt>.
151:             *
152:             * @param session a <tt>JwmaAdminSession</tt> instance.
153:             * @param dome the task as <tt>String</tt>.
154:             *
155:             * @throws JwmaException if it fails to dispatch the request to a
156:             *         method (i.e. invalid request), or the action method fails
157:             *         to execute the task.
158:             *
159:             private void doDispatchSessionActions(JwmaAdminSession session,String dome)
160:             throws JwmaException {
161:
162:             if(dome.equals("logout")) {
163:             doLogout(session);
164:             } else if(dome.equals("login")) {
165:             String user=session.getRequest().getParameter("username");
166:             String passwd=session.getRequest().getParameter("password");
167:             doLogin(session,user,passwd);
168:             return;
169:             } else if(dome.equals("redirect")) {
170:             String view=session.getRequest().getParameter("view");
171:             doRedirect(session,view);
172:             } else {
173:             throw new JwmaException("session.action.invalid");
174:             }
175:             }//doDispatchSessionActions
176:             */
177:
178:            /**
179:             * Dispatches actions targeting the <tt>system</tt>.
180:             *
181:             * @param session a <tt>JwmaAdminSession</tt> instance.
182:             * @param dome the task as <tt>String</tt>.
183:             *
184:             * @throws JwmaException if it fails to dispatch the request to a
185:             *         method (i.e. invalid request), or the action method fails
186:             *         to execute the task.
187:             */
188:            private void doDispatchSystemActions(JwmaSession session,
189:                    String dome) throws JwmaException {
190:
191:                if (dome.equals("status")) {
192:                    doStatus(session);
193:                } else {
194:                    throw new JwmaException("session.action.invalid");
195:                }
196:            }//doDispatchSystemActions
197:
198:            /*** End Dispatchers *************************************************/
199:
200:            /*** Session Actions  ************************************************/
201:
202:            /**
203:             * Handles an admin login.
204:             *
205:             * @param session actual <tt>JwmaAdminSession</tt> instance.
206:             * @param username of the user as <tt>String</tt>.
207:             * @param password of the user as <tt>String</tt>.
208:             *
209:             *
210:             * @throws JwmaException if it fails to execute properly.
211:             *
212:             private void doLogin(JwmaAdminSession session,String user, String passwd)
213:             throws JwmaException {
214:
215:             if(session.authenticate(user,passwd)) {
216:             session.redirect(JwmaKernel.ADMIN_MENU_VIEW);
217:             } else {
218:             throw new JwmaException("session.login.authentication");
219:             }
220:             }//doLogin
221:
222:             /**
223:             * Logs the admin out of the admin session.
224:             *
225:             * @param session a <tt>JwmaAdminSession</tt> instance.
226:             *
227:             * @throws JwmaException if it fails to execute properly.
228:             *
229:             private void doLogout(JwmaAdminSession session)
230:             throws JwmaException {
231:
232:             try{
233:             //remove authentication and beans
234:             session.end();
235:             session.redirect(JwmaKernel.ADMIN_MENU_VIEW);
236:             } catch (Exception ex) {
237:             throw new JwmaException("session.logout.failed");
238:             }
239:             }//doLogout
240:             */
241:
242:            /**
243:             * Redirects a request to a given & possible view,
244:             * to the last view or to the menu view otherwise
245:             * <i><b>Note:</b> the bean instances are updated!</i>
246:             *
247:             * @param session a <tt>JwmaAdminSession</tt> instance.
248:             * @param view the view as <tt>String</tt>.
249:             */
250:            private void doRedirect(JwmaSession session, String view) {
251:                try {
252:                    if (view != null) {
253:                        //clean whitespace
254:                        view.trim();
255:                        if (view.equals("last")) {
256:                            session.redirectToLast();
257:                            return;
258:                        } else if (view.equals("actual")) {
259:                            session.redirectToActual();
260:                            return;
261:                        } else if (view.equals("preferences")) {
262:
263:                            return;
264:                        } else if (view.equals("settings")) {
265:                            return;
266:                        } else if (view.equals("menu")) {
267:                            session.redirect(JwmaKernel.ADMIN_MENU_VIEW);
268:                            return;
269:                        }
270:                    }
271:                    //if fall through here display menu
272:                    session.redirect(JwmaKernel.ADMIN_MENU_VIEW);
273:                    return;
274:                } catch (Exception ex) {
275:                    //?
276:                    //JwmaKernel.getReference().debugLog().writeStackTrace(ex);
277:                }
278:            }//doRedirect
279:
280:            /*** End Session Actions  ***********************************************/
281:
282:            /**
283:             * Prepares for displaying the status page.
284:             *
285:             * @param session a <tt>JwmaAdminSession</tt> instance.
286:             *
287:             * @throws JwmaException if it fails to execute properly.
288:             */
289:            private void doStatus(JwmaSession session) throws JwmaException {
290:
291:                if (JwmaKernel.getReference().isJwmaStatusEnabled()) {
292:                    session.storeBean("jwma.admin.status", JwmaStatus
293:                            .getReference());
294:                    session.redirect(JwmaKernel.ADMIN_STATUS_VIEW);
295:                } else {
296:                    throw new JwmaException("system.status.disabled");
297:                }
298:
299:            }//doStatus
300:
301:            /*** System Actions  ****************************************************/
302:
303:            /*** End System Actions  ************************************************/
304:
305:            /**
306:             * Returns servlet info as <tt>String</tt>.
307:             *
308:             * @return Info about this servlet as <tt>String</tt>.
309:             */
310:            public String getServletInfo() {
311:                return "jwma (Java WebMail) AdminController Servlet";
312:            }//getServletInfo()
313:
314:        }//class JwmaAdminController
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.