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