Source Code Cross Referenced for RequestProxy.java in  » Portal » DLOG4J » dlog4j » proxy » 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 » Portal » DLOG4J » dlog4j.proxy 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  This program is free software; you can redistribute it and/or modify
003:         *  it under the terms of the GNU General Public License as published by
004:         *  the Free Software Foundation; either version 2 of the License, or
005:         *  (at your option) any later version.
006:         *
007:         *  This program is distributed in the hope that it will be useful,
008:         *  but WITHOUT ANY WARRANTY; without even the implied warranty of
009:         *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
010:         *  GNU Library General Public License for more details.
011:         *
012:         *  You should have received a copy of the GNU General Public License
013:         *  along with this program; if not, write to the Free Software
014:         *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
015:         */
016:        package dlog4j.proxy;
017:
018:        import java.lang.reflect.InvocationHandler;
019:        import java.lang.reflect.InvocationTargetException;
020:        import java.lang.reflect.Method;
021:        import java.lang.reflect.Proxy;
022:        import java.util.HashMap;
023:        import java.util.Iterator;
024:        import java.util.Map;
025:
026:        import javax.servlet.ServletException;
027:        import javax.servlet.ServletRequest;
028:        import javax.servlet.http.HttpServletRequest;
029:
030:        /**
031:         * HttpServletRequest的代理
032:         * 用于进行参数编码的统一处理
033:         * @author liudong
034:         */
035:        public class RequestProxy implements  InvocationHandler {
036:            final static String METHOD_GP = "getParameter";
037:            final static String METHOD_GPM = "getParameterMap";
038:            final static String METHOD_GPN = "getParameterNames";
039:            final static String METHOD_GPV = "getParameterValues";
040:
041:            final static String ENC_8859_1 = "8859_1";
042:            final static String ENC_UTF_8 = "UTF-8";
043:
044:            protected String encoding;
045:
046:            public String getEncoding() {
047:                return encoding;
048:            }
049:
050:            public void setEncoding(String encoding) {
051:                this .encoding = encoding;
052:            }
053:
054:            private ServletRequest req;
055:
056:            /**
057:             * 获取代理实例
058:             * @param servlet
059:             * @param request
060:             * @return
061:             * @throws ServletException
062:             */
063:            public final static RequestProxy getProxy(ServletRequest req,
064:                    String encoding) throws ServletException {
065:                return new RequestProxy(req, encoding);
066:            }
067:
068:            private RequestProxy(ServletRequest req, String encoding) {
069:                this .req = req;
070:                this .encoding = encoding;
071:            }
072:
073:            /* (non-Javadoc)
074:             * @see java.lang.reflect.InvocationHandler#invoke(java.lang.Object, java.lang.reflect.Method, java.lang.Object[])
075:             */
076:            public Object invoke(Object proxy, Method m, Object[] args)
077:                    throws Throwable {
078:                //调用相应的操作
079:                Object obj = null;
080:                String encode = (encoding == null) ? ENC_UTF_8 : encoding;
081:                try {
082:                    obj = m.invoke(req, args);
083:                    if (obj != null) {
084:                        String mn = m.getName();
085:                        if (METHOD_GP.equals(mn)) {
086:                            String value = (String) obj;
087:                            obj = new String(value.getBytes(ENC_8859_1), encode);
088:                        } else if (METHOD_GPV.equals(mn)) {
089:                            String[] values = (String[]) obj;
090:                            for (int i = 0; i < values.length; i++)
091:                                values[i] = new String(values[i]
092:                                        .getBytes(ENC_8859_1), encode);
093:                            obj = values;
094:                        } else if (METHOD_GPM.equals(mn)) {
095:                            Map params = (Map) obj;
096:                            HashMap new_params = new HashMap();
097:                            Iterator iter = params.keySet().iterator();
098:                            while (iter.hasNext()) {
099:                                String key = (String) iter.next();
100:                                Object oValue = params.get(key);
101:                                if (oValue.getClass().isArray()) {
102:                                    String[] values = (String[]) params
103:                                            .get(key);
104:                                    for (int i = 0; i < values.length; i++)
105:                                        values[i] = new String(values[i]
106:                                                .getBytes(ENC_8859_1), encode);
107:                                    new_params.put(key, values);
108:                                } else {
109:                                    String value = (String) params.get(key);
110:                                    String new_value = (value != null) ? new String(
111:                                            value.getBytes(ENC_8859_1), encode)
112:                                            : null;
113:                                    new_params.put(key, new_value);
114:                                }
115:                            }
116:                        }
117:                    }
118:                } catch (InvocationTargetException e) {
119:                    throw e.getTargetException();
120:                }
121:                return obj;
122:            }
123:
124:            /* (non-Javadoc)
125:             * @see ibibio.goweb.http.ObjectProxy#getInstance()
126:             */
127:            public HttpServletRequest getInstance() {
128:                return (HttpServletRequest) Proxy.newProxyInstance(req
129:                        .getClass().getClassLoader(), request_cls, this );
130:            }
131:
132:            final static Class[] request_cls = new Class[] { HttpServletRequest.class };
133:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.