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
025     * {@link org.apache.commons.resources.ResourcesFactory} that creates
026     * {@link org.apache.commons.resources.Resources} instances that wrap
027     * a family (one per Locale) of properties files that share a base URL
028     * and have name suffices reflecting the Locale for which the document's
029     * messages apply.  Resources are looked up in a hierarchy of documents
030     * in a manner identical to that performed by
031     * <code>java.util.ResourceBundle.getBundle()</code>.</p>
032     *
033     * <p>The configuration variable passed to the <code>createResources()</code>
034     * method must be the URL of the base name of the properties file family.
035     * For example, if the configuration URL is passed as
036     * <code>http://localhost/foo/Bar</code>, the resources for the
037     * <code>en_US</code> Locale would be stored under URL
038     * <code>http://localhost/foo/Bar_en_US.properties</code>, and the default
039     * resources would be stored in
040     * <code>http://localhost/foo/Bar.properties</code>.</p>
041     */
042    public class PropertyResourcesFactory extends ResourcesFactoryBase {
043    
044    
045        // ------------------------------------------------------ Protected Methods
046    
047    
048        /**
049         * <p>Create and return a new {@link org.apache.commons.resources.Resources}
050         * instance with the specified logical name, after calling its <code>init()</code>
051         * method and delegating the relevant properties.</p>
052         *
053         * @param name Logical name of the {@link org.apache.commons.resources.Resources}
054         * instance to create
055         *
056         * @param config Configuration string for this resource (if any)
057         * @return The new Resources instance.
058         *
059         * @exception ResourcesException if a {@link org.apache.commons.resources.Resources}
060         * instance of the specified logical name cannot be created.
061         */
062        protected Resources createResources(String name, String config) {
063    
064            Resources res = new PropertyResources(name, config);
065            res.setReturnNull(isReturnNull());
066            res.init();
067            return (res);
068    
069        }
070    
071    
072    }