package com.l7tech.xml;

import com.l7tech.common.io.XmlUtil;
import com.l7tech.util.InvalidDocumentFormatException;
import com.l7tech.util.TooManyChildElementsException;
import com.l7tech.xml.xpath.CompiledXpath;
import com.l7tech.xml.xpath.XpathResult;
import com.l7tech.xml.xpath.XpathVariableFinder;
import java.io.IOException;
import java.io.OutputStream;
import javax.xml.xpath.XPathExpressionException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

public abstract class ElementCursor {
   private static final String e;

   public abstract ElementCursor duplicate();

   public abstract void pushPosition();

   public abstract void popPosition() throws IllegalStateException;

   public abstract void popPosition(boolean var1) throws IllegalStateException;

   public abstract void moveToDocumentElement();

   public abstract void moveToRoot();

   public abstract boolean moveToParentElement();

   public boolean moveToOnlyOneChildElement() throws TooManyChildElementsException {
      boolean var1 = this.moveToFirstChildElement();

      try {
         if (!var1) {
            return false;
         }
      } catch (TooManyChildElementsException var4) {
         throw b(var4);
      }

      this.pushPosition();
      if (this.moveToNextSiblingElement()) {
         this.moveToParentElement();
         String var2 = this.getLocalName();
         String var3 = this.getNamespaceUri();
         this.popPosition(true);
         throw new TooManyChildElementsException(var3, var2);
      } else {
         this.popPosition();
         return true;
      }
   }

   public abstract boolean moveToFirstChildElement();

   public boolean moveToFirstChildElement(String param1, String param2) {
      // $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: invokevirtual com/l7tech/xml/ElementCursor.pushPosition ()V
      // 04: aload 0
      // 05: invokevirtual com/l7tech/xml/ElementCursor.moveToFirstChildElement ()Z
      // 08: ifne 15
      // 0b: aload 0
      // 0c: invokevirtual com/l7tech/xml/ElementCursor.popPosition ()V
      // 0f: bipush 0
      // 10: ireturn
      // 11: invokestatic com/l7tech/xml/ElementCursor.b (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 14: athrow
      // 15: aload 1
      // 16: aload 0
      // 17: invokevirtual com/l7tech/xml/ElementCursor.getLocalName ()Ljava/lang/String;
      // 1a: invokevirtual java/lang/String.equals (Ljava/lang/Object;)Z
      // 1d: ifeq 3d
      // 20: aload 2
      // 21: aload 0
      // 22: invokevirtual com/l7tech/xml/ElementCursor.getNamespaceUri ()Ljava/lang/String;
      // 25: invokevirtual java/lang/String.equals (Ljava/lang/Object;)Z
      // 28: ifeq 3d
      // 2b: goto 32
      // 2e: invokestatic com/l7tech/xml/ElementCursor.b (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 31: athrow
      // 32: aload 0
      // 33: bipush 1
      // 34: invokevirtual com/l7tech/xml/ElementCursor.popPosition (Z)V
      // 37: bipush 1
      // 38: ireturn
      // 39: invokestatic com/l7tech/xml/ElementCursor.b (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 3c: athrow
      // 3d: aload 0
      // 3e: aload 1
      // 3f: aload 2
      // 40: invokevirtual com/l7tech/xml/ElementCursor.moveToNextSiblingElement (Ljava/lang/String;Ljava/lang/String;)Z
      // 43: ifne 50
      // 46: aload 0
      // 47: invokevirtual com/l7tech/xml/ElementCursor.popPosition ()V
      // 4a: bipush 0
      // 4b: ireturn
      // 4c: invokestatic com/l7tech/xml/ElementCursor.b (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 4f: athrow
      // 50: aload 0
      // 51: bipush 1
      // 52: invokevirtual com/l7tech/xml/ElementCursor.popPosition (Z)V
      // 55: bipush 1
      // 56: ireturn
      // try (0 -> 9): 9 java/lang/IllegalArgumentException
      // try (11 -> 21): 22 java/lang/IllegalArgumentException
      // try (16 -> 29): 29 java/lang/IllegalArgumentException
      // try (31 -> 40): 40 java/lang/IllegalArgumentException
   }

