⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fopprintapplet.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* * $Id: FopPrintApplet.java 6590 2006-01-26 07:21:36Z jaz $ * * Copyright (c) 2001-2006 The Open For Business Project - www.ofbiz.org * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * *///package print;package org.ofbiz.webtools.print.applet;import java.awt.*;import java.io.*;import java.net.URL;import java.net.URLConnection;import java.net.URLEncoder;import java.rmi.Naming;import java.util.ArrayList;import java.util.HashMap;import java.util.Iterator;import java.util.List;import java.util.Locale;import java.util.Map;import java.util.StringTokenizer;import java.util.Vector;import javax.print.Doc;import javax.print.DocFlavor;import javax.print.DocPrintJob;import javax.print.PrintException;import javax.print.PrintService;import javax.print.PrintServiceLookup;import javax.print.ServiceUI;import javax.print.SimpleDoc;import javax.print.event.PrintJobListener;import javax.print.event.PrintJobEvent;import javax.print.attribute.DocAttributeSet;import javax.print.attribute.HashDocAttributeSet;import javax.print.attribute.HashPrintRequestAttributeSet;import javax.print.attribute.PrintRequestAttributeSet;import javax.print.attribute.standard.Copies;import javax.print.attribute.standard.JobName;import javax.swing.*;import org.apache.commons.codec.binary.Base64;import org.apache.fop.apps.Driver;import org.apache.fop.layout.Page;import org.apache.fop.render.awt.AWTRenderer;import org.xml.sax.InputSource;import org.ofbiz.webtools.print.rmi.FopPrintRemote;/** * FopPrinter * * @author     <a href="mailto:jaz@ofbiz.org">Andy Zeneski</a> * @version    $Rev: 6590 $ * @since      Jan 23, 2006 */public class FopPrintApplet extends JApplet implements PrintJobListener {    public static final String module = FopPrintApplet.class.getName();    protected DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PAGEABLE;    protected String requestPath = "/webtools/control/getXslFo";    protected String sessionId = null;    protected String serverUrl = null;    protected String rmiHost = null;    protected String rmiName = null;    protected int rmiPort = 1099;    protected boolean resetCookies = false;    protected boolean started = false;    protected List printing = new ArrayList();    protected List noPrint = new ArrayList();    protected Map jobQueue = new HashMap();    protected Map jobList = new HashMap();    protected Map toPrint = new HashMap();    protected FopPrintApplet applet = null;    public void init(Map toPrint, String sessionId, String serverUrl, String rmiName, String rmiHost, int rmiPort, boolean reset) {        this.sessionId = sessionId;        this.serverUrl = serverUrl;        this.rmiName = rmiName;        this.rmiHost = rmiHost;        this.rmiPort = rmiPort;        this.toPrint = toPrint;        this.resetCookies = reset;        this.applet = this;        if (this.sessionId == null) {            this.sessionId = "";        }    }    public void init() {        int port = 1099;        if (this.getParameter("rmi-port") != null) {            try {                port = Integer.parseInt(this.getParameter("rmi-port"));            } catch (NumberFormatException e) {                System.out.println("INFO: not able to parse rmi-port parameter. Using default 1099");            }        }        String sessionId = this.getParameter("session-id");        String serverUrl = this.getParameter("server-url");        String rmiName = this.getParameter("rmi-name");        String rmiHost = this.getParameter("rmi-host");        String reset = this.getParameter("reset-cookies");        boolean resetCookies = reset != null && "true".equalsIgnoreCase(reset);        Map toPrint = new HashMap();        boolean look = true;        int count = 1;        while (look) {            String printer = this.getParameter("printer." + count);            String screen = this.getParameter("screen." + count);            if (screen != null && screen.length() > 0) {                toPrint.put(screen, printer);                count++;            } else {                look = false;            }        }        this.init(toPrint, sessionId, serverUrl, rmiName, rmiHost, port, resetCookies);    }    public void paint(Graphics g) {        super.paint(g);        g.setFont(new Font("Arial", Font.BOLD, 16));        g.drawString("Print spooler started with [" + jobQueue.size() + "] jobs queued...", 10, 30);        if (!started) {            started = true;            //Thread worker = new Thread() {                //public void run() {                    processJobs();                //}            //};            //worker.start();        }    }    public void printDataTransferCompleted(PrintJobEvent e) {        JobName jobNameAtt = (JobName) e.getPrintJob().getAttributes().get(JobName.class);        String jobName = jobNameAtt.getValue();        System.out.println("Calling notificaton that job data transfer is complete: " + jobName);    }    public void printJobCompleted(PrintJobEvent e) {        JobName jobNameAtt = (JobName) e.getPrintJob().getAttributes().get(JobName.class);        String jobName = jobNameAtt.getValue();        JOptionPane.showMessageDialog(null, "Print job completed: " + jobName, "Job Done", JOptionPane.INFORMATION_MESSAGE);        System.out.println("Calling notificaton that job is now complete: " + jobName);        try {            setJobComplete(jobName, false);        } catch (Exception e1) {            e1.printStackTrace();        }    }    public void printJobFailed(PrintJobEvent e) {        JobName jobNameAtt = (JobName) e.getPrintJob().getAttributes().get(JobName.class);        String jobName = jobNameAtt.getValue();        JOptionPane.showMessageDialog(null, "Print job faild: " + jobName, "Print Error", JOptionPane.ERROR_MESSAGE);        System.out.println("Calling notificaton that job has failed: " + jobName);        try {            setJobComplete(jobName, true);        } catch (Exception e1) {            e1.printStackTrace();        }    }    public void printJobCanceled(PrintJobEvent e) {        JobName jobNameAtt = (JobName) e.getPrintJob().getAttributes().get(JobName.class);        String jobName = jobNameAtt.getValue();        JOptionPane.showMessageDialog(null, "Print job was cancelled: " + jobName, "Print Error", JOptionPane.ERROR_MESSAGE);        System.out.println("Calling notificaton that job has been cancelled: " + jobName);        try {            setJobComplete(jobName, true);        } catch (Exception e1) {            e1.printStackTrace();        }    }    public void printJobNoMoreEvents(PrintJobEvent e) {        JobName jobNameAtt = (JobName) e.getPrintJob().getAttributes().get(JobName.class);        String jobName = jobNameAtt.getValue();        System.out.println("Calling notificaton that job has no more events: " + jobName);        try {            setJobComplete(jobName, true);        } catch (Exception e1) {            e1.printStackTrace();        }    }    public void printJobRequiresAttention(PrintJobEvent e) {        JobName jobNameAtt = (JobName) e.getPrintJob().getAttributes().get(JobName.class);        String jobName = jobNameAtt.getValue();        System.out.println("Calling notificaton that job requires attention: " + jobName);        try {            setJobComplete(jobName, true);        } catch (Exception e1) {            e1.printStackTrace();        }        JOptionPane.showMessageDialog(null, "Print Warning", "Print job requires attention: " + jobName, JOptionPane.WARNING_MESSAGE);    }    protected void processJobs() {        Iterator i = toPrint.keySet().iterator();        while (i.hasNext()) {            String screen = (String) i.next();            String printer = (String) toPrint.get(screen);            String screenUri = this.getScreenUri(screen);            PrintSettings settings = this.getPrintSettings(screenUri, printer);            if (settings != null) {                jobQueue.put(screenUri, settings);                jobList.put(screen, settings);                this.repaint();            } else {                System.out.println("No printer for job: " + screenUri);                this.getAppletContext().showStatus("No printer(s) available.");            }        }        // if nothing to do, call complete        if (jobQueue.size() == 0) {            try {                this.sendComplete();            } catch (Exception e) {                e.printStackTrace();            }        } else {            // begin processing            Iterator x = jobList.keySet().iterator();            while (x.hasNext()) {                final String screen = (String) x.next();                Thread worker = new Thread() {                    public void run() {                        try {                            printFo((rmiHost == null ? serverUrl : rmiHost), screen);                        } catch (Exception e) {                            e.printStackTrace();                            getAppletContext().showStatus("Unable to render print job.");                        }                    }                };                worker.start();            }        }        this.repaint();    }    protected void printFo(String url, String screenUrl) throws Exception {        if (url.startsWith("http")) {            this.printFoFromHttp(url, screenUrl);        } else if (url.startsWith("rmi")) {            this.printFoFromRmi(url, screenUrl);        } else {            this.getAppletContext().showStatus("Unsupported protocol used.");        }    }    protected void printFoFromRmi(String lookup, String screenUrl) throws Exception {        InputSource source = this.getScreenFromRmi(lookup, screenUrl);        this.renderFO(this.getScreenUri(screenUrl), source);    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -