Search in sources :

Example 6 with MAttachmentEntry

use of org.compiere.model.MAttachmentEntry in project lar_361 by comitsrl.

the class ReportStarterWithTxtExporter method getAttachmentResourceFile.

/**
 * Get .property resource file from process attachment
 * @param jasperName
 * @param currLang
 * @return File
 */
private File getAttachmentResourceFile(String jasperName, Language currLang) {
    File resFile = null;
    MAttachmentEntry[] entries = attachment.getEntries();
    // try baseName + "_" + language
    for (int i = 0; i < entries.length; i++) {
        if (entries[i].getName().equals(jasperName + currLang.getLocale().getLanguage() + ".properties")) {
            resFile = getAttachmentEntryFile(entries[i]);
            break;
        }
    }
    if (resFile == null) {
        // try baseName only
        for (int i = 0; i < entries.length; i++) {
            if (entries[i].getName().equals(jasperName + ".properties")) {
                resFile = getAttachmentEntryFile(entries[i]);
                break;
            }
        }
    }
    return resFile;
}
Also used : MAttachmentEntry(org.compiere.model.MAttachmentEntry) DigestOfFile(org.compiere.utils.DigestOfFile) File(java.io.File) JasperPrint(net.sf.jasperreports.engine.JasperPrint)

Example 7 with MAttachmentEntry

use of org.compiere.model.MAttachmentEntry in project adempiere by adempiere.

the class WAttachment method displaySelected.

//  displayData
/**
	 * Use to refresh preview frame, don't call directly.
	 */
public void displaySelected() {
    MAttachmentEntry entry = m_attachment.getEntry(displayIndex);
    log.config("Index=" + displayIndex + " - " + entry);
    if (entry != null && entry.getData() != null) {
        bSave.setEnabled(true);
        bDelete.setEnabled(true);
        log.config(entry.toStringX());
        try {
            AMedia media = new AMedia(entry.getName(), null, entry.getContentType(), entry.getData());
            preview.setContent(media);
            preview.setVisible(true);
            preview.invalidate();
        } catch (Exception e) {
            log.log(Level.SEVERE, "attachment", e);
        }
    }
}
Also used : AMedia(org.zkoss.util.media.AMedia) MAttachmentEntry(org.compiere.model.MAttachmentEntry) IOException(java.io.IOException)

Example 8 with MAttachmentEntry

use of org.compiere.model.MAttachmentEntry in project adempiere by adempiere.

the class WAttachment method saveAttachmentToFile.

//	deleteAttachment
/**
	 *	Save Attachment to File
	 */
private void saveAttachmentToFile() {
    int index = cbContent.getSelectedIndex();
    log.info("index=" + index);
    if (m_attachment.getEntryCount() < index)
        return;
    MAttachmentEntry entry = m_attachment.getEntry(index);
    if (entry != null && entry.getData() != null) {
        try {
            AMedia media = new AMedia(entry.getName(), null, entry.getContentType(), entry.getData());
            Filedownload.save(media);
        } catch (Exception e) {
            log.log(Level.SEVERE, "attachment", e);
        }
    }
}
Also used : AMedia(org.zkoss.util.media.AMedia) MAttachmentEntry(org.compiere.model.MAttachmentEntry) IOException(java.io.IOException)

Example 9 with MAttachmentEntry

use of org.compiere.model.MAttachmentEntry in project adempiere by adempiere.

the class ReportStarter method getAttachmentSubreports.

/**
     * Get subreports from attachment. Assume all other jasper attachment is subreport.
     * @param reportPath
     * @return File[]
     */
private File[] getAttachmentSubreports(String reportPath) {
    String name = reportPath.substring("attachment:".length()).trim();
    ArrayList<File> subreports = new ArrayList<File>();
    MAttachmentEntry[] entries = attachment.getEntries();
    for (int i = 0; i < entries.length; i++) {
        // @Trifon
        if (!entries[i].getName().equals(name) && (entries[i].getName().toLowerCase().endsWith(".jrxml") || entries[i].getName().toLowerCase().endsWith(".jasper") || entries[i].getName().toLowerCase().endsWith(".jpg") || entries[i].getName().toLowerCase().endsWith(".png"))) {
            File reportFile = getAttachmentEntryFile(entries[i]);
            if (reportFile != null)
                subreports.add(reportFile);
        }
    }
    File[] subreportsTemp = new File[0];
    subreportsTemp = subreports.toArray(subreportsTemp);
    return subreportsTemp;
}
Also used : MAttachmentEntry(org.compiere.model.MAttachmentEntry) ArrayList(java.util.ArrayList) DigestOfFile(org.compiere.util.DigestOfFile) File(java.io.File) JasperPrint(net.sf.jasperreports.engine.JasperPrint)

Example 10 with MAttachmentEntry

use of org.compiere.model.MAttachmentEntry in project adempiere by adempiere.

the class ReportStarter method getAttachmentResourceFile.

/**
     * Get .property resource file from process attachment
     * @param jasperName
     * @param currLang
     * @return File
     */
private File getAttachmentResourceFile(String jasperName, Language currLang) {
    File resFile = null;
    MAttachmentEntry[] entries = attachment.getEntries();
    // try baseName + "_" + language
    for (int i = 0; i < entries.length; i++) {
        if (entries[i].getName().equals(jasperName + currLang.getLocale().getLanguage() + ".properties")) {
            resFile = getAttachmentEntryFile(entries[i]);
            break;
        }
    }
    if (resFile == null) {
        // try baseName only
        for (int i = 0; i < entries.length; i++) {
            if (entries[i].getName().equals(jasperName + ".properties")) {
                resFile = getAttachmentEntryFile(entries[i]);
                break;
            }
        }
    }
    return resFile;
}
Also used : MAttachmentEntry(org.compiere.model.MAttachmentEntry) DigestOfFile(org.compiere.util.DigestOfFile) File(java.io.File) JasperPrint(net.sf.jasperreports.engine.JasperPrint)

Aggregations

MAttachmentEntry (org.compiere.model.MAttachmentEntry)13 File (java.io.File)7 JasperPrint (net.sf.jasperreports.engine.JasperPrint)6 IOException (java.io.IOException)5 DigestOfFile (org.compiere.util.DigestOfFile)3 DigestOfFile (org.compiere.utils.DigestOfFile)3 ArrayList (java.util.ArrayList)2 ServletOutputStream (javax.servlet.ServletOutputStream)2 MProcess (org.compiere.model.MProcess)2 AMedia (org.zkoss.util.media.AMedia)2 Dimension (java.awt.Dimension)1 Image (java.awt.Image)1 FileOutputStream (java.io.FileOutputStream)1 OutputStream (java.io.OutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 BigDecimal (java.math.BigDecimal)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 Transformer (javax.xml.transform.Transformer)1