encoding = encoding.substring(0,i).trim();
if (encoding.indexOf("\"")!=-1)
encoding = encoding.substring(1,encoding.length()+1);
}
Tidy tidy = (Tidy) perThreadTidy.get();
// If charset is specified in header, set JTidy's
// character encoding to either UTF-8, ISO-8859-1
// or ISO-2022 accordingly (NOTE that these are
// the only character encoding sets that are supported in
// JTidy). If character encoding is not specified,
// UTF-8 is the default.
if (encoding != null)
{
if (encoding.toLowerCase().equals("iso-8859-1"))
tidy.setCharEncoding(org.w3c.tidy.Configuration.LATIN1);
else if (encoding.toLowerCase().equals("iso-2022-jp"))
tidy.setCharEncoding(org.w3c.tidy.Configuration.ISO2022);
else
tidy.setCharEncoding(org.w3c.tidy.Configuration.UTF8);
}
else
{
tidy.setCharEncoding(org.w3c.tidy.Configuration.UTF8);
}
// tidy.setErrout(devNull);
ByteArrayOutputStream stream = new ByteArrayOutputStream (1024);
BufferedOutputStream out = new BufferedOutputStream (stream);
tidy.parse (urlConnect.getInputStream(), out);
tidiedXml = stream.toString();
stream.close();
out.close();
if ( tidy.getParseErrors() > 0 )
throw new GeneralRenderingException("Unable to convert input document to XHTML");
}finally{
long elapsedTimeMillis = System.currentTimeMillis()-start;
logAccess(uri, state, status, elapsedTimeMillis);
}