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