SendToPrinterServiceImpl.java
5.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
* 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;
}
}
}