View Javadoc

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