IDEMPIERE-5385 PDF attachments cannot be displayed in firefox (#1442)

* IDEMPIERE-5385 PDF attachments cannot be displayed in firefox
This commit is contained in:
Carlos Ruiz 2022-08-15 09:26:00 +02:00 committed by GitHub
parent 288e96fe8d
commit db2e59c163
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 37 additions and 7 deletions

View File

@ -60,6 +60,7 @@ import org.compiere.util.Env;
import org.compiere.util.Msg;
import org.compiere.util.Util;
import org.idempiere.ui.zk.media.IMediaView;
import org.idempiere.ui.zk.media.Medias;
import org.zkoss.util.media.AMedia;
import org.zkoss.util.media.Media;
import org.zkoss.zk.au.out.AuEcho;
@ -68,6 +69,7 @@ import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.event.Events;
import org.zkoss.zk.ui.event.UploadEvent;
import org.zkoss.zk.ui.ext.render.DynamicMedia;
import org.zkoss.zk.ui.util.Clients;
import org.zkoss.zul.Borderlayout;
import org.zkoss.zul.Center;
@ -79,6 +81,8 @@ import org.zkoss.zul.North;
import org.zkoss.zul.Progressmeter;
import org.zkoss.zul.South;
import org.zkoss.zul.Vlayout;
import org.zkoss.zul.impl.Utils;
import org.zkoss.zul.impl.XulElement;
/**
*
@ -90,7 +94,7 @@ public class WAttachment extends Window implements EventListener<Event>
/**
*
*/
private static final long serialVersionUID = 8266807399792500541L;
private static final long serialVersionUID = -710884973406502168L;
private static final CLogger log = CLogger.getCLogger(WAttachment.class);
@ -105,6 +109,9 @@ public class WAttachment extends Window implements EventListener<Event>
private Iframe preview = new Iframe();
protected AMedia media;
private int mediaVersion = 0;
private Textbox text = new Textbox();
private Label sizeLabel = new Label();
@ -513,7 +520,7 @@ public class WAttachment extends Window implements EventListener<Event>
if (view != null)
{
if (data.length <= maxPreviewSize) {
AMedia media = new AMedia(entry.getName(), null, mimeType, entry.getData());
media = new AMedia(entry.getName(), null, mimeType, entry.getData());
try {
customPreviewComponent = view.renderMediaView(previewPanel, media, true);
} catch (Exception e) {
@ -598,9 +605,16 @@ public class WAttachment extends Window implements EventListener<Event>
try
{
String contentType = entry.getContentType();
AMedia media = new AMedia(entry.getName(), null, contentType, entry.getData());
preview.setContent(media);
media = new AMedia(entry.getName(), null, contentType, entry.getData());
if ( MSysConfig.getBooleanValue(MSysConfig.ZK_USE_PDF_JS_VIEWER, false, Env.getAD_Client_ID(Env.getCtx()))
&& Medias.PDF_MIME_TYPE.equals(contentType)) {
mediaVersion++;
String url = Utils.getDynamicMediaURI(this, mediaVersion, media.getName(), media.getFormat());
String pdfJsUrl = "pdf.js/web/viewer.html?file="+url;
preview.setSrc(pdfJsUrl);
} else {
preview.setContent(media);
}
preview.setVisible(true);
preview.invalidate();
}
@ -841,7 +855,7 @@ public class WAttachment extends Window implements EventListener<Event>
{
try
{
AMedia media = new AMedia(entry.getName(), null, entry.getContentType(), entry.getData());
media = new AMedia(entry.getName(), null, entry.getContentType(), entry.getData());
Filedownload.save(media);
}
catch (Exception e)
@ -868,7 +882,7 @@ public class WAttachment extends Window implements EventListener<Event>
if (zipFile != null) {
String name = MTable.get(Env.getCtx(), m_attachment.getAD_Table_ID()).getTableName() + "_" + m_attachment.getRecord_ID();
AMedia media = null;
media = null;
try {
media = new AMedia(name, null, "application/zip", zipFile, true);
} catch (Exception e) {
@ -894,4 +908,20 @@ public class WAttachment extends Window implements EventListener<Event>
AEnv.showWindow(dialog);
}
//-- ComponentCtrl --//
public Object getExtraCtrl() {
return new ExtraCtrl();
}
/** A utility class to implement {@link #getExtraCtrl}.
* It is used only by component developers.
*/
protected class ExtraCtrl extends XulElement.ExtraCtrl
implements DynamicMedia {
//-- DynamicMedia --//
public Media getMedia(String pathInfo) {
return media;
}
}
}