Coverage Report - org.apache.tapestry5.services.AssetSource
 
Classes in this File Line Coverage Branch Coverage Complexity
AssetSource
N/A
N/A
0
 
 1  
 // Copyright 2006, 2007, 2008, 2009 The Apache Software Foundation
 2  
 //
 3  
 // Licensed under the Apache License, Version 2.0 (the "License");
 4  
 // you may not use this file except in compliance with the License.
 5  
 // You may obtain a copy of the License at
 6  
 //
 7  
 //     http://www.apache.org/licenses/LICENSE-2.0
 8  
 //
 9  
 // 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.tapestry5.services;
 16  
 
 17  
 import org.apache.tapestry5.Asset;
 18  
 import org.apache.tapestry5.ioc.Resource;
 19  
 import org.apache.tapestry5.ioc.annotations.UsesMappedConfiguration;
 20  
 import org.apache.tapestry5.ioc.services.ThreadLocale;
 21  
 
 22  
 import java.util.Locale;
 23  
 
 24  
 /**
 25  
  * Used to find or create an {@link org.apache.tapestry5.Asset} with a given path.
 26  
  * <p/>
 27  
  * Assets are defined with a domain, and the domain is indicated by a prefix.  The two builtin domains are "context:"
 28  
  * (for files inside the web application context) and "classpath:" for files stored on the classpath (typically, inside
 29  
  * a JAR, such as a component library). Other domains can be defined via contributions to the AssetSource service.
 30  
  * <p/>
 31  
  * Since 5.1.0.0, is is preferred that {@link org.apache.tapestry5.services.AssetFactory#createAsset(org.apache.tapestry5.ioc.Resource)}
 32  
  * return an instance of {@link org.apache.tapestry5.Asset2}.
 33  
  */
 34  
 @UsesMappedConfiguration(AssetFactory.class)
 35  
 public interface AssetSource
 36  
 {
 37  
     /**
 38  
      * Finds the asset. The path may either be a simple file name or a relative path (relative to the base resource)
 39  
      * <em>or</em> it may have a prefix, such as "context:" or "classpath:", in which case it is treated as a complete
 40  
      * path within the indicated domain. The resulting Resource is then localized (to the provided Locale) and returned
 41  
      * as an Asset.
 42  
      * <p/>
 43  
      * The AssetSource caches its results, so a single Asset instance may be shared among many different components.
 44  
      *
 45  
      * @param baseResource base resource for computing relative paths, or null to search the classpath
 46  
      * @param path         relative to the base resource
 47  
      * @param locale       locale to localize the final resource to, or null for the thread's current locale
 48  
      * @return the asset
 49  
      * @throws RuntimeException if the asset can not be found
 50  
      */
 51  
     Asset getAsset(Resource baseResource, String path, Locale locale);
 52  
 
 53  
     /**
 54  
      * Finds the asset, either on the classpath or (if prefixed), within the indicated domain. The result is not
 55  
      * localized. The underlying Asset may not exist.
 56  
      *
 57  
      * @param path to the resource to provide as an Asset
 58  
      * @return Resource for the path (the Resource may not exist)
 59  
      * @since 5.1.0.0
 60  
      */
 61  
     Resource resourceForPath(String path);
 62  
 
 63  
     /**
 64  
      * Convienience for finding assets on the classpath.
 65  
      *
 66  
      * @param path   path to the base resource, relative to classpath root
 67  
      * @param locale to localize the resource to
 68  
      * @return the asset
 69  
      * @throws RuntimeException if the asset can not be found
 70  
      */
 71  
     Asset getClasspathAsset(String path, Locale locale);
 72  
 
 73  
     /**
 74  
      * Convienience for finding assets in the context.
 75  
      *
 76  
      * @param path   path relative to the base resource (the context root)
 77  
      * @param locale to localize the resource to, or null for the locale for the current request
 78  
      * @return the asset
 79  
      * @throws RuntimeException if the asset can not be found
 80  
      * @since 5.1.0.0
 81  
      */
 82  
     Asset getContextAsset(String path, Locale locale);
 83  
 
 84  
     /**
 85  
      * Obtains a classpath alias in the current locale (as defined by the {@link ThreadLocale} service).
 86  
      *
 87  
      * @param path relative to the classpath root
 88  
      * @return the asset
 89  
      * @throws RuntimeException if the asset can not be found
 90  
      */
 91  
     Asset getClasspathAsset(String path);
 92  
 }