Ejemplo n.º 1
0
 /** Initializes the output. Sets the expected encoding and content type. */
 public void initResponse() {
   // set content type and encoding
   final SerializerOptions opts = sopts();
   final String enc = opts.get(SerializerOptions.ENCODING);
   res.setCharacterEncoding(enc);
   final String ct = mediaType(opts);
   res.setContentType(new TokenBuilder(ct).add(CHARSET).add(enc).toString());
 }
Ejemplo n.º 2
0
  /**
   * Initializes the output. Sets the expected encoding and content type.
   *
   * @param sprop serialization properties
   */
  public void initResponse(final SerializerProp sprop) {
    // set encoding
    final String encoding = sprop.get(SerializerProp.S_ENCODING);
    res.setCharacterEncoding(encoding);

    // set content type
    String type = sprop.get(SerializerProp.S_MEDIA_TYPE);
    if (type.isEmpty()) {
      // determine content type dependent on output method
      final String mt = sprop.get(SerializerProp.S_METHOD);
      if (mt.equals(M_RAW)) {
        type = APP_OCTET;
      } else if (mt.equals(M_XML)) {
        type = APP_XML;
      } else if (eq(mt, M_JSON, M_JSONML)) {
        type = APP_JSON;
      } else if (eq(mt, M_XHTML, M_HTML5, M_HTML)) {
        type = TEXT_HTML;
      } else {
        type = TEXT_PLAIN;
      }
    }
    res.setContentType(type + MimeTypes.CHARSET + encoding);
  }