Source Code Cross Referenced for ParameterRemoverInterceptor.java in  » J2EE » webwork-2.2.6 » com » opensymphony » xwork » interceptor » 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 » J2EE » webwork 2.2.6 » com.opensymphony.xwork.interceptor 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 2002-2006 by OpenSymphony
003:         * All rights reserved.
004:         */
005:        package com.opensymphony.xwork.interceptor;
006:
007:        import java.util.Collections;
008:        import java.util.Iterator;
009:        import java.util.Map;
010:        import java.util.Set;
011:
012:        import org.apache.commons.logging.Log;
013:        import org.apache.commons.logging.LogFactory;
014:
015:        import com.opensymphony.xwork.ActionContext;
016:        import com.opensymphony.xwork.ActionInvocation;
017:        import com.opensymphony.xwork.interceptor.AroundInterceptor;
018:        import com.opensymphony.xwork.interceptor.NoParameters;
019:        import com.opensymphony.xwork.util.TextParseUtil;
020:
021:        /**
022:         * <!-- START SNIPPET: description -->
023:         * This is a simple WebWork interceptor that allows parameters (matching
024:         * one of the paramNames attribute csv value) to be 
025:         * removed from the parameter map if they match a certain value
026:         * (matching one of the paramValues attribute csv value), before they 
027:         * are set on the action. A typical usage would be to want a dropdown/select 
028:         * to map onto a boolean value on an action. The select had the options 
029:         * none, yes and no with values -1, true and false. The true and false would 
030:         * map across correctly. However the -1 would be set to false. 
031:         * This was not desired as one might needed the value on the action to stay null. 
032:         * This interceptor fixes this by preventing the parameter from ever reaching 
033:         * the action.
034:         * <!-- END SNIPPET: description -->
035:         * 
036:         * 
037:         * <!-- START SNIPPET: parameters -->
038:         * <ul>
039:         * 	<li>paramNames - A comma separated value (csv) indicating the parameter name 
040:         * 								    whose param value should be considered that if they match any of the
041:         *                                     comma separated value (csv) from paramValues attribute, shall be 
042:         *                                     removed from the parameter map such that they will not be applied
043:         *                                     to the action</li>
044:         * 	<li>paramValues - A comma separated value (csv) indicating the parameter value that if 
045:         * 							      matched shall have its parameter be removed from the parameter map 
046:         * 							      such that they will not be applied to the action</li>
047:         * </ul>
048:         * <!-- END SNIPPET: parameters -->
049:         * 
050:         * 
051:         * <!-- START SNIPPET: extending -->
052:         * No intended extension point
053:         * <!-- END SNIPPET: extending -->
054:         * 
055:         * <pre>
056:         * <!-- START SNIPPET: example -->
057:         *	
058:         * &lt;action name="sample" class="org.martingilday.Sample"&gt;
059:         * 	&lt;interceptor-ref name="paramRemover"&gt;
060:         *   		&lt;param name="paramNames"&gt;aParam,anotherParam&lt;/param&gt;
061:         *   		&lt;param name="paramValues"&gt;--,-1&lt;/param&gt;
062:         * 	&lt;/interceptor-ref&gt;
063:         * 	&lt;interceptor-ref name="default-stack" /&gt;
064:         * 	...
065:         * &lt;/action&gt;
066:         *  
067:         * <!-- END SNIPPET: example -->
068:         * </pre>
069:         *  
070:         *  
071:         * @author martin.gilday
072:         * @version $Date$ $Id$
073:         */
074:        public class ParameterRemoverInterceptor extends AroundInterceptor {
075:
076:            private static final Log LOG = LogFactory
077:                    .getLog(ParameterRemoverInterceptor.class);
078:
079:            private static final long serialVersionUID = 1;
080:
081:            private Set paramNames = Collections.EMPTY_SET;
082:
083:            private Set paramValues = Collections.EMPTY_SET;
084:
085:            /**
086:             * Empty implementation.
087:             */
088:            protected void after(ActionInvocation dispatcher, String result)
089:                    throws Exception {
090:                // do nothing
091:            }
092:
093:            /**
094:             * Decide if the parameter should be removed from the parameter map based on
095:             * <code>paramNames</code> and <code>paramValues</code>.
096:             * 
097:             * @see com.opensymphony.xwork.interceptor.AroundInterceptor#before(com.opensymphony.xwork.ActionInvocation)
098:             */
099:            protected void before(ActionInvocation invocation) throws Exception {
100:
101:                if (!(invocation.getAction() instanceof  NoParameters)
102:                        && (null != this .paramNames)) {
103:                    ActionContext ac = invocation.getInvocationContext();
104:                    final Map parameters = ac.getParameters();
105:
106:                    if (parameters != null) {
107:                        for (Iterator i = paramNames.iterator(); i.hasNext();) {
108:                            Object removeName = i.next();
109:
110:                            // see if the field is in the parameter map
111:                            if (parameters.containsKey(removeName)) {
112:
113:                                try {
114:                                    String[] values = (String[]) parameters
115:                                            .get(removeName);
116:                                    String value = values[0];
117:                                    if (null != value
118:                                            && this .paramValues.contains(value)) {
119:                                        parameters.remove(removeName);
120:                                    }
121:                                } catch (Exception e) {
122:                                    LOG
123:                                            .error(
124:                                                    "Failed to convert parameter to string",
125:                                                    e);
126:                                }
127:                            }
128:                        }
129:                    }
130:                }
131:            }
132:
133:            /**
134:             * Allows <code>paramNames</code> attribute to be set as comma-separated-values (csv).
135:             * 
136:             * @param paramNames the paramNames to set
137:             */
138:            public void setParamNames(String paramNames) {
139:                this .paramNames = TextParseUtil
140:                        .commaDelimitedStringToSet(paramNames);
141:            }
142:
143:            /**
144:             * Allows <code>paramValues</code> attribute to be set as a comma-separated-values (csv).
145:             * 
146:             * @param paramValues the paramValues to set
147:             */
148:            public void setParamValues(String paramValues) {
149:                this.paramValues = TextParseUtil
150:                        .commaDelimitedStringToSet(paramValues);
151:            }
152:
153:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.