Example usage for org.dom4j Node getText

List of usage examples for org.dom4j Node getText

Introduction

In this page you can find the example usage for org.dom4j Node getText.

Prototype

String getText();

Source Link

Document

Returns the text of this node.

Usage

From source file:edu.scripps.fl.pubchem.PubChemFactory.java

License:Apache License

public void populateAssayFromSummaryDocument(PCAssay assay, Node docSumNode) throws Exception {
    Node errorNode = docSumNode.selectSingleNode("error");
    if (errorNode != null)
        throw new Exception("Entrez error: " + errorNode.getText());

    List<Node> list = docSumNode.selectNodes("*");
    String uid = docSumNode.valueOf("@uid");
    assay.setAID(Integer.parseInt(uid));
    for (Node node : list) {
        String name = node.getName();
        Object value = node.getText();
        if (node.selectNodes("*").size() > 0) {

        } else {/*from   w  ww  . j  a va  2s. co m*/
            String property = propMap.getProperty(name);
            if (null != property) {
                Class clazz = PropertyUtils.getPropertyType(assay, property);
                if (clazz.isAssignableFrom(Date.class))
                    value = parseDate(value);
                BeanUtils.setProperty(assay, property, value);
            } else {
                if (!unprocessedProperties.containsKey(name)) {
                    unprocessedProperties.put(name, "");
                    log.warn(String.format("Cannot determine PCAssay bean property '%s'", name));
                }
            }
        }
    }
    String desc = assay.getDescription();
    // eutils summary description doesn't contain new lines 
    // so don't update it if it already has a value (when we populate via xml first).
    if (desc == null || "".equals(desc) || !desc.contains("\n")) {
        Node node = docSumNode.selectSingleNode("AssayDescription");
        assay.setDescription(node.getText());
    }
    return;
}

From source file:edu.scripps.fl.pubchem.PubChemFactory.java

License:Apache License

public int populateRelations(Session session, Document document) throws IOException, DocumentException {
    String fromDb = document.selectSingleNode("/eLinkResult/LinkSet/DbFrom").getText();
    String idStr = document.selectSingleNode("/eLinkResult/LinkSet/IdList/Id").getText();
    Long id = Long.parseLong(idStr);
    List<Node> linkSetDbs = document.selectNodes("/eLinkResult/LinkSet/LinkSetDb");

    Transaction trx = session.beginTransaction();
    int counter = 0;
    for (Node linkSetDb : linkSetDbs) {
        String toDb = linkSetDb.selectSingleNode("DbTo").getText();
        String linkName = linkSetDb.selectSingleNode("LinkName").getText();
        List<Node> ids = linkSetDb.selectNodes("Link/Id");
        for (Node idNode : ids) {
            long relatedId = Long.parseLong(idNode.getText());
            if (id == relatedId)
                continue;
            Relation relation = new Relation();
            relation.setRelationName(linkName);
            relation.setFromDb(fromDb);//from  w  w w .  j a va  2  s.c  o m
            relation.setFromId(id);
            relation.setToDb(toDb);
            relation.setToId(relatedId);
            session.save(relation);
            if (counter++ % 100 == 0) {
                trx.commit();
                session.clear(); // cache grows hugely during very large
                // inserts
                trx = session.beginTransaction();
            }
        }
    }
    trx.commit();
    return counter;
}

From source file:edu.scripps.fl.pubchem.PubChemFactory.java

License:Apache License

public Collection<Long> getNeighbors(Long id) throws Exception {
    Document document = EUtilsWebSession.getInstance().getDocument(
            "http://eutils.ncbi.nlm.nih.gov/entrez/eutils/elink.fcgi", "dbfrom", "pcassay", "id", "" + id,
            "linkname", "pcassay_pcassay_neighbor_list");
    List<Node> linkSetDbs = document.selectNodes("/eLinkResult/LinkSet/LinkSetDb");
    Set<Long> relatedIds = new HashSet();
    int counter = 0;
    for (Node linkSetDb : linkSetDbs) {
        String linkName = linkSetDb.selectSingleNode("LinkName").getText();
        List<Node> ids = linkSetDb.selectNodes("Link/Id");
        for (Node idNode : ids) {
            Long relatedId = Long.parseLong(idNode.getText());
            relatedIds.add(relatedId);/*  ww  w.j a  v  a  2 s  .  c o  m*/
        }
    }
    return relatedIds;
}

