001 /* 002 * $Id: WebappPropertyResourcesFactory.java 354539 2005-12-06 20:40:16Z niallp $ 003 * $Revision: 354539 $ 004 * $Date: 2005-12-06 20:40:16 +0000 (Tue, 06 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 org.apache.commons.resources.Resources; 027 import org.apache.commons.resources.ResourcesException; 028 029 /** 030 * <p>Concrete implementation of {@link org.apache.commons.resources.ResourcesFactory} that creates 031 * {@link org.apache.commons.resources.Resources} instances that wrap a family (one per Locale) of 032 * property files that share a base context-relative path for 033 * servlet context resources, and have name suffixes reflecting 034 * the Locale for which the file's messages apply. Resources are 035 * looked up in a hierarchy of files in a manner identical to that 036 * performed by <code>java.util.ResourceBundle.getBundle()</code>.</p> 037 * 038 * <p>The configuration variable passed to the <code>createResources()</code> 039 * method must be the context-relative base name of the properties file family, 040 * and must begin with a slash ('/') character. 041 * For example, if the configuration URL is passed as 042 * <code>/WEB-INF/resources/MyResources</code>, the resources for the 043 * <code>en_US</code> Locale would be stored under context resource 044 * <code>/WEB-INF/resources/MyReesources_en_US.properties</code>, and the 045 * default resources would be stored in 046 * <code>/WEB-INF/resources/MyResources.properties</code>.</p> 047 */ 048 public class WebappPropertyResourcesFactory extends WebappResourcesFactoryBase { 049 050 051 /** 052 * <p>Create and return a new {@link org.apache.commons.resources.Resources} instance with the 053 * specified logical name, after calling its <code>init()</code> 054 * method and delegating the relevant properties.</p> 055 * 056 * @param name Logical name of the {@link org.apache.commons.resources.Resources} instance to create 057 * @param config Configuration string for this resource (if any) 058 * @return The new Resources instance. 059 * 060 * @exception ResourcesException if a {@link org.apache.commons.resources.Resources} instance 061 * of the specified logical name cannot be created. 062 */ 063 protected Resources createResources(String name, String config) { 064 065 Resources res = 066 new WebappPropertyResources(name, config, getServletContext()); 067 res.setReturnNull(isReturnNull()); 068 res.init(); 069 return (res); 070 071 } 072 073 074 }