Search in sources :

Example 1 with AMedia

use of org.zkoss.util.media.AMedia in project adempiere by adempiere.

the class WMediaDialog method createMedia.

//  displayData
private AMedia createMedia() throws SQLException {
    AMedia media;
    String contentType = null;
    if (m_data instanceof byte[]) {
        media = new AMedia(this.getTitle(), null, contentType, (byte[]) m_data);
    } else if (m_data instanceof Blob) {
        media = new AMedia(this.getTitle(), null, contentType, ((Blob) m_data).getBinaryStream());
    } else if (m_data instanceof Clob) {
        Clob clob = (Clob) m_data;
        long length = clob.length() > 100 ? 100 : clob.length();
        String data = ((Clob) m_data).getSubString(1, new Long(length).intValue());
        if (data.toUpperCase().indexOf("<html>") >= 0) {
            contentType = "text/html";
        } else {
            contentType = "text/plain";
        }
        media = new AMedia(this.getTitle(), null, contentType, ((Clob) m_data).getCharacterStream());
    } else {
        contentType = "text/plain";
        media = new AMedia(this.getTitle(), null, contentType, m_data.toString());
    }
    return media;
}
Also used : Blob(java.sql.Blob) AMedia(org.zkoss.util.media.AMedia) Clob(java.sql.Clob)

Example 2 with AMedia

use of org.zkoss.util.media.AMedia in project adempiere by adempiere.

the class ZkJRViewer method renderReport.

/***
	 * 
	 * This method is used for generate report in PDF or XLS based on previewType selection.
	 * 
	 * @throws Exception
	 */
private void renderReport() throws Exception {
    Listitem selected = previewType.getSelectedItem();
    //
    // Place Common code outside the If else block
    //
    String path = System.getProperty("java.io.tmpdir");
    String prefix = makePrefix(jasperPrint.getName());
    if (log.isLoggable(Level.FINE)) {
        log.log(Level.FINE, "Path=" + path + " Prefix=" + prefix);
    }
    if (selected == null || "PDF".equals(selected.getValue())) {
        file = File.createTempFile(prefix, ".pdf", new File(path));
        JasperExportManager.exportReportToPdfFile(jasperPrint, file.getAbsolutePath());
        media = new AMedia(this.title, "pdf", "application/pdf", file, true);
    } else if ("XLS".equals(previewType.getSelectedItem().getValue())) {
        file = File.createTempFile(prefix, ".xls", new File(path));
        FileOutputStream fos = new FileOutputStream(file);
        JRXlsExporter exporterXLS = new JRXlsExporter();
        exporterXLS.setParameter(JRXlsExporterParameter.JASPER_PRINT, jasperPrint);
        exporterXLS.setParameter(JRXlsExporterParameter.OUTPUT_STREAM, fos);
        exporterXLS.setParameter(JRXlsExporterParameter.OUTPUT_FILE, file.getAbsolutePath());
        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);
        exporterXLS.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_COLUMNS, Boolean.TRUE);
        exporterXLS.setParameter(JRXlsExporterParameter.IS_COLLAPSE_ROW_SPAN, Boolean.TRUE);
        exporterXLS.setParameter(JRXlsExporterParameter.IS_IGNORE_GRAPHICS, Boolean.FALSE);
        exporterXLS.exportReport();
        media = new AMedia(this.title, "xls", "application/vnd.ms-excel", file, true);
    } else if ("RTF".equals(previewType.getSelectedItem().getValue())) {
        FileOutputStream fos = new FileOutputStream(file);
        JRRtfExporter rtfExporter = new JRRtfExporter();
        rtfExporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
        rtfExporter.setParameter(JRExporterParameter.OUTPUT_STREAM, fos);
        rtfExporter.setParameter(JRExporterParameter.CHARACTER_ENCODING, "UTF-8");
        rtfExporter.exportReport();
        media = new AMedia(this.title, "doc", "application/vnd.ms-word", file, true);
    }
    iframe.setContent(media);
}
Also used : JRXlsExporter(net.sf.jasperreports.engine.export.JRXlsExporter) AMedia(org.zkoss.util.media.AMedia) FileOutputStream(java.io.FileOutputStream) Listitem(org.zkoss.zul.Listitem) File(java.io.File) JRRtfExporter(net.sf.jasperreports.engine.export.JRRtfExporter)

