Source Code Cross Referenced for ChainedHandlerInterceptor.java in  » Content-Management-System » riotfamily » org » riotfamily » common » web » 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 » Content Management System » riotfamily » org.riotfamily.common.web.interceptor 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* ***** BEGIN LICENSE BLOCK *****
002:         * Version: MPL 1.1
003:         * The contents of this file are subject to the Mozilla Public License Version
004:         * 1.1 (the "License"); you may not use this file except in compliance with
005:         * the License. You may obtain a copy of the License at
006:         * http://www.mozilla.org/MPL/
007:         * 
008:         * Software distributed under the License is distributed on an "AS IS" basis,
009:         * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
010:         * for the specific language governing rights and limitations under the
011:         * License.
012:         * 
013:         * The Original Code is Riot.
014:         * 
015:         * The Initial Developer of the Original Code is
016:         * Neteye GmbH.
017:         * Portions created by the Initial Developer are Copyright (C) 2007
018:         * the Initial Developer. All Rights Reserved.
019:         * 
020:         * Contributor(s):
021:         *   Felix Gnass [fgnass at neteye dot de]
022:         * 
023:         * ***** END LICENSE BLOCK ***** */
024:        package org.riotfamily.common.web.interceptor;
025:
026:        import java.util.List;
027:
028:        import javax.servlet.http.HttpServletRequest;
029:        import javax.servlet.http.HttpServletResponse;
030:
031:        import org.springframework.beans.factory.InitializingBean;
032:        import org.springframework.web.context.request.WebRequestInterceptor;
033:        import org.springframework.web.servlet.HandlerInterceptor;
034:        import org.springframework.web.servlet.ModelAndView;
035:        import org.springframework.web.servlet.handler.WebRequestHandlerInterceptorAdapter;
036:
037:        /**
038:         * HandlerInterceptor that delegates calls to a list of interceptors.
039:         * Supported interceptor types are HandlerInterceptor and WebRequestInterceptor.
040:         * 
041:         * @see #setInterceptors(List)
042:         * @author Felix Gnass [fgnass at neteye dot de]
043:         * @since 6.5
044:         */
045:        public class ChainedHandlerInterceptor implements  HandlerInterceptor,
046:                InitializingBean {
047:
048:            private List interceptors;
049:
050:            private HandlerInterceptor[] adaptedInterceptors;
051:
052:            /**
053:             * Set the interceptors to apply in a chain.
054:             * <p>Supported interceptor types are HandlerInterceptor and WebRequestInterceptor.
055:             * @param interceptors array of handler interceptors, or <code>null</code> if none
056:             * @see org.springframework.web.servlet.HandlerInterceptor
057:             * @see org.springframework.web.context.request.WebRequestInterceptor
058:             */
059:            public void setInterceptors(List interceptors) {
060:                this .interceptors = interceptors;
061:            }
062:
063:            /**
064:             * Calls the {@link #initInterceptors()} method.
065:             */
066:            public void afterPropertiesSet() throws Exception {
067:                initInterceptors();
068:            }
069:
070:            /**
071:             * Initialize the specified interceptors, adapting them where necessary.
072:             * @see #setInterceptors
073:             * @see #adaptInterceptor
074:             */
075:            protected void initInterceptors() {
076:                if (interceptors != null) {
077:                    adaptedInterceptors = new HandlerInterceptor[interceptors
078:                            .size()];
079:                    for (int i = 0; i < adaptedInterceptors.length; i++) {
080:                        Object interceptor = interceptors.get(i);
081:                        if (interceptor == null) {
082:                            throw new IllegalArgumentException("Entry number "
083:                                    + i + " in interceptors list is null");
084:                        }
085:                        adaptedInterceptors[i] = adaptInterceptor(interceptor);
086:                    }
087:                } else {
088:                    adaptedInterceptors = new HandlerInterceptor[0];
089:                }
090:            }
091:
092:            /**
093:             * Adapt the given interceptor object to the HandlerInterceptor interface.
094:             * <p>Supported interceptor types are HandlerInterceptor and WebRequestInterceptor.
095:             * Each given WebRequestInterceptor will be wrapped in a WebRequestHandlerInterceptorAdapter.
096:             * Can be overridden in subclasses.
097:             * @param interceptor the specified interceptor object
098:             * @return the interceptor wrapped as HandlerInterceptor
099:             * @see org.springframework.web.servlet.HandlerInterceptor
100:             * @see org.springframework.web.context.request.WebRequestInterceptor
101:             * @see WebRequestHandlerInterceptorAdapter
102:             */
103:            protected HandlerInterceptor adaptInterceptor(Object interceptor) {
104:                if (interceptor instanceof  HandlerInterceptor) {
105:                    return (HandlerInterceptor) interceptor;
106:                } else if (interceptor instanceof  WebRequestInterceptor) {
107:                    return new WebRequestHandlerInterceptorAdapter(
108:                            (WebRequestInterceptor) interceptor);
109:                } else {
110:                    throw new IllegalArgumentException(
111:                            "Interceptor type not supported: "
112:                                    + interceptor.getClass().getName());
113:                }
114:            }
115:
116:            /**
117:             * Delegates the call to all configured interceptors. If an interceptor 
118:             * returns <code>false</code> the chain is not further processes and the 
119:             * method returns <code>false</code> itself. Otherwise <code>true</code>
120:             * is returned after all interceptors have been called. 
121:             */
122:            public boolean preHandle(HttpServletRequest request,
123:                    HttpServletResponse response, Object handler)
124:                    throws Exception {
125:
126:                for (int i = 0; i < adaptedInterceptors.length; i++) {
127:                    HandlerInterceptor interceptor = adaptedInterceptors[i];
128:                    if (!interceptor.preHandle(request, response, handler)) {
129:                        return false;
130:                    }
131:                }
132:                return true;
133:            }
134:
135:            /**
136:             * Delegates the call to all configured interceptors.
137:             */
138:            public void postHandle(HttpServletRequest request,
139:                    HttpServletResponse response, Object handler,
140:                    ModelAndView modelAndView) throws Exception {
141:
142:                for (int i = 0; i < adaptedInterceptors.length; i++) {
143:                    HandlerInterceptor interceptor = adaptedInterceptors[i];
144:                    interceptor.postHandle(request, response, handler,
145:                            modelAndView);
146:                }
147:            }
148:
149:            /**
150:             * Delegates the call to all configured interceptors.
151:             */
152:            public void afterCompletion(HttpServletRequest request,
153:                    HttpServletResponse response, Object handler, Exception ex)
154:                    throws Exception {
155:
156:                for (int i = 0; i < adaptedInterceptors.length; i++) {
157:                    HandlerInterceptor interceptor = adaptedInterceptors[i];
158:                    interceptor.afterCompletion(request, response, handler, ex);
159:                }
160:            }
161:
162:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.