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.services.assets;
014
015import org.apache.tapestry5.ContentType;
016import org.apache.tapestry5.ioc.Resource;
017
018import java.io.IOException;
019import java.io.InputStream;
020
021/**
022 * A transformer is used to read a {@link Resource} and pass it through a transformation stage, to get a
023 * stream that can be used on the client side. Examples of this are languages that "compile" to
024 * JavaScript, or any of a few higher-level versions of CSS that are compiled to standard CSS.
025 * ResourceTransformers are contributed to the {@link StreamableResourceSource} service.
026 *
027 * @since 5.3
028 * @see StreamableResourceSource
029 */
030public interface ResourceTransformer
031{
032    /**
033     * Returns the MIME type of a transformed stream.
034     *
035     * @since 5.4
036     */
037    ContentType getTransformedContentType();
038
039    /**
040     * Read the source input stream and provide a new input stream of the transformed content.
041     *
042     * @param source
043     *         input content
044     * @param dependencies
045     *         allows additional dependencies of the source to be tracked
046     * @return stream of output content
047     * @throws IOException
048     */
049    InputStream transform(Resource source, ResourceDependencies dependencies) throws IOException;
050}