Mercurial Hosting > luan
annotate src/org/eclipse/jetty/http/MimeTypes.java @ 1031:921c25a05eaa
remove Buffer.asReadOnlyBuffer()
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 03 Nov 2016 02:04:40 -0600 |
parents | 27f3dc761452 |
children | 2b769da7f67d |
rev | line source |
---|---|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1 // |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2 // ======================================================================== |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3 // Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd. |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4 // ------------------------------------------------------------------------ |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5 // All rights reserved. This program and the accompanying materials |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
6 // are made available under the terms of the Eclipse Public License v1.0 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
7 // and Apache License v2.0 which accompanies this distribution. |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
8 // |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
9 // The Eclipse Public License is available at |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
10 // http://www.eclipse.org/legal/epl-v10.html |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
11 // |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
12 // The Apache License v2.0 is available at |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
13 // http://www.opensource.org/licenses/apache2.0.php |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
14 // |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
15 // You may elect to redistribute this code under either of these licenses. |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
16 // ======================================================================== |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
17 // |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
18 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
19 package org.eclipse.jetty.http; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
20 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
21 import java.util.Enumeration; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
22 import java.util.HashMap; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
23 import java.util.Iterator; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
24 import java.util.Map; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
25 import java.util.MissingResourceException; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
26 import java.util.ResourceBundle; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
27 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
28 import org.eclipse.jetty.io.Buffer; |
1023
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
29 import org.eclipse.jetty.io.StringCache; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
30 import org.eclipse.jetty.util.StringUtil; |
820
8e9db0bbf4f9
remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
31 import org.slf4j.Logger; |
8e9db0bbf4f9
remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
32 import org.slf4j.LoggerFactory; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
33 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
34 |
1023
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
35 public final class MimeTypes |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
36 { |
1020
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
37 private static final Logger LOG = LoggerFactory.getLogger(MimeTypes.class); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
38 |
1020
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
39 public final static String |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
40 FORM_ENCODED="application/x-www-form-urlencoded", |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
41 MESSAGE_HTTP="message/http", |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
42 MULTIPART_BYTERANGES="multipart/byteranges", |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
43 |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
44 TEXT_HTML="text/html", |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
45 TEXT_PLAIN="text/plain", |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
46 TEXT_XML="text/xml", |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
47 TEXT_JSON="text/json", |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
48 |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
49 TEXT_HTML_8859_1="text/html;charset=ISO-8859-1", |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
50 TEXT_PLAIN_8859_1="text/plain;charset=ISO-8859-1", |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
51 TEXT_XML_8859_1="text/xml;charset=ISO-8859-1", |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
52 |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
53 TEXT_HTML_UTF_8="text/html;charset=UTF-8", |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
54 TEXT_PLAIN_UTF_8="text/plain;charset=UTF-8", |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
55 TEXT_XML_UTF_8="text/xml;charset=UTF-8", |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
56 TEXT_JSON_UTF_8="text/json;charset=UTF-8"; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
57 |
1020
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
58 private final static String |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
59 TEXT_HTML__8859_1="text/html; charset=ISO-8859-1", |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
60 TEXT_PLAIN__8859_1="text/plain; charset=ISO-8859-1", |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
61 TEXT_XML__8859_1="text/xml; charset=ISO-8859-1", |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
62 TEXT_HTML__UTF_8="text/html; charset=UTF-8", |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
63 TEXT_PLAIN__UTF_8="text/plain; charset=UTF-8", |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
64 TEXT_XML__UTF_8="text/xml; charset=UTF-8", |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
65 TEXT_JSON__UTF_8="text/json; charset=UTF-8"; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
66 |
1020
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
67 private final static int |
1023
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
68 FORM_ENCODED_ORDINAL=1, |
1020
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
69 MESSAGE_HTTP_ORDINAL=2, |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
70 MULTIPART_BYTERANGES_ORDINAL=3, |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
71 |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
72 TEXT_HTML_ORDINAL=4, |
1023
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
73 TEXT_PLAIN_ORDINAL=5, |
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
74 TEXT_XML_ORDINAL=6, |
1020
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
75 TEXT_JSON_ORDINAL=7, |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
76 |
1020
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
77 TEXT_HTML_8859_1_ORDINAL=8, |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
78 TEXT_PLAIN_8859_1_ORDINAL=9, |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
79 TEXT_XML_8859_1_ORDINAL=10, |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
80 |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
81 TEXT_HTML_UTF_8_ORDINAL=11, |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
82 TEXT_PLAIN_UTF_8_ORDINAL=12, |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
83 TEXT_XML_UTF_8_ORDINAL=13, |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
84 TEXT_JSON_UTF_8_ORDINAL=14; |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
85 |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
86 private static int __index=15; |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
87 |
1023
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
88 public final static StringCache CACHE = new StringCache(); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
89 |
1023
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
90 public final static byte[] |
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
91 FORM_ENCODED_BYTES=CACHE.add(FORM_ENCODED,FORM_ENCODED_ORDINAL), |
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
92 MESSAGE_HTTP_BYTES=CACHE.add(MESSAGE_HTTP, MESSAGE_HTTP_ORDINAL), |
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
93 MULTIPART_BYTERANGES_BYTES=CACHE.add(MULTIPART_BYTERANGES,MULTIPART_BYTERANGES_ORDINAL), |
1020
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
94 |
1023
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
95 TEXT_HTML_BYTES=CACHE.add(TEXT_HTML,TEXT_HTML_ORDINAL), |
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
96 TEXT_PLAIN_BYTES=CACHE.add(TEXT_PLAIN,TEXT_PLAIN_ORDINAL), |
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
97 TEXT_XML_BYTES=CACHE.add(TEXT_XML,TEXT_XML_ORDINAL), |
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
98 TEXT_JSON_BYTES=CACHE.add(TEXT_JSON,TEXT_JSON_ORDINAL), |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
99 |
1023
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
100 TEXT_HTML_8859_1_BYTES=CACHE.add(TEXT_HTML_8859_1,TEXT_HTML_8859_1_ORDINAL), |
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
101 TEXT_PLAIN_8859_1_BYTES=CACHE.add(TEXT_PLAIN_8859_1,TEXT_PLAIN_8859_1_ORDINAL), |
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
102 TEXT_XML_8859_1_BYTES=CACHE.add(TEXT_XML_8859_1,TEXT_XML_8859_1_ORDINAL), |
1020
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
103 |
1023
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
104 TEXT_HTML_UTF_8_BYTES=CACHE.add(TEXT_HTML_UTF_8,TEXT_HTML_UTF_8_ORDINAL), |
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
105 TEXT_PLAIN_UTF_8_BYTES=CACHE.add(TEXT_PLAIN_UTF_8,TEXT_PLAIN_UTF_8_ORDINAL), |
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
106 TEXT_XML_UTF_8_BYTES=CACHE.add(TEXT_XML_UTF_8,TEXT_XML_UTF_8_ORDINAL), |
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
107 TEXT_JSON_UTF_8_BYTES=CACHE.add(TEXT_JSON_UTF_8,TEXT_JSON_UTF_8_ORDINAL), |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
108 |
1023
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
109 TEXT_HTML__8859_1_BYTES=CACHE.add(TEXT_HTML__8859_1,TEXT_HTML_8859_1_ORDINAL), |
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
110 TEXT_PLAIN__8859_1_BYTES=CACHE.add(TEXT_PLAIN__8859_1,TEXT_PLAIN_8859_1_ORDINAL), |
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
111 TEXT_XML__8859_1_BYTES=CACHE.add(TEXT_XML__8859_1,TEXT_XML_8859_1_ORDINAL), |
1020
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
112 |
1023
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
113 TEXT_HTML__UTF_8_BYTES=CACHE.add(TEXT_HTML__UTF_8,TEXT_HTML_UTF_8_ORDINAL), |
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
114 TEXT_PLAIN__UTF_8_BYTES=CACHE.add(TEXT_PLAIN__UTF_8,TEXT_PLAIN_UTF_8_ORDINAL), |
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
115 TEXT_XML__UTF_8_BYTES=CACHE.add(TEXT_XML__UTF_8,TEXT_XML_UTF_8_ORDINAL), |
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
116 TEXT_JSON__UTF_8_BYTES=CACHE.add(TEXT_JSON__UTF_8,TEXT_JSON_UTF_8_ORDINAL); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
117 |
1020
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
118 |
1023
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
119 private final static Map<String,String> __dftMimeMap = new HashMap<String,String>(); |
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
120 private final static Map<String,String> __encodings = new HashMap<String,String>(); |
1020
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
121 static |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
122 { |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
123 try |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
124 { |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
125 ResourceBundle mime = ResourceBundle.getBundle("org/eclipse/jetty/http/mime"); |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
126 Enumeration i = mime.getKeys(); |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
127 while(i.hasMoreElements()) |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
128 { |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
129 String ext = (String)i.nextElement(); |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
130 String m = mime.getString(ext); |
1023
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
131 // __dftMimeMap.put(ext.toLowerCase(),normalizeMimeType(m)); |
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
132 __dftMimeMap.put(ext.toLowerCase(),m); |
1020
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
133 } |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
134 } |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
135 catch(MissingResourceException e) |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
136 { |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
137 LOG.warn(e.toString()); |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
138 LOG.debug("",e); |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
139 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
140 |
1023
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
141 __encodings.put("text/html","ISO-8859-1"); |
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
142 __encodings.put("text/plain","ISO-8859-1"); |
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
143 __encodings.put("text/xml","UTF-8"); |
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
144 __encodings.put("text/json","UTF-8"); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
145 |
1023
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
146 /* |
1020
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
147 TEXT_HTML_BUFFER.setAssociate("ISO-8859-1",TEXT_HTML_8859_1_BUFFER); |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
148 TEXT_HTML_BUFFER.setAssociate("ISO_8859_1",TEXT_HTML_8859_1_BUFFER); |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
149 TEXT_HTML_BUFFER.setAssociate("iso-8859-1",TEXT_HTML_8859_1_BUFFER); |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
150 TEXT_PLAIN_BUFFER.setAssociate("ISO-8859-1",TEXT_PLAIN_8859_1_BUFFER); |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
151 TEXT_PLAIN_BUFFER.setAssociate("ISO_8859_1",TEXT_PLAIN_8859_1_BUFFER); |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
152 TEXT_PLAIN_BUFFER.setAssociate("iso-8859-1",TEXT_PLAIN_8859_1_BUFFER); |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
153 TEXT_XML_BUFFER.setAssociate("ISO-8859-1",TEXT_XML_8859_1_BUFFER); |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
154 TEXT_XML_BUFFER.setAssociate("ISO_8859_1",TEXT_XML_8859_1_BUFFER); |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
155 TEXT_XML_BUFFER.setAssociate("iso-8859-1",TEXT_XML_8859_1_BUFFER); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
156 |
1020
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
157 TEXT_HTML_BUFFER.setAssociate("UTF-8",TEXT_HTML_UTF_8_BUFFER); |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
158 TEXT_HTML_BUFFER.setAssociate("UTF8",TEXT_HTML_UTF_8_BUFFER); |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
159 TEXT_HTML_BUFFER.setAssociate("utf8",TEXT_HTML_UTF_8_BUFFER); |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
160 TEXT_HTML_BUFFER.setAssociate("utf-8",TEXT_HTML_UTF_8_BUFFER); |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
161 TEXT_PLAIN_BUFFER.setAssociate("UTF-8",TEXT_PLAIN_UTF_8_BUFFER); |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
162 TEXT_PLAIN_BUFFER.setAssociate("UTF8",TEXT_PLAIN_UTF_8_BUFFER); |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
163 TEXT_PLAIN_BUFFER.setAssociate("utf8",TEXT_PLAIN_UTF_8_BUFFER); |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
164 TEXT_PLAIN_BUFFER.setAssociate("utf-8",TEXT_PLAIN_UTF_8_BUFFER); |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
165 TEXT_XML_BUFFER.setAssociate("UTF-8",TEXT_XML_UTF_8_BUFFER); |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
166 TEXT_XML_BUFFER.setAssociate("UTF8",TEXT_XML_UTF_8_BUFFER); |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
167 TEXT_XML_BUFFER.setAssociate("utf8",TEXT_XML_UTF_8_BUFFER); |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
168 TEXT_XML_BUFFER.setAssociate("utf-8",TEXT_XML_UTF_8_BUFFER); |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
169 TEXT_JSON_BUFFER.setAssociate("UTF-8",TEXT_JSON_UTF_8_BUFFER); |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
170 TEXT_JSON_BUFFER.setAssociate("UTF8",TEXT_JSON_UTF_8_BUFFER); |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
171 TEXT_JSON_BUFFER.setAssociate("utf8",TEXT_JSON_UTF_8_BUFFER); |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
172 TEXT_JSON_BUFFER.setAssociate("utf-8",TEXT_JSON_UTF_8_BUFFER); |
1023
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
173 */ |
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
174 } |
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
175 |
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
176 // replace setAssociate() |
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
177 |
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
178 private static final Map<String,String> association = new HashMap<String,String>(); |
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
179 |
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
180 private static String key(String type,String charEncoding) { |
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
181 return (type+'~'+charEncoding).toLowerCase(); |
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
182 } |
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
183 |
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
184 private static void setAssociate(String type,String charEncoding,String result) { |
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
185 association.put( key(type,charEncoding), result ); |
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
186 } |
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
187 |
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
188 public static String getAssociate(String type,String charEncoding) { |
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
189 return association.get( key(type,charEncoding) ); |
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
190 } |
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
191 |
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
192 static { |
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
193 setAssociate(TEXT_HTML,"ISO-8859-1",TEXT_HTML_8859_1); |
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
194 setAssociate(TEXT_HTML,"ISO_8859_1",TEXT_HTML_8859_1); |
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
195 setAssociate(TEXT_PLAIN,"ISO-8859-1",TEXT_PLAIN_8859_1); |
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
196 setAssociate(TEXT_PLAIN,"ISO_8859_1",TEXT_PLAIN_8859_1); |
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
197 setAssociate(TEXT_XML,"ISO-8859-1",TEXT_XML_8859_1); |
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
198 setAssociate(TEXT_XML,"ISO_8859_1",TEXT_XML_8859_1); |
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
199 |
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
200 setAssociate(TEXT_HTML,"UTF-8",TEXT_HTML_UTF_8); |
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
201 setAssociate(TEXT_HTML,"UTF8",TEXT_HTML_UTF_8); |
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
202 setAssociate(TEXT_PLAIN,"UTF-8",TEXT_PLAIN_UTF_8); |
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
203 setAssociate(TEXT_PLAIN,"UTF8",TEXT_PLAIN_UTF_8); |
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
204 setAssociate(TEXT_XML,"UTF-8",TEXT_XML_UTF_8); |
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
205 setAssociate(TEXT_XML,"UTF8",TEXT_XML_UTF_8); |
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
206 setAssociate(TEXT_JSON,"UTF-8",TEXT_JSON_UTF_8); |
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
207 setAssociate(TEXT_JSON,"UTF8",TEXT_JSON_UTF_8); |
1020
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
208 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
209 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
210 |
1020
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
211 |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
212 /* ------------------------------------------------------------ */ |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
213 /** Get the MIME type by filename extension. |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
214 * @param filename A file name |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
215 * @return MIME type matching the longest dot extension of the |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
216 * file name. |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
217 */ |
1023
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
218 public String getMimeByExtension(String filename) |
1020
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
219 { |
1023
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
220 String type=null; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
221 |
1020
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
222 if (filename!=null) |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
223 { |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
224 int i=-1; |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
225 while(type==null) |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
226 { |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
227 i=filename.indexOf(".",i+1); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
228 |
1020
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
229 if (i<0 || i>=filename.length()) |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
230 break; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
231 |
1023
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
232 String ext = filename.substring(i+1).toLowerCase(); |
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
233 type = __dftMimeMap.get(ext); |
1020
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
234 } |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
235 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
236 |
1020
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
237 if (type==null) |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
238 { |
1023
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
239 type = __dftMimeMap.get("*"); |
1020
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
240 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
241 |
1020
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
242 return type; |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
243 } |
1023
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
244 /* |
1020
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
245 private static synchronized Buffer normalizeMimeType(String type) |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
246 { |
1023
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
247 Buffer b = CACHE.get(type); |
1020
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
248 if (b==null) |
1023
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
249 b = CACHE.add(type,__index++); |
1020
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
250 return b; |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
251 } |
1023
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
252 */ |
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
253 public static String getCharsetFromContentType(String value) |
1020
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
254 { |
1023
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
255 switch(CACHE.getOrdinal(value)) |
1020
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
256 { |
1023
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
257 case TEXT_HTML_8859_1_ORDINAL: |
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
258 case TEXT_PLAIN_8859_1_ORDINAL: |
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
259 case TEXT_XML_8859_1_ORDINAL: |
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
260 return StringUtil.__ISO_8859_1; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
261 |
1023
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
262 case TEXT_HTML_UTF_8_ORDINAL: |
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
263 case TEXT_PLAIN_UTF_8_ORDINAL: |
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
264 case TEXT_XML_UTF_8_ORDINAL: |
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
265 case TEXT_JSON_UTF_8_ORDINAL: |
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
266 return StringUtil.__UTF8; |
1020
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
267 } |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
268 |
1023
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
269 int i = 0; |
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
270 int end = value.length(); |
1020
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
271 int state=0; |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
272 int start=0; |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
273 boolean quote=false; |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
274 for (;i<end;i++) |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
275 { |
1023
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
276 char b = value.charAt(i); |
1020
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
277 |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
278 if (quote && state!=10) |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
279 { |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
280 if ('"'==b) |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
281 quote=false; |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
282 continue; |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
283 } |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
284 |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
285 switch(state) |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
286 { |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
287 case 0: |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
288 if ('"'==b) |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
289 { |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
290 quote=true; |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
291 break; |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
292 } |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
293 if (';'==b) |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
294 state=1; |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
295 break; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
296 |
1020
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
297 case 1: if ('c'==b) state=2; else if (' '!=b) state=0; break; |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
298 case 2: if ('h'==b) state=3; else state=0;break; |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
299 case 3: if ('a'==b) state=4; else state=0;break; |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
300 case 4: if ('r'==b) state=5; else state=0;break; |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
301 case 5: if ('s'==b) state=6; else state=0;break; |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
302 case 6: if ('e'==b) state=7; else state=0;break; |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
303 case 7: if ('t'==b) state=8; else state=0;break; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
304 |
1020
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
305 case 8: if ('='==b) state=9; else if (' '!=b) state=0; break; |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
306 |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
307 case 9: |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
308 if (' '==b) |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
309 break; |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
310 if ('"'==b) |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
311 { |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
312 quote=true; |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
313 start=i+1; |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
314 state=10; |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
315 break; |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
316 } |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
317 start=i; |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
318 state=10; |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
319 break; |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
320 |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
321 case 10: |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
322 if (!quote && (';'==b || ' '==b )|| |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
323 (quote && '"'==b )) |
1023
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
324 return value.substring(start,i); |
1020
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
325 } |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
326 } |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
327 |
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
328 if (state==10) |
1023
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
329 return value.substring(start,i); |
1020
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
330 |
1023
27f3dc761452
MimeTypes uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
1020
diff
changeset
|
331 return __encodings.get(value.toLowerCase()); |
1020
6be43ef1eb96
HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
332 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
333 } |