/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.gateway.common.audit.Audit
 *  com.l7tech.policy.AssertionResourceInfo
 *  com.l7tech.policy.MessageUrlResourceInfo
 *  com.l7tech.policy.SingleUrlResourceInfo
 *  com.l7tech.policy.StaticResourceInfo
 *  com.l7tech.policy.assertion.Assertion
 */
package com.l7tech.server.util.res;

import com.l7tech.gateway.common.audit.Audit;
import com.l7tech.policy.AssertionResourceInfo;
import com.l7tech.policy.MessageUrlResourceInfo;
import com.l7tech.policy.SingleUrlResourceInfo;
import com.l7tech.policy.StaticResourceInfo;
import com.l7tech.policy.assertion.Assertion;
import com.l7tech.server.policy.ServerPolicyException;
import com.l7tech.server.url.UrlResolver;
import com.l7tech.server.util.res.ResourceObjectFactory;
import com.l7tech.server.util.res.UrlFinder;
import com.l7tech.server.util.res.a;
import com.l7tech.server.util.res.b;
import com.l7tech.server.util.res.d;
import com.l7tech.server.util.res.e;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.util.Map;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;

public abstract class ResourceGetter<R, M> {
    protected static final Pattern MATCH_ALL;
    protected final Audit audit;
    private static final String[] f;

    protected ResourceGetter(Audit audit) {
        this.audit = audit;
    }

    public abstract void close();

    public abstract R getResource(M var1, Map<String, Object> var2) throws IOException, InvalidMessageException, UrlNotFoundException, MalformedResourceUrlException, UrlNotPermittedException, ResourceIOException, ResourceParseException, GeneralSecurityException;

    public static <R, M> ResourceGetter<R, M> createResourceGetter(Assertion assertion, AssertionResourceInfo assertionResourceInfo, ResourceObjectFactory<R> resourceObjectFactory, UrlFinder<M> urlFinder, UrlResolver<R> urlResolver, Audit audit) throws ServerPolicyException {
        try {
            if (assertionResourceInfo == null) {
                throw new ServerPolicyException(assertion, f[0]);
            }
        }
        catch (PatternSyntaxException patternSyntaxException) {
            throw ResourceGetter.b(patternSyntaxException);
        }
        try {
            if (assertionResourceInfo instanceof MessageUrlResourceInfo) {
                return new d<R, M>((MessageUrlResourceInfo)assertionResourceInfo, urlResolver, urlFinder, audit);
            }
        }
        catch (ServerPolicyException serverPolicyException) {
            throw ResourceGetter.b((Exception)((Object)serverPolicyException));
        }
        try {
            if (assertionResourceInfo instanceof SingleUrlResourceInfo) {
                return new e(assertion, (SingleUrlResourceInfo)assertionResourceInfo, urlResolver, audit);
            }
        }
        catch (ServerPolicyException serverPolicyException) {
            throw ResourceGetter.b((Exception)((Object)serverPolicyException));
        }
        try {
            if (assertionResourceInfo instanceof StaticResourceInfo) {
                return new b(assertion, (StaticResourceInfo)assertionResourceInfo, resourceObjectFactory, audit);
            }
        }
        catch (ServerPolicyException serverPolicyException) {
            throw ResourceGetter.b((Exception)((Object)serverPolicyException));
        }
        try {
            String[] stringArray = f;
            throw new ServerPolicyException(assertion, stringArray[2] + assertionResourceInfo.getClass().getName());
        }
        catch (PatternSyntaxException patternSyntaxException) {
            throw new ServerPolicyException(assertion, f[1] + patternSyntaxException.getPattern() + "'", patternSyntaxException);
        }
    }

    public static <R, M> ResourceGetter<R, M> createErrorResourceGetter(Exception exception) {
        return new a(null, exception);
    }

    /*
     * Enabled aggressive block sorting
     */
    static {
        String[] stringArray = new String[3];
        int n2 = 0;
        String string = "v\u0013kHqWmX\u000e8NlMpV\tv^#Mk\u00172}^lVvT\u0005QCeL$G\u0012w[jGaS%t\u000fmAgM#C@{BnSm[\u00058_fDq[\u0001j\rf[tE\u0005k^jLj\u0017G\u001bb\u000ekXsSkE\u0014}I#QaD\u000fm_`F$^\u000e~B9\u0003";
        int n3 = "v\u0013kHqWmX\u000e8NlMpV\tv^#Mk\u00172}^lVvT\u0005QCeL$G\u0012w[jGaS%t\u000fmAgM#C@{BnSm[\u00058_fDq[\u0001j\rf[tE\u0005k^jLj\u0017G\u001bb\u000ekXsSkE\u0014}I#QaD\u000fm_`F$^\u000e~B9\u0003".length();
        int n4 = 43;
        int n5 = -1;
        while (true) {
            int n6 = ++n5;
            stringArray[n2++] = ResourceGetter.a(12, ResourceGetter.b(string.substring(n6, n6 + n4)));
            if ((n5 += n4) >= n3) {
                f = stringArray;
                MATCH_ALL = Pattern.compile(".");
                return;
            }
            n4 = string.charAt(n5);
        }
    }

