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;
}
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);
}
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);
}
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");
}
}
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);
}
}
}
Aggregations