001    /*
002     * $Id: CollResources.java 354761 2005-12-07 15:11:58Z niallp $
003     * $Revision: 354761 $
004     * $Date: 2005-12-07 15:11:58 +0000 (Wed, 07 Dec 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 java.util.HashMap;
027    import java.util.Locale;
028    import java.util.Map;
029    
030    /**
031     * <p>Concrete implementation of {@link org.apache.commons.resources.Resources} for unit tests.</p>
032     *
033     * <p><strong>IMPLEMENTATION NOTE</strong> - The set of hard-coded resource
034     * maps returned by <code>getLocaleMap()</code> below must *exactly*
035     * match the resources stored in the <code>TestResources*.properties</code>
036     * and <code>TestResources*.xml</code> resource files.</p>
037     */
038    public class CollResources extends CollectionResourcesBase {
039    
040    
041        // ----------------------------------------------------------- Constructors
042    
043    
044        // Construct a test instance with the specified name and base URL
045        public CollResources(String name, String base) {
046            super(name, base);
047        }
048    
049    
050        // ----------------------------------------------------- Instance Variables
051    
052    
053        // ------------------------------------------------------ Lifecycle Methods
054    
055    
056        // ------------------------------------------------------------- Properties
057    
058    
059        // ---------------------------------------------- Content Retrieval Methods
060    
061    
062        // Concrete implementation of getLocaleMap()
063        protected Map getLocaleMap(String baseUrl, Locale locale) {
064    
065            String language = locale.getLanguage();
066            String country = locale.getCountry();
067            String variant = locale.getVariant();
068            if (variant.length() > 0) {
069                return (new HashMap());
070            }
071    
072            if (language.equals("en")) {
073                if (country.equals("US")) {
074                    Map map = new HashMap();
075                    map.put("test.specific", "[en_US] SPECIFIC");
076                    return (map);
077                } else if (country.equals("")) {
078                    Map map = new HashMap();
079                    map.put("test.specific", "[en] SPECIFIC");
080                    map.put("test.inherit", "[en] INHERIT");
081                    return (map);
082                } else {
083                    return (new HashMap());
084                }
085            } else if (language.equals("fr")) {
086                if (country.equals("")) {
087                    Map map = new HashMap();
088                    map.put("test.specific", "[fr] SPECIFIC");
089                    map.put("test.inherit", "[fr] INHERIT");
090                    return (map);
091                } else {
092                    return (new HashMap());
093                }
094            } else if (language.equals("")) {
095                if (country.equals("")) {
096                    Map map = new HashMap();
097                    map.put("test.base", "[Base] ONLY");
098                    map.put("test.specific", "[Base] SPECIFIC");
099                    map.put("test.inherit", "[Base] INHERIT");
100                    map.put("test.message", "[Base] REPLACE {0} WITH {1}");
101                    map.put("test.message.single", "[Base] TEST MSG SINGLE");
102                    return (map);
103                } else {
104                    return (new HashMap());
105                }
106            } else {
107                return (new HashMap());
108            }
109        }
110    
111    
112    }