IDEMPIERE-1083 Print shipping label applet is not working
This commit is contained in:
parent
bee9d53562
commit
2e3e4fc61f
|
@ -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
|
||||||
|
;
|
|
@ -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
|
||||||
|
;
|
|
@ -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 ZK_MAX_UPLOAD_SIZE = "ZK_MAX_UPLOAD_SIZE";
|
||||||
public static final String CALENDAR_ALTERNATE_TIMEZONE = "CALENDAR_ALTERNATE_TIMEZONE";
|
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_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
|
* Standard Constructor
|
||||||
|
|
|
@ -25,8 +25,8 @@ public class PrintLabelApplet extends JApplet {
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private static final long serialVersionUID = -3107445661561669767L;
|
private static final long serialVersionUID = 6576464056530627273L;
|
||||||
private ArrayList<String> filepaths = new ArrayList<String>();
|
private ArrayList<String> fileids = new ArrayList<String>();
|
||||||
private int listSize = 0;
|
private int listSize = 0;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -40,7 +40,7 @@ public class PrintLabelApplet extends JApplet {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < listSize; i++)
|
for (int i = 0; i < listSize; i++)
|
||||||
filepaths.add(getParameter("file_" + i));
|
fileids.add(getParameter("file_" + i));
|
||||||
|
|
||||||
super.init();
|
super.init();
|
||||||
}
|
}
|
||||||
|
@ -56,21 +56,11 @@ public class PrintLabelApplet extends JApplet {
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
URL url = new URL(getCodeBase(), "labeldata.jsp?filepath=" + filepaths.get(count) + "&count=" + (count + 1));
|
URL url = new URL(getCodeBase(), "labeldata.jsp?fileid=" + fileids.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());
|
|
||||||
URLConnection conn = url.openConnection();
|
URLConnection conn = url.openConnection();
|
||||||
int contentLength = conn.getContentLength();
|
|
||||||
System.out.println("ContentLength="+contentLength);
|
|
||||||
InputStream is = conn.getInputStream();
|
InputStream is = conn.getInputStream();
|
||||||
System.out.println("InputStream="+is.available());
|
|
||||||
byte[] data = null;
|
byte[] data = null;
|
||||||
BufferedInputStream bis = new BufferedInputStream(is);
|
BufferedInputStream bis = new BufferedInputStream(is);
|
||||||
System.out.println("BufferedInputStream="+bis.available());
|
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
while(bis.available() > 0) {
|
while(bis.available() > 0) {
|
||||||
baos.write(bis.read());
|
baos.write(bis.read());
|
||||||
|
@ -79,7 +69,6 @@ public class PrintLabelApplet extends JApplet {
|
||||||
bis.close();
|
bis.close();
|
||||||
data = baos.toByteArray();
|
data = baos.toByteArray();
|
||||||
baos.close();
|
baos.close();
|
||||||
System.out.println("ByteArrayOutputStream="+data.length);
|
|
||||||
if (data.length > 0) {
|
if (data.length > 0) {
|
||||||
count ++;
|
count ++;
|
||||||
if (pjob == null) {
|
if (pjob == null) {
|
||||||
|
|
|
@ -13,14 +13,14 @@
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
package org.adempiere.webui;
|
package org.adempiere.webui;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import org.adempiere.webui.component.ToolBarButton;
|
import org.adempiere.webui.component.ToolBarButton;
|
||||||
import org.adempiere.webui.component.Window;
|
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.CLogger;
|
||||||
|
import org.compiere.util.Env;
|
||||||
import org.zkoss.zk.ui.event.Event;
|
import org.zkoss.zk.ui.event.Event;
|
||||||
import org.zkoss.zk.ui.event.EventListener;
|
import org.zkoss.zk.ui.event.EventListener;
|
||||||
import org.zkoss.zk.ui.event.Events;
|
import org.zkoss.zk.ui.event.Events;
|
||||||
|
@ -54,33 +54,17 @@ public class LabelAppletWindow extends Window implements EventListener<Event>
|
||||||
applet.setHeight("0");
|
applet.setHeight("0");
|
||||||
applet.setParam("size", list.size() + "");
|
applet.setParam("size", list.size() + "");
|
||||||
|
|
||||||
File tempFile = null;
|
|
||||||
FileOutputStream fos = null;
|
|
||||||
for(int i = 0; i < list.size(); i++)
|
for(int i = 0; i < list.size(); i++)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
File directory = null;
|
MArchive archive = new MArchive(Env.getCtx(), 0, null);
|
||||||
String tempFolder = MSysConfig.getValue(MSysConfig.ZK_PRINT_SHIPPING_LABEL_SHARED_TEMP_FOLDER, null);
|
archive.setName("file_" + i);
|
||||||
if (tempFolder != null && tempFolder.trim().length() > 0)
|
archive.setBinaryData(list.get(i));
|
||||||
{
|
archive.saveEx();
|
||||||
directory = new File(tempFolder.trim());
|
applet.setParam("file_" + i, archive.getAD_Archive_ID() + "");
|
||||||
if (!directory.exists())
|
if (log.isLoggable(Level.INFO))
|
||||||
{
|
log.info("file_" + i + "=" + archive.getAD_Archive_ID());
|
||||||
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();
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,8 @@
|
||||||
<jar destfile="labelapplet.jar" basedir="bin">
|
<jar destfile="labelapplet.jar" basedir="bin">
|
||||||
<manifest>
|
<manifest>
|
||||||
<attribute name="Built-By" value="Trek Global"/>
|
<attribute name="Built-By" value="Trek Global"/>
|
||||||
|
<attribute name="Permissions" value="all-permissions" />
|
||||||
|
<attribute name="Codebase" value="*" />
|
||||||
</manifest>
|
</manifest>
|
||||||
</jar>
|
</jar>
|
||||||
</target>
|
</target>
|
||||||
|
|
|
@ -1,52 +1,44 @@
|
||||||
|
<%@ page language="java" contentType="application/octet-stream"%>
|
||||||
<%@ page trimDirectiveWhitespaces="true" %>
|
<%@ page trimDirectiveWhitespaces="true" %>
|
||||||
|
<%@page import="org.compiere.model.MArchive"%>
|
||||||
|
<%@page import="org.compiere.util.Env"%>
|
||||||
<%@page import="java.io.ByteArrayOutputStream"%>
|
<%@page import="java.io.ByteArrayOutputStream"%>
|
||||||
<%@page import="java.io.FileInputStream"%>
|
<%@page import="java.io.FileInputStream"%>
|
||||||
<%@page import="java.io.File"%>
|
<%@page import="java.io.File"%>
|
||||||
<%@page import="java.io.BufferedOutputStream"%>
|
<%@page import="java.io.BufferedOutputStream"%>
|
||||||
<%@page import="java.io.OutputStream"%>
|
<%@page import="java.io.OutputStream"%>
|
||||||
<%@ page language="java" contentType="application/octet-stream"%>
|
<%
|
||||||
<%
|
try
|
||||||
String filepath = request.getParameter("filepath");
|
{
|
||||||
if (filepath == null || filepath.trim().length() == 0 )
|
String fileid = request.getParameter("fileid");
|
||||||
return;
|
if (fileid == null || fileid.trim().length() == 0)
|
||||||
|
|
||||||
File file = new File(filepath);
|
|
||||||
if (file.exists())
|
|
||||||
{
|
|
||||||
FileInputStream fis = null;
|
|
||||||
ByteArrayOutputStream baos = null;
|
|
||||||
byte[] data = null;
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
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);
|
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);
|
response.setContentLength(0);
|
||||||
}
|
}
|
||||||
%>
|
%>
|
||||||
|
|
Loading…
Reference in New Issue