* This method supports gzipped sources.
* @param uri The document URI.
* @exception IOException if an error occured while reading the document.
*/
public SVGOMDocument createDocument(String uri) throws IOException {
ParsedURL purl = new ParsedURL(uri);
InputStream is = purl.openStream(MimeTypeConstants.MIME_TYPES_SVG);
InputSource isrc = new InputSource(is);
// now looking for a charset encoding in the content type such
// as "image/svg+xml; charset=iso8859-1" this is not official
// for image/svg+xml yet! only for text/xml and maybe
// for application/xml
String contentType = purl.getContentType();
int cindex = -1;
if (contentType != null) {
contentType = contentType.toLowerCase();
cindex = contentType.indexOf(HTTP_CHARSET);
}
if (cindex != -1) {
int i = cindex + HTTP_CHARSET.length();
int eqIdx = contentType.indexOf('=', i);
if (eqIdx != -1) {
eqIdx++; // no one is interested in the equals sign...
String charset;
// The patch had ',' as the terminator but I suspect
// that is the delimiter between possible charsets,
// but if another 'attribute' were in the accept header
// charset would be terminated by a ';'. So I look
// for both and take to closer of the two.
int idx = contentType.indexOf(',', eqIdx);
int semiIdx = contentType.indexOf(';', eqIdx);
if ((semiIdx != -1) && ((semiIdx < idx) || (idx == -1)))
idx = semiIdx;
if (idx != -1)
charset = contentType.substring(eqIdx, idx);
else
charset = contentType.substring(eqIdx);
isrc.setEncoding(charset.trim());
}
}
isrc.setSystemId(uri);
SVGOMDocument doc = (SVGOMDocument)super.createDocument
(SVGDOMImplementation.SVG_NAMESPACE_URI, "svg", uri, isrc);
try {
doc.setURLObject(new URL(purl.toString()));
} catch (MalformedURLException mue) {
// Not very likely to happen given we already opened the stream.
throw new IOException("Malformed URL: " + uri);
}