File: ServletDestination.java

package info (click to toggle)
libxt-java 0.19991105-5
  • links: PTS
  • area: main
  • in suites: woody
  • size: 1,908 kB
  • ctags: 2,762
  • sloc: java: 12,823; makefile: 52; xml: 46
file content (37 lines) | stat: -rw-r--r-- 1,215 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package com.jclark.xsl.sax;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import javax.servlet.*;

public class ServletDestination extends GenericDestination {
  private final ServletResponse response;

  public ServletDestination(ServletResponse response) {
    this.response = response;
  }

  public OutputStream getOutputStream(String contentType, String encoding)
    throws IOException {
    setEncoding(encoding);
    String lowerContentType = contentType.toLowerCase().trim();
    if (lowerContentType.startsWith("text")
	&& lowerContentType.indexOf("charset") < 0) {
      contentType = contentType + "; charset=" + getEncoding();
      response.setContentType(contentType);
      if (false) {
	// Disabled because getCharacterEncoding is broken in JSDK 2.1
	encoding = response.getCharacterEncoding();
	System.err.println("Set content-type to " + contentType + "; encoding was " + encoding);
	if (encoding != null)
	  setEncoding(encoding);
      }
    }
    else
      response.setContentType(contentType);
    return response.getOutputStream();
  }
}