Example 3 with AMedia

use of org.zkoss.util.media.AMedia in project adempiere by adempiere.

the class AboutWindow method downloadLog.

private void downloadLog() {
    String log = CLogErrorBuffer.get(true).getErrorInfo(Env.getCtx(), bErrorsOnly.isChecked());
    AMedia media = new AMedia("trace.log", null, "text/plain", log.getBytes());
    Filedownload.save(media);
}
Also used : AMedia(org.zkoss.util.media.AMedia)

Example 4 with AMedia

use of org.zkoss.util.media.AMedia in project adempiere by adempiere.

the class WCollect method printTicketWeb.

/**
	 * 	Print Ticket for Web
	 *  @return void
	 */
public void printTicketWeb() {
    try {
        if (posPanel.isToPrint() && posPanel.hasOrder()) {
            ReportCtl.startDocumentPrint(0, posPanel.getC_Order_ID(), false);
            ReportEngine m_reportEngine = ReportEngine.get(p_ctx, ReportEngine.ORDER, posPanel.getC_Order_ID());
            StringWriter sw = new StringWriter();
            m_reportEngine.createCSV(sw, '\t', m_reportEngine.getPrintFormat().getLanguage());
            byte[] data = sw.getBuffer().toString().getBytes();
            AMedia media = new AMedia(m_reportEngine.getPrintFormat().getName() + ".txt", null, "application/octet-stream", data);
            posPanel.printFile(media.getByteData(), posPanel.getC_Order_ID());
        }
    } catch (Exception e) {
        log.severe("PrintTicket - Error Printing Ticket");
    }
}
Also used : ReportEngine(org.compiere.print.ReportEngine) StringWriter(java.io.StringWriter) AMedia(org.zkoss.util.media.AMedia) POSaveFailedException(org.adempiere.pipo.exception.POSaveFailedException)

Example 5 with AMedia

use of org.zkoss.util.media.AMedia in project adempiere by adempiere.

the class WMediaDialog method displayData.

// dispose
/**
	 *  Display gif or jpg in gifPanel
	 * 	@param index index
	 */
private void displayData() {
    //	Reset UI		
    preview.setVisible(false);
    bDelete.setEnabled(false);
    bSave.setEnabled(false);
    if (m_data != null) {
        bSave.setEnabled(true);
        bDelete.setEnabled(true);
        try {
            AMedia media = createMedia();
            preview.setContent(media);
            preview.setVisible(true);
        } catch (Exception e) {
            log.log(Level.SEVERE, "Failed to preview content", e);
        }
    }
}
Also used : AMedia(org.zkoss.util.media.AMedia) SQLException(java.sql.SQLException)

Aggregations

AMedia (org.zkoss.util.media.AMedia)14 File (java.io.File)4 SQLException (java.sql.SQLException)4 IOException (java.io.IOException)2 StringWriter (java.io.StringWriter)2 AdempiereException (org.adempiere.exceptions.AdempiereException)2 MAttachmentEntry (org.compiere.model.MAttachmentEntry)2 Listitem (org.zkoss.zul.Listitem)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileOutputStream (java.io.FileOutputStream)1 Blob (java.sql.Blob)1 Clob (java.sql.Clob)1 JRRtfExporter (net.sf.jasperreports.engine.export.JRRtfExporter)1 JRXlsExporter (net.sf.jasperreports.engine.export.JRXlsExporter)1 POSaveFailedException (org.adempiere.pipo.exception.POSaveFailedException)1 ListItem (org.adempiere.webui.component.ListItem)1 HTMLExtension (org.adempiere.webui.report.HTMLExtension)1 ReportEngine (org.compiere.print.ReportEngine)1 Iframe (org.zkoss.zul.Iframe)1