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

import com.l7tech.gateway.common.audit.Audit;
import com.l7tech.policy.StaticResourceInfo;
import com.l7tech.policy.assertion.Assertion;
import com.l7tech.policy.variable.Syntax;
import com.l7tech.server.policy.ServerPolicyException;
import com.l7tech.server.policy.variable.ExpandVariables;
import com.l7tech.server.util.res.ResourceGetter;
import com.l7tech.server.util.res.ResourceObjectFactory;
import com.l7tech.util.CausedIOException;
import com.l7tech.util.ExceptionUtils;
import java.io.IOException;
import java.text.ParseException;
import java.util.Map;

class b<R, M>
extends ResourceGetter<R, M> {
    private final ResourceObjectFactory<R> a;
    private R b;
    private boolean c;
    private StaticResourceInfo d;
    private static final String[] e;

    b(Assertion assertion, StaticResourceInfo staticResourceInfo, ResourceObjectFactory<R> resourceObjectFactory, Audit audit) throws ServerPolicyException {
        super(audit);
        this.a = resourceObjectFactory;
        this.d = staticResourceInfo;
        String string = staticResourceInfo.getDocument();
        try {
            if (string == null) {
                throw new ServerPolicyException(assertion, e[2]);
            }
        }
        catch (ParseException parseException) {
            throw com.l7tech.server.util.res.b.a(parseException);
        }
        try {
            boolean bl2 = this.c = Syntax.getReferencedNames((String)string).length > 0;
        }
        catch (ParseException parseException) {
            throw com.l7tech.server.util.res.b.a(parseException);
        }
        if (!this.c) {
            try {
                R r2 = resourceObjectFactory.createResourceObject(string);
                try {
                    if (r2 == null) {
                        throw new ServerPolicyException(assertion, e[1]);
                    }
                }
                catch (ParseException parseException) {
                    throw com.l7tech.server.util.res.b.a(parseException);
                }
                this.b = r2;
            }
            catch (ParseException parseException) {
                throw new ServerPolicyException(assertion, e[0] + ExceptionUtils.getMessage((Throwable)parseException), parseException);
            }
        }
    }

    @Override
    public void close() {
        if (!this.c) {
            this.a.closeResourceObject(this.b);
        }
    }

    @Override
    public R getResource(M m2, Map<String, Object> map) throws IOException {
        R r2;
        try {
            if (!this.c) {
                return this.b;
            }
        }
        catch (ParseException parseException) {
            throw com.l7tech.server.util.res.b.a(parseException);
        }
        String string = ExpandVariables.process(this.d.getDocument(), map, this.audit);
        try {
            r2 = this.a.createResourceObject(string);
        }
        catch (ParseException parseException) {
            throw new CausedIOException(ExceptionUtils.getMessage((Throwable)parseException), ExceptionUtils.getDebugException((Throwable)parseException));
        }
        try {
            if (r2 == null) {
                throw new IOException(e[3]);
            }
        }
        catch (ParseException parseException) {
            throw com.l7tech.server.util.res.b.a(parseException);
        }
        return r2;
    }

    private static ParseException a(ParseException parseException) {
        return parseException;
    }

    /*
     * Unable to fully structure code
     */
    static {
        block10: {
            block9: {
                var5 = new String[4];
                var3_1 = 0;
                var2_2 = "\u0016\f&-b>W7\rg,|>\u00167\u0007g<z:\u0003*\u0001g:}>\u0005c\r%%k8\u0003yBH\u0016\f&-b>W7\rg,|>\u00167\u0007g<z:\u0003*\u0001g:}>\u0005c\r%%k8\u0003yB\u0015*}4\u00021\u0001\"\u0000l1\u0012 \u0016\u0001.m/\u00181\u001bg=k/\u00021\f\"+.5\u0002/\u000e";
                var4_3 = "\u0016\f&-b>W7\rg,|>\u00167\u0007g<z:\u0003*\u0001g:}>\u0005c\r%%k8\u0003yBH\u0016\f&-b>W7\rg,|>\u00167\u0007g<z:\u0003*\u0001g:}>\u0005c\r%%k8\u0003yB\u0015*}4\u00021\u0001\"\u0000l1\u0012 \u0016\u0001.m/\u00181\u001bg=k/\u00021\f\"+.5\u0002/\u000e".length();
                var1_4 = 37;
                var0_5 = -1;
lbl7:
                // 2 sources

                while (true) {
                    v0 = 109;
                    v1 = ++var0_5;
                    v2 = var2_2.substring(v1, v1 + var1_4);
                    v3 = -1;
                    break block9;
                    break;
                }
lbl13:
                // 1 sources

                while (true) {
                    var5[var3_1++] = com.l7tech.server.util.res.b.b(v0, com.l7tech.server.util.res.b.a(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    var2_2 = "OF~r>2M~Jzo$2ZeH{k\"|JH_Eod+w\u001e~D.e5w_~N.u3sJcH.s4wL*Dll\"qJ0\u000b\\c4}KxHkI%x[i_Hg$fQxR.t\"fKxEkbg|KfG";
                    var4_3 = "OF~r>2M~Jzo$2ZeH{k\"|JH_Eod+w\u001e~D.e5w_~N.u3sJcH.s4wL*Dll\"qJ0\u000b\\c4}KxHkI%x[i_Hg$fQxR.t\"fKxEkbg|KfG".length();
                    var1_4 = 21;
                    var0_5 = -1;
lbl22:
                    // 2 sources

                    while (true) {
                        v0 = 36;
                        v4 = ++var0_5;
                        v2 = var2_2.substring(v4, v4 + var1_4);
                        v3 = 0;
                        break block9;
                        break;
                    }
                    break;
                }
lbl28:
                // 1 sources

                while (true) {
                    var5[var3_1++] = com.l7tech.server.util.res.b.b(v0, com.l7tech.server.util.res.b.a(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    break block10;
                    break;
                }
            }
            switch (v3) {
                default: {
                    ** continue;
                }
                ** case 0:
lbl39:
                // 1 sources

                ** continue;
            }
        }
        com.l7tech.server.util.res.b.e = var5;
    }

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

    /*
     * Handled impossible loop by duplicating code
     * Enabled aggressive block sorting
     */
    private static String b(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 -> 46;
                    case 1 -> 15;
                    case 2 -> 42;
                    case 3 -> 34;
                    case 4 -> 99;
                    case 5 -> 54;
                    default -> 26;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

