Example usage for org.dom4j Element getText

List of usage examples for org.dom4j Element getText

Introduction

In this page you can find the example usage for org.dom4j Element getText.

Prototype

String getText();

Source Link

Document

Returns the text value of this element without recursing through child elements.

Usage

From source file:com.partycommittee.service.PcLicenseService.java

public PcLicenseVo getLicense() throws UnsupportedEncodingException {

    SAXReader saxReader = new SAXReader();
    Document document = null;//from  w ww .j  a  v a  2  s. c  o  m
    File file = new File(PcLicenseService.class.getClassLoader().getResource("/").getPath() + "license.xml");
    String license_proc;
    String license_tips;
    try {
        document = saxReader.read(file);
        Element root = document.getRootElement();

        Element license_element = root.element("license");

        license_proc = license_element.getText();

        Element tips_element = root.element("tips");

        license_tips = tips_element.getText();

    } catch (DocumentException e) {
        e.printStackTrace();
        return null;
    }

    Des des = new Des();

    String xml = des.DecryPwdStr(license_proc, "hrpweb30");// String 

    if (xml.indexOf("root") <= 0) {
        xml = "<root>" + xml + "</root>";
    }

    PcLicenseVo licensevo = setLicenseVo(xml, license_tips);

    return licensevo;
}

From source file:com.partycommittee.service.PcLicenseService.java

private PcLicenseVo setLicenseVo(String xml, String tips) {

    if (xml == null || xml.equals(""))
        return null;

    PcLicenseVo licensevo = new PcLicenseVo();

    SAXReader saxReader = new SAXReader();
    Document document = null;//from   w w w . j  a  v  a2 s  .  c om
    try {
        document = saxReader.read(new ByteArrayInputStream(xml.getBytes()));

        Element root = document.getRootElement();

        Element productno_element = root.element("productno");

        licensevo.setProductno(productno_element.getText());

        Element locknodw_element = root.element("locknodw");

        licensevo.setLocknodw(Integer.parseInt(locknodw_element.getText()));

        Element locknozb_element = root.element("locknozb");

        licensevo.setLocknozb(Integer.parseInt(locknozb_element.getText()));

        Element firstdate_element = root.element("firstdate");

        licensevo.setFirstdate(firstdate_element.getText());

        Element leftdays_element = root.element("leftdays");

        licensevo.setLeftdays(Integer.parseInt(leftdays_element.getText()));

        licensevo.setTips(tips);
    } catch (DocumentException e) {
        e.printStackTrace();
        return null;
    }

    return licensevo;

}

From source file:com.poka.util.XmlSax.java

public String getQuans(String mon, String kun) {
    Document doc = load(bankFile, false);
    Element rootElm = doc.getRootElement();
    Element root1Elm = rootElm.element("quans");
    if (root1Elm == null) {
        root1Elm = rootElm.addElement("quans");
        root1Elm.addElement("A100A10").setText("5A");
        root1Elm.addElement("A50A10").setText("5B");
        root1Elm.addElement("A20A10").setText("5C");
        root1Elm.addElement("A10A10").setText("5D");
        root1Elm.addElement("A5A10").setText("5E");
        root1Elm.addElement("A100A5").setText("9A");
        root1Elm.addElement("A50A5").setText("9B");
        root1Elm.addElement("A20A5").setText("9C");
        root1Elm.addElement("A10A5").setText("9D");
        root1Elm.addElement("A5A5").setText("9E");
        writeToXml(doc, bankFile);//from   w  w  w  .  j  av  a2s  .  c o  m
    }
    String tem;
    Element node = root1Elm.element("A" + mon.trim() + "A" + kun.trim());
    if (node == null) {
        tem = null;
    } else {
        tem = node.getText();
    }
    return tem;
}

From source file:com.poka.util.XmlSax.java

public String getFlowMoney(String type) {
    Document doc = load(bankFile, false);
    Element rootElm = doc.getRootElement();
    Element root1Elm = rootElm.element("folwMoney");
    if (root1Elm == null) {
        root1Elm = rootElm.addElement("folwMoney");
        root1Elm.addElement(flowMoney).setText("1|2");
        root1Elm.addElement(damagedMoney).setText("3");
        writeToXml(doc, bankFile);//from   www  .j  ava 2 s .  c o  m
    }
    String tem;
    Element node = root1Elm.element(type);
    if (node == null) {
        tem = null;
    } else {
        tem = node.getText();
    }
    return tem;
}

From source file:com.poka.util.XmlSax.java