   public boolean moveToFirstChildElement(String param1, String[] param2) {
      // $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: invokevirtual com/l7tech/xml/ElementCursor.pushPosition ()V
      // 04: aload 0
      // 05: invokevirtual com/l7tech/xml/ElementCursor.moveToFirstChildElement ()Z
      // 08: ifne 15
      // 0b: aload 0
      // 0c: invokevirtual com/l7tech/xml/ElementCursor.popPosition ()V
      // 0f: bipush 0
      // 10: ireturn
      // 11: invokestatic com/l7tech/xml/ElementCursor.b (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 14: athrow
      // 15: aload 1
      // 16: aload 0
      // 17: invokevirtual com/l7tech/xml/ElementCursor.getLocalName ()Ljava/lang/String;
      // 1a: invokevirtual java/lang/String.equals (Ljava/lang/Object;)Z
      // 1d: ifeq 3d
      // 20: aload 2
      // 21: aload 0
      // 22: invokevirtual com/l7tech/xml/ElementCursor.getNamespaceUri ()Ljava/lang/String;
      // 25: invokestatic com/l7tech/util/ArrayUtils.contains ([Ljava/lang/Object;Ljava/lang/Object;)Z
      // 28: ifeq 3d
      // 2b: goto 32
      // 2e: invokestatic com/l7tech/xml/ElementCursor.b (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 31: athrow
      // 32: aload 0
      // 33: bipush 1
      // 34: invokevirtual com/l7tech/xml/ElementCursor.popPosition (Z)V
      // 37: bipush 1
      // 38: ireturn
      // 39: invokestatic com/l7tech/xml/ElementCursor.b (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 3c: athrow
      // 3d: aload 0
      // 3e: aload 1
      // 3f: aload 2
      // 40: invokevirtual com/l7tech/xml/ElementCursor.moveToNextSiblingElement (Ljava/lang/String;[Ljava/lang/String;)Z
      // 43: ifne 50
      // 46: aload 0
      // 47: invokevirtual com/l7tech/xml/ElementCursor.popPosition ()V
      // 4a: bipush 0
      // 4b: ireturn
      // 4c: invokestatic com/l7tech/xml/ElementCursor.b (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 4f: athrow
      // 50: aload 0
      // 51: bipush 1
      // 52: invokevirtual com/l7tech/xml/ElementCursor.popPosition (Z)V
      // 55: bipush 1
      // 56: ireturn
      // try (0 -> 9): 9 java/lang/IllegalArgumentException
      // try (11 -> 21): 22 java/lang/IllegalArgumentException
      // try (16 -> 29): 29 java/lang/IllegalArgumentException
      // try (31 -> 40): 40 java/lang/IllegalArgumentException
   }

   public abstract boolean moveToNextSiblingElement();

   public abstract boolean moveToNextSiblingElement(String var1, String[] var2);

   public abstract boolean moveToNextSiblingElement(String var1, String var2);

   public abstract String getAttributeValue(String var1);

   public abstract String getAttributeValue(String var1, String var2);

   public abstract String getAttributeValue(String var1, String[] var2);

   public int matchAttributeValue(String var1, String[][] var2) {
      String var3 = this.getAttributeValue(var1);

      for (int var4 = 0; var4 < var2.length; var4++) {
         String[] var5 = var2[var4];

         for (String var9 : var5) {
            try {
               if (var3.equals(var9)) {
                  return var4;
               }
            } catch (IllegalArgumentException var10) {
               throw b(var10);
            }
         }
      }

      return -1;
   }

   public abstract boolean containsMixedModeContent(boolean var1, boolean var2);

   public abstract String getLocalName();

   public abstract String getNamespaceUri();

   public abstract String getPrefix();

   public abstract String getTextValue();

   public abstract void write(OutputStream var1) throws IOException;

   public abstract String asString() throws IOException;

   public abstract Element asDomElement(Document var1);

