CIFSPrintJob.java
4.45 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.fd.jcifs.wrapper.api.JCIFSWrapper
* com.adobe.fd.jcifs.wrapper.api.JCIFSWrapperException
*/
package com.adobe.fd.stp.internal.print.jobs;
import com.adobe.fd.jcifs.wrapper.api.JCIFSWrapper;
import com.adobe.fd.jcifs.wrapper.api.JCIFSWrapperException;
import com.adobe.fd.stp.api.PrinterProtocol;
import com.adobe.fd.stp.api.PrinterSpec;
import com.adobe.fd.stp.internal.CryptoService;
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.UUID;
import java.util.regex.Pattern;
public class CIFSPrintJob
implements IPrintJob {
private static STPServiceLogger logger = new STPServiceLogger(CIFSPrintJob.class);
private static final String CIFS = PrinterProtocol.CIFS.toString();
private static Pattern regexPattern = Pattern.compile("/+|\\\\+");
private final String printServer;
private final String smbURI;
private final String domainName;
private final String userName;
private final String userPassword;
JCIFSWrapper jcifsWrapper;
public CIFSPrintJob(PrinterSpec printerSpec, JCIFSWrapper jcifsWrapper, CryptoService cryptoService) throws Exception {
if (jcifsWrapper == null) {
throw new STPServiceException("AEM_STP_001_001", new String[]{"jcifsWrapper"});
}
this.jcifsWrapper = jcifsWrapper;
this.printServer = printerSpec.getPrintServer();
if (this.printServer == null) {
throw new STPServiceException("AEM_STP_001_001", new String[]{"inPrintServer"});
}
logger.debug("AEM_STP_001_003", new Object[]{"PrintServer=" + this.printServer});
this.smbURI = CIFSPrintJob.getSmbUri(this.printServer);
logger.debug("AEM_STP_001_003", new Object[]{"Smb URI=" + this.smbURI});
this.userName = printerSpec.getUsername();
this.domainName = printerSpec.getDomain();
if (cryptoService != null) {
this.userPassword = cryptoService.getPlainText(printerSpec.getPassword());
} else {
logger.warn("AEM_STP_001_003", new Object[]{"cryptoService is null"});
this.userPassword = printerSpec.getPassword();
}
logger.debug("AEM_STP_001_003", new Object[]{"Domain Name=" + this.domainName});
logger.debug("AEM_STP_001_003", new Object[]{"user Name=" + this.userName});
}
@Override
public boolean isAccessible() {
return this.jcifsWrapper.isAccessible(this.smbURI, this.domainName, this.userName, this.userPassword);
}
@Override
public void print(InputStream inStream) throws STPServiceException {
try {
UUID printJobName = UUID.randomUUID();
int total = this.jcifsWrapper.print(inStream, this.smbURI, printJobName.toString(), this.domainName, this.userName, this.userPassword);
logger.debug("AEM_STP_001_003", new String[]{"Total Bytes sent to printer:" + total});
if (total == -1) {
throw new STPServiceException("AEM_STP_001_006", new String[]{this.printServer});
}
}
catch (JCIFSWrapperException e) {
logger.error("AEM_STP_001_003", new String[]{e.getMessage() + " , " + this.smbURI + " , " + this.printServer + " , " + this.domainName + " , " + this.userName});
Throwable origException = e.getCause() != null ? e.getCause() : e;
throw new STPServiceException(origException);
}
catch (Exception e) {
logger.error("AEM_STP_001_003", new String[]{e.getMessage() + " , " + this.smbURI + " , " + this.printServer + " , " + this.domainName + " , " + this.userName});
throw new STPServiceException("AEM_STP_001_005", new String[]{CIFS, this.printServer}, e);
}
}
public static String getSmbUri(String printServerUri) {
String[] splitArray;
if (!printServerUri.startsWith("/") && !printServerUri.startsWith("\\")) {
return printServerUri;
}
StringBuilder ret = new StringBuilder("smb:/");
for (String uriFrag : splitArray = regexPattern.split(printServerUri)) {
if (uriFrag.length() <= 0) continue;
ret.append('/');
ret.append(uriFrag);
}
if ("smb:/".equals(ret.toString())) {
ret.append('/');
}
return ret.toString();
}
}