001 // Copyright 2005 The Apache Software Foundation
002 //
003 // Licensed under the Apache License, Version 2.0 (the "License");
004 // you may not use this file except in compliance with the License.
005 // You may obtain a copy of the License at
006 //
007 // http://www.apache.org/licenses/LICENSE-2.0
008 //
009 // Unless required by applicable law or agreed to in writing, software
010 // distributed under the License is distributed on an "AS IS" BASIS,
011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012 // See the License for the specific language governing permissions and
013 // limitations under the License.
014
015 package org.apache.tapestry.asset;
016
017 import org.apache.hivemind.Location;
018 import org.apache.hivemind.Resource;
019 import org.apache.tapestry.IAsset;
020 import org.apache.tapestry.spec.IComponentSpecification;
021
022 import java.util.Locale;
023
024 /**
025 * Used to create an {@link org.apache.tapestry.IAsset} instance for a particular asset path. The
026 * path may have a prefix that indicates its type, or it may be relative to some existing resource.
027 *
028 * @author Howard M. Lewis Ship
029 * @since 4.0
030 */
031 public interface AssetSource
032 {
033 /**
034 * Finds an asset relative to some existing resource (typically, a page, component or library
035 * specification).
036 *
037 * @param base
038 * The base resource used for resolving the asset
039 * @param path
040 * the path relative to the base resource; alternately, the path may include a prefix
041 * that defines a domain (such as "classpath:" or "context:") in which case the base
042 * resource is ignored and the resource resolved within that domain
043 * @param locale
044 * used to find a localized version of the asset, may be null to indicate no
045 * localization
046 * @param location
047 * used to report errors (such as missing resources)
048 *
049 * @return the asset, possibly localized
050 *
051 * @throws org.apache.hivemind.ApplicationRuntimeException
052 * if the asset does not exist
053 */
054 IAsset findAsset(Resource base, String path, Locale locale, Location location);
055
056 /**
057 * Finds an asset relative to the specified <code>base</code> resources OR {@link IComponentSpecification} passed in.
058 *
059 * @param base
060 * The base resource used for resolving the asset
061 * @param spec
062 * The specification the resource may be relative to if not found relative to base.
063 * @param path
064 * the path relative to the base resource; alternately, the path may include a prefix
065 * that defines a domain (such as "classpath:" or "context:") in which case the base
066 * resource is ignored and the resource resolved within that domain
067 * @param locale
068 * used to find a localized version of the asset, may be null to indicate no
069 * localization
070 * @param location
071 * used to report errors (such as missing resources)
072 *
073 * @return the asset, possibly localized
074 */
075 IAsset findAsset(Resource base, IComponentSpecification spec, String path, Locale locale, Location location);
076 }