Example usage for org.dom4j.io SAXReader read

List of usage examples for org.dom4j.io SAXReader read

Introduction

In this page you can find the example usage for org.dom4j.io SAXReader read.

Prototype

public Document read(InputSource in) throws DocumentException 

Source Link

Document

Reads a Document from the given InputSource using SAX

Usage

From source file:com.beetle.framework.business.service.server.ServiceConfig.java

License:Apache License

private static void loadFromConfig(InputStream xmlFileInputStream) {
    SAXReader reader = new SAXReader();
    Document doc = null;//from   w  w w.  j a  v a2 s .c  o  m
    try {
        doc = reader.read(xmlFileInputStream);
        gendoc(doc);
    } catch (Exception de) {
        throw new AppRuntimeException(de);
    } finally {
        if (doc != null) {
            doc.clearContent();
            doc = null;
        }
        reader = null;
    }
}

From source file:com.beetle.framework.business.service.server.ServiceConfig.java

License:Apache License

private static void loadFromConfig(File f) {
    SAXReader reader = new SAXReader();
    Document doc = null;//from   www . j  av a2s. c o m
    try {
        doc = reader.read(f);
        gendoc(doc);
    } catch (Exception de) {
        throw new AppRuntimeException(de);
    } finally {
        if (doc != null) {
            doc.clearContent();
            doc = null;
        }
        reader = null;
    }
}

From source file:com.beetle.framework.resource.dic.ReleBinder.java

License:Apache License

/**
 * ?/*ww w .j  a v  a  2  s  .co  m*/
 * 
 * @param xmlFileInputStream
 *            --??
 */
public void bindFromConfig(InputStream xmlFileInputStream) {
    SAXReader reader = new SAXReader();
    Document doc = null;
    try {
        doc = reader.read(xmlFileInputStream);
        gendoc(doc);
        // bindProperties();
    } catch (Exception de) {
        throw new AppRuntimeException(de);
    } finally {
        if (doc != null) {
            doc.clearContent();
            doc = null;
        }
        reader = null;
    }
}

From source file:com.beetle.framework.resource.dic.ReleBinder.java

License:Apache License

/**
 * ? XML?<br>/*from  ww  w .  ja v  a  2s. com*/
 * 
 * <pre>
 *  <binder>
 *     <!-- 
 * interface-?????
 * implement-??????interface
 * singleton-??implement?true
 *    -->
 *    <item interface=
"com.beetle.framework.util.pattern.di.IService" implement=
"com.beetle.framework.util.pattern.di.IServiceImp" singleton="true"/>
 * </binder>
 * </pre>
 * 
 * <br>
 * 
 * @param f
 *            --?
 */
public void bindFromConfig(File f) {
    SAXReader reader = new SAXReader();
    Document doc = null;
    try {
        doc = reader.read(f);
        gendoc(doc);
        // bindProperties();
    } catch (Exception de) {
        throw new AppRuntimeException(de);
    } finally {
        if (doc != null) {
            doc.clearContent();
            doc = null;
        }
        reader = null;
    }
}

From source file:com.beetle.framework.util.file.XMLReader.java

License:Apache License

/**
 * ?xmldocument/*from w ww  .j  a v a2 s  .  co  m*/
 * ??
 * @param filename
 * @return
 * @throws Exception
 */
public final static Document getXmlDoc(String filename) throws Exception {
    SAXReader reader = new SAXReader();
    File f = new File(filename);
    Document doc;
    if (f.exists()) {
        doc = reader.read(f);
    } else {
        InputStream is = ResourceLoader.getResAsStream(filename);
        doc = reader.read(is);
    }
    return doc;
}

From source file:com.beetle.framework.util.file.XMLReader.java

License:Apache License

/**
 * /*from  w  w w . j a v  a  2  s. c  om*/
 * @param xmlFileInputStream
 * @param itemPath
 * @param ElementName
 * @param keyName
 * @param valueName
 * @return
 */
