001// Copyright 2011, 2012 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 015package org.apache.tapestry5.services.assets; 016 017import org.apache.tapestry5.ContentType; 018import org.apache.tapestry5.ioc.Resource; 019import org.apache.tapestry5.ioc.annotations.UsesMappedConfiguration; 020 021import java.io.IOException; 022import java.util.Set; 023 024/** 025 * Converts {@link Resource}s into {@link StreamableResource}s, and may be responsible for 026 * {@linkplain ResourceTransformer transforming} resources based on file extension. Contributions map a file extension 027 * (such as "coffee") to a transformer for that file extension. 028 * Service decorators added to this service may provide additional processing (compression, minimization, and caching). 029 * 030 * @since 5.3 031 */ 032@UsesMappedConfiguration(ResourceTransformer.class) 033public interface StreamableResourceSource 034{ 035 /** 036 * Given a desired content type, identify which file extensions can be mapped to that extension based on 037 * contributed {@link ResourceTransformer}s that can 038 * {@linkplain org.apache.tapestry5.services.assets.ResourceTransformer#getTransformedContentType() produce the content type} 039 * based for a file with that extension. 040 * 041 * @param contentType 042 * to search for (just a MIME type, such as "text/javascript") 043 * @return set of file extension, possibly empty, in no particular order. These are the bare extensions, e.g., 044 * "js", "coffee". 045 * @since 5.4 046 */ 047 Set<String> fileExtensionsForContentType(ContentType contentType); 048 049 /** 050 * Converts a Resource (which must be non-null and exist) into a streamable resource, along with 051 * some additional optional behaviors. 052 * 053 * @param baseResource 054 * the resource to convert 055 * @param processing 056 * defines additional processing after the resource has been read and possibly transformed 057 * @param dependencies 058 * Passed to any {@link ResourceTransformer} to track additional dependencies of the base resource 059 * @return the contents of the Resource, possibly transformed, in a streamable format. 060 * @throws IOException 061 * if the resource does not exist or a URL for the content is not available 062 */ 063 StreamableResource getStreamableResource(Resource baseResource, StreamableResourceProcessing processing, ResourceDependencies dependencies) 064 throws IOException; 065}