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  
21  import org.apache.commons.resources.Resources;
22  import org.apache.commons.resources.ResourcesException;
23  
24  /**
25   * <p>Concrete implementation of {@link org.apache.commons.resources.ResourcesFactory} that creates
26   * {@link org.apache.commons.resources.Resources} instances that wrap a family (one per Locale) of
27   * XML documents that share a base context-relative path for
28   * servlet context resources, and have name suffixes reflecting
29   * the Locale for which the document's messages apply.  Resources are
30   * looked up in a hierarchy of documents in a manner identical to that
31   * performed by <code>java.util.ResourceBundle.getBundle()</code>.</p>
32   *
33   * <p>The configuration variable passed to the <code>createResources()</code>
34   * method must be the context-relative base name of the XML document family,
35   * and must begin with a slash ('/') character.
36   * For example, if the configuration URL is passed as
37   * <code>/WEB-INF/resources/MyResources</code>, the resources for the
38   * <code>en_US</code> Locale would be stored under context resource
39   * <code>/WEB-INF/resources/MyReesources_en_US.xml</code>, and the default
40   * resources would be stored in
41   * <code>/WEB-INF/resources/MyResources.xml</code>.</p>
42   */
43  public class WebappXMLResourcesFactory extends WebappResourcesFactoryBase {
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 WebappXMLResources(name, config, getServletContext());
61          res.setReturnNull(isReturnNull());
62          res.init();
63          return (res);
64  
65      }
66  
67  
68  }