KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > taglibs > i18n > ResourceHelper


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.i18n;
18
19 import java.util.ArrayList JavaDoc;
20 import java.util.Iterator JavaDoc;
21 import java.util.List JavaDoc;
22 import java.util.Locale JavaDoc;
23 import java.util.ResourceBundle JavaDoc;
24 import java.util.StringTokenizer JavaDoc;
25
26 import javax.servlet.ServletRequest JavaDoc;
27
28 import javax.servlet.jsp.PageContext JavaDoc;
29 import javax.servlet.jsp.tagext.BodyTagSupport JavaDoc;
30
31
32 /**
33  * This class is used by the bundle and message tags for caching the
34  * ResourceBundle in the session and request.
35  *
36  * @author <a HREF="mailto:tdawson@wamnet.com">Tim Dawson</a>
37  *
38  */

39 public class ResourceHelper
40 {
41     public static final String JavaDoc BUNDLE_REQUEST_KEY =
42           "org.apache.taglibs.i18n.ResourceHelper.Bundle";
43
44     /**
45      * Retrieves the bundle cached in the page by a previous call to
46      * getBundle(PageContext,String). This is used by the MessageTag since
47      * the bundle name is provided once, by the BundleTag.
48      * @return java.util.ResourceBundle the cached bundle
49      */

50     static public ResourceBundle JavaDoc getBundle(PageContext JavaDoc pageContext)
51     {
52         return (ResourceBundle JavaDoc)pageContext.findAttribute(BUNDLE_REQUEST_KEY);
53     }
54
55     /**
56      * Caches the Bundle in the request using the BUNDLE_REQUEST_KEY.
57      */

58     static public void setBundle(PageContext JavaDoc pageContext,
59                                  ResourceBundle JavaDoc bundle,
60                                  int scope)
61     {
62         // put this in the page so that the getMessage tag can get it quickly
63
pageContext.setAttribute(BUNDLE_REQUEST_KEY,bundle,scope);
64     }
65   
66 }
67
Popular Tags