Example usage for org.dom4j Element getTextTrim

List of usage examples for org.dom4j Element getTextTrim

Introduction

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

Prototype

String getTextTrim();

Source Link

Document

DOCUMENT ME!

Usage

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++;/* w w 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:to.networld.scrawler.common.RDFParser.java

License:Open Source License

protected synchronized String getConditionalSingleNode(String _nodeName, String _resourceName,
        String _resourceValue) {//from   w  w  w . ja v  a 2  s.  co m
    List<Element> nodeList = this.getLinkNodes(this.queryPrefix + "/" + _nodeName, this.namespace);
    if (nodeList.size() > 0) {
        for (Element node : nodeList) {
            if (node.valueOf("@" + _resourceName).equalsIgnoreCase(_resourceValue))
                return node.getTextTrim();
        }
    }
    return null;
}

From source file:to.networld.scrawler.common.RDFParser.java

License:Open Source License

/**
 * Please set before you call the function the variables this.namespace and this.queryPrefix.
 * /*from  w w  w.j ava2 s.co m*/
 * @param _nodeName The name of the node for example 'dive:name'
 * @return The string representation of the given node. If found more than one times the Vector has more elements.
 */
protected synchronized Vector<String> getNodes(String _nodeName) {
    List<Element> nodeList = this.getLinkNodes(this.queryPrefix + "/" + _nodeName, this.namespace);
    Vector<String> retValues = new Vector<String>();
    for (Element entry : nodeList) {
        String str = entry.getTextTrim();
        if (!str.equals(""))
            retValues.add(str);
    }
    return retValues;
}

From source file:to.networld.scrawler.foaf.Person.java

License:Open Source License

/**
 * @see to.networld.scrawler.interfaces.IFOAFPerson#getAccounts()
 *//* ww  w  .j a v a  2 s .c  o  m*/
@Override
public Vector<Account> getAccounts() {
    List<Element> elements = this.getLinkNodes(this.queryPrefix + "/foaf:holdsAccount");
    Vector<Account> retVector = new Vector<Account>();
    for (Element entry : elements) {
        Account account = new Account();
        Element nameNode = (Element) entry.selectSingleNode(entry.getUniquePath() + "//foaf:accountName");
        if (nameNode != null)
            account.setName(nameNode.getTextTrim());

        Element serviceHomepageNode = (Element) entry
                .selectSingleNode(entry.getUniquePath() + "//foaf:accountServiceHomepage");
        if (serviceHomepageNode != null)
            account.setServiceHomepage(serviceHomepageNode.valueOf("@rdf:resource"));

        Element profilePageNode = (Element) entry
                .selectSingleNode(entry.getUniquePath() + "//foaf:accountProfilePage");
        if (profilePageNode != null)
            account.setProfilePage(profilePageNode.valueOf("@rdf:resource"));

        retVector.add(account);
    }
    return retVector;
}

From source file:to.networld.security.common.data.GenericSAMLMessage.java

License:Open Source License

protected String getElementValue(String _xpath) {
    Element element = (Element) this.xmlDocument.selectSingleNode(_xpath);
    if (element != null)
        return element.getTextTrim();
    else/*from w  ww  .j  a v  a  2  s.co  m*/
        return null;
}

From source file:us.mn.state.health.lims.common.externalLinks.ExternalPatientSearchResultsXMLConverter.java

License:Mozilla Public License

private String getValueFor(Element patientElement, String elementName) {
    Element namedElement = patientElement.element(elementName);
    return namedElement == null ? null : namedElement.getTextTrim();
}

From source file:wuit.crawler.database.ExtractorDB.java

public synchronized void getPageClear(List<KeyValue> rulers) {
    List<PageLocalInfo> rs = new ArrayList<PageLocalInfo>();
    PageFeaturesDB db = new PageFeaturesDB();
    db.SelectPageClear(rs);//from   w  w w.j a  va2  s.co  m
    ;
    for (int i = 0; i < rs.size(); i++) {
        String xml = rs.get(i).content;
        Document doc = null;
        try {
            if (xml == null || xml.equals(""))
                continue;
            StringReader read = new StringReader(xml);
            InputSource source = new InputSource(read);
            SAXReader saxReader = new SAXReader();
            doc = saxReader.read(source);
            List list = doc.selectNodes("/items/item");
            for (int j = 0; j < list.size(); j++) {
                Element ele = (Element) list.get(j);
                KeyValue vals = new KeyValue();
                vals.key = ele.attributeValue("key");
                vals.order = Integer.parseInt(ele.attributeValue("order"));
                vals.value = ele.getTextTrim();
                rulers.add(vals);
            }
            //KeyValueSort sort = new KeyValueSort();
            //Collections.sort(rulers, sort);
        } catch (DocumentException e) {
            System.out.println(e.getMessage());
        }
    }
}

