You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by am...@apache.org on 2002/08/28 20:35:35 UTC
cvs commit: jakarta-tomcat-4.0/webapps/examples/WEB-INF/classes/compressionFilters CompressionServletResponseWrapper.java
amyroh 2002/08/28 11:35:35
Modified: webapps/examples/WEB-INF/classes/compressionFilters
CompressionServletResponseWrapper.java
Log:
Add support other content-types. Fixes bug 11910. Patch submitted by
"Peter Rajsky" <pe...@elline.sk>.
Revision Changes Path
1.7 +51 -5 jakarta-tomcat-4.0/webapps/examples/WEB-INF/classes/compressionFilters/CompressionServletResponseWrapper.java
Index: CompressionServletResponseWrapper.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-4.0/webapps/examples/WEB-INF/classes/compressionFilters/CompressionServletResponseWrapper.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- CompressionServletResponseWrapper.java 18 Jun 2002 19:53:26 -0000 1.6
+++ CompressionServletResponseWrapper.java 28 Aug 2002 18:35:35 -0000 1.7
@@ -144,10 +144,27 @@
*/
private int debug = 0;
+ /**
+ * Content type
+ */
+ protected String contentType = null;
+
// --------------------------------------------------------- Public Methods
/**
+ * Set content type
+ */
+ public void setContentType(String contentType) {
+ if (debug > 1) {
+ System.out.println("setContentType to "+contentType);
+ }
+ this.contentType = contentType;
+ origResponse.setContentType(contentType);
+ }
+
+
+ /**
* Set threshold number
*/
public void setCompressionThreshold(int threshold) {
@@ -259,13 +276,42 @@
if (debug > 1) {
System.out.println("stream is set to "+stream+" in getWriter");
}
- writer = new PrintWriter(stream);
+ String charset = getCharsetFromContentType(contentType);
+ if (charset == null) {
+ charset = "windows-1250";
+ }
+ writer = new PrintWriter(new OutputStreamWriter(stream, charset));
return (writer);
}
public void setContentLength(int length) {
+ }
+
+
+ /**
+ * Returns character from content type. This method was taken from tomcat.
+ * @author rajo
+ */
+ private static String getCharsetFromContentType(String type) {
+
+ if (type == null) {
+ return null;
+ }
+ int semi = type.indexOf(";");
+ if (semi == -1) {
+ return null;
+ }
+ String afterSemi = type.substring(semi + 1);
+ int charsetLocation = afterSemi.indexOf("charset=");
+ if(charsetLocation == -1) {
+ return null;
+ } else {
+ String afterCharset = afterSemi.substring(charsetLocation + 8);
+ String encoding = afterCharset.trim();
+ return encoding;
+ }
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: cvs commit:
jakarta-tomcat-4.0/webapps/examples/WEB-INF/classes/compressionFilters
CompressionServletResponseWrapper.java
Posted by Amy Roh <am...@apache.org>.
Can anyone with access to jakarta-servletapi-5 apply the same patch to
jakarta-servletapi-5/jsr154/examples/WEB-INF/classes/compressionFilters/CompressionServletResponseWrapper.java?
Thanks,
Amy
amyroh@apache.org wrote:
> amyroh 2002/08/28 11:35:35
>
> Modified: webapps/examples/WEB-INF/classes/compressionFilters
> CompressionServletResponseWrapper.java
> Log:
> Add support other content-types. Fixes bug 11910. Patch submitted by
> "Peter Rajsky" <pe...@elline.sk>.
>
> Revision Changes Path
> 1.7 +51 -5 jakarta-tomcat-4.0/webapps/examples/WEB-INF/classes/compressionFilters/CompressionServletResponseWrapper.java
>
> Index: CompressionServletResponseWrapper.java
> ===================================================================
> RCS file: /home/cvs/jakarta-tomcat-4.0/webapps/examples/WEB-INF/classes/compressionFilters/CompressionServletResponseWrapper.java,v
> retrieving revision 1.6
> retrieving revision 1.7
> diff -u -r1.6 -r1.7
> --- CompressionServletResponseWrapper.java 18 Jun 2002 19:53:26 -0000 1.6
> +++ CompressionServletResponseWrapper.java 28 Aug 2002 18:35:35 -0000 1.7
> @@ -144,10 +144,27 @@
> */
> private int debug = 0;
>
> + /**
> + * Content type
> + */
> + protected String contentType = null;
> +
> // --------------------------------------------------------- Public Methods
>
>
> /**
> + * Set content type
> + */
> + public void setContentType(String contentType) {
> + if (debug > 1) {
> + System.out.println("setContentType to "+contentType);
> + }
> + this.contentType = contentType;
> + origResponse.setContentType(contentType);
> + }
> +
> +
> + /**
> * Set threshold number
> */
> public void setCompressionThreshold(int threshold) {
> @@ -259,13 +276,42 @@
> if (debug > 1) {
> System.out.println("stream is set to "+stream+" in getWriter");
> }
> - writer = new PrintWriter(stream);
> + String charset = getCharsetFromContentType(contentType);
> + if (charset == null) {
> + charset = "windows-1250";
> + }
> + writer = new PrintWriter(new OutputStreamWriter(stream, charset));
> return (writer);
>
> }
>
>
> public void setContentLength(int length) {
> + }
> +
> +
> + /**
> + * Returns character from content type. This method was taken from tomcat.
> + * @author rajo
> + */
> + private static String getCharsetFromContentType(String type) {
> +
> + if (type == null) {
> + return null;
> + }
> + int semi = type.indexOf(";");
> + if (semi == -1) {
> + return null;
> + }
> + String afterSemi = type.substring(semi + 1);
> + int charsetLocation = afterSemi.indexOf("charset=");
> + if(charsetLocation == -1) {
> + return null;
> + } else {
> + String afterCharset = afterSemi.substring(charsetLocation + 8);
> + String encoding = afterCharset.trim();
> + return encoding;
> + }
> }
>
> }
>
>
>
>
> --
> To unsubscribe, e-mail: <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>