Source Code Cross Referenced for SubscriptionAction.java in  » Web-Framework » struts-1.3.8 » org » apache » struts » apps » mailreader » actions » 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 Framework » struts 1.3.8 » org.apache.struts.apps.mailreader.actions 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         *
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:        package org.apache.struts.apps.mailreader.actions;
018:
019:        import org.apache.commons.beanutils.PropertyUtils;
020:        import org.apache.struts.action.ActionForm;
021:        import org.apache.struts.action.ActionForward;
022:        import org.apache.struts.action.ActionMapping;
023:        import org.apache.struts.apps.mailreader.Constants;
024:        import org.apache.struts.apps.mailreader.dao.Subscription;
025:        import org.apache.struts.apps.mailreader.dao.User;
026:
027:        import javax.servlet.ServletException;
028:        import javax.servlet.http.HttpServletRequest;
029:        import javax.servlet.http.HttpServletResponse;
030:        import javax.servlet.http.HttpSession;
031:        import java.lang.reflect.InvocationTargetException;
032:
033:        /**
034:         * <p>
035:         * Provide an Edit method for retrieving an existing subscription,
036:         * and a Save method for updating or inserting a subscription.
037:         * </p>
038:         */
039:        public final class SubscriptionAction extends BaseAction {
040:
041:            // --- Public Constants --
042:
043:            /**
044:             * <p>
045:             * Name of autoConnect field ["autoConnect"].
046:             * </p>
047:             */
048:            public final static String AUTO_CONNECT = "autoConnect";
049:
050:            /**
051:             * <p>
052:             * Name of host field ["host"].
053:             * </p>
054:             */
055:            public final static String HOST = "host";
056:
057:            /**
058:             * <p>
059:             * Name of type field ["type"].
060:             * </p>
061:             */
062:            public final static String TYPE = "type";
063:
064:            // ---- Private Methods ----
065:
066:            final String LOG_SUBSCRIPTION_POPULATE = "SubscriptionForm.populate";
067:
068:            /**
069:             * <p>
070:             * Obtain subscription matching host for the given User,
071:             * or return null if not found.
072:             * </p>
073:             *
074:             * @param user Our User object
075:             * @param host The name of the mail server host
076:             * @return The matching Subscription or null
077:             */
078:            private Subscription doFindSubscription(User user, String host) {
079:
080:                Subscription subscription;
081:
082:                try {
083:                    subscription = user.findSubscription(host);
084:                } catch (NullPointerException e) {
085:                    subscription = null;
086:                }
087:
088:                if ((subscription == null) && (log.isTraceEnabled())) {
089:                    log.trace(" No subscription for user " + user.getUsername()
090:                            + " and host " + host);
091:                }
092:
093:                return subscription;
094:            }
095:
096:            /**
097:             * <p>
098:             * Helper method to populate the Subscription object from the input form.
099:             * </p>
100:             *
101:             * @param subscription User object to populate
102:             * @param form         Form with incoming values
103:             * @throws ServletException On any error
104:             */
105:            private void doPopulate(Subscription subscription, ActionForm form)
106:                    throws ServletException {
107:
108:                if (log.isTraceEnabled()) {
109:                    log.trace(Constants.LOG_POPULATE_SUBSCRIPTION
110:                            + subscription);
111:                }
112:
113:                try {
114:                    PropertyUtils.copyProperties(subscription, form);
115:                } catch (InvocationTargetException e) {
116:                    Throwable t = e.getTargetException();
117:                    if (t == null) {
118:                        t = e;
119:                    }
120:                    log.error(LOG_SUBSCRIPTION_POPULATE, t);
121:                    throw new ServletException(LOG_SUBSCRIPTION_POPULATE, t);
122:                } catch (Throwable t) {
123:                    log.error(LOG_SUBSCRIPTION_POPULATE, t);
124:                    throw new ServletException(LOG_SUBSCRIPTION_POPULATE, t);
125:                }
126:            }
127:
128:            /**
129:             * <p>
130:             * Helper method to populate the input form from the Subscription object.
131:             * </p>
132:             *
133:             * @param subscription User object to populate
134:             * @param form         Form with incoming values
135:             * @throws ServletException On any error
136:             */
137:            private void doPopulate(ActionForm form, Subscription subscription)
138:                    throws ServletException {
139:
140:                final String title = Constants.EDIT;
141:
142:                if (log.isTraceEnabled()) {
143:                    log.trace(Constants.LOG_POPULATE_FORM
144:                            + subscription.getHost());
145:                }
146:
147:                try {
148:                    PropertyUtils.copyProperties(form, subscription);
149:                    doSet(form, TASK, title);
150:                } catch (InvocationTargetException e) {
151:                    Throwable t = e.getTargetException();
152:                    if (t == null) {
153:                        t = e;
154:                    }
155:                    log.error(LOG_SUBSCRIPTION_POPULATE, t);
156:                    throw new ServletException(LOG_SUBSCRIPTION_POPULATE, t);
157:                } catch (Throwable t) {
158:                    log.error(LOG_SUBSCRIPTION_POPULATE, t);
159:                    throw new ServletException(LOG_SUBSCRIPTION_POPULATE, t);
160:                }
161:            }
162:
163:            /**
164:             * <p>
165:             * Remove the given subscription for this user.
166:             * </p>
167:             *
168:             * @param mapping      Our ActionMapping
169:             * @param session      Our HttpSession
170:             * @param user         Our User
171:             * @param subscription Subscription to delete
172:             * @return "Success" if delete is nominal, "Logon" if attributes are
173:             *         missing
174:             * @throws ServletException if updates fails
175:             */
176:            private ActionForward doRemoveSubscription(ActionMapping mapping,
177:                    HttpSession session, User user, Subscription subscription)
178:                    throws ServletException {
179:
180:                final String method = Constants.DELETE;
181:                doLogProcess(mapping, method);
182:
183:                if (log.isTraceEnabled()) {
184:                    log.trace(" Deleting subscription to mail server '"
185:                            + subscription.getHost() + "' for user '"
186:                            + user.getUsername() + "'");
187:                }
188:
189:                boolean missingAttributes = ((user == null) || (subscription == null));
190:                if (missingAttributes) {
191:                    return doFindLogon(mapping);
192:                }
193:
194:                user.removeSubscription(subscription);
195:                session.removeAttribute(Constants.SUBSCRIPTION_KEY);
196:                doSaveUser(user);
197:
198:                return doFindSuccess(mapping);
199:            }
200:
201:            // ----- Public Methods ----
202:
203:            /**
204:             * <p>
205:             * Prepare for a Delete operation by populating the form
206:             * and seting the action to Delete.
207:             * </p>
208:             *
209:             * @param mapping  Our ActionMapping
210:             * @param form     Our ActionForm
211:             * @param request  Our HttpServletRequest
212:             * @param response Our HttpServletResponse
213:             * @return The "Success" result for this mapping
214:             * @throws Exception on any error
215:             */
216:            public ActionForward Delete(ActionMapping mapping, ActionForm form,
217:                    HttpServletRequest request, HttpServletResponse response)
218:                    throws Exception {
219:
220:                final String method = Constants.DELETE;
221:                doLogProcess(mapping, method);
222:
223:                ActionForward result = Edit(mapping, form, request, response);
224:
225:                doSet(form, TASK, method);
226:                return result;
227:            }
228:
229:            /**
230:             * <p>
231:             * Retrieve the Subscription object to edit
232:             * or null if the Subscription does not exist.
233:             * </p><p>
234:             * The Subscription object is bound to the User,
235:             * and so if the User is not logged in,
236:             * control is forwarded to the Logon result.
237:             * </p>
238:             *
239:             * @param mapping  Our ActionMapping
240:             * @param form     Our ActionForm
241:             * @param request  Our HttpServletRequest
242:             * @param response Our HttpServletResponse
243:             * @return The "Success" result for this mapping
244:             * @throws Exception on any error
245:             */
246:            public ActionForward Edit(ActionMapping mapping, ActionForm form,
247:                    HttpServletRequest request, HttpServletResponse response)
248:                    throws Exception {
249:
250:                final String method = Constants.EDIT;
251:                doLogProcess(mapping, method);
252:
253:                HttpSession session = request.getSession();
254:                User user = doGetUser(session);
255:                if (user == null) {
256:                    return doFindLogon(mapping);
257:                }
258:
259:                // Retrieve the subscription, if there is one
260:                Subscription subscription;
261:                String host = doGet(form, HOST);
262:                boolean updating = (host != null);
263:                if (updating) {
264:                    subscription = doFindSubscription(user, host);
265:                    if (subscription == null) {
266:                        return doFindFailure(mapping);
267:                    }
268:                    session.setAttribute(Constants.SUBSCRIPTION_KEY,
269:                            subscription);
270:                    doPopulate(form, subscription);
271:                    doSet(form, TASK, method);
272:                }
273:
274:                return doFindSuccess(mapping);
275:            }
276:
277:            /**
278:             * <p>
279:             * Insert or update a Subscription object to the persistent store.
280:             * </p>
281:             *
282:             * @param mapping  Our ActionMapping
283:             * @param form     Our ActionForm
284:             * @param request  Our HttpServletRequest
285:             * @param response Our HttpServletResponse
286:             * @return The "Success" result for this mapping
287:             * @throws Exception on any error
288:             */
289:            public ActionForward Save(ActionMapping mapping, ActionForm form,
290:                    HttpServletRequest request, HttpServletResponse response)
291:                    throws Exception {
292:
293:                final String method = Constants.SAVE;
294:                doLogProcess(mapping, method);
295:
296:                User user = doGetUser(request);
297:                if (user == null) {
298:                    return doFindLogon(mapping);
299:                }
300:
301:                HttpSession session = request.getSession();
302:                if (isCancelled(request)) {
303:                    doCancel(session, method, Constants.SUBSCRIPTION_KEY);
304:                    return doFindSuccess(mapping);
305:                }
306:
307:                String action = doGet(form, TASK);
308:                Subscription subscription = doGetSubscription(request);
309:                boolean isDelete = action.equals(Constants.DELETE);
310:                if (isDelete) {
311:                    return doRemoveSubscription(mapping, session, user,
312:                            subscription);
313:                }
314:
315:                if (subscription == null) {
316:                    subscription = user.createSubscription(doGet(form, HOST));
317:                    session.setAttribute(Constants.SUBSCRIPTION_KEY,
318:                            subscription);
319:                }
320:
321:                doPopulate(subscription, form);
322:                doSaveUser(user);
323:                session.removeAttribute(Constants.SUBSCRIPTION_KEY);
324:
325:                return doFindSuccess(mapping);
326:            }
327:
328:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.