Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
WebappPropertyResourcesFactory |
|
| 1.0;1 |
1 | /* | |
2 | * $Id: WebappPropertyResourcesFactory.java 354539 2005-12-06 20:40:16Z niallp $ | |
3 | * $Revision: 354539 $ | |
4 | * $Date: 2005-12-06 20:40:16 +0000 (Tue, 06 Dec 2005) $ | |
5 | * | |
6 | * ==================================================================== | |
7 | * | |
8 | * Copyright 2003-2005 The Apache Software Foundation | |
9 | * | |
10 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
11 | * you may not use this file except in compliance with the License. | |
12 | * You may obtain a copy of the License at | |
13 | * | |
14 | * http://www.apache.org/licenses/LICENSE-2.0 | |
15 | * | |
16 | * Unless required by applicable law or agreed to in writing, software | |
17 | * distributed under the License is distributed on an "AS IS" BASIS, | |
18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
19 | * See the License for the specific language governing permissions and | |
20 | * limitations under the License. | |
21 | * | |
22 | */ | |
23 | ||
24 | package org.apache.commons.resources.impl; | |
25 | ||
26 | import org.apache.commons.resources.Resources; | |
27 | import org.apache.commons.resources.ResourcesException; | |
28 | ||
29 | /** | |
30 | * <p>Concrete implementation of {@link org.apache.commons.resources.ResourcesFactory} that creates | |
31 | * {@link org.apache.commons.resources.Resources} instances that wrap a family (one per Locale) of | |
32 | * property files that share a base context-relative path for | |
33 | * servlet context resources, and have name suffixes reflecting | |
34 | * the Locale for which the file's messages apply. Resources are | |
35 | * looked up in a hierarchy of files in a manner identical to that | |
36 | * performed by <code>java.util.ResourceBundle.getBundle()</code>.</p> | |
37 | * | |
38 | * <p>The configuration variable passed to the <code>createResources()</code> | |
39 | * method must be the context-relative base name of the properties file family, | |
40 | * and must begin with a slash ('/') character. | |
41 | * For example, if the configuration URL is passed as | |
42 | * <code>/WEB-INF/resources/MyResources</code>, the resources for the | |
43 | * <code>en_US</code> Locale would be stored under context resource | |
44 | * <code>/WEB-INF/resources/MyReesources_en_US.properties</code>, and the | |
45 | * default resources would be stored in | |
46 | * <code>/WEB-INF/resources/MyResources.properties</code>.</p> | |
47 | */ | |
48 | 0 | public class WebappPropertyResourcesFactory extends WebappResourcesFactoryBase { |
49 | ||
50 | ||
51 | /** | |
52 | * <p>Create and return a new {@link org.apache.commons.resources.Resources} instance with the | |
53 | * specified logical name, after calling its <code>init()</code> | |
54 | * method and delegating the relevant properties.</p> | |
55 | * | |
56 | * @param name Logical name of the {@link org.apache.commons.resources.Resources} instance to create | |
57 | * @param config Configuration string for this resource (if any) | |
58 | * @return The new Resources instance. | |
59 | * | |
60 | * @exception ResourcesException if a {@link org.apache.commons.resources.Resources} instance | |
61 | * of the specified logical name cannot be created. | |
62 | */ | |
63 | protected Resources createResources(String name, String config) { | |
64 | ||
65 | 0 | Resources res = |
66 | new WebappPropertyResources(name, config, getServletContext()); | |
67 | 0 | res.setReturnNull(isReturnNull()); |
68 | 0 | res.init(); |
69 | 0 | return (res); |
70 | ||
71 | } | |
72 | ||
73 | ||
74 | } |