JCIFSWrapperImpl.java 4.65 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  jcifs.smb.NtlmPasswordAuthentication
 *  jcifs.smb.SmbException
 *  jcifs.smb.SmbFile
 *  jcifs.util.LogStream
 *  org.apache.felix.scr.annotations.Activate
 *  org.apache.felix.scr.annotations.Component
 *  org.apache.felix.scr.annotations.Service
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 */
package com.adobe.fd.jcifs.wrapper.impl;

import com.adobe.fd.jcifs.wrapper.api.JCIFSWrapper;
import com.adobe.fd.jcifs.wrapper.api.JCIFSWrapperException;
import com.adobe.fd.jcifs.wrapper.internal.exception.GeneralJCIFSWrapperException;
import com.adobe.fd.jcifs.wrapper.internal.exception.PrinterAccessDeniedException;
import com.adobe.fd.jcifs.wrapper.internal.exception.PrinterNotFoundException;
import com.adobe.fd.jcifs.wrapper.internal.exception.TooManyConnectionsException;
import com.adobe.fd.jcifs.wrapper.internal.util.ThirdPartyOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.MalformedURLException;
import jcifs.smb.NtlmPasswordAuthentication;
import jcifs.smb.SmbException;
import jcifs.smb.SmbFile;
import jcifs.util.LogStream;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Component(label="AEMFD JCIFSWrapper ", description="AEMFD JCIFSWrapper ")
@Service(value={JCIFSWrapper.class})
public class JCIFSWrapperImpl
implements JCIFSWrapper {
    private static Logger logger = LoggerFactory.getLogger(JCIFSWrapperImpl.class);

    @Activate
    void activate() {
        LogStream.setInstance((PrintStream)new PrintStream(new ThirdPartyOutputStream(logger)));
        if (logger.isDebugEnabled()) {
            LogStream.setLevel((int)10);
        }
    }

    @Override
    public int print(InputStream is, String smbUri, String jobName, String domainName, String userName, String password) throws JCIFSWrapperException {
        try {
            SmbFile smbFile = this.getPrinter(smbUri, domainName, userName, password);
            return smbFile.print(is, jobName);
        }
        catch (MalformedURLException e) {
            throw new GeneralJCIFSWrapperException(e);
        }
        catch (SmbException e) {
            switch (e.getNtStatus()) {
                case -1073741819: 
                case -1073741790: 
                case -1073741730: 
                case -1073741724: 
                case -1073741718: 
                case -1073741715: 
                case -1073741714: 
                case -1073741713: 
                case -1073741711: 
                case -1073741710: 
                case -1073741709: 
                case -1073741622: 
                case -1073741477: 
                case -1073741428: 
                case -1073741276: 
                case -1073741260: {
                    throw new PrinterAccessDeniedException((Throwable)e);
                }
                case -1073741616: {
                    throw new TooManyConnectionsException((Throwable)e);
                }
                case -1073741810: 
                case -1073741809: 
                case -1073741773: 
                case -1073741772: 
                case -1073741767: 
                case -1073741766: 
                case -1073741765: 
                case -1073741620: 
                case -1073741606: 
                case -1073741601: 
                case -1073741487: 
                case -1073741275: {
                    throw new PrinterNotFoundException((Throwable)e);
                }
            }
            throw new GeneralJCIFSWrapperException((Throwable)e);
        }
        catch (IOException e) {
            throw new GeneralJCIFSWrapperException(e);
        }
    }

    @Override
    public boolean isAccessible(String smbURI, String domainName, String userName, String password) {
        try {
            SmbFile printer = this.getPrinter(smbURI, domainName, userName, password);
            printer.connect();
            logger.debug("SmbURI=" + smbURI + " is accessible");
        }
        catch (Exception e) {
            logger.debug(e.getMessage(), (Throwable)e);
            return false;
        }
        return true;
    }

    private SmbFile getPrinter(String smbURI, String domainName, String userName, String password) throws MalformedURLException {
        NtlmPasswordAuthentication auth = null;
        if (userName != null) {
            auth = new NtlmPasswordAuthentication(domainName, userName, password);
        }
        SmbFile printer = new SmbFile(smbURI, auth);
        return printer;
    }
}