KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > guiframework > event > handlers > ResourceBundleHandlers


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.tools.guiframework.event.handlers;
25
26 import com.iplanet.jato.RequestContext;
27
28 import com.sun.enterprise.tools.guiframework.view.HandlerContext;
29 import com.sun.enterprise.tools.guiframework.exception.FrameworkException;
30
31 import com.sun.web.ui.common.CCI18N;
32
33 import java.util.List JavaDoc;
34 import java.util.Map JavaDoc;
35
36
37 /**
38  * This class defines a Source mappings from a resource bundle value.
39  */

40 public class ResourceBundleHandlers {
41
42     /**
43      * This method retrieves a localized String from a resource bundle. The
44      * resource bundle should be stored on one of the parent ViewDescriptors
45      * of this mapper. The closest one will be used. Optionally you can
46      * explicitly pass in the "resourceBundle" to use.
47      *
48      * @param reqCtx The RequestContext
49      * @param handlerCtx The HandlerContext
50      */

51     public void getMessage(RequestContext reqCtx, HandlerContext handlerCtx) {
52     // Get the key
53
String JavaDoc key = (String JavaDoc)handlerCtx.getInputValue(KEY);
54     if (key == null) {
55         throw new FrameworkException("'"+KEY+
56         "' is required by ResourceBundleMapper.getMappedSource().");
57     }
58
59     // Get the resource bundle to use
60
String JavaDoc bundle = (String JavaDoc)handlerCtx.getInputValue(RESOURCE_BUNDLE);
61     if (bundle == null) {
62         bundle = handlerCtx.getViewDescriptor().getResourceBundle();
63     }
64     if (bundle == null) {
65         throw new FrameworkException("Resource bundle was not specified!");
66     }
67
68     // Create a CCI18N object to help us out
69
CCI18N i18n = new CCI18N(reqCtx, bundle); //, null, null);
70

71     // Get the optional list of arguments...
72
Object JavaDoc args = handlerCtx.getInputValue(ARGS);
73     if (args instanceof List JavaDoc) {
74         args = ((List JavaDoc)args).toArray();
75     } else if (args != null) {
76         args = new Object JavaDoc[] {args};
77     }
78
79     // Return the result
80
handlerCtx.setOutputValue(
81         VALUE, i18n.getMessage(key, (Object JavaDoc [])args));
82     }
83
84
85     /**
86      *
87      */

88     public static final String JavaDoc VALUE = "value";
89
90     /**
91      * This parameter refers to the key within the resource bundle to use.
92      */

93     public static final String JavaDoc KEY = "key";
94
95     /**
96      * This parameter can specify 0 or more arguments to be inserted into the
97      * localized message.
98      */

99     public static final String JavaDoc ARGS = "arguments";
100
101     /**
102      * This optional parameter specifies the resourceBundle to use, this has
103      * the highest precedence if used.
104      */

105     public static final String JavaDoc RESOURCE_BUNDLE = "resourceBundle";
106 }
107
Popular Tags