From source file:edu.scripps.fl.pubchem.PubChemFactory.java

License:Apache License

public List<Relation> getRelations(Document document) {
    String fromDb = document.selectSingleNode("/eLinkResult/LinkSet/DbFrom").getText();
    String idStr = document.selectSingleNode("/eLinkResult/LinkSet/IdList/Id").getText();
    Long id = Long.parseLong(idStr);
    List<Node> linkSetDbs = document.selectNodes("/eLinkResult/LinkSet/LinkSetDb");
    ArrayList<Relation> list = new ArrayList();
    for (Node linkSetDb : linkSetDbs) {
        String toDb = linkSetDb.selectSingleNode("DbTo").getText();
        String linkName = linkSetDb.selectSingleNode("LinkName").getText();
        List<Node> ids = linkSetDb.selectNodes("Link/Id");
        list.ensureCapacity(list.size() + ids.size());
        for (Node idNode : ids) {
            long relatedId = Long.parseLong(idNode.getText());
            if (id == relatedId)
                continue;
            Relation relation = new Relation();
            relation.setRelationName(linkName);
            relation.setFromDb(fromDb);//  www  . jav  a 2s  .  c  o m
            relation.setFromId(id);
            relation.setToDb(toDb);
            relation.setToId(relatedId);
            list.add(relation);
        }
    }
    return list;
}

From source file:edu.scripps.fl.pubchem.PubChemXMLParserFactory.java

License:Apache License

protected PCAssay populateAssayFromXMLNode(Node topNode) throws Exception {
    //      String assayDescPath = "PC-AssaySubmit_assay/PC-AssaySubmit_assay_descr/PC-AssayDescription";
    Node assayDescNode = null;/*from   ww w. ja  v a 2  s .c om*/
    if (topNode.getName().equals("PC-AssayDescription"))
        assayDescNode = topNode;
    else {
        assayDescNode = topNode.selectSingleNode(".//PC-AssayDescription");
    }
    if (assayDescNode == null)
        throw new Exception(
                String.format("Cannot find PC-AssayDescription node in provided node %s", topNode.getPath()));

    Node node = assayDescNode.selectSingleNode("PC-AssayDescription_aid/PC-ID/PC-ID_id");
    Integer aid = new Integer(node.getText());

    try {
        PCAssay assay = new PCAssay();
        if (aid > 0)
            assay.setAID(aid);

        node = assayDescNode.selectSingleNode("PC-AssayDescription_aid/PC-ID/PC-ID_version");
        Integer version = new Integer(node.getText());
        assay.setVersion(version);

        node = assayDescNode.selectSingleNode("PC-AssayDescription_revision");
        Integer revision = new Integer(node.getText());
        assay.setRevision(revision);

        Node trackingNode = assayDescNode
                .selectSingleNode("PC-AssayDescription_aid-source/PC-Source/PC-Source_db/PC-DBTracking");

        node = trackingNode.selectSingleNode("PC-DBTracking_name");
        assay.setSourceName(node.getText());

        node = trackingNode.selectSingleNode("PC-DBTracking_source-id/Object-id/Object-id_str");
        assay.setExtRegId(node.getText());

        // hold until date
        node = trackingNode.selectSingleNode("PC-DBTracking_date");
        if (node != null) {
            String year = node.selectSingleNode("Date/Date_std/Date-std/Date-std_year").getText();
            String month = node.selectSingleNode("Date/Date_std/Date-std/Date-std_month").getText();
            String day = node.selectSingleNode("Date/Date_std/Date-std/Date-std_day").getText();
            if (DEBUGGING)
                log.info("year: " + year + " month: " + month + " day: " + day);
            Calendar calendar = Calendar.getInstance();
            calendar.set(Integer.parseInt(year), Integer.parseInt(month) - 1, Integer.parseInt(day));
            assay.setHoldUntilDate(calendar.getTime());
            if (DEBUGGING)
                log.info(calendar.getTime().toString());
        }

        node = assayDescNode.selectSingleNode("PC-AssayDescription_name");
        assay.setName(node.getText());

        List<Node> nodes = assayDescNode
                .selectNodes("PC-AssayDescription_description/PC-AssayDescription_description_E");
        assay.setDescription(join(nodes, separator));

        nodes = assayDescNode.selectNodes("PC-AssayDescription_protocol/PC-AssayDescription_protocol_E");
        assay.setProtocol(join(nodes, separator));

        nodes = assayDescNode.selectNodes("PC-AssayDescription_comment/PC-AssayDescription_comment_E");
        assay.setComment(join(nodes, separator));

        node = assayDescNode.selectSingleNode("PC-AssayDescription_activity-outcome-method");
        if (node != null)
            assay.setActivityOutcomeMethod(node.valueOf("@value"));

        node = assayDescNode
                .selectSingleNode("PC-AssayDescription_grant-number/PC-AssayDescription_grant-number_E");
        if (node != null)
            assay.setGrantNumber(node.getText());

        node = assayDescNode.selectSingleNode("PC-AssayDescription_project-category");
        if (node != null)
            assay.setProjectCategory(node.valueOf("@value"));

        assay.getAssayXRefs().removeAll(assay.getAssayXRefs());

        nodes = assayDescNode.selectNodes("PC-AssayDescription_xref/PC-AnnotatedXRef");
        handleXRefs(assay, null, nodes);

        nodes = assayDescNode.selectNodes("PC-AssayDescription_target/PC-AssayTargetInfo");
        handleTargetXRefs(assay, null, nodes);

        handlePanels(assay, assayDescNode);

        handleColumns(assay, assayDescNode);

        handleComments(assay, assayDescNode);

        return assay;
    } catch (Exception ex) {
        throw new RuntimeException("Problem with AID " + aid, ex);
    }
}

