package com.l7tech.gateway.pm2.graphql.helper;

import com.l7tech.gateway.common.resources.ResourceAdmin;
import com.l7tech.gateway.common.resources.ResourceEntry;
import com.l7tech.gateway.common.resources.ResourceEntryHeader;
import com.l7tech.objectmodel.FindException;
import java.io.IOException;
import java.util.Collection;
import org.xml.sax.InputSource;
import org.xml.sax.ext.EntityResolver2;

public class PM2ResourceAdminEntityResolver implements EntityResolver2 {
   private final ResourceAdmin a;
   private final boolean b;
   private static final String[] c;

   public PM2ResourceAdminEntityResolver(ResourceAdmin var1, boolean var2) {
      this.a = var1;
      this.b = var2;
   }

   @Override
   public InputSource getExternalSubset(String var1, String var2) {
      return null;
   }

   @Override
   public InputSource resolveEntity(String var1, String var2, String var3, String var4) throws IOException {
      return this.a(var2, var3, var4);
   }

   @Override
   public InputSource resolveEntity(String var1, String var2) throws IOException {
      return this.a(var1, var2, var2);
   }

   private InputSource a(String param1, String param2, String param3) throws IOException {
      // $VF: Couldn't be decompiled
      // Please report this to the Vineflower issue tracker, at https://github.com/Vineflower/vineflower/issues with a copy of the class file (if you have the rights to distribute it!)
      // java.lang.RuntimeException: parsing failure!
      //   at org.jetbrains.java.decompiler.modules.decompiler.decompose.DomHelper.parseGraph(DomHelper.java:211)
      //   at org.jetbrains.java.decompiler.main.rels.MethodProcessor.codeToJava(MethodProcessor.java:174)
      //
      // Bytecode:
      // 000: aconst_null
      // 001: astore 4
      // 003: aload 0
      // 004: aload 1
      // 005: invokevirtual com/l7tech/gateway/pm2/graphql/helper/PM2ResourceAdminEntityResolver.a (Ljava/lang/String;)Lcom/l7tech/gateway/common/resources/ResourceEntry;
      // 008: astore 5
      // 00a: aload 5
      // 00c: ifnonnull 01e
      // 00f: aload 0
      // 010: getfield com/l7tech/gateway/pm2/graphql/helper/PM2ResourceAdminEntityResolver.a Lcom/l7tech/gateway/common/resources/ResourceAdmin;
      // 013: aload 3
      // 014: getstatic com/l7tech/gateway/common/resources/ResourceType.DTD Lcom/l7tech/gateway/common/resources/ResourceType;
      // 017: invokeinterface com/l7tech/gateway/common/resources/ResourceAdmin.findResourceEntryByUriAndType (Ljava/lang/String;Lcom/l7tech/gateway/common/resources/ResourceType;)Lcom/l7tech/gateway/common/resources/ResourceEntry; 3
      // 01c: astore 5
      // 01e: aconst_null
      // 01f: astore 6
      // 021: aload 5
      // 023: ifnonnull 077
      // 026: aload 2
      // 027: ifnull 077
      // 02a: goto 02e
      // 02d: athrow
      // 02e: new java/net/URI
      // 031: dup
      // 032: aload 3
      // 033: invokespecial java/net/URI.<init> (Ljava/lang/String;)V
      // 036: astore 7
      // 038: aload 7
      // 03a: invokevirtual java/net/URI.isAbsolute ()Z
      // 03d: ifne 071
      // 040: new java/net/URI
      // 043: dup
      // 044: aload 2
      // 045: invokespecial java/net/URI.<init> (Ljava/lang/String;)V
      // 048: astore 8
      // 04a: aload 8
      // 04c: invokevirtual java/net/URI.isAbsolute ()Z
      // 04f: ifeq 06e
      // 052: aload 8
      // 054: aload 7
      // 056: invokevirtual java/net/URI.resolve (Ljava/net/URI;)Ljava/net/URI;
      // 059: invokevirtual java/net/URI.toString ()Ljava/lang/String;
      // 05c: astore 6
      // 05e: aload 0
      // 05f: getfield com/l7tech/gateway/pm2/graphql/helper/PM2ResourceAdminEntityResolver.a Lcom/l7tech/gateway/common/resources/ResourceAdmin;
      // 062: aload 6
      // 064: getstatic com/l7tech/gateway/common/resources/ResourceType.DTD Lcom/l7tech/gateway/common/resources/ResourceType;
      // 067: invokeinterface com/l7tech/gateway/common/resources/ResourceAdmin.findResourceEntryByUriAndType (Ljava/lang/String;Lcom/l7tech/gateway/common/resources/ResourceType;)Lcom/l7tech/gateway/common/resources/ResourceEntry; 3
      // 06c: astore 5
      // 06e: goto 074
      // 071: aload 3
      // 072: astore 6
      // 074: goto 07a
      // 077: aload 3
      // 078: astore 6
      // 07a: aload 5
      // 07c: ifnull 0a6
      // 07f: new org/xml/sax/InputSource
      // 082: dup
      // 083: invokespecial org/xml/sax/InputSource.<init> ()V
      // 086: astore 4
      // 088: aload 4
      // 08a: aload 5
      // 08c: invokevirtual com/l7tech/gateway/common/resources/ResourceEntry.getUri ()Ljava/lang/String;
      // 08f: invokevirtual org/xml/sax/InputSource.setSystemId (Ljava/lang/String;)V
      // 092: aload 4
      // 094: new java/io/StringReader
      // 097: dup
      // 098: aload 5
      // 09a: invokevirtual com/l7tech/gateway/common/resources/ResourceEntry.getContent ()Ljava/lang/String;
      // 09d: invokespecial java/io/StringReader.<init> (Ljava/lang/String;)V
      // 0a0: invokevirtual org/xml/sax/InputSource.setCharacterStream (Ljava/io/Reader;)V
      // 0a3: goto 109
      // 0a6: aload 0
      // 0a7: getfield com/l7tech/gateway/pm2/graphql/helper/PM2ResourceAdminEntityResolver.b Z
      // 0aa: ifeq 109
      // 0ad: aload 6
      // 0af: ifnull 109
      // 0b2: goto 0b6
      // 0b5: athrow
      // 0b6: aload 6
      // 0b8: invokevirtual java/lang/String.toLowerCase ()Ljava/lang/String;
      // 0bb: getstatic com/l7tech/gateway/pm2/graphql/helper/PM2ResourceAdminEntityResolver.c [Ljava/lang/String;
      // 0be: bipush 0
      // 0bf: aaload
      // 0c0: invokevirtual java/lang/String.startsWith (Ljava/lang/String;)Z
      // 0c3: ifne 0de
      // 0c6: goto 0ca
      // 0c9: athrow
      // 0ca: aload 6
      // 0cc: invokevirtual java/lang/String.toLowerCase ()Ljava/lang/String;
      // 0cf: getstatic com/l7tech/gateway/pm2/graphql/helper/PM2ResourceAdminEntityResolver.c [Ljava/lang/String;
      // 0d2: bipush 1
      // 0d3: aaload
      // 0d4: invokevirtual java/lang/String.startsWith (Ljava/lang/String;)Z
      // 0d7: ifeq 109
      // 0da: goto 0de
      // 0dd: athrow
      // 0de: aload 0
      // 0df: getfield com/l7tech/gateway/pm2/graphql/helper/PM2ResourceAdminEntityResolver.a Lcom/l7tech/gateway/common/resources/ResourceAdmin;
      // 0e2: aload 6
      // 0e4: invokeinterface com/l7tech/gateway/common/resources/ResourceAdmin.resolveResource (Ljava/lang/String;)Ljava/lang/String; 2
      // 0e9: astore 7
      // 0eb: new org/xml/sax/InputSource
      // 0ee: dup
      // 0ef: invokespecial org/xml/sax/InputSource.<init> ()V
      // 0f2: astore 4
      // 0f4: aload 4
      // 0f6: aload 6
      // 0f8: invokevirtual org/xml/sax/InputSource.setSystemId (Ljava/lang/String;)V
      // 0fb: aload 4
      // 0fd: new java/io/StringReader
      // 100: dup
      // 101: aload 7
      // 103: invokespecial java/io/StringReader.<init> (Ljava/lang/String;)V
      // 106: invokevirtual org/xml/sax/InputSource.setCharacterStream (Ljava/io/Reader;)V
      // 109: goto 124
      // 10c: astore 5
      // 10e: new com/l7tech/util/CausedIOException
      // 111: dup
      // 112: aload 5
      // 114: invokespecial com/l7tech/util/CausedIOException.<init> (Ljava/lang/Throwable;)V
      // 117: athrow
      // 118: astore 5
      // 11a: new com/l7tech/util/CausedIOException
      // 11d: dup
      // 11e: aload 5
      // 120: invokespecial com/l7tech/util/CausedIOException.<init> (Ljava/lang/Throwable;)V
      // 123: athrow
      // 124: aload 4
      // 126: areturn
      // try (80 -> 96): 97 com/l7tech/objectmodel/FindException
      // try (76 -> 87): 88 com/l7tech/objectmodel/FindException
      // try (73 -> 78): 79 com/l7tech/objectmodel/FindException
      // try (16 -> 20): 21 com/l7tech/objectmodel/FindException
      // try (2 -> 116): 117 com/l7tech/objectmodel/FindException
      // try (2 -> 116): 123 java/net/URISyntaxException
   }

