/*
 * Decompiled with CFR 0_110.
 * 
 * Could not load the following classes:
 *  java.lang.Exception
 *  java.lang.Object
 *  java.lang.Throwable
 *  java.util.List
 */
package org.dom4j.io;

import java.util.List;
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.ElementHandler;
import org.dom4j.ElementPath;
import org.dom4j.Node;
import org.dom4j.io.ElementModifier;
import org.dom4j.io.ElementStack;
import org.dom4j.io.SAXModifyException;

class SAXModifyElementHandler
implements ElementHandler {
    private ElementModifier elemModifier;
    private Element modifiedElement;

    public SAXModifyElementHandler(ElementModifier elementModifier) {
        this.elemModifier = elementModifier;
    }

    protected Element getModifiedElement() {
        return this.modifiedElement;
    }

    /*
     * Enabled aggressive block sorting
     * Enabled unnecessary exception pruning
     * Enabled aggressive exception aggregation
     */
    @Override
    public void onEnd(ElementPath elementPath) {
        try {
            Element element = elementPath.getCurrent();
            Element element2 = element.getParent();
            if (element2 != null) {
                Element element3 = (Element)element.clone();
                this.modifiedElement = this.elemModifier.modifyElement(element3);
                if (this.modifiedElement != null) {
                    this.modifiedElement.setParent(element.getParent());
                    this.modifiedElement.setDocument(element.getDocument());
                    int n = element2.indexOf((Node)element);
                    element2.content().set(n, (Object)this.modifiedElement);
                }
                element.detach();
            } else if (element.isRootElement()) {
                Element element4 = (Element)element.clone();
                this.modifiedElement = this.elemModifier.modifyElement(element4);
                if (this.modifiedElement != null) {
                    this.modifiedElement.setDocument(element.getDocument());
                    element.getDocument().setRootElement(this.modifiedElement);
                }
                element.detach();
            }
            if (!(elementPath instanceof ElementStack)) return;
            {
                ElementStack elementStack = (ElementStack)elementPath;
                elementStack.popElement();
                elementStack.pushElement(this.modifiedElement);
                return;
            }
        }
        catch (Exception var2_8) {
            throw new SAXModifyException((Throwable)var2_8);
        }
    }

    @Override
    public void onStart(ElementPath elementPath) {
        this.modifiedElement = elementPath.getCurrent();
    }
}

