001// Copyright 2006-2013 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.internal.services;
016
017import org.apache.tapestry5.Asset;
018import org.apache.tapestry5.commons.Resource;
019import org.apache.tapestry5.http.services.ResponseCompressionAnalyzer;
020import org.apache.tapestry5.internal.services.assets.ResourceChangeTracker;
021import org.apache.tapestry5.ioc.annotations.Marker;
022import org.apache.tapestry5.ioc.internal.util.ClasspathResource;
023import org.apache.tapestry5.services.AssetAlias;
024import org.apache.tapestry5.services.ClasspathAssetAliasManager;
025import org.apache.tapestry5.services.ClasspathProvider;
026import org.apache.tapestry5.services.assets.AssetPathConstructor;
027import org.apache.tapestry5.services.assets.StreamableResourceSource;
028
029/**
030 * Generates Assets for files on the classpath.
031 *
032 * @see AssetDispatcher
033 */
034@Marker(ClasspathProvider.class)
035public class ClasspathAssetFactory extends AbstractAssetFactory
036{
037    private final ClasspathAssetAliasManager aliasManager;
038
039    public ClasspathAssetFactory(ResponseCompressionAnalyzer compressionAnalyzer,
040                                 ResourceChangeTracker resourceChangeTracker,
041                                 StreamableResourceSource streamableResourceSource,
042                                 AssetPathConstructor assetPathConstructor,
043                                 ClasspathAssetAliasManager aliasManager)
044    {
045        super(compressionAnalyzer, resourceChangeTracker, streamableResourceSource, assetPathConstructor,
046                new ClasspathResource(""));
047
048        this.aliasManager = aliasManager;
049    }
050
051    public Asset createAsset(Resource resource)
052    {
053        AssetAlias alias = aliasManager.extractAssetAlias(resource);
054
055        return createAsset(resource, alias.virtualFolder, alias.path);
056    }
057}