/*
 * Decompiled with CFR 0_110.
 * 
 * Could not load the following classes:
 *  java.lang.Exception
 *  java.lang.Object
 *  java.lang.String
 *  java.util.Iterator
 *  java.util.List
 *  org.jaxen.XPath
 */
package org.dom4j.rule;

import java.util.Iterator;
import java.util.List;
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.Node;
import org.dom4j.XPath;
import org.dom4j.rule.Action;
import org.dom4j.rule.Mode;
import org.dom4j.rule.Rule;
import org.dom4j.rule.RuleManager;

public class Stylesheet {
    private String modeName;
    private RuleManager ruleManager = new RuleManager();

    public void addRule(Rule rule) {
        this.ruleManager.addRule(rule);
    }

    public void applyTemplates(Object object) throws Exception {
        this.applyTemplates(object, this.modeName);
    }

    /*
     * Enabled aggressive block sorting
     */
    public void applyTemplates(Object object, String string2) throws Exception {
        Mode mode = this.ruleManager.getMode(string2);
        if (object instanceof Element) {
            Element element = (Element)object;
            int n = element.nodeCount();
            for (int i = 0; i < n; ++i) {
                mode.fireRule(element.node(i));
            }
            return;
        }
        if (object instanceof Document) {
            Document document = (Document)object;
            int n = document.nodeCount();
            for (int i = 0; i < n; ++i) {
                mode.fireRule(document.node(i));
            }
            return;
        }
        if (!(object instanceof List)) return;
        List list = (List)object;
        int n = list.size();
        for (int i = 0; i < n; ++i) {
            Object object2 = list.get(i);
            if (object2 instanceof Element) {
                this.applyTemplates((Object)((Element)object2), string2);
                continue;
            }
            if (!(object2 instanceof Document)) continue;
            this.applyTemplates((Object)((Document)object2), string2);
        }
    }

    public void applyTemplates(Object object, XPath xPath) throws Exception {
        this.applyTemplates(object, xPath, this.modeName);
    }

    public void applyTemplates(Object object, XPath xPath, String string2) throws Exception {
        Mode mode = this.ruleManager.getMode(string2);
        Iterator iterator = xPath.selectNodes(object).iterator();
        while (iterator.hasNext()) {
            mode.fireRule((Node)iterator.next());
        }
    }

    public void applyTemplates(Object object, org.jaxen.XPath xPath) throws Exception {
        this.applyTemplates(object, xPath, this.modeName);
    }

    public void applyTemplates(Object object, org.jaxen.XPath xPath, String string2) throws Exception {
        Mode mode = this.ruleManager.getMode(string2);
        Iterator iterator = xPath.selectNodes(object).iterator();
        while (iterator.hasNext()) {
            mode.fireRule((Node)iterator.next());
        }
    }

    public void clear() {
        this.ruleManager.clear();
    }

    public String getModeName() {
        return this.modeName;
    }

    public Action getValueOfAction() {
        return this.ruleManager.getValueOfAction();
    }

    public void removeRule(Rule rule) {
        this.ruleManager.removeRule(rule);
    }

    public void run(Object object) throws Exception {
        this.run(object, this.modeName);
    }

    /*
     * Enabled aggressive block sorting
     */
    public void run(Object object, String string2) throws Exception {
        if (object instanceof Node) {
            this.run((Node)object, string2);
            return;
        } else {
            if (!(object instanceof List)) return;
            {
                this.run((List)object, string2);
                return;
            }
        }
    }

    public void run(List list) throws Exception {
        this.run(list, this.modeName);
    }

    public void run(List list, String string2) throws Exception {
        int n = list.size();
        for (int i = 0; i < n; ++i) {
            Object object = list.get(i);
            if (!(object instanceof Node)) continue;
            this.run((Node)object, string2);
        }
    }

    public void run(Node node) throws Exception {
        this.run(node, this.modeName);
    }

    public void run(Node node, String string2) throws Exception {
        this.ruleManager.getMode(string2).fireRule(node);
    }

    public void setModeName(String string2) {
        this.modeName = string2;
    }

    public void setValueOfAction(Action action) {
        this.ruleManager.setValueOfAction(action);
    }
}

