IDEMPIERE-4205 Remove usage of applet
This commit is contained in:
parent
0480d7a678
commit
1b6aa35c97
|
@ -1,109 +0,0 @@
|
|||
import java.awt.print.PrinterJob;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.print.Doc;
|
||||
import javax.print.DocFlavor;
|
||||
import javax.print.DocPrintJob;
|
||||
import javax.print.PrintService;
|
||||
import javax.print.SimpleDoc;
|
||||
import javax.print.attribute.HashDocAttributeSet;
|
||||
import javax.print.attribute.standard.DocumentName;
|
||||
import javax.swing.JApplet;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Low Heng Sin
|
||||
*
|
||||
*/
|
||||
public class PrintLabelApplet extends JApplet {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 6576464056530627273L;
|
||||
private ArrayList<String> fileids = new ArrayList<String>();
|
||||
private int listSize = 0;
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
String s = getParameter("size");
|
||||
try {
|
||||
listSize = Integer.parseInt(s);
|
||||
} catch (Exception e) {
|
||||
System.out.println("Invalid listSize param=" + s);
|
||||
listSize = 0;
|
||||
}
|
||||
|
||||
for (int i = 0; i < listSize; i++)
|
||||
fileids.add(getParameter("file_" + i));
|
||||
|
||||
super.init();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
System.out.println(this.getClass().getName() + " start()");
|
||||
PrinterJob pjob = null;
|
||||
PrintService service = null;
|
||||
DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
|
||||
|
||||
try {
|
||||
int count = 0;
|
||||
|
||||
while (true) {
|
||||
URL url = new URL(getCodeBase(), "labeldata.jsp?fileid=" + fileids.get(count) + "&count=" + (count + 1));
|
||||
URLConnection conn = url.openConnection();
|
||||
InputStream is = conn.getInputStream();
|
||||
byte[] data = null;
|
||||
BufferedInputStream bis = new BufferedInputStream(is);
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
while(bis.available() > 0) {
|
||||
baos.write(bis.read());
|
||||
}
|
||||
is.close();
|
||||
bis.close();
|
||||
data = baos.toByteArray();
|
||||
baos.close();
|
||||
if (data.length > 0) {
|
||||
count ++;
|
||||
if (pjob == null) {
|
||||
// Create Print Job
|
||||
pjob = PrinterJob.getPrinterJob();
|
||||
if (pjob.printDialog())
|
||||
service = pjob.getPrintService();
|
||||
else
|
||||
break;
|
||||
}
|
||||
DocPrintJob job = service.createPrintJob();
|
||||
HashDocAttributeSet as = new HashDocAttributeSet();
|
||||
as.add(new DocumentName("shipping label", null));
|
||||
Doc doc = new SimpleDoc(data, flavor, as);
|
||||
job.print(doc, null);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
if (count >= listSize)
|
||||
break;
|
||||
}
|
||||
this.showStatus(count + " label printed.");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
this.showStatus("Failed to print label - " + e.getLocalizedMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
System.out.println(this.getClass().getName() + " destroy()");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
System.out.println(this.getClass().getName() + " stop()");
|
||||
}
|
||||
}
|
|
@ -1,89 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Copyright (C) 2012 Low Heng Sin *
|
||||
* Copyright (C) 2012 Trek Global
|
||||
* This program is free software; you can redistribute it and/or modify it *
|
||||
* under the terms version 2 of the GNU General Public License as published *
|
||||
* by the Free Software Foundation. This program is distributed in the hope *
|
||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
||||
* See the GNU General Public License for more details. *
|
||||
* You should have received a copy of the GNU General Public License along *
|
||||
* with this program; if not, write to the Free Software Foundation, Inc., *
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
|
||||
*****************************************************************************/
|
||||
package org.adempiere.webui;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.adempiere.webui.component.ToolBarButton;
|
||||
import org.adempiere.webui.component.Window;
|
||||
import org.adempiere.webui.util.ZKUpdateUtil;
|
||||
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;
|
||||
import org.zkoss.zul.Applet;
|
||||
import org.zkoss.zul.Div;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Low Heng Sin
|
||||
*
|
||||
*/
|
||||
public class LabelAppletWindow extends Window implements EventListener<Event>
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -592770994381511142L;
|
||||
private final static CLogger log = CLogger.getCLogger(LabelAppletWindow.class);
|
||||
|
||||
public LabelAppletWindow(List<byte[]> list)
|
||||
{
|
||||
super();
|
||||
|
||||
Div div = new Div();
|
||||
appendChild(div);
|
||||
|
||||
Applet applet = new Applet();
|
||||
applet.setCode("PrintLabelApplet.class");
|
||||
applet.setArchive("labelapplet.jar");
|
||||
ZKUpdateUtil.setWidth(applet, "0");
|
||||
ZKUpdateUtil.setHeight(applet, "0");
|
||||
applet.setParam("size", list.size() + "");
|
||||
|
||||
for(int i = 0; i < list.size(); i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
div.appendChild(applet);
|
||||
|
||||
ToolBarButton link = new ToolBarButton();
|
||||
link.setLabel("Click here to close this popup after printing is completed.");
|
||||
link.addEventListener(Events.ON_CLICK, this);
|
||||
appendChild(link);
|
||||
|
||||
this.setBorder("normal");
|
||||
}
|
||||
|
||||
public void onEvent(Event event) throws Exception
|
||||
{
|
||||
if (Events.ON_CLICK.equals(event.getName()))
|
||||
this.detach();
|
||||
}
|
||||
}
|
|
@ -18,7 +18,6 @@ import java.util.List;
|
|||
|
||||
import org.adempiere.process.IPrintShippingLabel;
|
||||
import org.adempiere.webui.FedexLabelWindow;
|
||||
import org.adempiere.webui.LabelAppletWindow;
|
||||
import org.adempiere.webui.UPSHtmlLabelWindow;
|
||||
import org.adempiere.webui.apps.AEnv;
|
||||
import org.adempiere.webui.component.Window;
|
||||
|
@ -36,29 +35,7 @@ public class DefaultPrintShippingLabel implements IPrintShippingLabel
|
|||
{
|
||||
public String printToLabelPrinter(MAttachment attachment, MShipperLabels labelType) throws Exception
|
||||
{
|
||||
MAttachmentEntry[] entries = attachment.getEntries();
|
||||
List<byte[]> list = new ArrayList<byte[]>();
|
||||
if (entries != null && entries.length > 0)
|
||||
{
|
||||
for (MAttachmentEntry entry : entries)
|
||||
{
|
||||
if (entry.getName().startsWith("shipping_label"))
|
||||
list.add(entry.getData());
|
||||
}
|
||||
if (list.size() > 0)
|
||||
{
|
||||
final List<byte[]> dataList = list;
|
||||
AEnv.executeAsyncDesktopTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
LabelAppletWindow law = new LabelAppletWindow(dataList);
|
||||
law.setAttribute(Window.MODE_KEY, Window.MODE_HIGHLIGHTED);
|
||||
SessionManager.getAppDesktop().showWindow(law);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
return list.size() + " labels loaded.";
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public String printImageLabel(MAttachment attachment, MShipperLabels labelType, String title) throws Exception
|
||||
|
|
|
@ -1,29 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE project>
|
||||
<project name="labelapplet" basedir="." default="sign">
|
||||
<target name="build">
|
||||
<mkdir dir="bin"/>
|
||||
<javac srcdir="WEB-INF/src"
|
||||
destdir="bin"
|
||||
debug="on"
|
||||
listfiles="yes"
|
||||
excludes="**/fi/**, **/metainfo/**, **/org/**, **/web/**"/>
|
||||
</target>
|
||||
|
||||
<target name="jar" depends="build">
|
||||
<jar destfile="labelapplet.jar" basedir="bin">
|
||||
<manifest>
|
||||
<attribute name="Built-By" value="Trek Global"/>
|
||||
<attribute name="Permissions" value="all-permissions" />
|
||||
<attribute name="Codebase" value="*" />
|
||||
</manifest>
|
||||
</jar>
|
||||
</target>
|
||||
|
||||
<target name="sign" depends="jar">
|
||||
<signjar alias="labelapplet"
|
||||
storepass="labelapplet"
|
||||
jar="labelapplet.jar"
|
||||
keystore="labelappletkeystore"/>
|
||||
</target>
|
||||
</project>
|
|
@ -30,7 +30,6 @@ bin.includes = META-INF/,\
|
|||
OSGI-INF/banktransferparameterslistener.xml,\
|
||||
sessiontimeout.zul,\
|
||||
*.jsp,\
|
||||
labelapplet.jar,\
|
||||
OSGI-INF/jfgchartrenderer.xml,\
|
||||
manifest.json,\
|
||||
pdf.js/,\
|
||||
|
|
Binary file not shown.
|
@ -1,44 +0,0 @@
|
|||
<%@ 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"%>
|
||||
<%
|
||||
try
|
||||
{
|
||||
String fileid = request.getParameter("fileid");
|
||||
if (fileid == null || fileid.trim().length() == 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
response.setContentLength(0);
|
||||
}
|
||||
%>
|
|
@ -31,13 +31,6 @@
|
|||
</includes>
|
||||
<followSymlinks>false</followSymlinks>
|
||||
</fileset>
|
||||
<fileset>
|
||||
<directory>${project.basedir}</directory>
|
||||
<includes>
|
||||
<include>labelapplet.jar</include>
|
||||
</includes>
|
||||
<followSymlinks>false</followSymlinks>
|
||||
</fileset>
|
||||
</filesets>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
@ -76,24 +69,6 @@
|
|||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>com.googlecode.maven-download-plugin</groupId>
|
||||
<artifactId>download-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>validate</phase>
|
||||
<goals>
|
||||
<goal>wget</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<url>${url.file.srv}/extra.jar/labelapplet.jar</url>
|
||||
<unpack>false</unpack>
|
||||
<outputDirectory>./</outputDirectory>
|
||||
<retries>5</retries>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
|
Loading…
Reference in New Issue