Example usage for org.dom4j.io SAXReader getDocumentFactory

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

Introduction

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

Prototype

public DocumentFactory getDocumentFactory() 

Source Link

Document

DOCUMENT ME!

Usage

From source file:com.wabacus.config.xml.XmlAssistant.java

License:Open Source License

public Document loadXmlDocument(File file) {
    BufferedInputStream bis = null;
    try {//from w w  w . ja va2s  . co m
        SAXReader saxReader = new SAXReader();
        Map map = new HashMap();
        map.put(Consts.XML_NAMESPACE_KEY, Consts.XML_NAMESPACE_VALUE);
        saxReader.getDocumentFactory().setXPathNamespaceURIs(map);
        bis = new BufferedInputStream(new FileInputStream(file));
        //            ConfigLoadAssistant.getInstance().addOpenedInputFileObj(inputstreamKey,bis);//??
        Document doc = saxReader.read(bis);
        return doc;
    } catch (FileNotFoundException fnfe) {
        throw new WabacusConfigLoadingException(
                "?" + file.getName() + "?", fnfe);
    } catch (DocumentException de) {
        throw new WabacusConfigLoadingException(
                "?" + file.getName() + "??XML?", de);
    } finally {
        try {
            if (bis != null)
                bis.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:com.wabacus.config.xml.XmlAssistant.java

License:Open Source License

public Document loadXmlDocument(InputStream in) throws DocumentException {
    SAXReader saxReader = new SAXReader();
    Map map = new HashMap();
    map.put(Consts.XML_NAMESPACE_KEY, Consts.XML_NAMESPACE_VALUE);
    saxReader.getDocumentFactory().setXPathNamespaceURIs(map);
    return saxReader.read(new BufferedInputStream(in));
}

From source file:tw.edu.sinica.iis.GUI.Operate.XMLConfigParser.java

License:Apache License

public boolean load(final String xmlPath) {
    Map<String, String> ns = new HashMap<String, String>();
    ns.put("p", "http://clouddoe.iis.sinica.edu.tw/confXML");

    SAXReader reader = new SAXReader();
    reader.getDocumentFactory().setXPathNamespaceURIs(ns);

    try {/*from   w w  w . j av  a 2  s.  c o m*/
        removeAll();

        Document doc = reader.read(new File(xmlPath));

        Element info = (Element) doc.selectSingleNode("//p:program");
        programInfo.set(info.elementTextTrim("name"), info.elementTextTrim("jarfile"),
                info.elementTextTrim("clsname"), info.elementTextTrim("version"),
                info.elementTextTrim("author"), info.elementTextTrim("lastupd"),
                info.elementTextTrim("website"), info.elementTextTrim("argformat"),
                info.elementTextTrim("streaming"));

        List<?> list = doc.selectNodes("//p:parameters/p:parameter");
        for (Iterator<?> iter = list.iterator(); iter.hasNext();) {
            Element element = (Element) iter.next();

            parameterItems.add(new ParameterItem(element.elementTextTrim("label"),
                    element.elementTextTrim("arg"), element.elementTextTrim("value"),
                    element.elementTextTrim("type"), element.elementTextTrim("editable")));
        }
        list.clear();

        list = doc.selectNodes("//p:logs/p:log");
        for (Iterator<?> iter = list.iterator(); iter.hasNext();) {
            Element element = (Element) iter.next();
            logItems.add(new LogItem(element.elementTextTrim("name"), element.elementTextTrim("type")));
        }
        list.clear();

        list = doc.selectNodes("//p:downloads/p:download");
        for (Iterator<?> iter = list.iterator(); iter.hasNext();) {
            Element element = (Element) iter.next();
            downloadItems.add(new DownloadItem(element.elementTextTrim("src"), element.elementTextTrim("dst"),
                    element.elementTextTrim("merge")));
        }
        list.clear();

        return true;
    } catch (DocumentException e) {
        removeAll();

        return false;
    }
}