From 2e3e4fc61fb01e4bd8e836c9ce142e7e3d6d8fc0 Mon Sep 17 00:00:00 2001 From: Elaine Tan Date: Thu, 7 Nov 2013 14:51:50 +0800 Subject: [PATCH] IDEMPIERE-1083 Print shipping label applet is not working --- .../oracle/201311061318_IDEMPIERE-1083.sql | 9 +++ .../201311061318_IDEMPIERE-1083.sql | 6 ++ .../src/org/compiere/model/MSysConfig.java | 1 - .../WEB-INF/src/PrintLabelApplet.java | 19 ++---- .../adempiere/webui/LabelAppletWindow.java | 38 +++-------- org.adempiere.ui.zk/build-labelapplet.xml | 2 + org.adempiere.ui.zk/labeldata.jsp | 68 ++++++++----------- 7 files changed, 62 insertions(+), 81 deletions(-) create mode 100644 migration/i1.0c/oracle/201311061318_IDEMPIERE-1083.sql create mode 100644 migration/i1.0c/postgresql/201311061318_IDEMPIERE-1083.sql diff --git a/migration/i1.0c/oracle/201311061318_IDEMPIERE-1083.sql b/migration/i1.0c/oracle/201311061318_IDEMPIERE-1083.sql new file mode 100644 index 0000000000..095287a09f --- /dev/null +++ b/migration/i1.0c/oracle/201311061318_IDEMPIERE-1083.sql @@ -0,0 +1,9 @@ +SET SQLBLANKLINES ON +SET DEFINE OFF + +-- IDEMPIERE-1083 Print shipping label applet is not working +DELETE FROM AD_SysConfig WHERE AD_SysConfig_ID = 200036 +; + +SELECT register_migration_script('201311061318_IDEMPIERE-1083.sql') FROM dual +; \ No newline at end of file diff --git a/migration/i1.0c/postgresql/201311061318_IDEMPIERE-1083.sql b/migration/i1.0c/postgresql/201311061318_IDEMPIERE-1083.sql new file mode 100644 index 0000000000..397885e67b --- /dev/null +++ b/migration/i1.0c/postgresql/201311061318_IDEMPIERE-1083.sql @@ -0,0 +1,6 @@ +-- IDEMPIERE-1083 Print shipping label applet is not working +DELETE FROM AD_SysConfig WHERE AD_SysConfig_ID = 200036 +; + +SELECT register_migration_script('201311061318_IDEMPIERE-1083.sql') FROM dual +; \ No newline at end of file diff --git a/org.adempiere.base/src/org/compiere/model/MSysConfig.java b/org.adempiere.base/src/org/compiere/model/MSysConfig.java index b18173898d..715871b255 100644 --- a/org.adempiere.base/src/org/compiere/model/MSysConfig.java +++ b/org.adempiere.base/src/org/compiere/model/MSysConfig.java @@ -118,7 +118,6 @@ public class MSysConfig extends X_AD_SysConfig public static final String ZK_MAX_UPLOAD_SIZE = "ZK_MAX_UPLOAD_SIZE"; public static final String CALENDAR_ALTERNATE_TIMEZONE = "CALENDAR_ALTERNATE_TIMEZONE"; public static final String ZK_REPORT_JASPER_OUTPUT_TYPE = "ZK_REPORT_JASPER_OUTPUT_TYPE"; - public static final String ZK_PRINT_SHIPPING_LABEL_SHARED_TEMP_FOLDER = "ZK_PRINT_SHIPPING_LABEL_SHARED_TEMP_FOLDER"; /** * Standard Constructor diff --git a/org.adempiere.ui.zk/WEB-INF/src/PrintLabelApplet.java b/org.adempiere.ui.zk/WEB-INF/src/PrintLabelApplet.java index 2c76f431f7..e14200f51e 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/PrintLabelApplet.java +++ b/org.adempiere.ui.zk/WEB-INF/src/PrintLabelApplet.java @@ -25,8 +25,8 @@ public class PrintLabelApplet extends JApplet { /** * */ - private static final long serialVersionUID = -3107445661561669767L; - private ArrayList filepaths = new ArrayList(); + private static final long serialVersionUID = 6576464056530627273L; + private ArrayList fileids = new ArrayList(); private int listSize = 0; @Override @@ -40,7 +40,7 @@ public class PrintLabelApplet extends JApplet { } for (int i = 0; i < listSize; i++) - filepaths.add(getParameter("file_" + i)); + fileids.add(getParameter("file_" + i)); super.init(); } @@ -56,21 +56,11 @@ public class PrintLabelApplet extends JApplet { int count = 0; while (true) { - URL url = new URL(getCodeBase(), "labeldata.jsp?filepath=" + filepaths.get(count) + "&count=" + (count + 1)); - System.out.println("Protocol="+url.getProtocol()); - System.out.println("Host="+url.getHost()); - System.out.println("Port="+url.getPort()); - System.out.println("Default Port="+url.getDefaultPort()); - System.out.println("Path"+url.getPath()); - System.out.println("URL="+url.toString()); + URL url = new URL(getCodeBase(), "labeldata.jsp?fileid=" + fileids.get(count) + "&count=" + (count + 1)); URLConnection conn = url.openConnection(); - int contentLength = conn.getContentLength(); - System.out.println("ContentLength="+contentLength); InputStream is = conn.getInputStream(); - System.out.println("InputStream="+is.available()); byte[] data = null; BufferedInputStream bis = new BufferedInputStream(is); - System.out.println("BufferedInputStream="+bis.available()); ByteArrayOutputStream baos = new ByteArrayOutputStream(); while(bis.available() > 0) { baos.write(bis.read()); @@ -79,7 +69,6 @@ public class PrintLabelApplet extends JApplet { bis.close(); data = baos.toByteArray(); baos.close(); - System.out.println("ByteArrayOutputStream="+data.length); if (data.length > 0) { count ++; if (pjob == null) { diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/LabelAppletWindow.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/LabelAppletWindow.java index 9fba9147a4..0151d1f361 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/LabelAppletWindow.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/LabelAppletWindow.java @@ -13,14 +13,14 @@ *****************************************************************************/ package org.adempiere.webui; -import java.io.File; -import java.io.FileOutputStream; import java.util.List; +import java.util.logging.Level; import org.adempiere.webui.component.ToolBarButton; import org.adempiere.webui.component.Window; -import org.compiere.model.MSysConfig; +import org.compiere.model.MArchive; import org.compiere.util.CLogger; +import org.compiere.util.Env; import org.zkoss.zk.ui.event.Event; import org.zkoss.zk.ui.event.EventListener; import org.zkoss.zk.ui.event.Events; @@ -54,33 +54,17 @@ public class LabelAppletWindow extends Window implements EventListener applet.setHeight("0"); applet.setParam("size", list.size() + ""); - File tempFile = null; - FileOutputStream fos = null; for(int i = 0; i < list.size(); i++) { try - { - File directory = null; - String tempFolder = MSysConfig.getValue(MSysConfig.ZK_PRINT_SHIPPING_LABEL_SHARED_TEMP_FOLDER, null); - if (tempFolder != null && tempFolder.trim().length() > 0) - { - directory = new File(tempFolder.trim()); - if (!directory.exists()) - { - log.severe("Directory doesn't exists " + tempFolder); - directory = null; - } - else if (!directory.canWrite()) - { - log.severe("Directory cannot write " + tempFolder); - directory = null; - } - } - tempFile = File.createTempFile("lblapp", Long.toString(System.nanoTime()), directory); - fos = new FileOutputStream(tempFile); - applet.setParam("file_" + i, tempFile.getAbsolutePath()); - fos.write(list.get(i)); - fos.close(); + { + MArchive archive = new MArchive(Env.getCtx(), 0, null); + archive.setName("file_" + i); + archive.setBinaryData(list.get(i)); + archive.saveEx(); + applet.setParam("file_" + i, archive.getAD_Archive_ID() + ""); + if (log.isLoggable(Level.INFO)) + log.info("file_" + i + "=" + archive.getAD_Archive_ID()); } catch (Exception e) { e.printStackTrace(); } diff --git a/org.adempiere.ui.zk/build-labelapplet.xml b/org.adempiere.ui.zk/build-labelapplet.xml index 15b40e591d..78b1d8c7e7 100644 --- a/org.adempiere.ui.zk/build-labelapplet.xml +++ b/org.adempiere.ui.zk/build-labelapplet.xml @@ -12,6 +12,8 @@ + + diff --git a/org.adempiere.ui.zk/labeldata.jsp b/org.adempiere.ui.zk/labeldata.jsp index c227f776ff..5c807b6c21 100644 --- a/org.adempiere.ui.zk/labeldata.jsp +++ b/org.adempiere.ui.zk/labeldata.jsp @@ -1,52 +1,44 @@ +<%@ page language="java" contentType="application/octet-stream"%> <%@ page trimDirectiveWhitespaces="true" %> +<%@page import="org.compiere.model.MArchive"%> +<%@page import="org.compiere.util.Env"%> <%@page import="java.io.ByteArrayOutputStream"%> <%@page import="java.io.FileInputStream"%> <%@page import="java.io.File"%> <%@page import="java.io.BufferedOutputStream"%> <%@page import="java.io.OutputStream"%> -<%@ page language="java" contentType="application/octet-stream"%> -<% - String filepath = request.getParameter("filepath"); - if (filepath == null || filepath.trim().length() == 0 ) - return; - - File file = new File(filepath); - if (file.exists()) - { - FileInputStream fis = null; - ByteArrayOutputStream baos = null; - byte[] data = null; - try +<% + try + { + String fileid = request.getParameter("fileid"); + if (fileid == null || fileid.trim().length() == 0) { - fis = new FileInputStream (file); - baos = new ByteArrayOutputStream(); - byte[] buffer = new byte[1024*8]; // 8kB - int length = -1; - while ((length = fis.read(buffer)) != -1) - baos.write(buffer, 0, length); - data = baos.toByteArray(); - fis.close(); - baos.close(); - - response.setContentLength(data.length); - - OutputStream os = response.getOutputStream(); - BufferedOutputStream bos = new BufferedOutputStream(os); - bos.write(data); - bos.flush(); - bos.close(); - - file.delete(); - } - catch (Exception e) - { - e.printStackTrace(); response.setContentLength(0); + return; + } + + int AD_Archive_ID = Integer.parseInt(fileid); + if (AD_Archive_ID > 0) + { + MArchive archive = new MArchive(Env.getCtx(), AD_Archive_ID, null); + if (archive != null && archive.getAD_Archive_ID() > 0) + { + byte[] data = archive.getBinaryData(); + response.setContentLength(data.length); + + OutputStream os = response.getOutputStream(); + BufferedOutputStream bos = new BufferedOutputStream(os); + bos.write(data); + bos.flush(); + bos.close(); + + archive.delete(false); + } } } - else + catch (Exception e) { - System.out.println("file not found=" + filepath); + e.printStackTrace(); response.setContentLength(0); } %>