/*
 * Decompiled with CFR 0_110.
 * 
 * Could not load the following classes:
 *  java.io.IOException
 *  java.lang.String
 *  java.lang.Throwable
 *  org.xml.sax.Attributes
 *  org.xml.sax.Locator
 *  org.xml.sax.SAXException
 */
package org.dom4j.io;

import java.io.IOException;
import org.dom4j.DocumentFactory;
import org.dom4j.Element;
import org.dom4j.ElementHandler;
import org.dom4j.io.DispatchHandler;
import org.dom4j.io.ElementStack;
import org.dom4j.io.SAXContentHandler;
import org.dom4j.io.SAXModifyElementHandler;
import org.dom4j.io.SAXModifyException;
import org.dom4j.io.XMLWriter;
import org.xml.sax.Attributes;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;

class SAXModifyContentHandler
extends SAXContentHandler {
    private XMLWriter xmlWriter;

    public SAXModifyContentHandler() {
    }

    public SAXModifyContentHandler(DocumentFactory documentFactory) {
        super(documentFactory);
    }

    public SAXModifyContentHandler(DocumentFactory documentFactory, ElementHandler elementHandler) {
        super(documentFactory, elementHandler);
    }

    public SAXModifyContentHandler(DocumentFactory documentFactory, ElementHandler elementHandler, ElementStack elementStack) {
        super(documentFactory, elementHandler, elementStack);
    }

    private boolean activeHandlers() {
        if (this.getElementStack().getDispatchHandler().getActiveHandlerCount() > 0) {
            return true;
        }
        return false;
    }

    @Override
    public void characters(char[] arrc, int n, int n2) throws SAXException {
        super.characters(arrc, n, n2);
        if (!super.activeHandlers() && this.xmlWriter != null) {
            this.xmlWriter.characters(arrc, n, n2);
        }
    }

    @Override
    public void comment(char[] arrc, int n, int n2) throws SAXException {
        super.comment(arrc, n, n2);
        if (!super.activeHandlers() && this.xmlWriter != null) {
            this.xmlWriter.comment(arrc, n, n2);
        }
    }

    @Override
    public void endCDATA() throws SAXException {
        super.endCDATA();
        if (!this.activeHandlers() && this.xmlWriter != null) {
            this.xmlWriter.endCDATA();
        }
    }

    @Override
    public void endDTD() throws SAXException {
        super.endDTD();
        if (this.xmlWriter != null) {
            this.xmlWriter.endDTD();
        }
    }

    @Override
    public void endDocument() throws SAXException {
        super.endDocument();
        if (this.xmlWriter != null) {
            this.xmlWriter.endDocument();
        }
    }

    /*
     * Enabled aggressive block sorting
     * Enabled unnecessary exception pruning
     * Enabled aggressive exception aggregation
     */
    @Override
    public void endElement(String string2, String string3, String string4) throws SAXException {
        ElementHandler elementHandler = this.getElementStack().getDispatchHandler().getHandler(this.getElementStack().getPath());
        super.endElement(string2, string3, string4);
        if (super.activeHandlers() || this.xmlWriter == null) return;
        if (elementHandler == null) {
            this.xmlWriter.endElement(string2, string3, string4);
            return;
        }
        if (!(elementHandler instanceof SAXModifyElementHandler)) return;
        Element element = ((SAXModifyElementHandler)elementHandler).getModifiedElement();
        try {
            this.xmlWriter.write(element);
            return;
        }
        catch (IOException var6_6) {
            throw new SAXModifyException((Throwable)var6_6);
        }
    }

    @Override
    public void endEntity(String string2) throws SAXException {
        super.endEntity(string2);
        if (this.xmlWriter != null) {
            this.xmlWriter.endEntity(string2);
        }
    }

    @Override
    public void endPrefixMapping(String string2) throws SAXException {
        super.endPrefixMapping(string2);
        if (this.xmlWriter != null) {
            this.xmlWriter.endPrefixMapping(string2);
        }
    }

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

    public void ignorableWhitespace(char[] arrc, int n, int n2) throws SAXException {
        super.ignorableWhitespace(arrc, n, n2);
        if (!super.activeHandlers() && this.xmlWriter != null) {
            this.xmlWriter.ignorableWhitespace(arrc, n, n2);
        }
    }

    @Override
    public void notationDecl(String string2, String string3, String string4) throws SAXException {
        super.notationDecl(string2, string3, string4);
        if (this.xmlWriter != null) {
            this.xmlWriter.notationDecl(string2, string3, string4);
        }
    }

    @Override
    public void processingInstruction(String string2, String string3) throws SAXException {
        super.processingInstruction(string2, string3);
        if (!super.activeHandlers() && this.xmlWriter != null) {
            this.xmlWriter.processingInstruction(string2, string3);
        }
    }

    @Override
    public void setDocumentLocator(Locator locator) {
        super.setDocumentLocator(locator);
        if (this.xmlWriter != null) {
            this.xmlWriter.setDocumentLocator(locator);
        }
    }

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

    public void skippedEntity(String string2) throws SAXException {
        super.skippedEntity(string2);
        if (!super.activeHandlers() && this.xmlWriter != null) {
            this.xmlWriter.skippedEntity(string2);
        }
    }

    @Override
    public void startCDATA() throws SAXException {
        super.startCDATA();
        if (!this.activeHandlers() && this.xmlWriter != null) {
            this.xmlWriter.startCDATA();
        }
    }

    @Override
    public void startDTD(String string2, String string3, String string4) throws SAXException {
        super.startDTD(string2, string3, string4);
        if (this.xmlWriter != null) {
            this.xmlWriter.startDTD(string2, string3, string4);
        }
    }

    @Override
    public void startDocument() throws SAXException {
        super.startDocument();
        if (this.xmlWriter != null) {
            this.xmlWriter.startDocument();
        }
    }

    @Override
    public void startElement(String string2, String string3, String string4, Attributes attributes) throws SAXException {
        super.startElement(string2, string3, string4, attributes);
        if (!super.activeHandlers() && this.xmlWriter != null) {
            this.xmlWriter.startElement(string2, string3, string4, attributes);
        }
    }

    @Override
    public void startEntity(String string2) throws SAXException {
        super.startEntity(string2);
        if (this.xmlWriter != null) {
            this.xmlWriter.startEntity(string2);
        }
    }

    @Override
    public void startPrefixMapping(String string2, String string3) throws SAXException {
        super.startPrefixMapping(string2, string3);
        if (this.xmlWriter != null) {
            this.xmlWriter.startPrefixMapping(string2, string3);
        }
    }

    @Override
    public void unparsedEntityDecl(String string2, String string3, String string4, String string5) throws SAXException {
        super.unparsedEntityDecl(string2, string3, string4, string5);
        if (!super.activeHandlers() && this.xmlWriter != null) {
            this.xmlWriter.unparsedEntityDecl(string2, string3, string4, string5);
        }
    }
}