From source file:edu.scripps.fl.pubchem.PubChemXMLParserFactory.java

License:Apache License

protected void handleColumns(PCAssay assay, Node assayDescNode) {
    Map<Integer, PCAssayColumn> map = new HashMap();
    for (PCAssayColumn col : assay.getColumns())
        map.put(col.getTID(), col);//from  w  w w . ja v a  2s  . c  om

    ensureColumn(assay, -1, "Outcome", "string");
    ensureColumn(assay, 0, "Score", "float");

    Map<Integer, PCAssayPanel> mapPanels = new HashMap();
    for (PCAssayPanel panel : assay.getPanels())
        mapPanels.put(panel.getPanelNumber(), panel);

    List<Node> nodes = assayDescNode.selectNodes("PC-AssayDescription_results/PC-ResultType");
    for (Node n : nodes) {
        String tid = n.selectSingleNode("PC-ResultType_tid").getText();
        String name = n.selectSingleNode("PC-ResultType_name").getText();
        String type = n.selectSingleNode("PC-ResultType_type").valueOf("@value");
        PCAssayColumn column = ensureColumn(assay, Integer.parseInt(tid), name, type);

        Node node = n.selectSingleNode("PC-ResultType_unit");
        if (node != null)
            column.setUnit(node.valueOf("@value"));

        List<Node> descNodes = n.selectNodes("PC-ResultType_description/PC-ResultType_description_E");
        column.setDescription(join(descNodes, separator));
        if (DEBUGGING)
            log.info("Column description: " + join(descNodes, separator));

        node = n.selectSingleNode("PC-ResultType_ac");
        if (node != null)
            column.setActiveConcentration("true".equals(node.valueOf("@value")));

        node = n.selectSingleNode("PC-ResultType_tc");
        if (node != null) {
            Node node2 = node.selectSingleNode("PC-ConcentrationAttr/PC-ConcentrationAttr_dr-id");
            if (node2 != null) {
                column.setCurvePlotLabel(Integer.parseInt(node2.getText()));
            }
            String testedConc = node.selectSingleNode("PC-ConcentrationAttr/PC-ConcentrationAttr_concentration")
                    .getText();
            column.setTestedConcentration(Double.parseDouble(testedConc));
            String testedUnit = node.selectSingleNode("PC-ConcentrationAttr/PC-ConcentrationAttr_unit")
                    .valueOf("@value");
            column.setTestedConcentrationUnit(testedUnit);
        }

        node = n.selectSingleNode("PC-ResultType_panel-info/PC-AssayPanelTestResult");
        if (node != null) {
            String panelId = node.selectSingleNode("PC-AssayPanelTestResult_mid").getText();
            PCAssayPanel panel = mapPanels.get(Integer.parseInt(panelId));
            column.setPanel(panel);
            String panelColumnType = node.selectSingleNode("PC-AssayPanelTestResult_readout-annot")
                    .valueOf("@value");
            column.setPanelReadoutType(panelColumnType);
        }
    }
}

