View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one   *
3    * or more contributor license agreements.  See the NOTICE file *
4    * distributed with this work for additional information        *
5    * regarding copyright ownership.  The ASF licenses this file   *
6    * to you under the Apache License, Version 2.0 (the            *
7    * "License"); you may not use this file except in compliance   *
8    * with the License.  You may obtain a copy of the License at   *
9    *                                                              *
10   *   http://www.apache.org/licenses/LICENSE-2.0                 *
11   *                                                              *
12   * Unless required by applicable law or agreed to in writing,   *
13   * software distributed under the License is distributed on an  *
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
15   * KIND, either express or implied.  See the License for the    *
16   * specific language governing permissions and limitations      *
17   * under the License.                                           *
18   */
19  package org.apache.rat.api;
20  
21  import java.util.Collections;
22  import java.util.HashMap;
23  import java.util.Locale;
24  import java.util.Map;
25  
26  /**
27   * Describe the MIME content type of a resource.
28   */
29  public class ContentType {
30      private final String mediaType;
31      private final String subType;
32      private final Map<String, String> parameters;
33  
34      /**
35       * Constructs content types, 
36       * performing any necessary conversions.
37       * @param mediaType not null
38       * @param subType not null
39       * @param parameters not null
40       */
41      public ContentType(final String mediaType, final String subType, final Map<String, String> parameters) {
42          super();
43          this.mediaType = mediaType.toLowerCase(Locale.US);
44          this.subType = subType.toLowerCase(Locale.US);
45          this.parameters = new HashMap<>(parameters.size());
46          for (Map.Entry<String, String> entry : parameters.entrySet()) {
47              this.parameters.put(entry.getKey().toLowerCase(Locale.US), entry.getValue());
48          }
49      }
50  
51      /**
52       * Gets the media type,
53       * normalised to lower case.
54       * @return media type, not null
55       */
56      public String getMediaType() {
57          return mediaType;
58      }
59      
60      /**
61       * Gets the media sub type
62       * normalised to lower case
63       * @return sub type, not null
64       */
65      public String getSubType() {
66          return subType;
67      }
68      
69      /**
70       * Gets an immutable map
71       * containing all content type parameters 
72       * with keys normalised to lower case.
73       * @return not null
74       */
75      public Map<String, String> getParameters() {
76          return Collections.unmodifiableMap(parameters);
77      }
78  }