SendToPrinterServiceImpl.java 5.23 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.adobe.aemfd.docmanager.Document
 *  org.apache.felix.scr.annotations.Component
 *  org.apache.felix.scr.annotations.Reference
 *  org.apache.felix.scr.annotations.ReferenceCardinality
 *  org.apache.felix.scr.annotations.ReferencePolicy
 *  org.apache.felix.scr.annotations.Service
 */
package com.adobe.fd.stp.impl;

import com.adobe.aemfd.docmanager.Document;
import com.adobe.fd.stp.api.PrinterProtocol;
import com.adobe.fd.stp.api.PrinterSpec;
import com.adobe.fd.stp.api.SendToPrinterService;
import com.adobe.fd.stp.internal.CIFSPrintJobService;
import com.adobe.fd.stp.internal.exception.STPServiceException;
import com.adobe.fd.stp.internal.print.jobs.CUPSPrintJob;
import com.adobe.fd.stp.internal.print.jobs.DirectIPPrintJob;
import com.adobe.fd.stp.internal.print.jobs.IPrintJob;
import com.adobe.fd.stp.internal.print.jobs.LPDPrintJob;
import com.adobe.fd.stp.internal.print.jobs.SharedPrinterPrintJob;
import java.io.InputStream;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.ReferencePolicy;
import org.apache.felix.scr.annotations.Service;

@Component(label="AEMFD  SendToPrinterService Service", description="AEMFD SendToPrinterService Service")
@Service(value={SendToPrinterService.class})
public class SendToPrinterServiceImpl
implements SendToPrinterService {
    @Reference(cardinality=ReferenceCardinality.OPTIONAL_UNARY, policy=ReferencePolicy.DYNAMIC)
    CIFSPrintJobService cifsPrintJobService;

    @Override
    public void print(Document inDoc, PrinterSpec printerSpec) throws STPServiceException {
        if (inDoc == null) {
            throw new STPServiceException("AEM_STP_001_001", new Object[]{"inDoc"});
        }
        if (printerSpec == null) {
            throw new STPServiceException("AEM_STP_001_001", new Object[]{"printerSpec"});
        }
        PrinterProtocol printerProtocol = printerSpec.getPrinterProtocol();
        String printServer = printerSpec.getPrintServer();
        String printerName = printerSpec.getPrinterName();
        try {
            if (printerProtocol == null) {
                printerProtocol = PrinterProtocol.SharedPrinter;
            }
            if (printServer != null && (printServer = printServer.trim()).length() == 0) {
                printServer = null;
            }
            if (printerName != null && (printerName = printerName.trim()).length() == 0) {
                printerName = null;
            }
            InputStream inStream = inDoc.getInputStream();
            IPrintJob iPrintJob = null;
            switch (printerProtocol) {
                case SharedPrinter: {
                    if (printerName == null) {
                        throw new STPServiceException("AEM_STP_001_001", new Object[]{"printerName"});
                    }
                    iPrintJob = new SharedPrinterPrintJob(null, printerName);
                    break;
                }
                case LPD: {
                    if (printerName == null) {
                        throw new STPServiceException("AEM_STP_001_001", new Object[]{"printerName"});
                    }
                    if (printServer == null) {
                        throw new STPServiceException("AEM_STP_001_001", new Object[]{"printServer"});
                    }
                    iPrintJob = new LPDPrintJob(printServer, printerName);
                    break;
                }
                case CUPS: {
                    if (printServer == null) {
                        throw new STPServiceException("AEM_STP_001_001", new Object[]{"printServer"});
                    }
                    iPrintJob = new CUPSPrintJob(printServer, printerName);
                    break;
                }
                case DirectIP: {
                    if (printServer == null) {
                        throw new STPServiceException("AEM_STP_001_001", new Object[]{"printServer"});
                    }
                    iPrintJob = new DirectIPPrintJob(printServer, printerName);
                    break;
                }
                case CIFS: {
                    if (printServer == null) {
                        throw new STPServiceException("AEM_STP_001_001", new Object[]{"printServer"});
                    }
                    if (this.cifsPrintJobService == null) {
                        throw new STPServiceException("AEM_STP_001_001", new Object[]{"cifsPrintJobService"});
                    }
                    iPrintJob = this.cifsPrintJobService.createCIFSPrintJob(printerSpec);
                }
            }
            iPrintJob.print(inStream);
        }
        catch (STPServiceException ose) {
            throw ose;
        }
        catch (Exception e) {
            throw new STPServiceException(e);
        }
    }

    protected void bindCifsPrintJobService(CIFSPrintJobService cIFSPrintJobService) {
        this.cifsPrintJobService = cIFSPrintJobService;
    }

    protected void unbindCifsPrintJobService(CIFSPrintJobService cIFSPrintJobService) {
        if (this.cifsPrintJobService == cIFSPrintJobService) {
            this.cifsPrintJobService = null;
        }
    }

}