KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > taglibs > standard > tag > common > fmt > RequestEncodingSupport


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.taglibs.standard.tag.common.fmt;
18
19 import java.io.UnsupportedEncodingException JavaDoc;
20
21 import javax.servlet.jsp.JspException JavaDoc;
22 import javax.servlet.jsp.JspTagException JavaDoc;
23 import javax.servlet.jsp.PageContext JavaDoc;
24 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
25
26 /**
27  * Support for tag handlers for <requestEncoding>, the tag for setting
28  * the request character encoding in JSTL 1.0.
29  *
30  * @author Jan Luehe
31  * @author Pierre Delisle
32  */

33
34 public abstract class RequestEncodingSupport extends TagSupport JavaDoc {
35
36     //*********************************************************************
37
// Package-scoped constants
38

39     static final String JavaDoc REQUEST_CHAR_SET =
40     "javax.servlet.jsp.jstl.fmt.request.charset";
41
42
43     //*********************************************************************
44
// Private constants
45

46     private static final String JavaDoc DEFAULT_ENCODING = "ISO-8859-1";
47
48
49     //*********************************************************************
50
// Tag attributes
51

52     protected String JavaDoc value; // 'value' attribute
53

54
55     //*********************************************************************
56
// Derived information
57

58     protected String JavaDoc charEncoding; // derived from 'value' attribute
59

60
61     //*********************************************************************
62
// Constructor and initialization
63

64     public RequestEncodingSupport() {
65     super();
66     init();
67     }
68
69     private void init() {
70     value = null;
71     }
72
73
74     //*********************************************************************
75
// Tag logic
76

77     public int doEndTag() throws JspException JavaDoc {
78         charEncoding = value;
79     if ((charEncoding == null)
80             && (pageContext.getRequest().getCharacterEncoding() == null)) {
81             // Use charset from session-scoped attribute
82
charEncoding = (String JavaDoc)
83         pageContext.getAttribute(REQUEST_CHAR_SET,
84                      PageContext.SESSION_SCOPE);
85         if (charEncoding == null) {
86         // Use default encoding
87
charEncoding = DEFAULT_ENCODING;
88         }
89     }
90
91     /*
92      * If char encoding was already set in the request, we don't need to
93      * set it again.
94      */

95     if (charEncoding != null) {
96         try {
97         pageContext.getRequest().setCharacterEncoding(charEncoding);
98         } catch (UnsupportedEncodingException JavaDoc uee) {
99         throw new JspTagException JavaDoc(uee.toString(), uee);
100         }
101     }
102
103     return EVAL_PAGE;
104     }
105
106     // Releases any resources we may have (or inherit)
107
public void release() {
108     init();
109     }
110 }
111
Popular Tags