// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package org.apache.tapestry5.internal.services.assets;

import java.util.Map;

import org.apache.tapestry5.services.assets.CompressionAnalyzer;

public class CompressionAnalyzerImpl implements CompressionAnalyzer
{
    private final Map<String, Boolean> configuration;

    public CompressionAnalyzerImpl(Map<String, Boolean> configuration)
    {
        this.configuration = configuration;
    }

    public boolean isCompressable(String contentType)
    {
        assert contentType != null;

        int x = contentType.indexOf(';');

        String key = x < 0 ? contentType : contentType.substring(0, x);

        Boolean result = configuration.get(key);

        if (result != null) {
            return result.booleanValue();
        }

        // Now look for a wild card.

        x = contentType.indexOf('/');

        String wildKey = contentType.substring(0, x) + "/*";

        result = configuration.get(wildKey);

        return result == null ? true : result.booleanValue();
    }
}

@@ -1,556 +1,4 @@
-// Licensed under the Apache License, Version 2.0 (the %22License%22);%0A// you may not use this file except in compliance with the License.%0A// You may obtain a copy of the License at%0A//%0A// http://www.apache.org/licenses/LICENSE-2.0%0A//%0A// Unless required by applicable law or agreed to in writing, software%0A// distributed under the License is distributed on an %22AS IS%22 BASIS,%0A// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A// See the License for the specific language governing permissions and%0A// limitations under the License.%0A%0A
 pack
@@ -463,35 +463,168 @@
     
-assert c
+if (contentType == null) %7B%0A            throw new IllegalStateException(%22C
 ontent
-T
+ t
 ype 
-!= null;
+provided to CompressionAnalyzer is null, which is not allowed.%22);%0A        %7D
 %0A%0A  
@@ -838,39 +838,24 @@
 eturn result
-.booleanValue()
 ;%0A        %7D%0A
@@ -1036,24 +1036,24 @@
 (wildKey);%0A%0A
+
         retu
@@ -1089,23 +1089,8 @@
 sult
-.booleanValue()
 ;%0A  

Throw an exception in the case that the content type is null.