001/*
002 * Copyright 2002-2012 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.web.portlet.handler;
018
019import javax.portlet.ActionRequest;
020import javax.portlet.ActionResponse;
021import javax.portlet.EventRequest;
022import javax.portlet.EventResponse;
023import javax.portlet.PortletRequest;
024import javax.portlet.PortletResponse;
025import javax.portlet.RenderRequest;
026import javax.portlet.RenderResponse;
027import javax.portlet.ResourceRequest;
028import javax.portlet.ResourceResponse;
029
030import org.springframework.web.portlet.HandlerInterceptor;
031import org.springframework.web.portlet.ModelAndView;
032
033/**
034 * Abstract adapter class for the {@link HandlerInterceptor} interface,
035 * for simplified implementation of pre-only/post-only interceptors.
036 *
037 * @author Juergen Hoeller
038 * @author John A. Lewis
039 * @since 2.0
040 */
041public abstract class HandlerInterceptorAdapter implements HandlerInterceptor {
042
043        /**
044         * This implementation delegates to {@link #preHandle}.
045         */
046        @Override
047        public boolean preHandleAction(ActionRequest request, ActionResponse response, Object handler)
048                        throws Exception {
049
050                return preHandle(request, response, handler);
051        }
052
053        /**
054         * This implementation delegates to {@link #afterCompletion}.
055         */
056        @Override
057        public void afterActionCompletion(
058                        ActionRequest request, ActionResponse response, Object handler, Exception ex)
059                        throws Exception {
060
061                afterCompletion(request, response, handler, ex);
062        }
063
064
065        /**
066         * This implementation delegates to {@link #preHandle}.
067         */
068        @Override
069        public boolean preHandleRender(RenderRequest request, RenderResponse response, Object handler)
070                        throws Exception {
071
072                return preHandle(request, response, handler);
073        }
074
075        /**
076         * This implementation is empty.
077         */
078        @Override
079        public void postHandleRender(
080                        RenderRequest request, RenderResponse response, Object handler, ModelAndView modelAndView)
081                        throws Exception {
082        }
083
084        /**
085         * This implementation delegates to {@link #afterCompletion}.
086         */
087        @Override
088        public void afterRenderCompletion(
089                        RenderRequest request, RenderResponse response, Object handler, Exception ex)
090                        throws Exception {
091
092                afterCompletion(request, response, handler, ex);
093        }
094
095
096        /**
097         * This implementation delegates to {@link #preHandle}.
098         */
099        @Override
100        public boolean preHandleResource(ResourceRequest request, ResourceResponse response, Object handler)
101                        throws Exception {
102
103                return preHandle(request, response, handler);
104        }
105
106        /**
107         * This implementation is empty.
108         */
109        @Override
110        public void postHandleResource(
111                        ResourceRequest request, ResourceResponse response, Object handler, ModelAndView modelAndView)
112                        throws Exception {
113        }
114
115        /**
116         * This implementation delegates to {@link #afterCompletion}.
117         */
118        @Override
119        public void afterResourceCompletion(
120                        ResourceRequest request, ResourceResponse response, Object handler, Exception ex)
121                        throws Exception {
122
123                afterCompletion(request, response, handler, ex);
124        }
125
126
127        /**
128         * This implementation delegates to {@link #preHandle}.
129         */
130        @Override
131        public boolean preHandleEvent(EventRequest request, EventResponse response, Object handler)
132                        throws Exception {
133
134                return preHandle(request, response, handler);
135        }
136
137        /**
138         * This implementation delegates to {@link #afterCompletion}.
139         */
140        @Override
141        public void afterEventCompletion(
142                        EventRequest request, EventResponse response, Object handler, Exception ex)
143                        throws Exception {
144
145                afterCompletion(request, response, handler, ex);
146        }
147
148
149        /**
150         * Default callback that all "pre*" methods delegate to.
151         * <p>This implementation always returns {@code true}.
152         */
153        protected boolean preHandle(PortletRequest request, PortletResponse response, Object handler)
154                        throws Exception {
155
156                return true;
157        }
158
159        /**
160         * Default callback that all "after*" methods delegate to.
161         * <p>This implementation is empty.
162         */
163        protected void afterCompletion(
164                        PortletRequest request, PortletResponse response, Object handler, Exception ex)
165                        throws Exception {
166
167        }
168
169}