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.HashMap;
22  import java.util.Locale;
23  import java.util.Map;
24  
25  /**
26   * Describe the MIME content type of a resource.
27   */
28  public class ContentType {
29      private final String mediaType;
30      private final String subType;
31      private final Map<String, String> parameters;
32  
33      /**
34       * Constructs content types, 
35       * performing any necessary conversions.
36       * @param mediaType not null
37       * @param subType not null
38       * @param parameters not null
39       */
40      public ContentType(final String mediaType, final String subType, final Map<String, String> parameters) {
41          super();
42          this.mediaType = mediaType.toLowerCase(Locale.US);
43          this.subType = subType.toLowerCase(Locale.US);
44          this.parameters = new HashMap<>(parameters.size());
45          for (Map.Entry<String, String> entry : parameters.entrySet()) {
46              this.parameters.put(entry.getKey().toLowerCase(Locale.US), entry.getValue());
47          }
48      }
49  
50      /**
51       * Gets the media type,
52       * normalised to lower case.
53       * @return media type, not null
54       */
55      public String getMediaType() {
56          return mediaType;
57      }
58      
59      /**
60       * Gets the media sub type
61       * normalised to lower case
62       * @return sub type, not null
63       */
64      public String getSubType() {
65          return subType;
66      }
67      
68      /**
69       * Gets an immutable map
70       * containing all content type parameters 
71       * with keys normalised to lower case.
72       * @return not null
73       */
74      public Map<String, String> getParameters() {
75          return parameters;
76      }
77  }