public static Map<String, String> getProperties(InputStream xmlFileInputStream, String itemPath,
        String ElementName, String keyName, String valueName) {
    Map<String, String> map = new HashMap<String, String>();
    if (xmlFileInputStream == null) {
        // System.out.println("WARN:the resource do not exist");
        return map;
    }
    SAXReader reader = new SAXReader();
    Document doc = null;
    try {
        doc = reader.read(xmlFileInputStream);
        // Document doc = reader.read(new File(xmlFileName));
        Node node = doc.selectSingleNode(convertPath(itemPath));
        if (node != null) {
            Iterator<?> it = node.selectNodes(ElementName).iterator();
            while (it.hasNext()) {
                Element e = (Element) it.next();
                map.put(e.valueOf("@" + keyName), e.valueOf("@" + valueName));
            }
        } else {
            // throw new com.beetle.framework.AppRuntimeException(
            // "?????!");
            // System.out.println("WARN:Can't find the paht[" + itemPath
            // + "],please check it!");
            // throw new RuntimeException("{" + itemPath +
            // "}does not exist");
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (doc != null) {
            doc.clearContent();
        }
        reader = null;
    }
    // xmlFileInputStream.close();
    return map;
}

From source file:com.beetle.framework.util.file.XMLReader.java

License:Apache License

public static Map<String, String> getProperties(String xmlFileName, String itemPath, String ElementName,
        String keyName, String valueName) {
    Map<String, String> map = new HashMap<String, String>();
    SAXReader reader = new SAXReader();
    Document doc = null;//from w ww.  ja v a2  s .c om
    try {
        //
        // InputStream
        // in=ClassLoader.getSystemResourceAsStream(xmlFileName);
        // Document doc=reader.read(in);
        //
        doc = reader.read(new File(xmlFileName));
        Node node = doc.selectSingleNode(convertPath(itemPath));
        if (node != null) {
            Iterator<?> it = node.selectNodes(ElementName).iterator();
            while (it.hasNext()) {
                Element e = (Element) it.next();
                map.put(e.valueOf("@" + keyName), e.valueOf("@" + valueName));
            }
        } else {
            // throw new com.beetle.framework.AppRuntimeException(
            // "?????!");
            System.out.println("WARN:Can't find the paht[" + itemPath + "],please check it!");
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (doc != null) {
            doc.clearContent();
        }
        reader = null;
    }
    return map;
}

From source file:com.beetle.framework.util.file.XMLReader.java

License:Apache License

public static String getTagContent(String xmlFileName, String TagPath) {
    String a = "";
    SAXReader reader = new SAXReader();
    Document doc = null;/*from  ww w.j av a 2  s .c om*/
    try {
        doc = reader.read(new File(xmlFileName));
        Node node = doc.selectSingleNode(convertPath(TagPath));
        if (node != null) {
            a = node.getText();
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (doc != null) {
            doc.clearContent();
        }
        reader = null;
    }
    return a;
}

From source file:com.beetle.framework.util.file.XMLReader.java

License:Apache License

/**
 * ???????//from ww  w  . ja v  a  2 s  .  c  o  m
 * 
 * 
 * @param xmlFileInputStream
 * @param TagPath
 * @return
 */
public static String getTagContent(InputStream xmlFileInputStream, String TagPath) {
    String a = "";
    if (xmlFileInputStream == null) {
        // System.out.println("WARN:the resource do not exist");
        return a;
    }
    SAXReader reader = new SAXReader();
    Document doc = null;
    try {
        doc = reader.read(xmlFileInputStream);
        Node node = doc.selectSingleNode(convertPath(TagPath));
        if (node != null) {
            a = node.getText();
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (doc != null) {
            doc.clearContent();
        }
        reader = null;
    }
    return a;
}

From source file:com.beetle.framework.util.file.XMLReader.java

License:Apache License

public static void setTagContent(String xmlFileName, String TagPath, String value) {
    synchronized (writeLock) {
        SAXReader reader = new SAXReader();
        XMLWriter writer = null;//from  ww w. j  a v a 2s .c  o m
        try {
            Document doc = reader.read(new File(xmlFileName));
            Node node = doc.selectSingleNode(convertPath(TagPath));
            if (node != null) {
                node.setText(value);
            }
            writer = new XMLWriter(new FileWriter(xmlFileName));
            writer.write(doc);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            reader = null;
            if (writer != null) {
                try {
                    writer.close();
                } catch (IOException ex) {
                    ex.printStackTrace();
                }
            }
        }
    }
}