本文整理汇总了Java中net.sf.jasperreports.engine.export.JRHtmlExporter类的典型用法代码示例。如果您正苦于以下问题:Java JRHtmlExporter类的具体用法?Java JRHtmlExporter怎么用?Java JRHtmlExporter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JRHtmlExporter类属于net.sf.jasperreports.engine.export包,在下文中一共展示了JRHtmlExporter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: export
import net.sf.jasperreports.engine.export.JRHtmlExporter; //导入依赖的package包/类
public void export(HttpServletRequest req, HttpServletResponse res) throws Exception {
res.setContentType("text/html;charset=UTF-8");
JRHtmlExporter exporter=new JRHtmlExporter(DefaultJasperReportsContext.getInstance());
JasperPrint jasperPrint=this.getJasperPrint(req);
req.getSession().setAttribute(BaseHttpServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE, jasperPrint);
exporter.setParameter(JRExporterParameter.JASPER_PRINT,jasperPrint);
OutputStream ouputStream = res.getOutputStream();
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream);
String path=req.getContextPath();
if(path.endsWith("/")){
path+="dorado/bdf2/jasperreports/html.image";
}else{
path+="/dorado/bdf2/jasperreports/html.image";
}
exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI,path+"?image=");
try {
exporter.exportReport();
} catch (JRException e) {
throw new ServletException(e);
} finally {
if (ouputStream != null) {
ouputStream.flush();
ouputStream.close();
}
}
}
示例2: exportPrintObject
import net.sf.jasperreports.engine.export.JRHtmlExporter; //导入依赖的package包/类
private void exportPrintObject(ReporterConfig rc, final JasperPrint print, final ComponentExecutionApi reporter) {
// build the export filename
String filename = buildFilename(reporter, rc);
// do each export option
if (rc.isCsv()) {
export(new JRCsvExporter(), print, filename, "csv", rc.isOpenExportFile());
}
if (rc.isDocx()) {
export(new JRDocxExporter(), print, filename, "docx", rc.isOpenExportFile());
}
if (rc.isOdt()) {
export(new JROdtExporter(), print, filename, "odt", rc.isOpenExportFile());
}
if (rc.isHtml()) {
export(new JRHtmlExporter(), print, filename, "html", rc.isOpenExportFile());
}
if (rc.isPdf()) {
export(new JRPdfExporter(), print, filename, "pdf", rc.isOpenExportFile());
}
if (rc.isXls()) {
export(new JRXlsExporter(), print, filename, "xls", rc.isOpenExportFile());
}
// do show viewer at the end so it pops up after everything else
if (rc.isShowViewer()) {
reporter.submitControlLauncher(new ControlLauncherCallback() {
@Override
public void launchControls(ComponentControlLauncherApi launcherApi) {
class DisposableViewer extends JRViewer implements Disposable {
DisposableViewer(JasperPrint jrPrint) {
super(jrPrint);
}
@Override
public void dispose() {
}
}
DisposableViewer viewer = new DisposableViewer(print);
launcherApi.registerPanel("report", null, viewer, true);
}
});
}
}
示例3: exportToHTML
import net.sf.jasperreports.engine.export.JRHtmlExporter; //导入依赖的package包/类
private void exportToHTML() {
log.debug("exporting to HTML");
htmlExporter = new JRHtmlExporter();
setExportParameter(JRHtmlExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.TRUE);
setExportParameter(JRHtmlExporterParameter.IMAGES_URI,"servlets/image?image=");
setExportParameter(JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN, Boolean.TRUE);
setExportParameter(JRHtmlExporterParameter.IS_OUTPUT_IMAGES_TO_DIR, Boolean.TRUE);
setExportParameter(JRHtmlExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE);
htmlExporter.setParameters(getExportParameters());
try {
start = System.currentTimeMillis();
htmlExporter.exportReport();
log.info("export running time (msec): "
+ (System.currentTimeMillis() - start));
} catch (JRException jre) {
jre.printStackTrace();
}
}
示例4: getHTML
import net.sf.jasperreports.engine.export.JRHtmlExporter; //导入依赖的package包/类
public static byte[] getHTML(StorageService storageService, JasperPrint jasperPrint)
throws JRException {
byte[] content = null;
ByteArrayOutputStream baos = null;
try {
baos = new ByteArrayOutputStream();
JRHtmlExporter exporter = new JRHtmlExporter();
// Jasper Images will be stored to reports home directory
// so to be accesed from HTML
exporter.setParameter(JRHtmlExporterParameter.IS_OUTPUT_IMAGES_TO_DIR, Boolean.TRUE);
exporter.setParameter(JRHtmlExporterParameter.IMAGES_DIR_NAME, storageService.getSettings().getReportsHome());
exporter.setParameter(JRHtmlExporterParameter.SIZE_UNIT, "px");
exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, "./");
content = getBytes(exporter, baos, jasperPrint);
} finally {
if (baos != null) {
try {
baos.flush();
baos.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
return content;
}
示例5: renderWithWriter
import net.sf.jasperreports.engine.export.JRHtmlExporter; //导入依赖的package包/类
@Test
public void renderWithWriter() throws Exception {
StringWriter writer = new StringWriter();
JasperPrint print = JasperFillManager.fillReport(getReport(), getParameters(), getDataSource());
JasperReportsUtils.render(new JRHtmlExporter(), print, writer);
String output = writer.getBuffer().toString();
assertHtmlOutputCorrect(output);
}
示例6: getJREXporter
import net.sf.jasperreports.engine.export.JRHtmlExporter; //导入依赖的package包/类
private static JRExporter getJREXporter(final String extension) {
if ("pdf".equalsIgnoreCase(extension)) {
JRPdfExporter exporter = new JRPdfExporter();
// exporter.setParameter(JRPdfExporterParameter.PDF_JAVASCRIPT, "this.print();");
return exporter;
} else if ("html".equalsIgnoreCase(extension)) {
return new JRHtmlExporter();
} else if ("xls".equalsIgnoreCase(extension)) {
JRXlsExporter exporterXLS = new JRXlsExporter();
exporterXLS.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.FALSE);
exporterXLS.setParameter(JRXlsExporterParameter.IS_DETECT_CELL_TYPE, Boolean.TRUE);
exporterXLS.setParameter(JRXlsExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.FALSE);
exporterXLS.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE);
return exporterXLS;
} else if ("txt".equalsIgnoreCase(extension)) {
return new JRTextExporter();
} else if ("csv".equalsIgnoreCase(extension)) {
return new JRCsvExporter();
} else if ("docx".equalsIgnoreCase(extension)) {
return new JRDocxExporter();
}
return null;
}
示例7: getViewImplementation
import net.sf.jasperreports.engine.export.JRHtmlExporter; //导入依赖的package包/类
@Override
protected AbstractJasperReportsView getViewImplementation() {
ConfigurableJasperReportsView view = new ConfigurableJasperReportsView();
view.setExporterClass(JRHtmlExporter.class);
view.setUseWriter(true);
view.setContentType("application/pdf");
return view;
}
示例8: testRenderWithWriter
import net.sf.jasperreports.engine.export.JRHtmlExporter; //导入依赖的package包/类
public void testRenderWithWriter() throws Exception {
StringWriter writer = new StringWriter();
JasperPrint print = JasperFillManager.fillReport(getReport(), getParameters(), getDataSource());
JasperReportsUtils.render(new JRHtmlExporter(), print, writer);
String output = writer.getBuffer().toString();
assertHtmlOutputCorrect(output);
}
示例9: getHtmlExporter
import net.sf.jasperreports.engine.export.JRHtmlExporter; //导入依赖的package包/类
protected JRHtmlExporter getHtmlExporter() {
JRHtmlExporter exporter = new JRHtmlExporter();
String random = "" + Math.random() * 1000.0;
random = random.replace('.', '0').replace(',', '0');
exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, Utils.getWebContextPath(EnterpriseApplication.getInstance()) + "/image?r=" + random + "&image=");
return exporter;
}
示例10: getHtmlExporter
import net.sf.jasperreports.engine.export.JRHtmlExporter; //导入依赖的package包/类
protected JRHtmlExporter getHtmlExporter() {
JRHtmlExporter exporter = new JRHtmlExporter();
String random = "" + Math.random() * 1000.0;
random = random.replace('.', '0').replace(',', '0');
exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, getWebContextPath() + "/image?r=" + random + "&image=");
return exporter;
}
示例11: getHtmlFragment
import net.sf.jasperreports.engine.export.JRHtmlExporter; //导入依赖的package包/类
@Override
public String getHtmlFragment(JRHtmlExporterContext context,
JRGenericPrintElement element) {
Map<String, Object> contextMap = new HashMap<String, Object>();
contextMap.put("mapCanvasId", "map_canvas_" + element.hashCode());
if (context.getExporter() instanceof JRXhtmlExporter) {
contextMap.put("xhtml", "xhtml");
JRXhtmlExporter xhtmlExporter = (JRXhtmlExporter) context.getExporter();
contextMap.put("elementX", xhtmlExporter.toSizeUnit(element.getX()));
contextMap.put("elementY", xhtmlExporter.toSizeUnit(element.getY()));
} else {
JRHtmlExporter htmlExporter = (JRHtmlExporter) context.getExporter();
contextMap.put("elementX", htmlExporter.toSizeUnit(element.getX()));
contextMap.put("elementY", htmlExporter.toSizeUnit(element.getY()));
}
contextMap.put("elementId", element.getKey());
contextMap.put("elementWidth", element.getWidth());
contextMap.put("elementHeight", element.getHeight());
if (element.getModeValue() == ModeEnum.OPAQUE) {
contextMap.put("backgroundColor",
JRColorUtil.getColorHexa(element.getBackcolor()));
}
WmsRequestBuilder requestBuilder =
WmsMapElementImageProvider.mapRequestBuilder(element);
try {
contextMap.put("wmsMapUrl", requestBuilder.toMapUrl());
} catch (MalformedURLException e) {
throw new RuntimeException("Unable to build WMS map service url", e);
}
return VelocityUtil.processTemplate(MAP_ELEMENT_HTML_TEMPLATE, contextMap);
}
示例12: createExporter
import net.sf.jasperreports.engine.export.JRHtmlExporter; //导入依赖的package包/类
@Override
protected JRExporter createExporter() {
return new JRHtmlExporter();
}
示例13: download
import net.sf.jasperreports.engine.export.JRHtmlExporter; //导入依赖的package包/类
/**
* metodo responsavel pelo preenchimento do relatorio, a partir do arquivo jasper compilado, do nome do arquivo html,
* e considerando os dados sob a forma de List e os par�metros
*
* @param nomeArquivo
* @param streamRelatorio
* @param parametros
* @param dados
* @throws RelatorioException
*/
public void download(String nomeArquivo, InputStream streamRelatorio, Map parametros, List dados) throws RelatorioException {
String caminhoRelatorio = caminhoRelatorioHTML + nomeArquivo;
System.out.println("CAMINHO RELAT�RIO: " + caminhoRelatorio);
File relatorio = new File(caminhoRelatorio);
byte[] buffer = null;
try {
FacesContext context = FacesContext.getCurrentInstance();
HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse();
HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getResponse();
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition", "attachment;filename=\"" + nomeArquivo + "\"");
if (parametros == null) {
parametros = new HashMap();
}
//Neste ponto, a nossa lista preenchida com o modelo � entregue ao Jasper, que cria um DataSource com ela
JRBeanCollectionDataSource dataSource = new JRBeanCollectionDataSource(dados);
//Aqui � onde ocorre de fato o preenchimento do relat�rio, com os par�metros e DataSource passados
JasperPrint impressao = JasperFillManager.fillReport(streamRelatorio, parametros, dataSource);
//Ponto onde o relat�rio com os dados montados � exportado para o formato HTML
JasperExportManager.exportReportToHtmlFile(impressao, caminhoRelatorio);
FileInputStream fis = new FileInputStream(relatorio);
OutputStream os = response.getOutputStream();
response.setContentType("text/html");
JRHtmlExporter htmlExporter = new JRHtmlExporter();
request.getSession().setAttribute(ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE, impressao);
htmlExporter.setParameter(JRExporterParameter.JASPER_PRINT, impressao);
htmlExporter.setParameter(JRExporterParameter.OUTPUT_WRITER, os);
htmlExporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, "/gesplan/image?image=");
htmlExporter.exportReport();
int read = 0;
buffer = new byte[1024];
while ((read = fis.read(buffer)) != -1) {
os.write(buffer, 0, read);
}
os.flush();
os.close();
fis.close();
FacesContext.getCurrentInstance().responseComplete();
} catch (Throwable ex) {
ex.printStackTrace();
throw new RelatorioException(ex);
} finally {
buffer = null;
}
}
示例14: doPost
import net.sf.jasperreports.engine.export.JRHtmlExporter; //导入依赖的package包/类
@SuppressWarnings("unchecked")
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
String nomeDoRelatorio = (String)request.getAttribute("nomeDoRelatorio");
System.out.println(">>>>>>>>>>>>>>>Nome do relatorio="+nomeDoRelatorio);
List lista = (List)request.getAttribute("lista");
HashMap<String, String> parametros = (HashMap<String, String>)request.getAttribute("parametros");
ServletContext context = this.getServletContext();
String nomeDoArquivoCompilado = context.getRealPath(nomeDoRelatorio);
System.out.println(">>>>>>>>>>>>>>>>>>>> nomeDoArquivoCompilado="+nomeDoArquivoCompilado);
File arquivo = new File(nomeDoArquivoCompilado);
PrintWriter printWriter = response.getWriter();
try
{ JasperReport relatorioCompilado = (JasperReport) JRLoader.loadObject(arquivo);
JRBeanCollectionDataSource ds = new JRBeanCollectionDataSource(lista);
JasperPrint impressao = JasperFillManager.fillReport(relatorioCompilado, parametros, ds);
JRHtmlExporter htmlExporter = new JRHtmlExporter();
response.setContentType("text/html");
request.getSession().setAttribute(ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE, impressao);
htmlExporter.setParameter(JRExporterParameter.JASPER_PRINT, impressao);
htmlExporter.setParameter(JRExporterParameter.OUTPUT_WRITER, printWriter);
htmlExporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, "/gesplan/image?image=");
htmlExporter.exportReport();
}
catch(JRException e)
{ e.printStackTrace(printWriter);
}
}
示例15: getHandler
import net.sf.jasperreports.engine.export.JRHtmlExporter; //导入依赖的package包/类
@Override
public GenericElementHandler getHandler(String elementName,
String exporterKey) {
if (WmsMapPrintElement.WMS_MAP_ELEMENT_NAME.equals(elementName)) {
if (JRGraphics2DExporter.GRAPHICS2D_EXPORTER_KEY
.equals(exporterKey)) {
return WmsMapElementGraphics2DHandler.getInstance();
}
if (JRHtmlExporter.HTML_EXPORTER_KEY.equals(exporterKey)
|| JRXhtmlExporter.XHTML_EXPORTER_KEY.equals(exporterKey)) {
return WmsMapElementHtmlHandler.getInstance();
}
else if (JRPdfExporter.PDF_EXPORTER_KEY.equals(exporterKey)) {
return WmsMapElementPdfHandler.getInstance();
}
else if (JRXlsExporter.XLS_EXPORTER_KEY.equals(exporterKey)) {
return WmsMapElementXlsHandler.getInstance();
}
else if (JExcelApiExporter.JXL_EXPORTER_KEY.equals(exporterKey)) {
return WmsMapElementJExcelApiHandler.getInstance();
}
// else
// if(JExcelApiMetadataExporter.JXL_METADATA_EXPORTER_KEY.equals(exporterKey))
// {
// return MapElementJExcelApiMetadataHandler.getInstance();
// }
else if (JRXlsxExporter.XLSX_EXPORTER_KEY.equals(exporterKey)) {
return WmsMapElementXlsxHandler.getInstance();
}
else if (JRDocxExporter.DOCX_EXPORTER_KEY.equals(exporterKey)) {
return WmsMapElementDocxHandler.getInstance();
}
else if (JRPptxExporter.PPTX_EXPORTER_KEY.equals(exporterKey)) {
return WmsMapElementPptxHandler.getInstance();
}
else if (JRRtfExporter.RTF_EXPORTER_KEY.equals(exporterKey)) {
return WmsMapElementRtfHandler.getInstance();
}
else if (JROdtExporter.ODT_EXPORTER_KEY.equals(exporterKey)) {
return WmsMapElementOdtHandler.getInstance();
}
else if (JROdsExporter.ODS_EXPORTER_KEY.equals(exporterKey)) {
return WmsMapElementOdsHandler.getInstance();
}
}
return null;
}