/*
 * Decompiled with CFR 0_110.
 * 
 * Could not load the following classes:
 *  java.io.PrintStream
 *  java.lang.Object
 *  java.lang.String
 *  java.lang.StringBuffer
 *  java.lang.System
 *  java.util.List
 *  org.w3c.dom.Attr
 *  org.w3c.dom.DOMException
 *  org.w3c.dom.Document
 *  org.w3c.dom.DocumentType
 *  org.w3c.dom.Element
 *  org.w3c.dom.NamedNodeMap
 *  org.w3c.dom.Node
 *  org.w3c.dom.NodeList
 *  org.w3c.dom.Text
 */
package org.dom4j.dom;

import java.io.PrintStream;
import java.util.List;
import org.dom4j.Branch;
import org.dom4j.CharacterData;
import org.dom4j.Document;
import org.dom4j.DocumentType;
import org.dom4j.Element;
import org.dom4j.Node;
import org.dom4j.dom.DOMNodeHelper$1;
import org.w3c.dom.Attr;
import org.w3c.dom.DOMException;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.NodeList;
import org.w3c.dom.Text;

public class DOMNodeHelper {
    public static final NodeList EMPTY_NODE_LIST = new EmptyNodeList();

    protected DOMNodeHelper() {
    }

    public static org.w3c.dom.Node appendChild(Node node, org.w3c.dom.Node node2) throws DOMException {
        if (node instanceof Branch) {
            Branch branch = (Branch)node;
            org.w3c.dom.Node node3 = node2.getParentNode();
            if (node3 != null) {
                node3.removeChild(node2);
            }
            branch.add((Node)node2);
            return node2;
        }
        throw new DOMException(3, new StringBuffer().append("Children not allowed for this node: ").append((Object)node).toString());
    }

    public static void appendData(CharacterData characterData, String string2) throws DOMException {
        if (characterData.isReadOnly()) {
            throw new DOMException(7, new StringBuffer().append("CharacterData node is read only: ").append((Object)characterData).toString());
        }
        String string3 = characterData.getText();
        if (string3 == null) {
            characterData.setText(string3);
            return;
        }
        characterData.setText(new StringBuffer().append(string3).append(string2).toString());
    }

    public static void appendElementsByTagName(List list, Branch branch, String string2) {
        boolean bl = "*".equals((Object)string2);
        int n = branch.nodeCount();
        for (int i = 0; i < n; ++i) {
            Node node = branch.node(i);
            if (!(node instanceof Element)) continue;
            Element element = (Element)node;
            if (bl || string2.equals((Object)element.getName())) {
                list.add((Object)element);
            }
            DOMNodeHelper.appendElementsByTagName(list, element, string2);
        }
    }

    public static void appendElementsByTagNameNS(List list, Branch branch, String string2, String string3) {
        boolean bl = "*".equals((Object)string2);
        boolean bl2 = "*".equals((Object)string3);
        int n = branch.nodeCount();
        for (int i = 0; i < n; ++i) {
            Node node = branch.node(i);
            if (!(node instanceof Element)) continue;
            Element element = (Element)node;
            if ((bl || (string2 == null || string2.length() == 0) && (element.getNamespaceURI() == null || element.getNamespaceURI().length() == 0) || string2 != null && string2.equals((Object)element.getNamespaceURI())) && (bl2 || string3.equals((Object)element.getName()))) {
                list.add((Object)element);
            }
            DOMNodeHelper.appendElementsByTagNameNS(list, element, string2, string3);
        }
    }

    public static Attr asDOMAttr(Node node) {
        if (node == null) {
            return null;
        }
        if (node instanceof Attr) {
            return (Attr)node;
        }
        DOMNodeHelper.notSupported();
        return null;
    }

    public static org.w3c.dom.Document asDOMDocument(Document document) {
        if (document == null) {
            return null;
        }
        if (document instanceof org.w3c.dom.Document) {
            return (org.w3c.dom.Document)document;
        }
        DOMNodeHelper.notSupported();
        return null;
    }

    public static org.w3c.dom.DocumentType asDOMDocumentType(DocumentType documentType) {
        if (documentType == null) {
            return null;
        }
        if (documentType instanceof org.w3c.dom.DocumentType) {
            return (org.w3c.dom.DocumentType)documentType;
        }
        DOMNodeHelper.notSupported();
        return null;
    }

