Java Code Examples for org.dom4j.Element.elementTextTrim()

The following are Jave code examples for showing how to use elementTextTrim() of the org.dom4j.Element class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: PackagePlugin   File: FileUtil.java   View Source Code Vote up 4 votes
/**
 * 获取配置
 *
 * @param name
 * @return
 * @throws Exception
 */
public static HttpConfig getConfig(String name) throws Exception {
    HttpConfig hc = CONFIG_MAP.get(name);
    if (hc == null) {
        SAXReader reader = new SAXReader();
        File xml = new File(HTTP_CONFIG_FILE);
        Document doc;
        Element root;
        if (xml.exists()) {
            try (FileInputStream in = new FileInputStream(xml); Reader read = new InputStreamReader(in, "UTF-8")) {
                doc = reader.read(read);
                root = doc.getRootElement();
                List<Element> els = root.selectNodes("/root/configs/config");
                for (Element el : els) {
                    String nameStr = el.attributeValue("name");
                    String encodeType = el.attributeValue("encodeType");
                    String charset = el.attributeValue("charset");
                    String requestType = el.attributeValue("requestType");
                    String sendXML = el.attributeValue("sendXML");
                    String packHead = el.attributeValue("packHead");
                    String lowercaseEncode = el.attributeValue("lowercaseEncode");
                    String url = el.elementTextTrim("url");
                    String header = el.elementTextTrim("header");
                    String parameter = el.elementTextTrim("parameter");
                    String encodeField = el.elementTextTrim("encodeField");
                    String encodeKey = el.elementTextTrim("encodeKey");
                    String contentType = el.elementTextTrim("contentType");

                    HttpConfig config = new HttpConfig(nameStr, url, charset, header, parameter, requestType, contentType);
                    config.setSendXML(Boolean.valueOf(sendXML));
                    config.setEncodeKey(encodeKey);
                    config.setEncodeType(encodeType);
                    config.setEncodeFieldName(encodeField);
                    config.setLowercaseEncode(Boolean.valueOf(lowercaseEncode));
                    config.setPackHead(Boolean.valueOf(packHead));
                    CONFIG_MAP.put(nameStr, config);
                    if (nameStr.equals(name)) {
                        hc = config;
                    }
                }
            }
        }
    }
    return hc;
}