PrefixedResources.java

/***************************************************************************
   Copyright 2014 Emily Estes

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
***************************************************************************/
package net.metanotion.simpletemplate;


/** This is a resource factory that prefixes a path to resource requests from a delegated resource factory. */
public final class PrefixedResources implements ResourceFactory {
	private final String prefix;
	private final ResourceFactory resources;
	/** Create a new prefixed resource factory.
		@param prefix The prefix to prepend to resource requests.
		@param resources The factory to delegate requests to.
	*/
	public PrefixedResources(final String prefix, final ResourceFactory resources) {
		this.prefix = prefix;
		this.resources = resources;
	}

	@Override public Resource get(final String urn) { return this.resources.get(prefix + urn); }
}