Esempio n. 1
0
  @Override
  public PrintWriter getWriter() throws IOException {
    if (_outputType == OutputType.STREAM) throw new IllegalStateException("STREAM");

    if (_outputType == OutputType.NONE) {
      /* get encoding from Content-Type header */
      String encoding = _characterEncoding;
      if (encoding == null) {
        encoding = MimeTypes.inferCharsetFromContentType(_contentType);
        if (encoding == null) encoding = StringUtil.__ISO_8859_1;
        setCharacterEncoding(encoding);
      }

      if (_writer != null && _writer.isFor(encoding)) _writer.reopen();
      else {
        if (StringUtil.__ISO_8859_1.equalsIgnoreCase(encoding))
          _writer = new ResponseWriter(new Iso88591HttpWriter(_out), encoding);
        else if (StringUtil.__UTF8.equalsIgnoreCase(encoding))
          _writer = new ResponseWriter(new Utf8HttpWriter(_out), encoding);
        else _writer = new ResponseWriter(new EncodingHttpWriter(_out, encoding), encoding);
      }

      // Set the output type at the end, because setCharacterEncoding() checks for it
      _outputType = OutputType.WRITER;
    }
    return _writer;
  }