01: // Copyright 2006, 2007 The Apache Software Foundation
02: //
03: // Licensed under the Apache License, Version 2.0 (the "License");
04: // you may not use this file except in compliance with the License.
05: // You may obtain a copy of the License at
06: //
07: // http://www.apache.org/licenses/LICENSE-2.0
08: //
09: // Unless required by applicable law or agreed to in writing, software
10: // distributed under the License is distributed on an "AS IS" BASIS,
11: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: // See the License for the specific language governing permissions and
13: // limitations under the License.
14:
15: package org.apache.tapestry.services;
16:
17: import java.util.Locale;
18:
19: import org.apache.tapestry.Asset;
20: import org.apache.tapestry.ioc.Resource;
21: import org.apache.tapestry.ioc.services.ThreadLocale;
22:
23: /**
24: * Used to find or create an {@link Asset} with a given path.
25: */
26: public interface AssetSource {
27: /**
28: * Finds the asset. The path may either be a simple file name or a relative path (relative to
29: * the base resource) <em>or</em> it may have a prefix, such as "context:" or "classpath:", in
30: * which case it is treated as a complete path within the indicated domain. The resulting
31: * Resource is then localized (to the provided Locale) and returned as an Asset.
32: * <p>
33: * The AssetSource caches its results, so a single Asset instance may be shared among many
34: * different components.
35: *
36: * @param baseResource
37: * base resource for computing relative paths, or null to search the classpath
38: * @param path
39: * relative to the base resource
40: * @param locale
41: * locale to localize the final resource to, or null for the thread's current locale
42: * @return the asset
43: */
44: Asset findAsset(Resource baseResource, String path, Locale locale);
45:
46: /**
47: * Convienience for finding assets on the classpath.
48: *
49: * @param path
50: * path to the base resource, relative to classpath root
51: * @param locale
52: * to localize the resource to
53: * @return the asset
54: */
55: Asset getClasspathAsset(String path, Locale locale);
56:
57: /**
58: * Obtains a classpath alias in the current locale (as defined by the {@link ThreadLocale}
59: * service).
60: *
61: * @param path
62: * @return the asset
63: */
64: Asset getClasspathAsset(String path);
65: }
|