001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018 package org.apache.commons.resources.impl;
019
020 import org.apache.commons.resources.Resources;
021 import org.apache.commons.resources.ResourcesException;
022
023 /**
024 * <p>Concrete implementation of {@link org.apache.commons.resources.ResourcesFactory} that creates
025 * {@link org.apache.commons.resources.Resources} instances that wrap a family (one per Locale) of
026 * property files that share a base context-relative path for
027 * servlet context resources, and have name suffixes reflecting
028 * the Locale for which the file's messages apply. Resources are
029 * looked up in a hierarchy of files in a manner identical to that
030 * performed by <code>java.util.ResourceBundle.getBundle()</code>.</p>
031 *
032 * <p>The configuration variable passed to the <code>createResources()</code>
033 * method must be the context-relative base name of the properties file family,
034 * and must begin with a slash ('/') character.
035 * For example, if the configuration URL is passed as
036 * <code>/WEB-INF/resources/MyResources</code>, the resources for the
037 * <code>en_US</code> Locale would be stored under context resource
038 * <code>/WEB-INF/resources/MyReesources_en_US.properties</code>, and the
039 * default resources would be stored in
040 * <code>/WEB-INF/resources/MyResources.properties</code>.</p>
041 */
042 public class WebappPropertyResourcesFactory extends WebappResourcesFactoryBase {
043
044
045 /**
046 * <p>Create and return a new {@link org.apache.commons.resources.Resources} instance with the
047 * specified logical name, after calling its <code>init()</code>
048 * method and delegating the relevant properties.</p>
049 *
050 * @param name Logical name of the {@link org.apache.commons.resources.Resources} instance to create
051 * @param config Configuration string for this resource (if any)
052 * @return The new Resources instance.
053 *
054 * @exception ResourcesException if a {@link org.apache.commons.resources.Resources} instance
055 * of the specified logical name cannot be created.
056 */
057 protected Resources createResources(String name, String config) {
058
059 Resources res =
060 new WebappPropertyResources(name, config, getServletContext());
061 res.setReturnNull(isReturnNull());
062 res.init();
063 return (res);
064
065 }
066
067
068 }