Exemple #1
0
  /**
   * Returns the media type defined in the specified serialization parameters.
   *
   * @param sopts serialization parameters
   * @return media type
   */
  public static String mediaType(final SerializerOptions sopts) {
    // set content type
    final String type = sopts.get(SerializerOptions.MEDIA_TYPE);
    if (!type.isEmpty()) return type;

    // determine content type dependent on output method
    final SerialMethod sm = sopts.get(SerializerOptions.METHOD);
    if (sm == SerialMethod.RAW) return APP_OCTET;
    if (sm == SerialMethod.XML) return APP_XML;
    if (sm == SerialMethod.XHTML || sm == SerialMethod.HTML) return TEXT_HTML;
    if (sm == SerialMethod.JSON) {
      final JsonSerialOptions jprop = sopts.get(SerializerOptions.JSON);
      return jprop.get(JsonOptions.FORMAT) == JsonFormat.JSONML ? APP_JSONML : APP_JSON;
    }
    return TEXT_PLAIN;
  }