1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.myfaces.tobago.internal.util;
21
22 public class ContentType {
23 private String primaryType;
24 private String subType;
25
26 public ContentType(final String contentType) {
27 parse(contentType);
28 }
29
30 private void parse(final String contentType) {
31
32 final String[] values = StringUtils.split(contentType, "/");
33 if (values.length == 2) {
34 primaryType = values[0];
35 subType = values[1];
36 } else {
37 throw new IllegalArgumentException("ContentType '" + contentType + "' not recognized.");
38 }
39 }
40
41 public String getPrimaryType() {
42 return primaryType;
43 }
44
45 public String getSubType() {
46 return subType;
47 }
48
49 public boolean match(final ContentType contentType) {
50 return primaryType.equalsIgnoreCase(contentType.getPrimaryType())
51 && ("*".equals(subType) || subType.equalsIgnoreCase(contentType.getSubType()));
52 }
53
54 public String toString() {
55 return primaryType + "/" + subType;
56 }
57
58 public static ContentType valueOf(final String s) {
59 return new ContentType(s);
60 }
61 }