Source Code Cross Referenced for InputMaskAction.java in  » Development » ivatamasks » com » ivata » mask » web » struts » 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 » Development » ivatamasks » com.ivata.mask.web.struts 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 2001 - 2005 ivata limited.
003:         * All rights reserved.
004:         * -----------------------------------------------------------------------------
005:         * ivata masks may be redistributed under the GNU General Public
006:         * License as published by the Free Software Foundation;
007:         * version 2 of the License.
008:         *
009:         * These programs are free software; you can redistribute them and/or
010:         * modify them under the terms of the GNU General Public License
011:         * as published by the Free Software Foundation; version 2 of the License.
012:         *
013:         * These programs are distributed in the hope that they will be useful,
014:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
015:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
016:         *
017:         * See the GNU General Public License in the file LICENSE.txt for more
018:         * details.
019:         *
020:         * If you would like a copy of the GNU General Public License write to
021:         *
022:         * Free Software Foundation, Inc.
023:         * 59 Temple Place - Suite 330
024:         * Boston, MA 02111-1307, USA.
025:         *
026:         *
027:         * To arrange commercial support and licensing, contact ivata at
028:         *                  http://www.ivata.com/contact.jsp
029:         * -----------------------------------------------------------------------------
030:         * $Log: InputMaskAction.java,v $
031:         * Revision 1.20  2005/11/03 14:27:16  colinmacleod
032:         * Set input mask in the session (workaround for bugs in ivata cms).
033:         *
034:         * Revision 1.19  2005/10/14 14:04:53  colinmacleod
035:         * Uncommented onConfirm - why oh why did I ever comment this out?!!
036:         *
037:         * Revision 1.18  2005/10/11 18:54:06  colinmacleod
038:         * Fixed some checkstyle and javadoc issues.
039:         *
040:         * Revision 1.17  2005/10/09 09:55:17  colinmacleod
041:         * Merged changes from ivata masks v0.6.2 into main trunk.
042:         *
043:         * Revision 1.16  2005/10/03 10:17:25  colinmacleod
044:         * Fixed some style and javadoc issues.
045:         *
046:         * Revision 1.15  2005/10/02 14:06:34  colinmacleod
047:         * Added/improved log4j logging.
048:         *
049:         * Revision 1.14  2005/09/29 12:18:44  colinmacleod
050:         * Added session parameter to persistenceManager.openSession().
051:         *
052:         * Revision 1.13  2005/09/14 12:56:28  colinmacleod
053:         * Removed unread class and local
054:         * variables.
055:         *
056:         * Revision 1.12.2.1  2005/10/08 10:53:22  colinmacleod
057:         * Added debug logging when value object is modified or added.
058:         *
059:         * Revision 1.12  2005/04/11 14:52:05  colinmacleod
060:         * Added execute override.
061:         *
062:         * Revision 1.11  2005/04/09 18:04:18  colinmacleod
063:         * Changed copyright text to GPL v2 explicitly.
064:         *
065:         * Revision 1.10  2005/03/10 10:37:56  colinmacleod
066:         * Added handling of client-program session to
067:         * persistence session.
068:         *
069:         * Revision 1.9  2005/01/19 12:56:36  colinmacleod
070:         * Added OperationNotSupportedException to clear.
071:         *
072:         * Revision 1.8  2005/01/10 19:06:02  colinmacleod
073:         * Applied persistence manager methods to remove.
074:         *
075:         * Revision 1.7  2005/01/07 08:08:24  colinmacleod
076:         * Moved up a version number.
077:         * Changed copyright notices to 2005.
078:         * Updated the documentation:
079:         *   - started working on multiproject:site docu.
080:         *   - changed the logo.
081:         * Added checkstyle and fixed LOADS of style issues.
082:         * Added separate thirdparty subproject.
083:         * Added struts (in web), util and webgui (in webtheme) from ivata op.
084:         *
085:         * Revision 1.6  2004/12/29 15:32:19  colinmacleod
086:         * List/input mask actions are no longer hard-coded.
087:         * Overrides added via request parameters
088:         * - defaults via new methods on the factory.
089:         *
090:         * Revision 1.5  2004/12/23 21:28:32  colinmacleod
091:         * Modifications to add ivata op compatibility.
092:         *
093:         * Revision 1.4  2004/11/12 15:10:42  colinmacleod
094:         * Moved persistence classes from ivata op as a replacement for
095:         * ValueObjectLocator.
096:         *
097:         * Revision 1.3  2004/11/11 13:49:46  colinmacleod
098:         * Added log4j logging.
099:         *
100:         * Revision 1.2  2004/05/19 20:34:17  colinmacleod
101:         * Added methods to add, amend and remove value objects.
102:         *
103:         * Revision 1.1.1.1  2004/05/16 20:40:33  colinmacleod
104:         * Ready for 0.1 release
105:         * -----------------------------------------------------------------------------
106:         */
107:        package com.ivata.mask.web.struts;
108:
109:        import org.apache.log4j.Logger;
110:
111:        import javax.servlet.http.HttpServletRequest;
112:        import javax.servlet.http.HttpServletResponse;
113:        import javax.servlet.http.HttpSession;
114:
115:        import org.apache.struts.action.ActionForm;
116:        import org.apache.struts.action.ActionMapping;
117:        import org.sourceforge.clientsession.ClientSession;
118:
119:        import com.ivata.mask.MaskFactory;
120:        import com.ivata.mask.persistence.PersistenceManager;
121:        import com.ivata.mask.persistence.PersistenceSession;
122:        import com.ivata.mask.util.StringHandling;
123:        import com.ivata.mask.util.SystemException;
124:        import com.ivata.mask.valueobject.ValueObject;
125:
126:        /**
127:         * <p>
128:         * Add, amend or remove an existing value object in the list of value objects.
129:         * </p>
130:         *
131:         * @since ivata masks 0.4 (2004-05-10)
132:         * @author Colin MacLeod
133:         * <a href='mailto:colin.macleod@ivata.com'>colin.macleod@ivata.com</a>
134:         * @version $Revision: 1.20 $
135:         */
136:        public class InputMaskAction extends MaskAction {
137:            /**
138:             * Logger for this class.
139:             */
140:            private static final Logger logger = Logger
141:                    .getLogger(InputMaskAction.class);
142:
143:            /**
144:             * <p>
145:             * Used to locate the value objects by their shared base class.
146:             * </p>
147:             */
148:            private PersistenceManager persistenceManager;
149:
150:            /**
151:             * <p>
152:             * Create a new AddAction with the given value object locator.
153:             * </p>
154:             *
155:             * @param persistenceManagerParam
156:             *            used to locate the value objects by their shared base class.
157:             * @param maskFactoryParam
158:             *            <copyDoc>Refer to {@link MaskAction#MaskAction}.</copyDoc>
159:             * @param authenticatorParam
160:             *            <copyDoc>Refer to {@link MaskAction#MaskAction}.</copyDoc>
161:             */
162:            public InputMaskAction(final MaskFactory maskFactoryParam,
163:                    final PersistenceManager persistenceManagerParam,
164:                    final MaskAuthenticator authenticatorParam) {
165:                super (maskFactoryParam, authenticatorParam);
166:                this .persistenceManager = persistenceManagerParam;
167:            }
168:
169:            /**
170:             * Overridden to trap the Clear/New button. If this is pressed, the forward
171:             * <code>new</code> is returned which you can then route to
172:             * <code>NewAction</code> via the <strong>Struts</strong> framework.
173:             *
174:             * @param mappingParam {@inheritDoc}
175:             * @param formParam {@inheritDoc}
176:             * @param requestParam {@inheritDoc}
177:             * @param responseParam {@inheritDoc}
178:             * @param sessionParam {@inheritDoc}
179:             * @param clientSessionParam {@inheritDoc}
180:             * @return <code>new</code> if the new/clear button was pressed, otherwise
181:             * the same as the super constructor.
182:             * @throws SystemException {@inheritDoc}
183:             */
184:            public String execute(final ActionMapping mappingParam,
185:                    final ActionForm formParam,
186:                    final HttpServletRequest requestParam,
187:                    final HttpServletResponse responseParam,
188:                    final HttpSession sessionParam,
189:                    final ClientSession clientSessionParam)
190:                    throws SystemException {
191:                if (logger.isDebugEnabled()) {
192:                    logger.debug("execute(ActionMapping mappingParam = "
193:                            + mappingParam + ", ActionForm formParam = "
194:                            + formParam
195:                            + ", HttpServletRequest requestParam = "
196:                            + requestParam
197:                            + ", HttpServletResponse responseParam = "
198:                            + responseParam + ", HttpSession sessionParam = "
199:                            + sessionParam + ", ClientSession clientSession = "
200:                            + clientSessionParam + ") - start");
201:                }
202:
203:                String clear = getFromRequestOrForm("clear", requestParam,
204:                        formParam);
205:                if (!StringHandling.isNullOrEmpty(clear)) {
206:                    if (logger.isDebugEnabled()) {
207:                        logger.debug("execute - end - return value = new");
208:                    }
209:                    return "new";
210:                }
211:                String returnString = super .execute(mappingParam, formParam,
212:                        requestParam, responseParam, sessionParam,
213:                        clientSessionParam);
214:                sessionParam.setAttribute(InputMaskForm.REQUEST_ATTRIBUTE,
215:                        formParam);
216:                if (logger.isDebugEnabled()) {
217:                    logger.debug("execute - end - return value = "
218:                            + returnString);
219:                }
220:                return returnString;
221:            }
222:
223:            /**
224:             * <p>
225:             * Adds the value object to the list, or amends an existing value object.
226:             * </p>
227:             *
228:             * @param mapping {@inheritDoc}
229:             * @param form {@inheritDoc}
230:             * @param request {@inheritDoc}
231:             * @param response {@inheritDoc}
232:             * @param session {@inheritDoc}
233:             * @param clientSession {@inheritDoc}
234:             * @param defaultForward {@inheritDoc}
235:             * @return {@inheritDoc}
236:             * @throws SystemException {@inheritDoc}
237:             */
238:            public String onConfirm(final ActionMapping mapping,
239:                    final ActionForm form, final HttpServletRequest request,
240:                    final HttpServletResponse response,
241:                    final HttpSession session,
242:                    final ClientSession clientSession,
243:                    final String defaultForward) throws SystemException {
244:                if (logger.isDebugEnabled()) {
245:                    logger.debug("onConfirm(ActionMapping mapping = " + mapping
246:                            + ", ActionForm form = " + form
247:                            + ", HttpServletRequest request = " + request
248:                            + ", HttpServletResponse response = " + response
249:                            + ", HttpSession session = " + session
250:                            + ", ClientSession clientSession = "
251:                            + clientSession + ", String defaultForward = "
252:                            + defaultForward + ") - start");
253:                }
254:
255:                assert (form != null);
256:                InputMaskForm maskForm = (InputMaskForm) form;
257:                ValueObject valueObject = maskForm.getValueObject();
258:                String this IdString = valueObject.getIdString();
259:                // if the id string is null or empty, we should add a new item to the
260:                // list
261:                PersistenceSession persistenceSession = persistenceManager
262:                        .openSession(session.getAttribute("securitySession"));
263:                try {
264:                    if (StringHandling.isNullOrEmpty(this IdString)) {
265:                        if (logger.isDebugEnabled()) {
266:                            logger
267:                                    .debug("onConfirm - Adding new value object with "
268:                                            + valueObject.getClass()
269:                                            + ": "
270:                                            + valueObject);
271:                        }
272:                        valueObject = persistenceManager.add(
273:                                persistenceSession, valueObject);
274:                    } else {
275:                        if (logger.isDebugEnabled()) {
276:                            logger
277:                                    .debug("onConfirm - Modifying value object with "
278:                                            + valueObject.getClass()
279:                                            + ", id "
280:                                            + valueObject.getIdString()
281:                                            + ": "
282:                                            + valueObject);
283:                        }
284:                        // if it is not a new item, find the existing one and amend it
285:                        persistenceManager.amend(persistenceSession,
286:                                valueObject);
287:                    }
288:                } finally {
289:                    persistenceSession.close();
290:                }
291:                if (maskForm.isRefreshOpener()) {
292:                    request.setAttribute("refreshOpener", "true");
293:                }
294:
295:                if (logger.isDebugEnabled()) {
296:                    logger.debug("onConfirm - end - return value = "
297:                            + defaultForward);
298:                }
299:                return defaultForward;
300:            }
301:
302:            /**
303:             * <p>
304:             * Removes the value object from the list.
305:             * </p>
306:             * @param mapping {@inheritDoc}
307:             * @param form {@inheritDoc}
308:             * @param request {@inheritDoc}
309:             * @param response {@inheritDoc}
310:             * @param session {@inheritDoc}
311:             * @param clientSession {@inheritDoc}
312:             * @param defaultForward {@inheritDoc}
313:             * @throws SystemException {@inheritDoc}
314:             * @return Always returns <code>defaultForward</code>.
315:             */
316:            public String onDelete(final ActionMapping mapping,
317:                    final ActionForm form, final HttpServletRequest request,
318:                    final HttpServletResponse response,
319:                    final HttpSession session,
320:                    final ClientSession clientSession,
321:                    final String defaultForward) throws SystemException {
322:                if (logger.isDebugEnabled()) {
323:                    logger.debug("onDelete(ActionMapping mapping = " + mapping
324:                            + ", ActionForm form = " + form
325:                            + ", HttpServletRequest request = " + request
326:                            + ", HttpServletResponse response = " + response
327:                            + ", HttpSession session = " + session
328:                            + ", ClientSession clientSession = "
329:                            + clientSession + ", String defaultForward = "
330:                            + defaultForward + ") - start");
331:                }
332:
333:                InputMaskForm maskForm = (InputMaskForm) form;
334:                Class baseClass = maskForm.getBaseClass();
335:                PersistenceSession persistenceSession = persistenceManager
336:                        .openSession(session);
337:                ValueObject this ValueObject = maskForm.getValueObject();
338:                String this IdString = this ValueObject.getIdString();
339:                try {
340:                    persistenceManager.remove(persistenceSession, baseClass,
341:                            this IdString);
342:                } finally {
343:                    persistenceSession.close();
344:                }
345:                clear(mapping, form, request, response, session, clientSession);
346:                if (maskForm.isRefreshOpener()) {
347:                    request.setAttribute("refreshOpener", "true");
348:                }
349:
350:                if (logger.isDebugEnabled()) {
351:                    logger.debug("onDelete - end - return value = "
352:                            + defaultForward);
353:                }
354:                return defaultForward;
355:            }
356:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.