   public Element asDomElement() {
      return this.asDomElement(XmlUtil.createEmptyDocument());
   }

   public abstract XpathResult getXpathResult(CompiledXpath var1, XpathVariableFinder var2, boolean var3) throws XPathExpressionException;

   public XpathResult getXpathResult(CompiledXpath var1) throws XPathExpressionException {
      return this.getXpathResult(var1, null, false);
   }

   public boolean matches(CompiledXpath param1) throws XPathExpressionException {
      // $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 1
      // 01: ifnonnull 13
      // 04: new java/lang/IllegalArgumentException
      // 07: dup
      // 08: getstatic com/l7tech/xml/ElementCursor.e Ljava/lang/String;
      // 0b: invokespecial java/lang/IllegalArgumentException.<init> (Ljava/lang/String;)V
      // 0e: athrow
      // 0f: invokestatic com/l7tech/xml/ElementCursor.b (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 12: athrow
      // 13: aload 0
      // 14: aload 1
      // 15: aconst_null
      // 16: bipush 0
      // 17: invokevirtual com/l7tech/xml/ElementCursor.getXpathResult (Lcom/l7tech/xml/xpath/CompiledXpath;Lcom/l7tech/xml/xpath/XpathVariableFinder;Z)Lcom/l7tech/xml/xpath/XpathResult;
      // 1a: astore 2
      // 1b: aload 2
      // 1c: ifnull 37
      // 1f: aload 2
      // 20: invokeinterface com/l7tech/xml/xpath/XpathResult.matches ()Z 1
      // 25: ifeq 37
      // 28: goto 2f
      // 2b: invokestatic com/l7tech/xml/ElementCursor.b (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 2e: athrow
      // 2f: bipush 1
      // 30: goto 38
      // 33: invokestatic com/l7tech/xml/ElementCursor.b (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 36: athrow
      // 37: bipush 0
      // 38: ireturn
      // try (0 -> 7): 7 javax/xml/xpath/XPathExpressionException
      // try (15 -> 20): 21 javax/xml/xpath/XPathExpressionException
      // try (17 -> 25): 25 javax/xml/xpath/XPathExpressionException
   }

   public int visitChildElements(ElementCursor.Visitor var1) throws InvalidDocumentFormatException {
      this.pushPosition();

      try {
         if (!this.moveToFirstChildElement()) {
            return 0;
         }

         int var2 = 0;

         do {
            this.pushPosition();

            try {
               var1.visit(this);
            } finally {
               this.popPosition(false);
            }

            var2++;
         } while (this.moveToNextSiblingElement());

         return var2;
      } finally {
         this.popPosition(false);
      }
   }

   public void visitElements(ElementCursor.Visitor var1) throws InvalidDocumentFormatException {
      this.a(var1, false);
   }

   private void a(ElementCursor.Visitor var1, boolean var2) throws InvalidDocumentFormatException {
      this.pushPosition();

      try {
         var1.visit(this);
      } finally {
         this.popPosition(false);
      }

      this.pushPosition();

      try {
         if (this.moveToFirstChildElement()) {
            this.a(var1, true);
         }
      } finally {
         this.popPosition(false);
      }

      if (var2) {
         this.pushPosition();

         try {
            if (this.moveToNextSiblingElement()) {
               this.a(var1, true);
            }
         } finally {
            this.popPosition(false);
         }
      }
   }

   public abstract byte[] canonicalize(String[] var1) throws IOException;

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

   static {
      String var10002 = a(32, a("/\u0017Y\"LO\u0016( D3QKS!\rG&\u0005A\u0016l\bF=SJ\u0017)\u001c"));
      byte var10001 = -1;
      e = var10002;
   }

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

      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 -> 108;
            case 1 -> 88;
            case 2 -> 20;
            case 3 -> 114;
            case 4 -> 5;
            case 5 -> 3;
            default -> 83;
         });
      }

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

   public interface Visitor {
      void visit(ElementCursor var1) throws InvalidDocumentFormatException;
   }
}
