View Javadoc

1   /*
2    * $Id: PropertyResourcesFactory.java 349025 2005-11-25 21:09:54Z niallp $
3    * $Revision: 349025 $
4    * $Date: 2005-11-25 21:09:54 +0000 (Fri, 25 Nov 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 
31   * {@link org.apache.commons.resources.ResourcesFactory} that creates
32   * {@link org.apache.commons.resources.Resources} instances that wrap 
33   * a family (one per Locale) of properties files that share a base URL
34   * and have name suffices reflecting the Locale for which the document's 
35   * messages apply.  Resources are looked up in a hierarchy of documents 
36   * in a manner identical to that performed by 
37   * <code>java.util.ResourceBundle.getBundle()</code>.</p>
38   *
39   * <p>The configuration variable passed to the <code>createResources()</code>
40   * method must be the URL of the base name of the properties file family.
41   * For example, if the configuration URL is passed as
42   * <code>http://localhost/foo/Bar</code>, the resources for the
43   * <code>en_US</code> Locale would be stored under URL
44   * <code>http://localhost/foo/Bar_en_US.properties</code>, and the default
45   * resources would be stored in
46   * <code>http://localhost/foo/Bar.properties</code>.</p>
47   */
48  public class PropertyResourcesFactory extends ResourcesFactoryBase {
49  
50  
51      // ------------------------------------------------------ Protected Methods
52  
53  
54      /**
55       * <p>Create and return a new {@link org.apache.commons.resources.Resources} 
56       * instance with the specified logical name, after calling its <code>init()</code>
57       * method and delegating the relevant properties.</p>
58       *
59       * @param name Logical name of the {@link org.apache.commons.resources.Resources} 
60       * instance to create
61       * 
62       * @param config Configuration string for this resource (if any)
63       * @return The new Resources instance.
64       *
65       * @exception ResourcesException if a {@link org.apache.commons.resources.Resources} 
66       * instance of the specified logical name cannot be created.
67       */
68      protected Resources createResources(String name, String config) {
69  
70          Resources res = new PropertyResources(name, config);
71          res.setReturnNull(isReturnNull());
72          res.init();
73          return (res);
74  
75      }
76  
77  
78  }