    private static Exception b(Exception exception) {
        return exception;
    }

    private static char[] b(String string) {
        char[] cArray = string.toCharArray();
        if (cArray.length < 2) {
            cArray = cArray;
            cArray[0] = (char)(cArray[0] ^ 8);
        }
        return cArray;
    }

    /*
     * Handled impossible loop by duplicating code
     * Enabled aggressive block sorting
     */
    private static String a(int n2, char[] cArray) {
        char[] cArray2;
        block11: {
            int n3;
            int n4;
            int n5;
            block10: {
                n5 = n2;
                cArray2 = cArray;
                n4 = cArray.length;
                n3 = 0;
                if (!true) break block10;
                n4 = n4;
                if (n4 <= n3) break block11;
            }
            do {
                n5 = n5;
                cArray2 = cArray2;
                int n6 = n3;
                cArray2[n6] = (char)(cArray2[n6] ^ (n5 ^ (switch (n3 % 7) {
                    case 0 -> 59;
                    case 1 -> 108;
                    case 2 -> 20;
                    case 3 -> 33;
                    case 4 -> 15;
                    case 5 -> 47;
                    default -> 8;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }

    public static class ResourceIOException
    extends UrlResourceException {
        static final long serialVersionUID = 5586329984478951953L;

        public ResourceIOException(IOException iOException, String string) {
            super(iOException, string);
        }

        public ResourceIOException(String string, IOException iOException, String string2) {
            super(string, iOException, string2);
        }

        public ResourceIOException(String string, String string2) {
            super(string, string2);
        }

        public IOException getIOException() {
            return (IOException)this.getCause();
        }
    }

    public static class UrlNotFoundException
    extends Exception {
        static final long serialVersionUID = -871264281722028198L;
        private static final String a = UrlNotFoundException.a(46, UrlNotFoundException.a("::]\u0004*,\u0017\u0006;\u001c\rr*\u0017\u0007:\b\u00131=R!\u00071A%9\u0001T3\u0012\u0014<<R\u001d;]\u0015:1\u0001T8\u0018\u0012!9\u0015\u0011"));

        public UrlNotFoundException() {
            super(a);
        }

        private static char[] a(String string) {
            char[] cArray = string.toCharArray();
            if (cArray.length < 2) {
                cArray = cArray;
                cArray[0] = (char)(cArray[0] ^ 0x5C);
            }
            return cArray;
        }

        /*
         * Handled impossible loop by duplicating code
         * Enabled aggressive block sorting
         */
        private static String a(int n2, char[] cArray) {
            char[] cArray2;
            block11: {
                int n3;
                int n4;
                int n5;
                block10: {
                    n5 = n2;
                    cArray2 = cArray;
                    n4 = cArray.length;
                    n3 = 0;
                    if (!true) break block10;
                    n4 = n4;
                    if (n4 <= n3) break block11;
                }
                do {
                    n5 = n5;
                    cArray2 = cArray2;
                    int n6 = n3;
                    cArray2[n6] = (char)(cArray2[n6] ^ (n5 ^ (switch (n3 % 7) {
                        case 0 -> 90;
                        case 1 -> 123;
                        case 2 -> 83;
                        case 3 -> 79;
                        case 4 -> 124;
                        case 5 -> 118;
                        default -> 92;
                    })));
                    ++n3;
                    n4 = n4;
                } while (n4 > n3);
            }
            return new String(cArray2).intern();
        }
    }

    public static class ResourceParseException
    extends UrlResourceException {
        static final long serialVersionUID = 6458749143587660808L;

        public ResourceParseException(Throwable throwable, String string) {
            super(throwable, string);
        }

        public ResourceParseException(String string, Throwable throwable, String string2) {
            super(string, throwable, string2);
        }
    }

    public static class UrlNotPermittedException
    extends UrlResourceException {
        static final long serialVersionUID = -5375029166527170667L;

        public UrlNotPermittedException(String string, String string2) {
            super(string, string2);
        }
    }

    public static class MalformedResourceUrlException
    extends UrlResourceException {
        static final long serialVersionUID = 4845964503271521352L;

        public MalformedResourceUrlException(String string, String string2) {
            super(string, string2);
        }
    }

    public static class InvalidMessageException
    extends Exception {
        static final long serialVersionUID = -2820066767261379525L;

        public InvalidMessageException() {
        }

        public InvalidMessageException(String string) {
            super(string);
        }

        public InvalidMessageException(String string, Throwable throwable) {
            super(string, throwable);
        }

        public InvalidMessageException(Throwable throwable) {
            super(throwable);
        }
    }

    public static class UrlResourceException
    extends Exception {
        private final String url;
        static final long serialVersionUID = 7016479975932594557L;

        public UrlResourceException(String string, String string2) {
            super(string);
            this.url = string2;
        }

        public UrlResourceException(String string, Throwable throwable, String string2) {
            super(string, throwable);
            this.url = string2;
        }

        public UrlResourceException(Throwable throwable, String string) {
            super(throwable);
            this.url = string;
        }

        public String getUrl() {
            return this.url;
        }
    }
}

