001// Licensed under the Apache License, Version 2.0 (the "License"); 002// you may not use this file except in compliance with the License. 003// You may obtain a copy of the License at 004// 005// http://www.apache.org/licenses/LICENSE-2.0 006// 007// Unless required by applicable law or agreed to in writing, software 008// distributed under the License is distributed on an "AS IS" BASIS, 009// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 010// See the License for the specific language governing permissions and 011// limitations under the License. 012 013package org.apache.tapestry5; 014 015import org.apache.tapestry5.commons.Resource; 016 017/** 018 * An Asset is any kind of resource that can be exposed to the client web browser. Although quite often an Asset is a 019 * resource in a web application's context folder, within Tapestry, Assets may also be resources on the classpath (i.e., 020 * packaged inside JARs). 021 * 022 * An Asset's toString() will return the URL for the resource (the same value as {@link #toClientURL()}). 023 * 024 * Release 5.1.0.0 introduced <code>org.apache.tapestry5.Asset2</code>, which extends this interface with an additional 025 * method. 026 * 027 * Release 5.7.0 merged Asset2 into Asset and Asset2 got removed. 028 * 029 * @see org.apache.tapestry5.services.AssetPathConverter 030 */ 031public interface Asset 032{ 033 /** 034 * Returns a URL that can be passed, unchanged, to the client in order for it to access the resource. The same value 035 * is returned from <code>toString()</code>. 036 * 037 * Tapestry's built-in asset types (context and classpath) always incorporate a checksum as part of the path, 038 * and alternate implementations are encouraged to do so as well. In addition, Tapestry ensures that context and 039 * classpath assets have a far-future expires header (to ensure aggressive caching by the client). 040 * Note that starting in Tapestry 5.4, it is expected that Asset instances recognize 041 * when the underlying Resource's content has changed, and update the clientURL to reflect the new content's 042 * checksum. This wasn't an issue in earlier releases where the clientURL incorporated a version number. 043 * 044 * Finally, starting in 5.4, this value will often be <em>variant</em>: the exact URL returned will depend on 045 * whether the underlying resource content is compressable, whether the current {@link org.apache.tapestry5.http.services.Request} 046 * supports compression. 047 * 048 * @see org.apache.tapestry5.services.AssetSource 049 * @see org.apache.tapestry5.services.AssetPathConverter 050 */ 051 String toClientURL(); 052 053 /** 054 * Returns the underlying Resource for the Asset. 055 */ 056 Resource getResource(); 057 058 /** 059 * Returns true if the Asset is invariant (meaning that it returns the same value from {@link Asset#toClientURL()} 060 * at all times). Most Assets are invariant. Assets that are used as binding values will be cached more aggressively by Tapestry if they are 061 * invariant. This default implementation returns <code>false</code> 062 * 063 * @return true if invariant 064 * @see org.apache.tapestry5.services.AssetPathConverter#isInvariant() 065 * @see Binding#isInvariant() 066 * @since 5.1.0.0 (in Asset2), 5.7.0 (in Asset). 067 */ 068 default boolean isInvariant() 069 { 070 return false; 071 } 072 073}