001    // Copyright 2006, 2008 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    
015    package org.apache.tapestry5.services;
016    
017    import org.apache.tapestry5.ioc.annotations.UsesConfiguration;
018    
019    import java.net.URL;
020    
021    /**
022     * Responsible for determining which classpath resources require checksums, and for generating checksums for such
023     * resources.
024     * <p/>
025     * The service's configuration identifies which file extensions will be secured using an checksum. The default list is
026     * "class" and "tml".
027     *
028     * @see org.apache.tapestry5.ioc.internal.util.ClasspathResource
029     * @see org.apache.tapestry5.internal.services.ClasspathAssetFactory
030     */
031    @UsesConfiguration(String.class)
032    public interface ResourceDigestGenerator
033    {
034        /**
035         * Examines the path (typically, the file name extension at the end of the path) to determine if a checksum is
036         * required for the path. The path is {@link org.apache.tapestry5.ioc.Resource} style, without a leading slash.
037         */
038        boolean requiresDigest(String path);
039    
040        /**
041         * Reads the content of a URL (presumably, for a resource on the classpath) and generates a digest of its content.
042         * This digest will be incorporated into the URL provided to the client, to verify that the client has been
043         * "granted" access to this resource. This is only used for resources where {@link #requiresDigest(String)} is
044         * true.
045         *
046         * @param url
047         * @return the digest for the resource
048         */
049        String generateDigest(URL url);
050    }