/*
 * Decompiled with CFR 0_110.
 * 
 * Could not load the following classes:
 *  java.io.Reader
 *  java.io.StringReader
 *  java.lang.Object
 *  java.lang.String
 *  java.util.List
 *  java.util.Map
 *  java.util.StringTokenizer
 *  org.jaxen.VariableContext
 *  org.xml.sax.InputSource
 */
package org.dom4j;

import java.io.Reader;
import java.io.StringReader;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
import org.dom4j.Attribute;
import org.dom4j.Branch;
import org.dom4j.CDATA;
import org.dom4j.Comment;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentFactory;
import org.dom4j.Element;
import org.dom4j.Entity;
import org.dom4j.InvalidXPathException;
import org.dom4j.Namespace;
import org.dom4j.Node;
import org.dom4j.NodeFilter;
import org.dom4j.ProcessingInstruction;
import org.dom4j.QName;
import org.dom4j.Text;
import org.dom4j.XPath;
import org.dom4j.io.SAXReader;
import org.dom4j.rule.Pattern;
import org.jaxen.VariableContext;
import org.xml.sax.InputSource;

public final class DocumentHelper {
    private DocumentHelper() {
    }

    public static Attribute createAttribute(Element element, String string2, String string3) {
        return DocumentHelper.getDocumentFactory().createAttribute(element, string2, string3);
    }

    public static Attribute createAttribute(Element element, QName qName, String string2) {
        return DocumentHelper.getDocumentFactory().createAttribute(element, qName, string2);
    }

    public static CDATA createCDATA(String string2) {
        return DocumentFactory.getInstance().createCDATA(string2);
    }

    public static Comment createComment(String string2) {
        return DocumentFactory.getInstance().createComment(string2);
    }

    public static Document createDocument() {
        return DocumentHelper.getDocumentFactory().createDocument();
    }

    public static Document createDocument(Element element) {
        return DocumentHelper.getDocumentFactory().createDocument(element);
    }

    public static Element createElement(String string2) {
        return DocumentHelper.getDocumentFactory().createElement(string2);
    }

    public static Element createElement(QName qName) {
        return DocumentHelper.getDocumentFactory().createElement(qName);
    }

    public static Entity createEntity(String string2, String string3) {
        return DocumentFactory.getInstance().createEntity(string2, string3);
    }

    public static Namespace createNamespace(String string2, String string3) {
        return DocumentFactory.getInstance().createNamespace(string2, string3);
    }

    public static Pattern createPattern(String string2) {
        return DocumentHelper.getDocumentFactory().createPattern(string2);
    }

    public static ProcessingInstruction createProcessingInstruction(String string2, String string3) {
        return DocumentHelper.getDocumentFactory().createProcessingInstruction(string2, string3);
    }

    public static ProcessingInstruction createProcessingInstruction(String string2, Map map) {
        return DocumentHelper.getDocumentFactory().createProcessingInstruction(string2, map);
    }

    public static QName createQName(String string2) {
        return DocumentHelper.getDocumentFactory().createQName(string2);
    }

    public static QName createQName(String string2, Namespace namespace) {
        return DocumentHelper.getDocumentFactory().createQName(string2, namespace);
    }

    public static Text createText(String string2) {
        return DocumentFactory.getInstance().createText(string2);
    }

    public static XPath createXPath(String string2) throws InvalidXPathException {
        return DocumentHelper.getDocumentFactory().createXPath(string2);
    }

    public static XPath createXPath(String string2, VariableContext variableContext) throws InvalidXPathException {
        return DocumentHelper.getDocumentFactory().createXPath(string2, variableContext);
    }

    public static NodeFilter createXPathFilter(String string2) {
        return DocumentHelper.getDocumentFactory().createXPathFilter(string2);
    }

    private static DocumentFactory getDocumentFactory() {
        return DocumentFactory.getInstance();
    }

    /*
     * Enabled force condition propagation
     * Lifted jumps to return sites
     */
    private static String getEncoding(String string2) {
        String string3 = string2.trim();
        boolean bl = string3.startsWith("<?xml");
        String string4 = null;
        if (!bl) return string4;
        StringTokenizer stringTokenizer = new StringTokenizer(string3.substring(0, string3.indexOf("?>")), " =\"'");
        do {
            boolean bl2 = stringTokenizer.hasMoreTokens();
            string4 = null;
            if (!bl2) return string4;
        } while (!"encoding".equals((Object)stringTokenizer.nextToken()));
        boolean bl3 = stringTokenizer.hasMoreTokens();
        string4 = null;
        if (!bl3) return string4;
        return stringTokenizer.nextToken();
    }

    /*
     * Enabled aggressive block sorting
     */
    public static Element makeElement(Branch branch, String string2) {
        Element element;
        StringTokenizer stringTokenizer = new StringTokenizer(string2, "/");
        if (branch instanceof Document) {
            Document document = (Document)branch;
            element = document.getRootElement();
            String string3 = stringTokenizer.nextToken();
            if (element == null) {
                element = document.addElement(string3);
            }
        } else {
            element = (Element)branch;
        }
        Element element2 = null;
        while (stringTokenizer.hasMoreTokens()) {
            String string4 = stringTokenizer.nextToken();
            element2 = string4.indexOf(58) > 0 ? element.element(element.getQName(string4)) : element.element(string4);
            if (element2 == null) {
                element2 = element.addElement(string4);
            }
            element = element2;
        }
        return element2;
    }

    public static Document parseText(String string2) throws DocumentException {
        SAXReader sAXReader = new SAXReader();
        String string3 = DocumentHelper.getEncoding(string2);
        InputSource inputSource = new InputSource((Reader)new StringReader(string2));
        inputSource.setEncoding(string3);
        Document document = sAXReader.read(inputSource);
        if (document.getXMLEncoding() == null) {
            document.setXMLEncoding(string3);
        }
        return document;
    }

    public static List selectNodes(String string2, List list) {
        return DocumentHelper.createXPath(string2).selectNodes((Object)list);
    }

    public static List selectNodes(String string2, Node node) {
        return DocumentHelper.createXPath(string2).selectNodes(node);
    }

    public static void sort(List list, String string2) {
        DocumentHelper.createXPath(string2).sort(list);
    }

    public static void sort(List list, String string2, boolean bl) {
        DocumentHelper.createXPath(string2).sort(list, bl);
    }
}

