XmlDocument.java 3.4 KB
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.airport.util.parse;

import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;

public class XmlDocument {
    private Document document = null;
    private SAXBuilder builder = null;
    private Element root = null;
    private String xmlFile;

    public XmlDocument(String xmlFileName) {
        this.xmlFile = xmlFileName;

        try {
            this.builder = new SAXBuilder();
            this.document = new Document();
            this.document = this.builder.build(this.xmlFile);
        } catch (JDOMException var3) {
            var3.printStackTrace();
        } catch (IOException var4) {
            var4.printStackTrace();
        }

    }

    public void destory() {
        this.document = null;
        this.root = null;
        this.builder = null;
    }

    public String getStringFromInnerText(String xmlNodePath) {
        String[] nodes = xmlNodePath.split("/");
        LinkedList<SubNode> listNode = new LinkedList();
        String value = "";

        try {
            for(int i = 1; i < nodes.length; ++i) {
                SubNode snode;
                if (i > 1) {
                    snode = (SubNode)listNode.getLast();
                    List<Element> eList = snode.getElement().getChildren(nodes[i]);
                    if (eList != null && eList.size() > 0) {
                        SubNode s1 = new SubNode((Element)eList.get(0));
                        listNode.add(s1);
                    }
                } else if (1 == i) {
                    this.root = this.document.getRootElement();
                    snode = new SubNode(this.root);
                    listNode.add(snode);
                }
            }

            SubNode n = (SubNode)listNode.getLast();
            value = n.getElement().getText();
            n = null;
        } catch (Exception var12) {
            var12.printStackTrace();
        } finally {
            listNode.clear();
        }

        return value;
    }

    public String getStringFromXmlNodeAttribute(String xmlNodePath, String attributeName, String defaultValue) {
        String[] nodes = xmlNodePath.split("/");
        LinkedList<SubNode> listNode = new LinkedList();
        String value = "";

        try {
            for(int i = 1; i < nodes.length; ++i) {
                SubNode snode;
                if (i > 1) {
                    snode = (SubNode)listNode.getLast();
                    List<Element> eList = snode.getElement().getChildren(nodes[i]);
                    if (eList != null && eList.size() > 0) {
                        SubNode s1 = new SubNode((Element)eList.get(0));
                        listNode.add(s1);
                    }
                } else if (1 == i) {
                    this.root = this.document.getRootElement();
                    snode = new SubNode(this.root);
                    listNode.add(snode);
                }
            }

            SubNode n = (SubNode)listNode.getLast();
            value = n.getElement().getAttributeValue(attributeName, defaultValue);
            n = null;
        } catch (Exception var14) {
            var14.printStackTrace();
        } finally {
            listNode.clear();
        }

        return value;
    }
}