KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > javabb > interceptor > ParameterInterceptor


1 package org.javabb.interceptor;
2
3 import java.util.Iterator JavaDoc;
4 import java.util.Map JavaDoc;
5
6 import org.apache.commons.lang.StringUtils;
7
8 import com.opensymphony.xwork.ActionContext;
9 import com.opensymphony.xwork.ActionInvocation;
10 import com.opensymphony.xwork.interceptor.Interceptor;
11
12 /*
13  * Copyright 2004 JavaFree.org
14  *
15  * Licensed under the Apache License, Version 2.0 (the "License");
16  * you may not use this file except in compliance with the License.
17  * You may obtain a copy of the License at
18  *
19  * http://www.apache.org/licenses/LICENSE-2.0
20  *
21  * Unless required by applicable law or agreed to in writing, software
22  * distributed under the License is distributed on an "AS IS" BASIS,
23  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24  * See the License for the specific language governing permissions and
25  * limitations under the License.
26  */

27
28 /**
29  * $Id: ParameterInterceptor.java,v 1.3.8.2 2006/04/17 17:47:08 daltoncamargo Exp $
30  * @author Ronald Tetsuo Miura
31  */

32 public class ParameterInterceptor implements Interceptor {
33
34     String JavaDoc allowedBeans = "";
35
36     /**
37      * @param allowedBeans
38      */

39     public void setAllowedBeans(String JavaDoc[] allowedBeans) {
40         this.allowedBeans = StringUtils.join(allowedBeans, '|');
41     }
42
43     /**
44      * @see com.opensymphony.xwork.interceptor.Interceptor#intercept(com.opensymphony.xwork.ActionInvocation)
45      */

46     public String JavaDoc intercept(ActionInvocation invocation) throws Exception JavaDoc {
47         String JavaDoc regex = "^(?:" + allowedBeans + ")?\\.?[^.]*$";
48
49         Map JavaDoc parameters = ActionContext.getContext().getParameters();
50         Iterator JavaDoc it = parameters.keySet().iterator();
51         while (it.hasNext()) {
52             String JavaDoc param = (String JavaDoc) it.next();
53             if (!param.matches(regex)) {
54                 it.remove();
55             }
56         }
57         return invocation.invoke();
58     }
59
60     /**
61      * @see com.opensymphony.xwork.interceptor.Interceptor#destroy()
62      */

63     public void destroy() {
64         // TODO Auto-generated method stub
65
}
66
67     /**
68      * @see com.opensymphony.xwork.interceptor.Interceptor#init()
69      */

70     public void init() {
71         // TODO Auto-generated method stub
72
}
73 }
74
Popular Tags