001package org.apache.tapestry5.internal.services.assets;
002
003import java.util.Map;
004
005import org.apache.tapestry5.services.assets.CompressionAnalyzer;
006
007public class CompressionAnalyzerImpl implements CompressionAnalyzer
008{
009    private final Map<String, Boolean> configuration;
010
011    public CompressionAnalyzerImpl(Map<String, Boolean> configuration)
012    {
013        this.configuration = configuration;
014    }
015
016    public boolean isCompressable(String contentType)
017    {
018        if (contentType == null) {
019            throw new IllegalStateException("Content type provided to CompressionAnalyzer is null, which is not allowed.");
020        }
021
022        int x = contentType.indexOf(';');
023
024        String key = x < 0 ? contentType : contentType.substring(0, x);
025
026        Boolean result = configuration.get(key);
027
028        if (result != null) {
029            return result;
030        }
031
032        // Now look for a wild card.
033
034        x = contentType.indexOf('/');
035
036        String wildKey = contentType.substring(0, x) + "/*";
037
038        result = configuration.get(wildKey);
039
040        return result == null ? true : result;
041    }
042}