1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.esigate.http;
17
18 import java.util.Collection;
19 import java.util.Properties;
20
21 import org.apache.http.HttpHeaders;
22 import org.apache.http.HttpResponse;
23 import org.esigate.Parameters;
24
25 public class ContentTypeHelper {
26 private Collection<String> parsableContentTypes;
27
28 public ContentTypeHelper(Properties properties) {
29 parsableContentTypes = Parameters.PARSABLE_CONTENT_TYPES.getValue(properties);
30 }
31
32
33
34
35
36
37
38
39 public boolean isTextContentType(HttpResponse httpResponse) {
40 String contentType = HttpResponseUtils.getFirstHeader(HttpHeaders.CONTENT_TYPE, httpResponse);
41 return isTextContentType(contentType);
42 }
43
44
45
46
47
48
49
50
51 public boolean isTextContentType(String contentType) {
52 if (contentType != null) {
53 String lowerContentType = contentType.toLowerCase();
54 for (String textContentType : this.parsableContentTypes) {
55 if (lowerContentType.startsWith(textContentType)) {
56 return true;
57 }
58 }
59 }
60 return false;
61 }
62
63 }