    public static org.w3c.dom.Element asDOMElement(Node node) {
        if (node == null) {
            return null;
        }
        if (node instanceof org.w3c.dom.Element) {
            return (org.w3c.dom.Element)node;
        }
        DOMNodeHelper.notSupported();
        return null;
    }

    public static org.w3c.dom.Node asDOMNode(Node node) {
        if (node == null) {
            return null;
        }
        if (node instanceof org.w3c.dom.Node) {
            return (org.w3c.dom.Node)node;
        }
        System.out.println(new StringBuffer().append("Cannot convert: ").append((Object)node).append(" into a W3C DOM Node").toString());
        DOMNodeHelper.notSupported();
        return null;
    }

    public static Text asDOMText(CharacterData characterData) {
        if (characterData == null) {
            return null;
        }
        if (characterData instanceof Text) {
            return (Text)characterData;
        }
        DOMNodeHelper.notSupported();
        return null;
    }

    public static org.w3c.dom.Node cloneNode(Node node, boolean bl) {
        return DOMNodeHelper.asDOMNode((Node)node.clone());
    }

    public static NodeList createNodeList(List list) {
        return new DOMNodeHelper$1(list);
    }

    public static void deleteData(CharacterData characterData, int n, int n2) throws DOMException {
        if (characterData.isReadOnly()) {
            throw new DOMException(7, new StringBuffer().append("CharacterData node is read only: ").append((Object)characterData).toString());
        }
        if (n2 < 0) {
            throw new DOMException(1, new StringBuffer().append("Illegal value for count: ").append(n2).toString());
        }
        String string2 = characterData.getText();
        if (string2 != null) {
            int n3 = string2.length();
            if (n < 0 || n >= n3) {
                throw new DOMException(1, new StringBuffer().append("No text at offset: ").append(n).toString());
            }
            StringBuffer stringBuffer = new StringBuffer(string2);
            stringBuffer.delete(n, n + n2);
            characterData.setText(stringBuffer.toString());
        }
    }

    public static NamedNodeMap getAttributes(Node node) {
        return null;
    }

    public static NodeList getChildNodes(Node node) {
        return EMPTY_NODE_LIST;
    }

    public static String getData(CharacterData characterData) throws DOMException {
        return characterData.getText();
    }

    public static org.w3c.dom.Node getFirstChild(Node node) {
        return null;
    }

    public static org.w3c.dom.Node getLastChild(Node node) {
        return null;
    }

    public static int getLength(CharacterData characterData) {
        String string2 = characterData.getText();
        if (string2 != null) {
            return string2.length();
        }
        return 0;
    }

    public static String getLocalName(Node node) {
        return null;
    }

    public static String getNamespaceURI(Node node) {
        return null;
    }

    public static org.w3c.dom.Node getNextSibling(Node node) {
        int n;
        int n2;
        Element element = node.getParent();
        if (element != null && (n2 = element.indexOf(node)) >= 0 && (n = n2 + 1) < element.nodeCount()) {
            return DOMNodeHelper.asDOMNode(element.node(n));
        }
        return null;
    }

    public static String getNodeValue(Node node) throws DOMException {
        return node.getText();
    }

    public static org.w3c.dom.Document getOwnerDocument(Node node) {
        return DOMNodeHelper.asDOMDocument(node.getDocument());
    }

    public static org.w3c.dom.Node getParentNode(Node node) {
        return DOMNodeHelper.asDOMNode(node.getParent());
    }

    public static String getPrefix(Node node) {
        return null;
    }

    public static org.w3c.dom.Node getPreviousSibling(Node node) {
        int n;
        Element element = node.getParent();
        if (element != null && (n = element.indexOf(node)) > 0) {
            return DOMNodeHelper.asDOMNode(element.node(n - 1));
        }
        return null;
    }

    public static boolean hasAttributes(Node node) {
        boolean bl = false;
        if (node != null) {
            boolean bl2 = node instanceof Element;
            bl = false;
            if (bl2) {
                int n = ((Element)node).attributeCount();
                bl = false;
                if (n > 0) {
                    bl = true;
                }
            }
        }
        return bl;
    }

    public static boolean hasChildNodes(Node node) {
        return false;
    }

