001 /* 002 * $Id: WebappXMLResourcesFactory.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 027 import org.apache.commons.resources.Resources; 028 import org.apache.commons.resources.ResourcesException; 029 030 /** 031 * <p>Concrete implementation of {@link org.apache.commons.resources.ResourcesFactory} that creates 032 * {@link org.apache.commons.resources.Resources} instances that wrap a family (one per Locale) of 033 * XML documents that share a base context-relative path for 034 * servlet context resources, and have name suffixes reflecting 035 * the Locale for which the document's messages apply. Resources are 036 * looked up in a hierarchy of documents in a manner identical to that 037 * performed by <code>java.util.ResourceBundle.getBundle()</code>.</p> 038 * 039 * <p>The configuration variable passed to the <code>createResources()</code> 040 * method must be the context-relative base name of the XML document family, 041 * and must begin with a slash ('/') character. 042 * For example, if the configuration URL is passed as 043 * <code>/WEB-INF/resources/MyResources</code>, the resources for the 044 * <code>en_US</code> Locale would be stored under context resource 045 * <code>/WEB-INF/resources/MyReesources_en_US.xml</code>, and the default 046 * resources would be stored in 047 * <code>/WEB-INF/resources/MyResources.xml</code>.</p> 048 */ 049 public class WebappXMLResourcesFactory extends WebappResourcesFactoryBase { 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 WebappXMLResources(name, config, getServletContext()); 067 res.setReturnNull(isReturnNull()); 068 res.init(); 069 return (res); 070 071 } 072 073 074 }