From: <bra...@us...> - 2009-05-20 02:28:41
|
Revision: 2721 http://archive-access.svn.sourceforge.net/archive-access/?rev=2721&view=rev Author: bradtofel Date: 2009-05-20 02:28:33 +0000 (Wed, 20 May 2009) Log Message: ----------- FEATURE: Now compares chaset case-insensitive in meta tags and HTTP headers FEATURE: exposed setResultBytes() FEATURE: new insertAtStartOfDocument() method FEATURE: now detects charset by: a) document META tag, b) byte-detection, c) HTTP header. before was c,b,a. Modified Paths: -------------- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/replay/TextDocument.java Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/replay/TextDocument.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/replay/TextDocument.java 2009-05-20 02:22:20 UTC (rev 2720) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/replay/TextDocument.java 2009-05-20 02:28:33 UTC (rev 2721) @@ -31,6 +31,7 @@ import java.nio.charset.Charset; import java.nio.charset.IllegalCharsetNameException; import java.text.ParseException; +import java.util.Iterator; import java.util.Map; import javax.servlet.ServletException; @@ -102,7 +103,9 @@ } private String contentTypeToCharset(final String contentType) { - int offset = contentType.indexOf(CHARSET_TOKEN); + int offset = + contentType.toUpperCase().indexOf(CHARSET_TOKEN.toUpperCase()); + if (offset != -1) { String cs = contentType.substring(offset + CHARSET_TOKEN.length()); if(isCharsetSupported(cs)) { @@ -135,7 +138,16 @@ String charsetName = null; Map<String,String> httpHeaders = resource.getHttpHeaders(); - String ctype = httpHeaders.get(HTTP_CONTENT_TYPE_HEADER); + Iterator<String> keys = httpHeaders.keySet().iterator(); + String ctype = null; + while(keys.hasNext()) { + String headerKey = keys.next(); + String keyCmp = headerKey.toUpperCase().trim(); + if(keyCmp.equals(HTTP_CONTENT_TYPE_HEADER.toUpperCase())) { + ctype = httpHeaders.get(headerKey); + break; + } + } if (ctype != null) { charsetName = contentTypeToCharset(ctype); } @@ -212,11 +224,11 @@ */ protected String guessCharset() throws IOException { - String charSet = getCharsetFromMeta(resource); + String charSet = getCharsetFromHeaders(resource); if(charSet == null) { charSet = getCharsetFromBytes(resource); if(charSet == null) { - charSet = getCharsetFromHeaders(resource); + charSet = getCharsetFromMeta(resource); if(charSet == null) { charSet = "UTF-8"; } @@ -365,6 +377,9 @@ * @throws UnsupportedEncodingException */ public byte[] getBytes() throws UnsupportedEncodingException { + if(resultBytes != null) { + return resultBytes; + } if(sb == null) { throw new IllegalStateException("No interal StringBuffer"); } @@ -374,6 +389,10 @@ return resultBytes; } + public void setResultBytes(byte[] resultBytes) { + this.resultBytes = resultBytes; + } + /** * Write the contents of the page to the client. * @@ -396,6 +415,13 @@ /** * @param toInsert */ + public void insertAtStartOfDocument(String toInsert) { + sb.insert(0,toInsert); + } + + /** + * @param toInsert + */ public void insertAtStartOfHead(String toInsert) { int insertPoint = TagMagix.getEndOfFirstTag(sb,"head"); if (-1 == insertPoint) { @@ -450,9 +476,6 @@ StringHttpServletResponseWrapper wrappedResponse = new StringHttpServletResponseWrapper(httpResponse); uiResults.forward(httpRequest, wrappedResponse, jspPath); -// uiResults.storeInRequest(httpRequest,jspPath); -// RequestDispatcher dispatcher = httpRequest.getRequestDispatcher(jspPath); -// dispatcher.forward(httpRequest, wrappedResponse); return wrappedResponse.getStringResponse(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |