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.Iterator;
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 an 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 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 (Iterator it=parameters.entrySet().iterator();it.hasNext();) {
47              final Map.Entry entry = (Map.Entry) it.next();
48              this.parameters.put(entry.getKey().toString().toLowerCase(Locale.US), entry.getValue());
49          }
50      }
51  
52      /**
53       * Gets the media type,
54       * normalised to lower case.
55       * @return media type, not null
56       */
57      public String getMediaType() {
58          return mediaType;
59      }
60      
61      /**
62       * Gets the media sub type
63       * normalised to lower case
64       * @return sub type, not null
65       */
66      public String getSubType() {
67          return subType;
68      }
69      
70      /**
71       * Gets an immutable map
72       * containing all content type parameters 
73       * with keys normalised to lower case.
74       * @return not null
75       */
76      public Map/*<String, String>*/ getParameters() {
77          return parameters;
78      }
79  }