package com.l7tech.security.xml;

import com.l7tech.common.io.ByteLimitInputStream;
import com.l7tech.common.mime.NoSuchPartException;
import com.l7tech.common.mime.PartInfo;
import com.l7tech.common.mime.PartIterator;
import com.l7tech.util.CausedIOException;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.SequenceInputStream;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.logging.Logger;
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

public class AttachmentEntityResolver implements EntityResolver {
   private static final Logger a;
   private static final String b;
   private final PartIterator c;
   private final Map<String, PartInfo> d;
   private final EntityResolver e;
   private final long f;
   private Collection<PartInfo> g;
   private static final String[] h;

   public AttachmentEntityResolver(PartIterator var1, EntityResolver var2) throws IOException {
      this(var1, var2, new HashMap<>(), 0L);
   }

   public AttachmentEntityResolver(PartIterator var1, EntityResolver var2, Map<String, PartInfo> var3, long var4) throws IOException {
      this.c = var1;
      this.d = var3;
      this.e = var2;
      this.f = var4;
      this.b();
   }

   @Override
   public InputSource resolveEntity(String param1, String param2) throws SAXException, 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:
      // 00: aload 0
      // 01: getfield com/l7tech/security/xml/AttachmentEntityResolver.c Lcom/l7tech/common/mime/PartIterator;
      // 04: ifnull af
      // 07: aload 2
      // 08: ifnull af
      // 0b: goto 12
      // 0e: invokestatic com/l7tech/security/xml/AttachmentEntityResolver.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 11: athrow
      // 12: aload 2
      // 13: invokevirtual java/lang/String.toLowerCase ()Ljava/lang/String;
      // 16: getstatic com/l7tech/security/xml/AttachmentEntityResolver.h [Ljava/lang/String;
      // 19: bipush 9
      // 1b: aaload
      // 1c: invokevirtual java/lang/String.startsWith (Ljava/lang/String;)Z
      // 1f: ifeq af
      // 22: goto 29
      // 25: invokestatic com/l7tech/security/xml/AttachmentEntityResolver.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 28: athrow
      // 29: aload 0
      // 2a: invokevirtual com/l7tech/security/xml/AttachmentEntityResolver.a ()Ljava/util/Collection;
      // 2d: astore 4
      // 2f: aload 0
      // 30: aload 2
      // 31: invokevirtual com/l7tech/security/xml/AttachmentEntityResolver.a (Ljava/lang/String;)Ljava/lang/String;
      // 34: astore 5
      // 36: aload 5
      // 38: invokevirtual java/lang/String.length ()I
      // 3b: ifne 5d
      // 3e: new com/l7tech/util/CausedIOException
      // 41: dup
      // 42: aload 2
      // 43: getstatic com/l7tech/security/xml/AttachmentEntityResolver.h [Ljava/lang/String;
      // 46: bipush 6
      // 48: aaload
      // 49: swap
      // 4a: getstatic com/l7tech/security/xml/AttachmentEntityResolver.h [Ljava/lang/String;
      // 4d: bipush 8
      // 4f: aaload
      // 50: invokedynamic makeConcatWithConstants (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String; bsm=java/lang/invoke/StringConcatFactory.makeConcatWithConstants (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/invoke/CallSite; args=[ "\u0001\u0001\u0001" ]
      // 55: invokespecial com/l7tech/util/CausedIOException.<init> (Ljava/lang/String;)V
      // 58: athrow
      // 59: invokestatic com/l7tech/security/xml/AttachmentEntityResolver.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 5c: athrow
      // 5d: aload 0
      // 5e: aload 4
      // 60: aload 5
      // 62: invokevirtual com/l7tech/security/xml/AttachmentEntityResolver.a (Ljava/util/Collection;Ljava/lang/String;)Lcom/l7tech/common/mime/PartInfo;
      // 65: astore 6
      // 67: aload 6
      // 69: ifnonnull 8a
      // 6c: new com/l7tech/util/CausedIOException
      // 6f: dup
      // 70: aload 5
      // 72: getstatic com/l7tech/security/xml/AttachmentEntityResolver.h [Ljava/lang/String;
      // 75: bipush 3
      // 76: aaload
      // 77: swap
      // 78: getstatic com/l7tech/security/xml/AttachmentEntityResolver.h [Ljava/lang/String;
      // 7b: bipush 5
      // 7c: aaload
      // 7d: invokedynamic makeConcatWithConstants (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String; bsm=java/lang/invoke/StringConcatFactory.makeConcatWithConstants (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/invoke/CallSite; args=[ "\u0001\u0001\u0001" ]
      // 82: invokespecial com/l7tech/util/CausedIOException.<init> (Ljava/lang/String;)V
      // 85: athrow
      // 86: invokestatic com/l7tech/security/xml/AttachmentEntityResolver.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 89: athrow
      // 8a: aload 0
      // 8b: getfield com/l7tech/security/xml/AttachmentEntityResolver.d Ljava/util/Map;
      // 8e: ifnull a5
      // 91: aload 0
      // 92: getfield com/l7tech/security/xml/AttachmentEntityResolver.d Ljava/util/Map;
      // 95: aload 2
      // 96: aload 6
      // 98: invokeinterface java/util/Map.put (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; 3
      // 9d: pop
      // 9e: goto a5
      // a1: invokestatic com/l7tech/security/xml/AttachmentEntityResolver.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // a4: athrow
      // a5: aload 0
      // a6: aload 6
      // a8: invokevirtual com/l7tech/security/xml/AttachmentEntityResolver.a (Lcom/l7tech/common/mime/PartInfo;)Lorg/xml/sax/InputSource;
      // ab: astore 3
      // ac: goto f0
      // af: aload 0
      // b0: getfield com/l7tech/security/xml/AttachmentEntityResolver.e Lorg/xml/sax/EntityResolver;
      // b3: ifnonnull e4
      // b6: new java/io/IOException
      // b9: dup
      // ba: aload 0
      // bb: aload 2
      // bc: invokevirtual com/l7tech/security/xml/AttachmentEntityResolver.a (Ljava/lang/Object;)Ljava/lang/String;
      // bf: aload 0
      // c0: aload 1
      // c1: invokevirtual com/l7tech/security/xml/AttachmentEntityResolver.a (Ljava/lang/Object;)Ljava/lang/String;
      // c4: getstatic com/l7tech/security/xml/AttachmentEntityResolver.h [Ljava/lang/String;
      // c7: bipush 2
      // c8: aaload
      // c9: dup_x2
      // ca: pop
      // cb: getstatic com/l7tech/security/xml/AttachmentEntityResolver.h [Ljava/lang/String;
      // ce: bipush 7
      // d0: aaload
      // d1: swap
      // d2: getstatic com/l7tech/security/xml/AttachmentEntityResolver.h [Ljava/lang/String;
      // d5: bipush 5
      // d6: aaload
      // d7: invokedynamic makeConcatWithConstants (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String; bsm=java/lang/invoke/StringConcatFactory.makeConcatWithConstants (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/invoke/CallSite; args=[ "\u0001\u0001\u0001\u0001\u0001" ]
      // dc: invokespecial java/io/IOException.<init> (Ljava/lang/String;)V
      // df: athrow
      // e0: invokestatic com/l7tech/security/xml/AttachmentEntityResolver.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // e3: athrow
      // e4: aload 0
      // e5: getfield com/l7tech/security/xml/AttachmentEntityResolver.e Lorg/xml/sax/EntityResolver;
      // e8: aload 1
      // e9: aload 2
      // ea: invokeinterface org/xml/sax/EntityResolver.resolveEntity (Ljava/lang/String;Ljava/lang/String;)Lorg/xml/sax/InputSource; 3
      // ef: astore 3
      // f0: aload 3
      // f1: areturn
      // try (0 -> 5): 6 org/xml/sax/SAXException
      // try (3 -> 15): 16 org/xml/sax/SAXException
      // try (25 -> 41): 41 org/xml/sax/SAXException
      // try (48 -> 63): 63 org/xml/sax/SAXException
      // try (65 -> 74): 75 org/xml/sax/SAXException
      // try (82 -> 108): 108 org/xml/sax/SAXException
   }

   private String a(Object var1) {
      String var2 = "";
      if (var1 != null) {
         var2 = var1.toString();
      }

      return var2;
   }

   private String a(String var1) {
      return var1.substring(h[1].length());
   }

   private PartInfo a(Collection<PartInfo> var1, String var2) {
      PartInfo var3 = null;

      for (PartInfo var5 : var1) {
         String var6 = var5.getContentId(true);

         try {
            if (var6 == null || !var6.equals(var2)) {
               continue;
            }
         } catch (NoSuchElementException var7) {
            throw a(var7);
         }

         var3 = var5;
         break;
      }

      return var3;
   }

   private Collection<PartInfo> a() throws IOException {
      Collection var1 = this.g;

      try {
         if (var1 != null || this.c == null) {
            return var1;
         }
      } catch (IOException var2) {
         throw a(var2);
      }

      var1 = this.a(this.c);
      this.a(var1);
      this.g = var1;
      return var1;
   }

   private void b() 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:
      // 00: aload 0
      // 01: getfield com/l7tech/security/xml/AttachmentEntityResolver.c Lcom/l7tech/common/mime/PartIterator;
      // 04: ifnull 35
      // 07: aload 0
      // 08: getfield com/l7tech/security/xml/AttachmentEntityResolver.c Lcom/l7tech/common/mime/PartIterator;
      // 0b: invokeinterface com/l7tech/common/mime/PartIterator.hasNext ()Z 1
      // 10: ifeq 35
      // 13: goto 1a
      // 16: invokestatic com/l7tech/security/xml/AttachmentEntityResolver.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 19: athrow
      // 1a: aload 0
      // 1b: getfield com/l7tech/security/xml/AttachmentEntityResolver.c Lcom/l7tech/common/mime/PartIterator;
      // 1e: invokeinterface com/l7tech/common/mime/PartIterator.next ()Lcom/l7tech/common/mime/PartInfo; 1
      // 23: pop
      // 24: goto 35
      // 27: invokestatic com/l7tech/security/xml/AttachmentEntityResolver.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 2a: athrow
      // 2b: astore 1
      // 2c: new com/l7tech/util/CausedIOException
      // 2f: dup
      // 30: aload 1
      // 31: invokespecial com/l7tech/util/CausedIOException.<init> (Ljava/lang/Throwable;)V
      // 34: athrow
      // 35: return
      // try (0 -> 7): 8 java/util/NoSuchElementException
      // try (10 -> 14): 17 java/util/NoSuchElementException
      // try (3 -> 15): 15 java/io/IOException
   }

   private Collection<PartInfo> a(PartIterator param1) 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:
      // 00: new java/util/ArrayList
      // 03: dup
      // 04: invokespecial java/util/ArrayList.<init> ()V
      // 07: astore 2
      // 08: aload 1
      // 09: ifnull 30
      // 0c: aload 1
      // 0d: invokeinterface com/l7tech/common/mime/PartIterator.hasNext ()Z 1
      // 12: ifeq 30
      // 15: goto 1c
      // 18: invokestatic com/l7tech/security/xml/AttachmentEntityResolver.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 1b: athrow
      // 1c: aload 2
      // 1d: aload 1
      // 1e: invokeinterface com/l7tech/common/mime/PartIterator.next ()Lcom/l7tech/common/mime/PartInfo; 1
      // 23: invokeinterface java/util/List.add (Ljava/lang/Object;)Z 2
      // 28: pop
      // 29: goto 0c
      // 2c: invokestatic com/l7tech/security/xml/AttachmentEntityResolver.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 2f: athrow
      // 30: goto 3d
      // 33: astore 3
      // 34: new com/l7tech/util/CausedIOException
      // 37: dup
      // 38: aload 3
      // 39: invokespecial com/l7tech/util/CausedIOException.<init> (Ljava/lang/Throwable;)V
      // 3c: athrow
      // 3d: aload 2
      // 3e: invokestatic java/util/Collections.unmodifiableCollection (Ljava/util/Collection;)Ljava/util/Collection;
      // 41: areturn
      // try (6 -> 18): 18 java/util/NoSuchElementException
      // try (4 -> 9): 10 java/util/NoSuchElementException
      // try (4 -> 20): 21 java/util/NoSuchElementException
   }

   private void a(Collection<PartInfo> param1) {
      // $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:
      // 00: new java/util/HashSet
      // 03: dup
      // 04: invokespecial java/util/HashSet.<init> ()V
      // 07: astore 2
      // 08: aload 1
      // 09: invokeinterface java/util/Collection.iterator ()Ljava/util/Iterator; 1
      // 0e: astore 3
      // 0f: aload 3
      // 10: invokeinterface java/util/Iterator.hasNext ()Z 1
      // 15: ifeq 94
      // 18: aload 3
      // 19: invokeinterface java/util/Iterator.next ()Ljava/lang/Object; 1
      // 1e: checkcast com/l7tech/common/mime/PartInfo
      // 21: astore 4
      // 23: aload 4
      // 25: bipush 1
      // 26: invokeinterface com/l7tech/common/mime/PartInfo.getContentId (Z)Ljava/lang/String; 2
      // 2b: astore 5
      // 2d: aload 5
      // 2f: ifnull 91
      // 32: aload 5
      // 34: ldc "<"
      // 36: invokevirtual java/lang/String.startsWith (Ljava/lang/String;)Z
      // 39: ifeq 60
      // 3c: goto 43
      // 3f: invokestatic com/l7tech/security/xml/AttachmentEntityResolver.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 42: athrow
      // 43: getstatic com/l7tech/security/xml/AttachmentEntityResolver.a Ljava/util/logging/Logger;
      // 46: getstatic java/util/logging/Level.WARNING Ljava/util/logging/Level;
      // 49: getstatic com/l7tech/security/xml/AttachmentEntityResolver.h [Ljava/lang/String;
      // 4c: bipush 4
      // 4d: aaload
      // 4e: aload 5
      // 50: invokevirtual java/util/logging/Logger.log (Ljava/util/logging/Level;Ljava/lang/String;Ljava/lang/Object;)V
      // 53: aload 1
      // 54: invokeinterface java/util/Collection.clear ()V 1
      // 59: goto 94
      // 5c: invokestatic com/l7tech/security/xml/AttachmentEntityResolver.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 5f: athrow
      // 60: aload 2
      // 61: aload 5
      // 63: invokeinterface java/util/Set.contains (Ljava/lang/Object;)Z 2
      // 68: ifeq 88
      // 6b: getstatic com/l7tech/security/xml/AttachmentEntityResolver.a Ljava/util/logging/Logger;
      // 6e: getstatic java/util/logging/Level.WARNING Ljava/util/logging/Level;
      // 71: getstatic com/l7tech/security/xml/AttachmentEntityResolver.h [Ljava/lang/String;
      // 74: bipush 0
      // 75: aaload
      // 76: aload 5
      // 78: invokevirtual java/util/logging/Logger.log (Ljava/util/logging/Level;Ljava/lang/String;Ljava/lang/Object;)V
      // 7b: aload 1
      // 7c: invokeinterface java/util/Collection.clear ()V 1
      // 81: goto 94
      // 84: invokestatic com/l7tech/security/xml/AttachmentEntityResolver.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 87: athrow
      // 88: aload 2
      // 89: aload 5
      // 8b: invokeinterface java/util/Set.add (Ljava/lang/Object;)Z 2
      // 90: pop
      // 91: goto 0f
      // 94: return
      // try (18 -> 24): 25 java/util/NoSuchElementException
      // try (20 -> 37): 37 java/util/NoSuchElementException
      // try (39 -> 53): 53 java/util/NoSuchElementException
   }

   private InputSource a(PartInfo var1) throws IOException {
      try {
         InputStream var2 = var1.getInputStream(false);
         ByteArrayInputStream var3 = new ByteArrayInputStream(var1.getHeaders().toByteArray());
         Object var4 = new SequenceInputStream(var3, var2);
         if (this.f > 0L) {
            var4 = new ByteLimitInputStream((InputStream)var4, 16, this.f);
         }

         return new InputSource((InputStream)var4);
      } catch (NoSuchPartException var5) {
         throw new CausedIOException(var5);
      }
   }

   static {
      String[] var5 = new String[10];
      int var3 = 0;
      String var2 = "/o\u0015r\u007fGW\u0001(\u001aiyOZ\u000ee\u001esy]\u0019\u0000g\t=`KJ\u0015i\u001cx-YP\u0012`[yx^U\u000fk\u001aihJ\u0019\u0005g\u0015ih@MKa\u001f=*\tBVu\\:#\u0004\u0005a\u001f'.%i\u0015sbZ\u0019\u0014m\braX\\Fm\u0015idZ@F\u007f\u0012ie\u000eJ\u001f{\u000fx`\u000eP\u0002m\u0015idHP\u0003z[:%'|\u000f|nFT\u0003f\u000f=cAMFn\u0014hcJ\u0019\u0000g\t=dJ\\\b|\u0012{dKKF/A/o\u0015r\u007fGW\u0001(\u001aiyOZ\u000ee\u001esy]\u0019\u0000g\t=`KJ\u0015i\u001cx-YP\u0012`[tcXX\na\u001f=nAW\u0012m\u0015i G]F/\\f=S\u001eA&\u0002A&\u001f/f\r|aG]Fi\u000filMQ\u000bm\u0015i-G]\u0003f\u000ftkG\\\u0014(\\\u0016A$[mxLU\u000fk[tiKW\u0012a\u001dth\\\u0019A";
      int var4 = "/o\u0015r\u007fGW\u0001(\u001aiyOZ\u000ee\u001esy]\u0019\u0000g\t=`KJ\u0015i\u001cx-YP\u0012`[yx^U\u000fk\u001aihJ\u0019\u0005g\u0015ih@MKa\u001f=*\tBVu\\:#\u0004\u0005a\u001f'.%i\u0015sbZ\u0019\u0014m\braX\\Fm\u0015idZ@F\u007f\u0012ie\u000eJ\u001f{\u000fx`\u000eP\u0002m\u0015idHP\u0003z[:%'|\u000f|nFT\u0003f\u000f=cAMFn\u0014hcJ\u0019\u0000g\t=dJ\\\b|\u0012{dKKF/A/o\u0015r\u007fGW\u0001(\u001aiyOZ\u000ee\u001esy]\u0019\u0000g\t=`KJ\u0015i\u001cx-YP\u0012`[tcXX\na\u001f=nAW\u0012m\u0015i G]F/\\f=S\u001eA&\u0002A&\u001f/f\r|aG]Fi\u000filMQ\u000bm\u0015i-G]\u0003f\u000ftkG\\\u0014(\\\u0016A$[mxLU\u000fk[tiKW\u0012a\u001dth\\\u0019A"
         .length();
      char var1 = 'D';
      int var7 = -1;

      label24:
      while (true) {
         byte var10000 = 93;
         String var10001 = var2.substring(++var7, var7 + var1);
         byte var10002 = -1;

         while (true) {
            String var8 = a(var10000, b(var10001));
            switch (var10002) {
               case 0:
                  var5[var3++] = var8;
                  if ((var7 += var1) >= var4) {
                     h = var5;
                     b = h[9];
                     a = Logger.getLogger(AttachmentEntityResolver.class.getName());
                     return;
                  }

                  var1 = var2.charAt(var7);
                  break;
               default:
                  var5[var3++] = var8;
                  if ((var7 += var1) < var4) {
                     var1 = var2.charAt(var7);
                     continue label24;
                  }

                  var2 = "q\u0016\u00045Q/\u0017";
                  var4 = "q\u0016\u00045Q/\u0017".length();
                  var1 = 2;
                  var7 = -1;
            }

            var10000 = 109;
            var10001 = var2.substring(++var7, var7 + var1);
            var10002 = 0;
         }
      }
   }

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

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

      return var10000;
   }

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

      for (int var2 = 0; var10000 > var2; var2++) {
         var10001[var2] = (char)(var10001[var2] ^ var10002 ^ switch (var2 % 7) {
            case 0 -> 59;
            case 1 -> 85;
            case 2 -> 38;
            case 3 -> 64;
            case 4 -> 80;
            case 5 -> 115;
            default -> 100;
         });
      }

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