Please include a "ReportFormat" enumerated data type with the JasperReports library that encapsulates the Media Type and filename extensions for report formats. Something like:
public enum ReportFormat {
/**
* Adobe Acrobat Portable Document Format.
*
* @see https://tools.ietf.org/html/rfc3778
*/
PDF("application/pdf", "pdf"),
/**
* Hypertext Mark-up Language.
*
* @see https://www.ietf.org/rfc/rfc2854.txt
*/
HTML("text/html", "html"),
/**
* Comma-separated Values.
*
* @see https://tools.ietf.org/html/rfc4180
*/
CSV("text/csv", "csv"),
/**
* Proprietary Microsoft Excel Format (see also: CSV).
*
* @see http://www.iana.org/assignments/media-types/application/vnd.ms-excel
*/
XLS("application/vnd.ms-excel", "xls"),
/**
* The media type as defined by IANA and IETF.
*
* @see http://www.iana.org/assignments/media-types/media-types.xhtml
*/
private final String mediaType;
/**
* The filename extension typically used for this format's media type.
*/
private final String extension;
private ReportFormat(
final String mediaType,
final String extension) {
this.mediaType = mediaType;
this.extension = extension;
}
public String getFilenameExtension() {
return this.extension;
}
/**
* Returns the media type (formerly MIME type) for this report format
* suitable for inclusion in the content-header of an HTTP response.
*
* @return The report format media type.
* @see http://www.iana.org/assignments/media-types/media-types.xhtml
*/
public String getMediaType() {
return this.mediaType;
}
}
There's really no need for developers to reinvent this wheel time and time and time again.
Recommended Comments