Source Code Cross Referenced for SetCharacterEncodingFilter.java in  » Report » pentaho-report » org » pentaho » ui » servlet » 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 » Report » pentaho report » org.pentaho.ui.servlet 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2004 The Apache Software Foundation
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:         *     http://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:
017:        package org.pentaho.ui.servlet;
018:
019:        import java.io.IOException;
020:
021:        import javax.servlet.Filter;
022:        import javax.servlet.FilterChain;
023:        import javax.servlet.FilterConfig;
024:        import javax.servlet.ServletException;
025:        import javax.servlet.ServletRequest;
026:        import javax.servlet.ServletResponse;
027:
028:        /**
029:         * <p>Example filter that sets the character encoding to be used in parsing the
030:         * incoming request, either unconditionally or only if the client did not
031:         * specify a character encoding.  Configuration of this filter is based on
032:         * the following initialization parameters:</p>
033:         * <ul>
034:         * <li><strong>encoding</strong> - The character encoding to be configured
035:         *     for this request, either conditionally or unconditionally based on
036:         *     the <code>ignore</code> initialization parameter.  This parameter
037:         *     is required, so there is no default.</li>
038:         * <li><strong>ignore</strong> - If set to "true", any character encoding
039:         *     specified by the client is ignored, and the value returned by the
040:         *     <code>selectEncoding()</code> method is set.  If set to "false,
041:         *     <code>selectEncoding()</code> is called <strong>only</strong> if the
042:         *     client has not already specified an encoding.  By default, this
043:         *     parameter is set to "true".</li>
044:         * </ul>
045:         *
046:         * <p>Although this filter can be used unchanged, it is also easy to
047:         * subclass it and make the <code>selectEncoding()</code> method more
048:         * intelligent about what encoding to choose, based on characteristics of
049:         * the incoming request (such as the values of the <code>Accept-Language</code>
050:         * and <code>User-Agent</code> headers, or a value stashed in the current
051:         * user's session.</p>
052:         *
053:         * @author Craig McClanahan
054:         * @version $Revision: 267129 $ $Date: 2004-03-18 11:40:35 -0500 (Thu, 18 Mar 2004) $
055:         */
056:
057:        public class SetCharacterEncodingFilter implements  Filter {
058:
059:            // ----------------------------------------------------- Instance Variables
060:
061:            /**
062:             * The default character encoding to set for requests that pass through
063:             * this filter.
064:             */
065:            protected String encoding = null;
066:
067:            /**
068:             * The filter configuration object we are associated with.  If this value
069:             * is null, this filter instance is not currently configured.
070:             */
071:            protected FilterConfig filterConfig = null;
072:
073:            /**
074:             * Should a character encoding specified by the client be ignored?
075:             */
076:            protected boolean ignore = true;
077:
078:            // --------------------------------------------------------- Public Methods
079:
080:            /**
081:             * Take this filter out of service.
082:             */
083:            public void destroy() {
084:
085:                this .encoding = null;
086:                this .filterConfig = null;
087:
088:            }
089:
090:            /**
091:             * Select and set (if specified) the character encoding to be used to
092:             * interpret request parameters for this request.
093:             *
094:             * @param request The servlet request we are processing
095:             * @param result The servlet response we are creating
096:             * @param chain The filter chain we are processing
097:             *
098:             * @exception IOException if an input/output error occurs
099:             * @exception ServletException if a servlet error occurs
100:             */
101:            public void doFilter(ServletRequest request,
102:                    ServletResponse response, FilterChain chain)
103:                    throws IOException, ServletException {
104:
105:                // Conditionally select and set the character encoding to be used
106:                if (ignore || (request.getCharacterEncoding() == null)) {
107:                    String localEncoding = selectEncoding(request);
108:                    if (localEncoding != null)
109:                        request.setCharacterEncoding(localEncoding);
110:                }
111:
112:                // Pass control on to the next filter
113:                chain.doFilter(request, response);
114:
115:            }
116:
117:            /**
118:             * Place this filter into service.
119:             *
120:             * @param localFilterConfig The filter configuration object
121:             */
122:            public void init(FilterConfig localFilterConfig)
123:                    throws ServletException {
124:
125:                this .filterConfig = localFilterConfig;
126:                this .encoding = filterConfig.getInitParameter("encoding"); //$NON-NLS-1$
127:                String value = filterConfig.getInitParameter("ignore"); //$NON-NLS-1$
128:                if (value == null)
129:                    this .ignore = true;
130:                else if (value.equalsIgnoreCase("true")) //$NON-NLS-1$
131:                    this .ignore = true;
132:                else if (value.equalsIgnoreCase("yes")) //$NON-NLS-1$
133:                    this .ignore = true;
134:                else
135:                    this .ignore = false;
136:
137:            }
138:
139:            // ------------------------------------------------------ Protected Methods
140:
141:            /**
142:             * Select an appropriate character encoding to be used, based on the
143:             * characteristics of the current request and/or filter initialization
144:             * parameters.  If no character encoding should be set, return
145:             * <code>null</code>.
146:             * <p>
147:             * The default implementation unconditionally returns the value configured
148:             * by the <strong>encoding</strong> initialization parameter for this
149:             * filter.
150:             *
151:             * @param request The servlet request we are processing
152:             */
153:            protected String selectEncoding(ServletRequest request) {
154:
155:                return (this.encoding);
156:
157:            }
158:
159:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.