1 | |
package org.codeforamerica.open311.facade; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | 2 | public enum Format { |
10 | 1 | XML("xml", "text/xml"), JSON("json", "application/json"); |
11 | |
|
12 | |
private String description; |
13 | |
private String httpContentType; |
14 | |
|
15 | 2 | Format(String description, String httpContentType) { |
16 | 2 | this.description = description; |
17 | 2 | this.httpContentType = httpContentType; |
18 | 2 | } |
19 | |
|
20 | |
public String getDescription() { |
21 | 13 | return description; |
22 | |
} |
23 | |
|
24 | |
public String getHTTPContentType() { |
25 | 2 | return httpContentType; |
26 | |
} |
27 | |
|
28 | |
public String toString() { |
29 | 11 | return getDescription(); |
30 | |
} |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
public static Format getFromHTTPContentTypeString(String contentTypeString) { |
40 | 27 | contentTypeString = contentTypeString.toLowerCase(); |
41 | 27 | if (contentTypeString.equals(JSON.httpContentType)) { |
42 | 1 | return Format.JSON; |
43 | |
} |
44 | 26 | if (contentTypeString.equals(XML.httpContentType)) { |
45 | 25 | return Format.XML; |
46 | |
} |
47 | 1 | return null; |
48 | |
} |
49 | |
} |