SharedPrinterPrintJob.java
3.18 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
/*
* Decompiled with CFR 0_118.
*/
package com.adobe.fd.stp.internal.print.jobs;
import com.adobe.fd.stp.api.PrinterProtocol;
import com.adobe.fd.stp.internal.exception.STPServiceException;
import com.adobe.fd.stp.internal.logging.STPServiceLogger;
import com.adobe.fd.stp.internal.print.jobs.IPrintJob;
import java.io.InputStream;
import java.util.Locale;
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.SimpleDoc;
import javax.print.attribute.Attribute;
import javax.print.attribute.DocAttributeSet;
import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.print.attribute.HashPrintServiceAttributeSet;
import javax.print.attribute.PrintRequestAttributeSet;
import javax.print.attribute.standard.PrinterName;
public class SharedPrinterPrintJob
implements IPrintJob {
private static String SHARED_PRINTER = PrinterProtocol.SharedPrinter.toString();
private static STPServiceLogger logger = new STPServiceLogger(SharedPrinterPrintJob.class);
private String msPrintServerUri = null;
private String msPrinterName = null;
private PrintService mPrintService = null;
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
int mbCheckAccessible = 0;
public SharedPrinterPrintJob(String sPrintServerUri, String sPrinterName) {
this.setPrinterName(sPrinterName);
this.setPrintServerUri(sPrintServerUri);
}
private void setPrinterName(String value) {
if (value != null) {
this.msPrinterName = value.trim();
}
}
private void setPrintServerUri(String value) {
if (value != null) {
this.msPrintServerUri = value.trim();
}
}
@Override
public boolean isAccessible() {
this.mbCheckAccessible = 1;
boolean bSuccess = false;
HashPrintServiceAttributeSet psAset = new HashPrintServiceAttributeSet();
psAset.add(new PrinterName(this.msPrinterName, null));
PrintService[] printServices = PrintServiceLookup.lookupPrintServices(null, psAset);
if (printServices.length > 0) {
for (PrintService service : printServices) {
if (!service.getName().equalsIgnoreCase(this.msPrinterName)) continue;
bSuccess = true;
this.mPrintService = service;
}
}
return bSuccess;
}
@Override
public void print(InputStream inStream) throws STPServiceException {
if (this.mbCheckAccessible == 0 && !this.isAccessible()) {
return;
}
DocFlavor.INPUT_STREAM flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
SimpleDoc psDoc = new SimpleDoc(inStream, flavor, null);
DocPrintJob job = this.mPrintService.createPrintJob();
try {
job.print(psDoc, this.aset);
}
catch (PrintException pe) {
logger.error("AEM_STP_001_005", new Object[]{SHARED_PRINTER, this.msPrinterName + " : " + pe.getMessage()});
throw new STPServiceException("AEM_STP_001_005", new String[]{SHARED_PRINTER, this.msPrinterName}, pe);
}
}
}