    public static org.w3c.dom.Node insertBefore(Node node, org.w3c.dom.Node node2, org.w3c.dom.Node node3) throws DOMException {
        if (node instanceof Branch) {
            Branch branch = (Branch)node;
            List list = branch.content();
            int n = list.indexOf((Object)node3);
            if (n < 0) {
                branch.add((Node)node2);
                return node2;
            }
            list.add(n, (Object)node2);
            return node2;
        }
        throw new DOMException(3, new StringBuffer().append("Children not allowed for this node: ").append((Object)node).toString());
    }

    public static void insertData(CharacterData characterData, int n, String string2) throws DOMException {
        if (characterData.isReadOnly()) {
            throw new DOMException(7, new StringBuffer().append("CharacterData node is read only: ").append((Object)characterData).toString());
        }
        String string3 = characterData.getText();
        if (string3 == null) {
            characterData.setText(string2);
            return;
        }
        int n2 = string3.length();
        if (n < 0 || n > n2) {
            throw new DOMException(1, new StringBuffer().append("No text at offset: ").append(n).toString());
        }
        StringBuffer stringBuffer = new StringBuffer(string3);
        stringBuffer.insert(n, string2);
        characterData.setText(stringBuffer.toString());
    }

    public static boolean isSupported(Node node, String string2, String string3) {
        return false;
    }

    public static void normalize(Node node) {
        DOMNodeHelper.notSupported();
    }

    public static void notSupported() {
        throw new DOMException(9, "Not supported yet");
    }

    public static org.w3c.dom.Node removeChild(Node node, org.w3c.dom.Node node2) throws DOMException {
        if (node instanceof Branch) {
            ((Branch)node).remove((Node)node2);
            return node2;
        }
        throw new DOMException(3, new StringBuffer().append("Children not allowed for this node: ").append((Object)node).toString());
    }

    public static org.w3c.dom.Node replaceChild(Node node, org.w3c.dom.Node node2, org.w3c.dom.Node node3) throws DOMException {
        if (node instanceof Branch) {
            List list = ((Branch)node).content();
            int n = list.indexOf((Object)node3);
            if (n < 0) {
                throw new DOMException(8, new StringBuffer().append("Tried to replace a non existing child for node: ").append((Object)node).toString());
            }
            list.set(n, (Object)node2);
            return node3;
        }
        throw new DOMException(3, new StringBuffer().append("Children not allowed for this node: ").append((Object)node).toString());
    }

    public static void replaceData(CharacterData characterData, int n, int n2, String string2) throws DOMException {
        if (characterData.isReadOnly()) {
            throw new DOMException(7, new StringBuffer().append("CharacterData node is read only: ").append((Object)characterData).toString());
        }
        if (n2 < 0) {
            throw new DOMException(1, new StringBuffer().append("Illegal value for count: ").append(n2).toString());
        }
        String string3 = characterData.getText();
        if (string3 != null) {
            int n3 = string3.length();
            if (n < 0 || n >= n3) {
                throw new DOMException(1, new StringBuffer().append("No text at offset: ").append(n).toString());
            }
            StringBuffer stringBuffer = new StringBuffer(string3);
            stringBuffer.replace(n, n + n2, string2);
            characterData.setText(stringBuffer.toString());
        }
    }

    public static void setData(CharacterData characterData, String string2) throws DOMException {
        characterData.setText(string2);
    }

    public static void setNodeValue(Node node, String string2) throws DOMException {
        node.setText(string2);
    }

    public static void setPrefix(Node node, String string2) throws DOMException {
        DOMNodeHelper.notSupported();
    }

    /*
     * Enabled aggressive block sorting
     */
    public static String substringData(CharacterData characterData, int n, int n2) throws DOMException {
        if (n2 < 0) {
            throw new DOMException(1, new StringBuffer().append("Illegal value for count: ").append(n2).toString());
        }
        String string2 = characterData.getText();
        int n3 = string2 != null ? string2.length() : 0;
        if (n < 0 || n >= n3) {
            throw new DOMException(1, new StringBuffer().append("No text at offset: ").append(n).toString());
        }
        if (n + n2 > n3) {
            return string2.substring(n);
        }
        return string2.substring(n, n + n2);
    }

    public static boolean supports(Node node, String string2, String string3) {
        return false;
    }

    public static class EmptyNodeList
    implements NodeList {
        public int getLength() {
            return 0;
        }

        public org.w3c.dom.Node item(int n) {
            return null;
        }
    }

}