public String getGRMech(String type) {
    Document doc = load(bankFile, false);
    Element rootElm = doc.getRootElement();
    Element root1Elm = rootElm.element("grmachine");
    if (root1Elm == null) {
        root1Elm = rootElm.addElement("grmachine");
        root1Elm.addElement(machineA).setText("1");
        root1Elm.addElement(machineB).setText("2");
        writeToXml(doc, bankFile);/*from   ww  w.  java2  s . com*/
    }
    String tem;
    Element node = root1Elm.element(type);
    if (node == null) {
        tem = null;
    } else {
        tem = node.getText();
    }
    return tem;
}

From source file:com.poka.util.XmlSax.java

public int getLastQF() {
    Document doc = load(bankFile, false);
    Element rootElm = doc.getRootElement();
    Element root1Elm = rootElm.element("QFJ");
    if (root1Elm == null) {
        return 0;
    }/*w  ww .  jav a2 s  .  c  om*/
    Element node = root1Elm.element("laftQF");
    if (node == null) {
        return 0;
    }
    return Integer.parseInt(node.getText().trim());
}

From source file:com.poka.util.XmlSax.java

public String readRegist() {
    Document doc = load(regis, false);
    Element rootElm = doc.getRootElement();
    Element root1Elm = rootElm.element("regist");
    if (root1Elm == null) {
        return "";
    } else {/*from w w w  . j av a  2 s.c  o  m*/
        return root1Elm.getText();
    }
}

From source file:com.poka.util.XmlSax.java

public String getDiaoChaoLogin() {
    Document doc = load(bankFile, false);
    Element rootElm = doc.getRootElement();
    Element root1Elm = rootElm.element("login");
    String res = "";
    if (root1Elm == null) {
        root1Elm = rootElm.addElement("login");
        root1Elm.setText("0");
        res = "0";
        writeToXml(doc, bankFile);//from  w ww. j  a  v a2 s . co  m
    } else {
        res = root1Elm.getText().trim();
    }
    return res;
}

From source file:com.poka.util.XmlSax.java

/**
 * ?sqlserver??/*  ww  w .  j a  v  a2  s  .co m*/
 *
 * @return
 */
public void getSqlServerXmlVal() {
    Document doc = load(sqlserverFile, true);
    Element rootElm = doc.getRootElement();
    Element root1Elm = rootElm.element("session-factory");
    List nodes = root1Elm.elements("property");
    for (Iterator it = nodes.iterator(); it.hasNext();) {
        Element elm = (Element) it.next();
        String name = elm.attributeValue("name");
        if (name.equals("connection.url")) {
            String url = elm.getText();
            int begingan = url.indexOf("//");
            ip = url.substring(begingan + 2, url.lastIndexOf(":"));
            port = url.substring(url.lastIndexOf(":") + 1, url.lastIndexOf(";"));
            names = url.substring(url.lastIndexOf("=") + 1);

        }
        if (name.equals("connection.username")) {
            user = elm.getText();
        }

        if (name.equals("connection.password")) {
            pwd = elm.getText();
        }
    }
}

From source file:com.poka.util.XmlSax.java

/**
 * ???dddddd/*from w  ww.  j  a  v a2  s. c  o m*/
 *
 * @return
 */
public void getHibernateXmlVal() {
    Document doc = load(f, true);
    Element rootElm = doc.getRootElement();
    Element root1Elm = rootElm.element("session-factory");
    List nodes = root1Elm.elements("property");
    for (Iterator it = nodes.iterator(); it.hasNext();) {
        Element elm = (Element) it.next();
        String name = elm.attributeValue("name");
        if (name.equals("connection.url")) {
            String url = elm.getText();
            if (this.dbTyep.equals("mysql")) {
                if (url.contains("mysql")) {
                    int begingan = url.indexOf("//");
                    ip = url.substring(begingan + 2, url.lastIndexOf(":"));
                    port = url.substring(url.lastIndexOf(":") + 1, url.lastIndexOf("/"));
                    names = url.substring(url.lastIndexOf("/") + 1, url.lastIndexOf("?"));
                } else {
                    ip = "";
                    port = "";
                    names = "";
                }
            } else {
                if (url.contains("sqlserver")) {
                    int begingan = url.indexOf("//");
                    ip = url.substring(begingan + 2, url.lastIndexOf(":"));
                    port = url.substring(url.lastIndexOf(":") + 1, url.lastIndexOf(";"));
                    names = url.substring(url.lastIndexOf("=") + 1);
                } else {
                    ip = "";
                    port = "";
                    names = "";
                }
            }
        }
        if (name.equals("connection.username")) {
            user = elm.getText();
        }

        if (name.equals("connection.password")) {
            pwd = elm.getText();
        }
    }
}