From source file:wuit.crawler.database.ExtractorDB.java

public synchronized void getPageFilters(Map<String, KeyValue> rulers) {
    List<PageLocalInfo> rs = new ArrayList<PageLocalInfo>();
    PageFeaturesDB db = new PageFeaturesDB();
    db.SelectPageFilters(rs);/*from   w w w  .  j  av  a 2  s.  c om*/
    for (int i = 0; i < rs.size(); i++) {
        String xml = rs.get(i).content;
        Document doc = null;
        try {
            if (xml == null || xml.equals(""))
                continue;
            StringReader read = new StringReader(xml);
            InputSource source = new InputSource(read);
            //SAXBuilder sb = new SAXBuilder();

            SAXReader saxReader = new SAXReader();
            doc = saxReader.read(source);
            List list = doc.selectNodes("/fields/field");
            for (int j = 0; j < list.size(); j++) {
                Element ele = (Element) list.get(j);
                KeyValue vals = new KeyValue();
                vals.key = ele.attributeValue("key");
                vals.value = ele.getTextTrim();
                rulers.put(vals.value, vals);
            }
        } catch (DocumentException e) {
            System.out.println(e.getMessage());
        }
    }
}

From source file:wuit.crawler.database.ExtractorDB.java

public synchronized void getfaultRule(List<KeyValue> rulers) {
    List<PageLocalInfo> rs = new ArrayList<PageLocalInfo>();
    PageFeaturesDB db = new PageFeaturesDB();
    db.SelectPageItems(rs);// w  w w  .j av a2 s .c  o m
    ;
    for (int i = 0; i < rs.size(); i++) {
        String xml = rs.get(i).content;
        Document doc = null;
        try {
            if (xml == null || xml.equals(""))
                continue;
            StringReader read = new StringReader(xml);
            InputSource source = new InputSource(read);
            //SAXBuilder sb = new SAXBuilder();

            SAXReader saxReader = new SAXReader();
            doc = saxReader.read(source);
            List list = doc.selectNodes("/fields/field");
            for (int j = 0; j < list.size(); j++) {
                Element ele = (Element) list.get(j);
                KeyValue vals = new KeyValue();
                vals.key = ele.attributeValue("key");
                vals.value = ele.getTextTrim();
                rulers.add(vals);
            }
        } catch (DocumentException e) {
            System.out.println(e.getMessage());
        }
    }
}

From source file:wuit.crawler.database.ExtractorDB.java

public synchronized void getItemRules(Map<String, List<KeyValue>> libRuler) {
    List<PageFeatureInfo> RS = new ArrayList<PageFeatureInfo>();
    PageFeaturesDB db = new PageFeaturesDB();
    db.SelectPageFeatures(RS);//from w  w w.j ava2  s.  c om
    for (int i = 0; i < RS.size(); i++) {
        String xml = RS.get(i).featrue;
        Document doc = null;
        try {
            if (xml == null || xml.equals(""))
                continue;
            StringReader read = new StringReader(xml);
            InputSource source = new InputSource(read);
            //SAXBuilder sb = new SAXBuilder();

            SAXReader saxReader = new SAXReader();
            doc = saxReader.read(source);
            List list = doc.selectNodes("/features/feature");
            for (int j = 0; j < list.size(); j++) {
                Element ele = (Element) list.get(j);
                List<?> childlist = ele.selectNodes("./child::*");

                String feature = ele.attributeValue("value");
                if (feature == null || feature.equals(""))
                    continue;
                List<KeyValue> keyVals = new ArrayList<KeyValue>();

                for (int n = 0; n < childlist.size(); n++) {
                    Element eleChild = (Element) childlist.get(n);
                    KeyValue vals = new KeyValue();
                    vals.key = eleChild.attributeValue("name");
                    vals.value = eleChild.getTextTrim();

                    keyVals.add(vals);
                    //                        System.out.println(feature + " : " + vals.key + " : " + vals.value);
                }
                libRuler.put(feature, keyVals);
            }
        } catch (DocumentException e) {
            System.out.println(e.getMessage());
        }
    }
}