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 java.util.Locale;
018
019 import org.apache.hivemind.Location;
020 import org.apache.hivemind.Resource;
021 import org.apache.tapestry.IAsset;
022
023 /**
024 * A service which creates an asset. In some cases, the asset is selected based on the Resource
025 * (typically of the component or page specification).
026 *
027 * @author Howard M. Lewis Ship
028 * @since 4.0
029 */
030 public interface AssetFactory
031 {
032 /**
033 * Creates a new asset relative to an existing asset.
034 *
035 * @param baseResource
036 * the base resource from which an asset path may be calculated. Each type of asset
037 * is linked to a particular implemenation of {@link Resource}, and generates a
038 * corresponding implementation of {@link org.apache.tapestry.IAsset}.
039 * @param path
040 * the path relative to the resource (if no leading slash), or an absolute path
041 * within the domain of the asset type (i.e, within the classpath, or within the web
042 * application).
043 * @param locale
044 * the desired locale of the asset; the closest match will be used.
045 * @param location
046 * the location to be associated with the returned asset, or null to not attempt to
047 * localize the asset
048 * @throws org.apache.hivemind.ApplicationRuntimeException
049 * if no matching asset may be found.
050 */
051 public IAsset createAsset(Resource baseResource, String path, Locale locale, Location location);
052
053 /**
054 * Creates a new asset relative to the root of the domain defined by the type of asset.
055 *
056 * @param path
057 * the absolute path for the resource
058 * @param locale
059 * the locale to localize the asset to, or null for no localization
060 * @param location
061 * the location used to report any errors
062 * @return an {@link IAsset}
063 */
064 public IAsset createAbsoluteAsset(String path, Locale locale, Location location);
065
066 /**
067 * Creates a new asset based on a known resource.
068 */
069
070 public IAsset createAsset(Resource resource, Location location);
071 }