/*
 * Decompiled with CFR 0_110.
 * 
 * Could not load the following classes:
 *  java.io.File
 *  java.io.InputStream
 *  java.io.Reader
 *  java.lang.Object
 *  java.lang.String
 *  java.lang.Throwable
 *  java.net.URL
 *  java.util.HashMap
 *  java.util.Map
 *  java.util.Map$Entry
 *  java.util.Set
 *  org.xml.sax.InputSource
 *  org.xml.sax.SAXException
 *  org.xml.sax.XMLReader
 */
package org.dom4j.io;

import java.io.File;
import java.io.InputStream;
import java.io.Reader;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentFactory;
import org.dom4j.ElementHandler;
import org.dom4j.io.DispatchHandler;
import org.dom4j.io.ElementModifier;
import org.dom4j.io.PruningDispatchHandler;
import org.dom4j.io.SAXHelper;
import org.dom4j.io.SAXModifyElementHandler;
import org.dom4j.io.SAXModifyException;
import org.dom4j.io.SAXModifyReader;
import org.dom4j.io.SAXReader;
import org.dom4j.io.XMLWriter;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;

public class SAXModifier {
    private HashMap modifiers;
    private SAXModifyReader modifyReader;
    private boolean pruneElements;
    private XMLReader xmlReader;
    private XMLWriter xmlWriter;

    public SAXModifier() {
        this.modifiers = new HashMap();
    }

    public SAXModifier(XMLReader xMLReader) {
        this.modifiers = new HashMap();
        this.xmlReader = xMLReader;
    }

    public SAXModifier(XMLReader xMLReader, boolean bl) {
        this.modifiers = new HashMap();
        this.xmlReader = xMLReader;
    }

    public SAXModifier(boolean bl) {
        this.modifiers = new HashMap();
        this.pruneElements = bl;
    }

    private SAXModifyReader getSAXModifyReader() {
        if (this.modifyReader == null) {
            this.modifyReader = new SAXModifyReader();
        }
        return this.modifyReader;
    }

    private XMLReader getXMLReader() throws SAXException {
        if (this.xmlReader == null) {
            this.xmlReader = SAXHelper.createXMLReader(false);
        }
        return this.xmlReader;
    }

    /*
     * Enabled aggressive block sorting
     * Enabled unnecessary exception pruning
     * Enabled aggressive exception aggregation
     */
    private SAXReader installModifyReader() throws DocumentException {
        try {
            SAXModifyReader sAXModifyReader = this.getSAXModifyReader();
            if (this.isPruneElements()) {
                this.modifyReader.setDispatchHandler(new PruningDispatchHandler());
            }
            sAXModifyReader.resetHandlers();
            for (Map.Entry entry : this.modifiers.entrySet()) {
                SAXModifyElementHandler sAXModifyElementHandler = new SAXModifyElementHandler((ElementModifier)entry.getValue());
                sAXModifyReader.addHandler((String)entry.getKey(), sAXModifyElementHandler);
            }
            sAXModifyReader.setXMLWriter(this.getXMLWriter());
            sAXModifyReader.setXMLReader(this.getXMLReader());
            return sAXModifyReader;
        }
        catch (SAXException var1_5) {
            throw new DocumentException(var1_5.getMessage(), (Throwable)var1_5);
        }
    }

    public void addModifier(String string2, ElementModifier elementModifier) {
        this.modifiers.put((Object)string2, (Object)elementModifier);
    }

    public DocumentFactory getDocumentFactory() {
        return this.getSAXModifyReader().getDocumentFactory();
    }

    public XMLWriter getXMLWriter() {
        return this.xmlWriter;
    }

    public boolean isPruneElements() {
        return this.pruneElements;
    }

    public Document modify(File file) throws DocumentException {
        try {
            Document document = super.installModifyReader().read(file);
            return document;
        }
        catch (SAXModifyException var2_3) {
            Throwable throwable = var2_3.getCause();
            throw new DocumentException(throwable.getMessage(), throwable);
        }
    }

    public Document modify(InputStream inputStream) throws DocumentException {
        try {
            Document document = super.installModifyReader().read(inputStream);
            return document;
        }
        catch (SAXModifyException var2_3) {
            Throwable throwable = var2_3.getCause();
            throw new DocumentException(throwable.getMessage(), throwable);
        }
    }

    public Document modify(InputStream inputStream, String string2) throws DocumentException {
        try {
            Document document = super.installModifyReader().read(inputStream);
            return document;
        }
        catch (SAXModifyException var3_4) {
            Throwable throwable = var3_4.getCause();
            throw new DocumentException(throwable.getMessage(), throwable);
        }
    }

    public Document modify(Reader reader) throws DocumentException {
        try {
            Document document = super.installModifyReader().read(reader);
            return document;
        }
        catch (SAXModifyException var2_3) {
            Throwable throwable = var2_3.getCause();
            throw new DocumentException(throwable.getMessage(), throwable);
        }
    }

    public Document modify(Reader reader, String string2) throws DocumentException {
        try {
            Document document = super.installModifyReader().read(reader);
            return document;
        }
        catch (SAXModifyException var3_4) {
            Throwable throwable = var3_4.getCause();
            throw new DocumentException(throwable.getMessage(), throwable);
        }
    }

    public Document modify(String string2) throws DocumentException {
        try {
            Document document = super.installModifyReader().read(string2);
            return document;
        }
        catch (SAXModifyException var2_3) {
            Throwable throwable = var2_3.getCause();
            throw new DocumentException(throwable.getMessage(), throwable);
        }
    }

    public Document modify(URL uRL) throws DocumentException {
        try {
            Document document = super.installModifyReader().read(uRL);
            return document;
        }
        catch (SAXModifyException var2_3) {
            Throwable throwable = var2_3.getCause();
            throw new DocumentException(throwable.getMessage(), throwable);
        }
    }

    public Document modify(InputSource inputSource) throws DocumentException {
        try {
            Document document = super.installModifyReader().read(inputSource);
            return document;
        }
        catch (SAXModifyException var2_3) {
            Throwable throwable = var2_3.getCause();
            throw new DocumentException(throwable.getMessage(), throwable);
        }
    }

    public void removeModifier(String string2) {
        this.modifiers.remove((Object)string2);
        super.getSAXModifyReader().removeHandler(string2);
    }

    public void resetModifiers() {
        this.modifiers.clear();
        this.getSAXModifyReader().resetHandlers();
    }

    public void setDocumentFactory(DocumentFactory documentFactory) {
        super.getSAXModifyReader().setDocumentFactory(documentFactory);
    }

    public void setXMLWriter(XMLWriter xMLWriter) {
        this.xmlWriter = xMLWriter;
    }
}

