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