   private ResourceEntry a(String var1) throws FindException {
      ResourceEntry var2 = null;
      if (var1 != null) {
         Collection var3 = this.a.findResourceHeadersByPublicIdentifier(var1);
         if (var3.size() == 1) {
            var2 = this.a.findResourceEntryByPrimaryKey(((ResourceEntryHeader)var3.iterator().next()).getGoid());
         }
      }

      return var2;
   }

   static {
      String[] var5 = new String[2];
      int var3 = 0;
      String var2 = "\u0018^`\u0016\u000e\u0006\u0018^`\u0016GQ";
      int var4 = "\u0018^`\u0016\u000e\u0006\u0018^`\u0016GQ".length();
      char var1 = 5;
      int var0 = -1;

      while (true) {
         String var10002 = a(b(var2.substring(++var0, var0 + var1)));
         byte var10001 = -1;
         var5[var3++] = var10002;
         if ((var0 += var1) >= var4) {
            c = var5;
            return;
         }

         var1 = var2.charAt(var0);
      }
   }

   private static char[] b(String var0) {
      char[] var10000 = var0.toCharArray();
      if (var10000.length < 2) {
         var10000[0] = (char)(var10000[0] ^ 93);
      }

      return var10000;
   }

   private static String a(char[] var0) {
      int var10002 = var0.length;
      char[] var10001 = var0;
      int var10000 = var10002;

      for (int var1 = 0; var10000 > var1; var1++) {
         var10001[var1] = (char)(var10001[var1] ^ switch (var1 % 7) {
            case 0 -> 112;
            case 1 -> 42;
            case 2 -> 20;
            case 3 -> 102;
            case 4 -> 52;
            case 5 -> 107;
            default -> 93;
         });
      }

      return new String(var10001).intern();
   }
}
