Example usage for org.dom4j Element elementTextTrim

List of usage examples for org.dom4j Element elementTextTrim

Introduction

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

Prototype

String elementTextTrim(QName qname);

Source Link

Usage

From source file:sse.storage.etc.Config.java

License:Open Source License

private void initVDisks(Element root) throws ConfigException, MalformedURLException, SmbException {
    vdisks = new HashMap<String, VDisk>();
    for (Iterator<?> it = root.elementIterator("vdisk"); it.hasNext();) {
        Element e = (Element) it.next();
        VDisk vdisk = new VDisk();
        vdisk.setId(e.elementTextTrim("id"));
        vdisk.setIp(e.elementTextTrim("ip"));
        vdisk.setUser(e.elementTextTrim("user"));
        vdisk.setPassword(e.elementTextTrim("password"));
        vdisk.setRootPath(e.elementTextTrim("root-path"));
        if (!vdisk.isValid()) {
            throw new ConfigException("VDisk " + vdisk.getId() + " is invalid");
        }/*from  w ww .ja  va2s . c om*/
        vdisks.put(vdisk.getId(), vdisk);

        Iterator<?> it2 = RES_DIRS.keySet().iterator();
        while (it2.hasNext()) {
            vdisk.mkdirs(RES_DIRS.get(it2.next()));
        }

        info("Load vdisk: " + vdisk);
    }
    if (vdisks.isEmpty()) {
        throw new ConfigException("No vdisk is defined in " + STORAGE_CONFIG);
    }
}

From source file:sse.storage.etc.Config.java

License:Open Source License

private void initClusters(Element root) throws ConfigException {
    int masterN = 0, backupN = 0;
    clusters = new HashMap<String, Cluster>();
    for (Iterator<?> it = root.elementIterator("cluster"); it.hasNext();) {
        Element e = (Element) it.next();
        Cluster cluster = new Cluster();
        cluster.setId(e.elementTextTrim("id"));
        cluster.setType(e.elementTextTrim("type"));
        if (cluster.isMaster()) {
            masterN++;/*from ww  w  . j a v  a 2 s .  c  o  m*/
        }
        if (cluster.isBackup()) {
            backupN++;
        }

        cluster.setDbId(e.elementTextTrim("database-id"));
        if (!databases.containsKey(cluster.getDbId())) {
            throw new ConfigException("Database " + cluster.getDbId() + " in the cluster " + cluster.getId()
                    + " should be first defined");
        }

        List<String> vdiskIds = new ArrayList<String>();
        for (Iterator<?> it2 = e.elementIterator("vdisk-id"); it2.hasNext();) {
            Element e2 = (Element) it2.next();
            String vdiskId = e2.getTextTrim();
            if (!vdisks.containsKey(vdiskId)) {
                throw new ConfigException(
                        "VDisk " + vdiskId + " in the cluster " + cluster.getId() + " should be first defined");
            }
            vdiskIds.add(vdiskId);
        }
        if (vdiskIds.isEmpty()) {
            throw new ConfigException("No vdisk is specified in cluster " + cluster.getId());
        }
        cluster.setVdiskIds(vdiskIds.toArray(new String[0]));
        clusters.put(cluster.getId(), cluster);

        info("Load cluster: " + cluster);
    }
    if (masterN != 1) {
        throw new ConfigException("There should be one master cluster defined.");
    }
    if (backupN <= 0) {
        throw new ConfigException("There should be at least one Backup cluster defined");
    }
}

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 ww  .jav a  2 s .c  om*/
        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;
    }
}