1 package ca.uhn.fhir.rest.server;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 import java.util.HashMap;
24
25 import ca.uhn.fhir.context.FhirContext;
26 import ca.uhn.fhir.parser.IParser;
27
28 public enum EncodingEnum {
29
30 XML(Constants.CT_FHIR_XML, Constants.CT_ATOM_XML, "application/xml", Constants.FORMAT_XML) {
31 @Override
32 public IParser newParser(FhirContext theContext) {
33 return theContext.newXmlParser();
34 }
35 },
36
37 JSON(Constants.CT_FHIR_JSON, Constants.CT_FHIR_JSON, Constants.CT_JSON, Constants.FORMAT_JSON) {
38 @Override
39 public IParser newParser(FhirContext theContext) {
40 return theContext.newJsonParser();
41 }
42 }
43
44 ;
45
46 private static HashMap<String, EncodingEnum> ourContentTypeToEncoding;
47
48 static {
49 ourContentTypeToEncoding = new HashMap<String, EncodingEnum>();
50 for (EncodingEnum next : values()) {
51 ourContentTypeToEncoding.put(next.getBundleContentType(), next);
52 ourContentTypeToEncoding.put(next.getResourceContentType(), next);
53 ourContentTypeToEncoding.put(next.getBrowserFriendlyBundleContentType(), next);
54 }
55
56
57
58
59
60 ourContentTypeToEncoding.put("application/json", JSON);
61 ourContentTypeToEncoding.put("application/xml", XML);
62 ourContentTypeToEncoding.put("text/json", JSON);
63 ourContentTypeToEncoding.put("text/xml", XML);
64
65 }
66
67 private String myResourceContentType;
68 private String myBundleContentType;
69 private String myBrowserFriendlyContentType;
70 private String myFormatContentType;
71
72 EncodingEnum(String theResourceContentType, String theBundleContentType, String theBrowserFriendlyContentType, String theFormatContentType) {
73 myResourceContentType = theResourceContentType;
74 myBundleContentType = theBundleContentType;
75 myBrowserFriendlyContentType = theBrowserFriendlyContentType;
76 myFormatContentType = theFormatContentType;
77 }
78
79 public String getRequestContentType() {
80 return myFormatContentType;
81 }
82
83 public abstract IParser newParser(FhirContext theContext);
84
85 public String getBundleContentType() {
86 return myBundleContentType;
87 }
88
89 public String getResourceContentType() {
90 return myResourceContentType;
91 }
92
93 public String getBrowserFriendlyBundleContentType() {
94 return myBrowserFriendlyContentType;
95 }
96
97 public static EncodingEnum forContentType(String theContentType) {
98 return ourContentTypeToEncoding.get(theContentType);
99 }
100
101 public String getFormatContentType() {
102 return myFormatContentType;
103 }
104
105 }