/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.common.io.XmlUtil
 *  com.l7tech.policy.bundle.BundleInfo
 *  com.l7tech.util.Functions
 *  com.l7tech.util.Functions$Unary
 *  com.l7tech.util.IOUtils
 *  com.l7tech.util.Pair
 *  org.apache.commons.lang3.StringUtils
 *  org.jetbrains.annotations.NotNull
 */
package com.l7tech.server.policy.bundle;

import com.l7tech.common.io.XmlUtil;
import com.l7tech.policy.bundle.BundleInfo;
import com.l7tech.server.policy.bundle.BundleResolver;
import com.l7tech.server.policy.bundle.a;
import com.l7tech.util.Functions;
import com.l7tech.util.IOUtils;
import com.l7tech.util.Pair;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.w3c.dom.Document;

/*
 * Exception performing whole class analysis ignored.
 */
public class BundleResolverImpl
implements BundleResolver {
    private final List<BundleInfo> a;
    private final Map<String, String> b;
    private final Class c;
    private static final String[] d;

    public BundleResolverImpl(@NotNull List<Pair<BundleInfo, String>> list, @NotNull Class clazz) {
        if (list == null) {
            BundleResolverImpl.a(0);
        }
        if (clazz == null) {
            BundleResolverImpl.a(1);
        }
        this.a = new ArrayList<BundleInfo>();
        this.b = new HashMap<String, String>();
        HashMap<String, String> hashMap = new HashMap<String, String>();
        for (Pair<BundleInfo, String> pair : list) {
            hashMap.put(((BundleInfo)pair.left).getId(), (String)pair.right);
        }
        this.a.addAll(Functions.map(list, (Functions.Unary)new a(this)));
        this.b.putAll(hashMap);
        this.c = clazz;
    }

    @Override
    public Document getBundleItem(@NotNull String string, @NotNull String string2, @NotNull BundleResolver.BundleItem bundleItem, boolean bl2) throws BundleResolver.UnknownBundleException, BundleResolver.BundleResolverException, BundleResolver.InvalidBundleException {
        Document document;
        block16: {
            try {
                if (string == null) {
                    BundleResolverImpl.a(2);
                }
            }
            catch (BundleResolver.InvalidBundleException invalidBundleException) {
                throw BundleResolverImpl.a(invalidBundleException);
            }
            try {
                if (string2 == null) {
                    BundleResolverImpl.a(3);
                }
            }
            catch (BundleResolver.InvalidBundleException invalidBundleException) {
                throw BundleResolverImpl.a(invalidBundleException);
            }
            try {
                if (bundleItem == null) {
                    BundleResolverImpl.a(4);
                }
            }
            catch (BundleResolver.InvalidBundleException invalidBundleException) {
                throw BundleResolverImpl.a(invalidBundleException);
            }
            try {
                document = this.getItemFromBundle(string, string2, bundleItem);
            }
            catch (BundleResolver.InvalidBundleException invalidBundleException) {
                throw new BundleResolver.BundleResolverException(invalidBundleException);
            }
            try {
                try {
                    if (document == null && !bl2) {
                    }
                    break block16;
                }
                catch (BundleResolver.InvalidBundleException invalidBundleException) {
                    throw BundleResolverImpl.a(invalidBundleException);
                }
                throw new BundleResolver.UnknownBundleItemException(d[5] + String.valueOf((Object)bundleItem) + d[14] + string + "'");
            }
            catch (BundleResolver.InvalidBundleException invalidBundleException) {
                throw BundleResolverImpl.a(invalidBundleException);
            }
        }
        return document;
    }

    @Override
    public Document getBundleItem(@NotNull String string, @NotNull BundleResolver.BundleItem bundleItem, boolean bl2) throws BundleResolver.UnknownBundleException, BundleResolver.BundleResolverException, BundleResolver.InvalidBundleException {
        try {
            if (string == null) {
                BundleResolverImpl.a(5);
            }
        }
        catch (BundleResolver.UnknownBundleException unknownBundleException) {
            throw BundleResolverImpl.a(unknownBundleException);
        }
        try {
            if (bundleItem == null) {
                BundleResolverImpl.a(6);
            }
        }
        catch (BundleResolver.UnknownBundleException unknownBundleException) {
            throw BundleResolverImpl.a(unknownBundleException);
        }
        return this.getBundleItem(string, "", bundleItem, bl2);
    }

    protected Document getItemFromBundle(@NotNull String string, @NotNull String string2, @NotNull BundleResolver.BundleItem bundleItem) throws BundleResolver.UnknownBundleException, BundleResolver.InvalidBundleException {
        Object object;
        String string3;
        String string4;
        block20: {
            try {
                if (string == null) {
                    BundleResolverImpl.a(7);
                }
            }
            catch (Exception exception) {
                throw BundleResolverImpl.a(exception);
            }
            try {
                if (string2 == null) {
                    BundleResolverImpl.a(8);
                }
            }
            catch (Exception exception) {
                throw BundleResolverImpl.a(exception);
            }
            try {
                if (bundleItem == null) {
                    BundleResolverImpl.a(9);
                }
            }
            catch (Exception exception) {
                throw BundleResolverImpl.a(exception);
            }
            try {
                if (!this.b.containsKey(string)) {
                    throw new BundleResolver.UnknownBundleException(d[8] + string);
                }
            }
            catch (Exception exception) {
                throw BundleResolverImpl.a(exception);
            }
            string4 = "/";
            string3 = this.b.get(string);
            if (string3.contains("\\")) {
                string4 = "\\";
            }
            try {
                if (!string3.endsWith("/") && !string3.endsWith("\\")) break block20;
            }
            catch (Exception exception) {
                throw BundleResolverImpl.a(exception);
            }
            string3 = string3.substring(0, string3.length() - 1);
        }
        try {
            object = StringUtils.isEmpty((CharSequence)string2) ? "" : string4 + string2;
        }
        catch (Exception exception) {
            throw BundleResolverImpl.a(exception);
        }
        String string5 = object;
        String string6 = string3 + string5 + string4 + bundleItem.getFileName();
        URL uRL = this.c.getResource(string6);
        Document document = null;
        if (uRL != null) {
            try {
                byte[] byArray = IOUtils.slurpUrl((URL)uRL);
                document = XmlUtil.parse((InputStream)new ByteArrayInputStream(byArray));
            }
            catch (Exception exception) {
                throw new BundleResolver.InvalidBundleException(exception);
            }
        }
        return document;
    }

    @Override
    @NotNull
    public List<BundleInfo> getResultList() {
        List<BundleInfo> list;
        try {
            list = Collections.unmodifiableList(this.a);
            if (list == null) {
                BundleResolverImpl.a(10);
            }
        }
        catch (IllegalArgumentException illegalArgumentException) {
            throw BundleResolverImpl.a(illegalArgumentException);
        }
        return list;
    }

    /*
     * Exception decompiling
     */
    private static /* synthetic */ void a(int var0) {
        /*
         * This method has failed to decompile.  When submitting a bug report, please provide this stack trace, and (if you hold appropriate legal rights) the relevant class file.
         * 
         * org.benf.cfr.reader.util.ConfusedCFRException: Tried to end blocks [0[TRYBLOCK]], but top level block is 6[SWITCH]
         *     at org.benf.cfr.reader.bytecode.analysis.opgraph.Op04StructuredStatement.processEndingBlocks(Op04StructuredStatement.java:435)
         *     at org.benf.cfr.reader.bytecode.analysis.opgraph.Op04StructuredStatement.buildNestedBlocks(Op04StructuredStatement.java:484)
         *     at org.benf.cfr.reader.bytecode.analysis.opgraph.Op03SimpleStatement.createInitialStructuredBlock(Op03SimpleStatement.java:736)
         *     at org.benf.cfr.reader.bytecode.CodeAnalyser.getAnalysisInner(CodeAnalyser.java:850)
         *     at org.benf.cfr.reader.bytecode.CodeAnalyser.getAnalysisOrWrapFail(CodeAnalyser.java:278)
         *     at org.benf.cfr.reader.bytecode.CodeAnalyser.getAnalysis(CodeAnalyser.java:201)
         *     at org.benf.cfr.reader.entities.attributes.AttributeCode.analyse(AttributeCode.java:94)
         *     at org.benf.cfr.reader.entities.Method.analyse(Method.java:531)
         *     at org.benf.cfr.reader.entities.ClassFile.analyseMid(ClassFile.java:1050)
         *     at org.benf.cfr.reader.entities.ClassFile.analyseTop(ClassFile.java:942)
         *     at org.benf.cfr.reader.Driver.doJarVersionTypes(Driver.java:257)
         *     at org.benf.cfr.reader.Driver.doJar(Driver.java:139)
         *     at org.benf.cfr.reader.CfrDriverImpl.analyse(CfrDriverImpl.java:76)
         *     at org.benf.cfr.reader.Main.main(Main.java:54)
         */
        throw new IllegalStateException("Decompilation failed");
    }

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

    /*
     * Unable to fully structure code
     */
    static {
        block10: {
            block9: {
                var5 = new String[17];
                var3_1 = 0;
                var2_2 = "(?t\u0016U6Z#.L-C1\b&.e)~$B*\u0011(?t\rD B\t(o)r0A+6e\n-/n \\ f;?m*\u000f\u0014o0~0C#zm!D-@+z%7\u001e`\\o7u7DeA . 6U1Z=4 *E)C\u0015\u001a4k*_2Ao8u*T)Jo3t!]e\b\u0012?(e6U4Z&)i0U\u0003@#>e6\r(?t\u0006E+K#?I0U(\u0013\u001a4k*_2Ao8u*T)Jo3d~\u00102,5mk\\r[*9hkC ]9?rk@*C&9ykR0A+6ekr0A+6e\u0016U6@#,e6y(_#\u0006s3n-D{\f,;l(Y+H\f6a7C2,5mk\\r[*9hkC ]9?rk@*C&9ykR0A+6ekr0A+6e\u0016U6@#,e6y(_#\u0012-/n \\ f!<o7v7@\"\u0010a6\u0019hzr!A0J<.e \u0010#] 7 &E+K#? c";
                var4_3 = "(?t\u0016U6Z#.L-C1\b&.e)~$B*\u0011(?t\rD B\t(o)r0A+6e\n-/n \\ f;?m*\u000f\u0014o0~0C#zm!D-@+z%7\u001e`\\o7u7DeA . 6U1Z=4 *E)C\u0015\u001a4k*_2Ao8u*T)Jo3t!]e\b\u0012?(e6U4Z&)i0U\u0003@#>e6\r(?t\u0006E+K#?I0U(\u0013\u001a4k*_2Ao8u*T)Jo3d~\u00102,5mk\\r[*9hkC ]9?rk@*C&9ykR0A+6ekr0A+6e\u0016U6@#,e6y(_#\u0006s3n-D{\f,;l(Y+H\f6a7C2,5mk\\r[*9hkC ]9?rk@*C&9ykR0A+6ekr0A+6e\u0016U6@#,e6y(_#\u0012-/n \\ f!<o7v7@\"\u0010a6\u0019hzr!A0J<.e \u0010#] 7 &E+K#? c".length();
                var1_4 = 13;
                var0_5 = -1;
lbl7:
                // 2 sources

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

                while (true) {
                    var5[var3_1++] = BundleResolverImpl.a(v0, BundleResolverImpl.a(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    var2_2 = "_y6`\fq\u0010j+7z\u00134>Pd%[\u0014x\u0012>{0g\u0000y\u001bjn#5F1\r9+>sA1\r0.\"5\fa\rj+?z\u00154\u001c{+?`\rx\b|~?q\rq7z";
                    var4_3 = "_y6`\fq\u0010j+7z\u00134>Pd%[\u0014x\u0012>{0g\u0000y\u001bjn#5F1\r9+>sA1\r0.\"5\fa\rj+?z\u00154\u001c{+?`\rx\b|~?q\rq7z".length();
                    var1_4 = 62;
                    var0_5 = -1;
lbl22:
                    // 2 sources

                    while (true) {
                        v0 = 61;
                        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++] = BundleResolverImpl.a(v0, BundleResolverImpl.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;
            }
        }
        BundleResolverImpl.d = var5;
    }

    private static char[] a(String string) {
        char[] cArray = string.toCharArray();
        if (cArray.length < 2) {
            cArray = cArray;
            cArray[0] = (char)(cArray[0] ^ 0x43);
        }
        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 -> 35;
                    case 1 -> 54;
                    case 2 -> 108;
                    case 3 -> 40;
                    case 4 -> 92;
                    case 5 -> 41;
                    default -> 67;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

