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