/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.common.io.XmlUtil
 *  com.l7tech.message.Message
 *  com.l7tech.message.XmlKnob
 *  com.l7tech.policy.assertion.ext.message.CustomMessage
 *  com.l7tech.policy.assertion.ext.message.CustomMessageAccessException
 *  org.jetbrains.annotations.NotNull
 */
package com.l7tech.server.custom.format;

import com.l7tech.common.io.XmlUtil;
import com.l7tech.message.Message;
import com.l7tech.message.XmlKnob;
import com.l7tech.policy.assertion.ext.message.CustomMessage;
import com.l7tech.policy.assertion.ext.message.CustomMessageAccessException;
import com.l7tech.server.StashManagerFactory;
import com.l7tech.server.custom.CustomMessageImpl;
import com.l7tech.server.custom.format.CustomMessageFormatBase;
import java.io.IOException;
import java.io.InputStream;
import org.jetbrains.annotations.NotNull;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;

/*
 * Exception performing whole class analysis ignored.
 */
public class CustomMessageXmlFormat
extends CustomMessageFormatBase<Document> {
    private static final String[] b;

    public CustomMessageXmlFormat(@NotNull StashManagerFactory stashManagerFactory, @NotNull String string, @NotNull String string2) {
        if (stashManagerFactory == null) {
            CustomMessageXmlFormat.b(0);
        }
        if (string == null) {
            CustomMessageXmlFormat.b(1);
        }
        if (string2 == null) {
            CustomMessageXmlFormat.b(2);
        }
        super(stashManagerFactory, string, string2);
    }

    public Class<Document> getRepresentationClass() {
        return Document.class;
    }

    public Document extract(CustomMessage customMessage) throws CustomMessageAccessException {
        block10: {
            try {
                if (customMessage == null) {
                    throw new CustomMessageAccessException(b[11]);
                }
            }
            catch (SAXException sAXException) {
                throw CustomMessageXmlFormat.a(sAXException);
            }
            try {
                if (!(customMessage instanceof CustomMessageImpl)) {
                    throw new CustomMessageAccessException(b[7]);
                }
            }
            catch (SAXException sAXException) {
                throw CustomMessageXmlFormat.a(sAXException);
            }
            Message message = ((CustomMessageImpl)customMessage).getMessage();
            try {
                try {
                    if (!message.isInitialized() || !message.isXml()) break block10;
                }
                catch (SAXException sAXException) {
                    throw CustomMessageXmlFormat.a(sAXException);
                }
                return message.getXmlKnob().getDocumentReadOnly();
            }
            catch (IOException | SAXException exception) {
                throw new CustomMessageAccessException(b[9], (Throwable)exception);
            }
        }
        return null;
    }

    public void overwrite(CustomMessage customMessage, Document document) throws CustomMessageAccessException {
        block9: {
            XmlKnob xmlKnob;
            block8: {
                try {
                    if (customMessage == null) {
                        throw new CustomMessageAccessException(b[10]);
                    }
                }
                catch (CustomMessageAccessException customMessageAccessException) {
                    throw CustomMessageXmlFormat.a((Exception)((Object)customMessageAccessException));
                }
                try {
                    if (!(customMessage instanceof CustomMessageImpl)) {
                        throw new CustomMessageAccessException(b[4]);
                    }
                }
                catch (CustomMessageAccessException customMessageAccessException) {
                    throw CustomMessageXmlFormat.a((Exception)((Object)customMessageAccessException));
                }
                Message message = ((CustomMessageImpl)customMessage).getMessage();
                xmlKnob = (XmlKnob)message.getKnob(XmlKnob.class);
                try {
                    if (xmlKnob != null) break block8;
                    message.initialize(document);
                    break block9;
                }
                catch (CustomMessageAccessException customMessageAccessException) {
                    throw CustomMessageXmlFormat.a((Exception)((Object)customMessageAccessException));
                }
            }
            xmlKnob.setDocument(document);
        }
    }

    /*
     * Enabled aggressive block sorting
     * Enabled unnecessary exception pruning
     * Enabled aggressive exception aggregation
     */
    public <K> Document createBody(K k2) throws CustomMessageAccessException {
        try {
            if (k2 == null) {
                throw new CustomMessageAccessException(b[13]);
            }
        }
        catch (SAXException sAXException) {
            throw CustomMessageXmlFormat.a(sAXException);
        }
        try {
            if (k2 instanceof String) {
                try {
                    return XmlUtil.stringToDocument((String)((String)k2));
                }
                catch (SAXException sAXException) {
                    String[] stringArray = b;
                    throw new CustomMessageAccessException(stringArray[1], (Throwable)sAXException);
                }
            }
        }
        catch (IOException iOException) {
            throw CustomMessageXmlFormat.a(iOException);
        }
        try {
            if (!(k2 instanceof InputStream)) throw new CustomMessageAccessException(b[12] + k2.getClass().getSimpleName());
            try {
                return XmlUtil.parse((InputStream)((InputStream)k2));
            }
            catch (IOException | SAXException exception) {
                String[] stringArray = b;
                throw new CustomMessageAccessException(stringArray[3], (Throwable)exception);
            }
        }
        catch (CustomMessageAccessException customMessageAccessException) {
            throw CustomMessageXmlFormat.a((Exception)((Object)customMessageAccessException));
        }
    }

    /*
     * Exception decompiling
     */
    private static /* synthetic */ void b(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 1[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[15];
                var3_1 = 0;
                var2_2 = "I\u0007]kO\u0011GY\u000bAf-h\u0010\\gOX@E\u000bBm\u001d\u001bEH\u0003ZaS\u001f\u0017i-c(y\u0017TX\u000fKfIXQ_\rC(N\fED\fI6N\rC'QOCH\u0001F'N\u001dE[\u0007\\'^\rDY\rC'[\u0017E@\u0003Z'~\rDY\rCEX\u000bDL\u0005KPP\u0014qB\u0010CiI2h\u0010\\gOX@E\u000bBm\u001d\u001bEH\u0003ZaS\u001f\u0017i-c(y\u0017TX\u000fKfIXQ_\rC(t\u0016GX\u0016}|O\u001dV@\u001e@\u0007]{\\\u001fR\r\u000b](R\u001e\u0017X\f]}M\bX_\u0016Kl\u001d\fN]\u0007\u0013^\u0016O{U5VC\u0003ImO>VN\u0016AzD\u0006\u0011\u000b@aIF\u001e@\u0007]{\\\u001fR\r\u000b](R\u001e\u0017X\f]}M\bX_\u0016Kl\u001d\fN]\u0007\u0004C\u0003Cm(h\u0010\\gOX@E\u000bBm\u001d\u001dOY\u0010OkI\u0011YJBCmN\u000bVJ\u0007\u000ePp4\u0017[\u0003B}X\u0016@\u0007]{\\\u001fR\r\u0001OfS\u0017C\r\u0000K(S\r[A\u0016@\u0007]{\\\u001fR\r\u0001OfS\u0017C\r\u0000K(S\r[A\u001ax\f]}M\bX_\u0016Kl\u001d\u001bXC\u0016KfIXCT\u0012K2\u001d";
                var4_3 = "I\u0007]kO\u0011GY\u000bAf-h\u0010\\gOX@E\u000bBm\u001d\u001bEH\u0003ZaS\u001f\u0017i-c(y\u0017TX\u000fKfIXQ_\rC(N\fED\fI6N\rC'QOCH\u0001F'N\u001dE[\u0007\\'^\rDY\rC'[\u0017E@\u0003Z'~\rDY\rCEX\u000bDL\u0005KPP\u0014qB\u0010CiI2h\u0010\\gOX@E\u000bBm\u001d\u001bEH\u0003ZaS\u001f\u0017i-c(y\u0017TX\u000fKfIXQ_\rC(t\u0016GX\u0016}|O\u001dV@\u001e@\u0007]{\\\u001fR\r\u000b](R\u001e\u0017X\f]}M\bX_\u0016Kl\u001d\fN]\u0007\u0013^\u0016O{U5VC\u0003ImO>VN\u0016AzD\u0006\u0011\u000b@aIF\u001e@\u0007]{\\\u001fR\r\u000b](R\u001e\u0017X\f]}M\bX_\u0016Kl\u001d\fN]\u0007\u0004C\u0003Cm(h\u0010\\gOX@E\u000bBm\u001d\u001dOY\u0010OkI\u0011YJBCmN\u000bVJ\u0007\u000ePp4\u0017[\u0003B}X\u0016@\u0007]{\\\u001fR\r\u0001OfS\u0017C\r\u0000K(S\r[A\u0016@\u0007]{\\\u001fR\r\u0001OfS\u0017C\r\u0000K(S\r[A\u001ax\f]}M\bX_\u0016Kl\u001d\u001bXC\u0016KfIXCT\u0012K2\u001d".length();
                var1_4 = 11;
                var0_5 = -1;
lbl7:
                // 2 sources

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

                while (true) {
                    var5[var3_1++] = CustomMessageXmlFormat.b(v0, CustomMessageXmlFormat.b(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    var2_2 = "Y\u001aWkO\u0001T\u001a\u0016XqD\u0000T\u001a\u0017\\?D\u001aLV>{\u0007^jG\nNNU_pXO`t\u001aMQ_\u0003L\u001a\u0005XmK\u0002EN\u0010K?\rJS\u001dUVy\nJS\u0014PJ?G\u001aSNUWp^OB_UWjF\u0003";
                    var4_3 = "Y\u001aWkO\u0001T\u001a\u0016XqD\u0000T\u001a\u0017\\?D\u001aLV>{\u0007^jG\nNNU_pXO`t\u001aMQ_\u0003L\u001a\u0005XmK\u0002EN\u0010K?\rJS\u001dUVy\nJS\u0014PJ?G\u001aSNUWp^OB_UWjF\u0003".length();
                    var1_4 = 22;
                    var0_5 = -1;
lbl22:
                    // 2 sources

                    while (true) {
                        v0 = 10;
                        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++] = CustomMessageXmlFormat.b(v0, CustomMessageXmlFormat.b(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;
            }
        }
        CustomMessageXmlFormat.b = var5;
    }

    private static char[] b(String string) {
        char[] cArray = string.toCharArray();
        if (cArray.length < 2) {
            cArray = cArray;
            cArray[0] = (char)(cArray[0] ^ 0x2A);
        }
        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 -> 48;
                    case 1 -> 127;
                    case 2 -> 51;
                    case 3 -> 21;
                    case 4 -> 32;
                    case 5 -> 101;
                    default -> 42;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

