001 /*
002 * $Id: PropertyResourcesFactory.java 349025 2005-11-25 21:09:54Z niallp $
003 * $Revision: 349025 $
004 * $Date: 2005-11-25 21:09:54 +0000 (Fri, 25 Nov 2005) $
005 *
006 * ====================================================================
007 *
008 * Copyright 2003-2005 The Apache Software Foundation
009 *
010 * Licensed under the Apache License, Version 2.0 (the "License");
011 * you may not use this file except in compliance with the License.
012 * You may obtain a copy of the License at
013 *
014 * http://www.apache.org/licenses/LICENSE-2.0
015 *
016 * Unless required by applicable law or agreed to in writing, software
017 * distributed under the License is distributed on an "AS IS" BASIS,
018 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
019 * See the License for the specific language governing permissions and
020 * limitations under the License.
021 *
022 */
023
024 package org.apache.commons.resources.impl;
025
026 import org.apache.commons.resources.Resources;
027 import org.apache.commons.resources.ResourcesException;
028
029 /**
030 * <p>Concrete implementation of
031 * {@link org.apache.commons.resources.ResourcesFactory} that creates
032 * {@link org.apache.commons.resources.Resources} instances that wrap
033 * a family (one per Locale) of properties files that share a base URL
034 * and have name suffices reflecting the Locale for which the document's
035 * messages apply. Resources are looked up in a hierarchy of documents
036 * in a manner identical to that performed by
037 * <code>java.util.ResourceBundle.getBundle()</code>.</p>
038 *
039 * <p>The configuration variable passed to the <code>createResources()</code>
040 * method must be the URL of the base name of the properties file family.
041 * For example, if the configuration URL is passed as
042 * <code>http://localhost/foo/Bar</code>, the resources for the
043 * <code>en_US</code> Locale would be stored under URL
044 * <code>http://localhost/foo/Bar_en_US.properties</code>, and the default
045 * resources would be stored in
046 * <code>http://localhost/foo/Bar.properties</code>.</p>
047 */
048 public class PropertyResourcesFactory extends ResourcesFactoryBase {
049
050
051 // ------------------------------------------------------ Protected Methods
052
053
054 /**
055 * <p>Create and return a new {@link org.apache.commons.resources.Resources}
056 * instance with the specified logical name, after calling its <code>init()</code>
057 * method and delegating the relevant properties.</p>
058 *
059 * @param name Logical name of the {@link org.apache.commons.resources.Resources}
060 * instance to create
061 *
062 * @param config Configuration string for this resource (if any)
063 * @return The new Resources instance.
064 *
065 * @exception ResourcesException if a {@link org.apache.commons.resources.Resources}
066 * instance of the specified logical name cannot be created.
067 */
068 protected Resources createResources(String name, String config) {
069
070 Resources res = new PropertyResources(name, config);
071 res.setReturnNull(isReturnNull());
072 res.init();
073 return (res);
074
075 }
076
077
078 }