DefaultReportOutputHandlerFactory implements ReportOutputHandlerFactory { public String getMimeType( final ReportOutputHandlerSelector selector ) { String outputTarget = selector.getOutputType(); if ( isHtmlPageAvailable() && HtmlTableModule.TABLE_HTML_STREAM_EXPORT_TYPE.equals( outputTarget ) ) { return SimpleReportingComponent.MIME_TYPE_HTML; } if ( isHtmlPageAvailable() && HtmlTableModule.TABLE_HTML_PAGE_EXPORT_TYPE.equals( outputTarget ) ) { return SimpleReportingComponent.MIME_TYPE_HTML; } if ( isXlsAvailable() && ExcelTableModule.EXCEL_FLOW_EXPORT_TYPE.equals( outputTarget ) ) { return SimpleReportingComponent.MIME_TYPE_XLS; } if ( isXlsxAvailable() && ExcelTableModule.XLSX_FLOW_EXPORT_TYPE.equals( outputTarget ) ) { return SimpleReportingComponent.MIME_TYPE_XLSX; } if ( isCsvAvailable() && CSVTableModule.TABLE_CSV_STREAM_EXPORT_TYPE.equals( outputTarget ) ) { return SimpleReportingComponent.MIME_TYPE_CSV; } if ( isRtfAvailable() && RTFTableModule.TABLE_RTF_FLOW_EXPORT_TYPE.equals( outputTarget ) ) { return SimpleReportingComponent.MIME_TYPE_RTF; } if ( isPdfAvailable() && PdfPageableModule.PDF_EXPORT_TYPE.equals( outputTarget ) ) { return SimpleReportingComponent.MIME_TYPE_PDF; } if ( isTextAvailable() && PlainTextPageableModule.PLAINTEXT_EXPORT_TYPE.equals( outputTarget ) ) { return SimpleReportingComponent.MIME_TYPE_TXT; } if ( isMailAvailable() && SimpleReportingComponent.MIME_TYPE_EMAIL.equals( outputTarget ) ) { return SimpleReportingComponent.MIME_TYPE_EMAIL; } if ( isXmlTableAvailable() && XmlTableModule.TABLE_XML_EXPORT_TYPE.equals( outputTarget ) ) { return SimpleReportingComponent.MIME_TYPE_XML; } if ( isXmlPageAvailable() && XmlPageableModule.PAGEABLE_XML_EXPORT_TYPE.equals( outputTarget ) ) { return SimpleReportingComponent.MIME_TYPE_XML; } if ( isPngAvailable() && SimpleReportingAction.PNG_EXPORT_TYPE.equals( outputTarget ) ) { return SimpleReportingComponent.MIME_TYPE_PNG; } return SimpleReportingAction.MIME_GENERIC_FALLBACK; } DefaultReportOutputHandlerFactory(); boolean isHtmlStreamVisible(); void setHtmlStreamVisible( final boolean htmlStreamVisible ); boolean isHtmlPageVisible(); void setHtmlPageVisible( final boolean htmlPageVisible ); boolean isXlsVisible(); void setXlsVisible( final boolean xlsVisible ); boolean isXlsxVisible(); void setXlsxVisible( final boolean xlsxVisible ); boolean isCsvVisible(); void setCsvVisible( final boolean csvVisible ); boolean isRtfVisible(); void setRtfVisible( final boolean rtfVisible ); boolean isPdfVisible(); void setPdfVisible( final boolean pdfVisible ); boolean isTextVisible(); void setTextVisible( final boolean textVisible ); boolean isMailVisible(); void setMailVisible( final boolean mailVisible ); boolean isXmlTableVisible(); void setXmlTableVisible( final boolean xmlTableVisible ); boolean isXmlPageVisible(); void setXmlPageVisible( final boolean xmlPageVisible ); boolean isPngVisible(); void setPngVisible( final boolean pngVisible ); boolean isHtmlStreamAvailable(); void setHtmlStreamAvailable( final boolean htmlStreamAvailable ); boolean isHtmlPageAvailable(); void setHtmlPageAvailable( final boolean htmlPageAvailable ); boolean isXlsAvailable(); void setXlsAvailable( final boolean xlsAvailable ); boolean isXlsxAvailable(); void setXlsxAvailable( final boolean xlsxAvailable ); boolean isCsvAvailable(); void setCsvAvailable( final boolean csvAvailable ); boolean isRtfAvailable(); void setRtfAvailable( final boolean rtfAvailable ); boolean isPdfAvailable(); void setPdfAvailable( final boolean pdfAvailable ); boolean isTextAvailable(); void setTextAvailable( final boolean textAvailable ); boolean isMailAvailable(); void setMailAvailable( final boolean mailAvailable ); boolean isXmlTableAvailable(); void setXmlTableAvailable( final boolean xmlTableAvailable ); boolean isXmlPageAvailable(); void setXmlPageAvailable( final boolean xmlPageAvailable ); boolean isPngAvailable(); void setPngAvailable( final boolean pngAvailable ); String getMimeType( final ReportOutputHandlerSelector selector ); Set<Map.Entry<String, String>> getSupportedOutputTypes(); ReportOutputHandler createOutputHandlerForOutputType( final ReportOutputHandlerSelector selector );  }
@Test public void testGetMimeType() throws Exception { MockOutputHandlerSelector selector = new MockOutputHandlerSelector(); HashMap<String, String> outputTypes = new HashMap<String, String>(); outputTypes.put( "table/html;page-mode=stream", "text/html" ); outputTypes.put( "table/html;page-mode=page", "text/html" ); outputTypes.put( "table/excel;page-mode=flow", "application/vnd.ms-excel" ); outputTypes.put( "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;page-mode=flow", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" ); outputTypes.put( "table/csv;page-mode=stream", "text/csv" ); outputTypes.put( "table/rtf;page-mode=flow", "application/rtf" ); outputTypes.put( "pageable/pdf", "application/pdf" ); outputTypes.put( "pageable/text", "text/plain" ); outputTypes.put( "mime-message/text/html", "mime-message/text/html" ); outputTypes.put( "table/xml", "application/xml" ); outputTypes.put( "pageable/xml", "application/xml" ); outputTypes.put( "pageable/X-AWT-Graphics;image-type=png", "image/png" ); outputTypes.put( "", "application/octet-stream" ); for ( Map.Entry<String, String> outputType : outputTypes.entrySet() ) { selector.setOutputType( outputType.getKey() ); assertEquals( outputType.getValue(), roh.getMimeType( selector ) ); } }