From source file:edu.scripps.fl.pubchem.PubChemXMLParserFactory.java

License:Apache License

protected void handleTargetXRefs(PCAssay assay, PCAssayPanel panel, List<Node> nodes) {
    for (Node n : nodes) {
        String name = n.selectSingleNode("PC-AssayTargetInfo_name").getText();
        String id = n.selectSingleNode("PC-AssayTargetInfo_mol-id").getText();
        String type = n.selectSingleNode("PC-AssayTargetInfo_molecule-type").valueOf("@value");
        String database = targetType.containsKey(type) ? targetType.get(type) : type;
        Node taxonNode = n.selectSingleNode("PC-AssayTargetInfo_organism/BioSource/BioSource_org/Org-ref");
        String taxonName = "", taxonCommon = "", taxon = "";
        if (taxonNode != null) {
            taxonName = taxonNode.selectSingleNode("Org-ref_taxname").getText();
            taxonCommon = nullSafeGet(taxonNode, "Org-ref_common", "text()");
            String db = nullSafeGet(taxonNode, "Org-ref_db/Dbtag/Dbtag_db", "text()");
            if (!"taxon".equals(db))
                throw new RuntimeException("Non taxon BioSource Org-ref_db (was " + db + ")");
            taxonNode = taxonNode.selectSingleNode("Org-ref_db/Dbtag/Dbtag_tag/Object-id/Object-id_id");
            taxon = taxonNode.getText();
        }/*w  w  w .j  av a  2s .  c o  m*/

        XRef xref = new XRef();
        xref.setXRefId(id);
        xref.setDatabase(database);
        xref.setType(type);
        xref.setName(name);

        PCAssayXRef aXref = new PCAssayXRef();
        aXref.setTarget(true);
        aXref.setPanel(panel);
        aXref.setAssay(assay);
        aXref.setXRef(xref);
        if (!taxon.equals("")) {
            aXref.setTaxon(Long.parseLong(taxon));
            aXref.setTaxonName(taxonName);
            aXref.setTaxonCommon(taxonCommon);
        }
        assay.getAssayXRefs().add(aXref);
    }
}

From source file:edu.scripps.fl.pubchem.web.entrez.EUtilsWebSession.java

License:Apache License

public Document getDocument(InputStream in) throws Exception {
    DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    DOMReader reader = new DOMReader();
    Document document = reader.read(builder.parse(new BufferedInputStream(in)));
    // SAXReader reader = new SAXReader();
    // Document document = reader.read(in);
    in.close();/* w  w  w  .  ja  v a 2 s .  c  o  m*/
    if (DEBUGGING)
        new XMLWriter().write(document);
    Node node = document.selectSingleNode("/eSearchResult/ERROR");
    if (node != null)
        throw new Exception(node.getText());
    return document;
}

From source file:edu.scripps.fl.pubchem.web.entrez.EUtilsWebSession.java

License:Apache License

public Set<String> getDatabases() throws Exception {
    Document document = getDocument("http://eutils.ncbi.nlm.nih.gov/entrez/eutils/einfo.fcgi");
    List<Node> list = document.selectNodes("/eInfoResult/DbList/DbName", ".");
    Set dbs = new HashSet(list.size());
    for (Node node : list)
        dbs.add(node.getText());
    return dbs;// w  w  w .j a  v a2s .  c om
}

From source file:edu.scripps.fl.pubchem.web.pug.PowerUserGateway.java

License:Apache License

public URL getResponseURL() throws IOException {
    URL url = null;//  w ww.ja  v a2 s .  com
    Node node = getResponse().selectSingleNode("//*/PCT-Download-URL_url");
    if (node != null)
        url = new URL(node.getText());
    return url;
}