Example usage for org.dom4j Node valueOf

List of usage examples for org.dom4j Node valueOf

Introduction

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

Prototype

String valueOf(String xpathExpression);

Source Link

Document

valueOf evaluates an XPath expression and returns the textual representation of the results the XPath string-value of this node.

Usage

From source file:bard.pubchem.xml.PubChemXMLParserFactory.java

License:Open Source License

protected void populateAssayResultsFromXML(PCAssay assay, Node assayDescriptionNode) {
    List<Node> assayResultNodes = assayDescriptionNode
            .selectNodes("../../../PC-AssaySubmit_data/PC-AssayResults");
    if (assayResultNodes.size() == 0)
        return;/*from   w w w . jav  a 2s  .  c  o m*/

    for (Node resultNode : assayResultNodes) {
        PCAssayResult result = new PCAssayResult();

        String val = resultNode.selectSingleNode("PC-AssayResults_sid").valueOf("text()");
        result.setSID(Long.parseLong(val));

        val = resultNode.selectSingleNode("PC-AssayResults_outcome").valueOf("@value");
        val = val.substring(0, 1).toUpperCase() + val.substring(1);
        result.setOutcome(val);

        val = resultNode.selectSingleNode("PC-AssayResults_rank").valueOf("text()");
        result.setRankScore(Integer.parseInt(val));

        List<Node> assayDataNodes = resultNode.selectNodes("PC-AssayResults_data/PC-AssayData");

        List<String> all = GrowthList.decorate(new ArrayList<String>(assay.getColumns().size() - 2));
        result.setAllValues(all);
        for (Node node : assayDataNodes) {
            val = node.valueOf("PC-AssayData_tid/text()");
            int index = Integer.parseInt(val) - 1;
            val = node.selectSingleNode(".//*[starts-with(name(),'PC-AssayData_value_')]").getText();
            all.set(index, val);
        }
        assay.getResults().add(result);
    }

}

From source file:bard.pubchem.xml.PubChemXMLParserFactory.java

License:Open Source License

protected PCAssay populateAssayFromXMLNode(Node topNode) throws PubChemException {
    // String assayDescPath =
    // "PC-AssaySubmit_assay/PC-AssaySubmit_assay_descr/PC-AssayDescription";
    Node assayDescNode = null;/*from  w ww.  j a va2 s  . co m*/
    if (topNode.getName().equals("PC-AssayDescription"))
        assayDescNode = topNode;
    else {
        assayDescNode = topNode.selectSingleNode(".//PC-AssayDescription");
    }
    if (assayDescNode == null)
        throw new PubChemException(
                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"));

        handlePlots(assay, assayDescNode);

        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:bard.pubchem.xml.PubChemXMLParserFactory.java

License:Open Source License

protected void handlePanels(PCAssay assay, Node assayDescNode) {
    Node node = assayDescNode.selectSingleNode("PC-AssayDescription_is-panel");
    if (node == null)
        assay.setPanel(false);/*  w w w. j  a  va 2  s.  c o  m*/
    else
        assay.setPanel("true".equals(node.valueOf("@value")));

    if (assay.isPanel()) {
        node = assayDescNode
                .selectSingleNode("PC-AssayDescription_panel-info/PC-AssayPanel/PC-AssayPanel_name");
        assay.setPanelName(node.valueOf("text()"));
        node = assayDescNode
                .selectSingleNode("PC-AssayDescription_panel-info/PC-AssayPanel/PC-AssayPanel_descr");
        assay.setPanelDescription(node == null ? "" : node.valueOf("text()"));
    }

    List<Node> nodes = assayDescNode.selectNodes(
            "PC-AssayDescription_panel-info/PC-AssayPanel/PC-AssayPanel_member/PC-AssayPanelMember");
    for (Node n : nodes) {
        String mid = n.selectSingleNode("PC-AssayPanelMember_mid").getText();
        Node node2 = n.selectSingleNode("PC-AssayPanelMember_name");
        String name = node2 == null ? "" : node2.getText();

        PCAssayPanel panel = new PCAssayPanel();
        panel.setAssay(assay);
        assay.getPanels().add(panel);
        panel.setPanelNumber(Integer.parseInt(mid));
        panel.setName(name);

        node2 = n.selectSingleNode("PC-AssayPanelMember_description");
        panel.setDescription(node2 == null ? "" : node2.getText());

        List<Node> nodes2 = n.selectNodes("PC-AssayPanelMember_protocol/PC-AssayPanelMember_protocol_E");
        panel.setProtocol(join(nodes2, separator));

        nodes2 = n.selectNodes("PC-AssayPanelMember_comment/PC-AssayPanelMember_comment_E");
        panel.setComment(join(nodes2, separator));

        List<Node> xrefNodes = n.selectNodes("PC-AssayPanelMember_xref/PC-AnnotatedXRef");
        handleXRefs(assay, panel, xrefNodes);

        List<Node> targetNodes = n.selectNodes("PC-AssayPanelMember_target/PC-AssayTargetInfo");
        handleTargetXRefs(assay, panel, targetNodes);
    }
}

From source file:bard.pubchem.xml.PubChemXMLParserFactory.java

License:Open Source License

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

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

    Map<Integer, PCAssayPanel> mapPanels = new HashMap<Integer, PCAssayPanel>();
    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:bard.pubchem.xml.PubChemXMLParserFactory.java

License:Open Source License

private String nullSafeGet(Node node, String xpath, String expression) {
    Node node2 = node.selectSingleNode(xpath);
    if (null != node2)
        return node2.valueOf(expression);
    return "";
}

From source file:com.adobe.ac.maven.ncss.NcssAggregateReportGenerator.java

License:Apache License

private void doModuleAnalysis(final List<ModuleReport> reports) {
    getSink().table();//w  w  w .  j  a v a  2 s.co m
    getSink().tableRow();
    headerCellHelper(getResourceBundle().getString("report.javancss.header.module"));
    headerCellHelper(getResourceBundle().getString("report.javancss.header.packages"));
    headerCellHelper(getResourceBundle().getString("report.javancss.header.classetotal"));
    headerCellHelper(getResourceBundle().getString("report.javancss.header.functiontotal"));
    headerCellHelper(getResourceBundle().getString("report.javancss.header.ncsstotal"));
    headerCellHelper(getResourceBundle().getString("report.javancss.header.javadoc"));
    headerCellHelper(getResourceBundle().getString("report.javancss.header.javadoc_line"));
    headerCellHelper(getResourceBundle().getString("report.javancss.header.single_comment"));
    headerCellHelper(getResourceBundle().getString("report.javancss.header.multi_comment"));
    getSink().tableRow_();

    int packages = 0;
    int classes = 0;
    int methods = 0;
    int ncss = 0;
    int javadocs = 0;
    int jdlines = 0;
    int single = 0;
    int multi = 0;
    for (final Iterator<ModuleReport> it = reports.iterator(); it.hasNext();) {
        final ModuleReport report = (ModuleReport) it.next();
        final Document document = report.getJavancssDocument();
        getSink().tableRow();
        getLog().debug("Aggregating " + report.getModule().getArtifactId());
        tableCellHelper(report.getModule().getArtifactId());
        final int packageSize = document.selectNodes("//javancss/packages/package").size();
        packages += packageSize;
        tableCellHelper(String.valueOf(packageSize));

        final Node node = document.selectSingleNode("//javancss/packages/total");

        final String classSize = node.valueOf("classes");
        tableCellHelper(classSize);
        classes += Integer.parseInt(classSize);

        final String methodSize = node.valueOf("functions");
        tableCellHelper(methodSize);
        methods += Integer.parseInt(methodSize);

        final String ncssSize = node.valueOf("ncss");
        tableCellHelper(ncssSize);
        ncss += Integer.parseInt(ncssSize);

        final String javadocSize = node.valueOf("javadocs");
        tableCellHelper(javadocSize);
        javadocs += Integer.parseInt(javadocSize);

        final String jdlineSize = node.valueOf("javadoc_lines");
        tableCellHelper(jdlineSize);
        jdlines += Integer.parseInt(jdlineSize);

        final String singleSize = node.valueOf("single_comment_lines");
        tableCellHelper(singleSize);
        single += Integer.parseInt(singleSize);

        final String multiSize = node.valueOf("multi_comment_lines");
        tableCellHelper(multiSize);
        multi += Integer.parseInt(multiSize);

        getSink().tableRow_();
    }

    // Totals row
    getSink().tableRow();
    tableCellHelper(getResourceBundle().getString("report.javancss.header.totals"));
    tableCellHelper(String.valueOf(packages));
    tableCellHelper(String.valueOf(classes));
    tableCellHelper(String.valueOf(methods));
    tableCellHelper(String.valueOf(ncss));
    tableCellHelper(String.valueOf(javadocs));
    tableCellHelper(String.valueOf(jdlines));
    tableCellHelper(String.valueOf(single));
    tableCellHelper(String.valueOf(multi));
    getSink().tableRow_();

    getSink().table_();
}

From source file:com.adobe.ac.maven.ncss.NcssReportGenerator.java

License:Apache License

private void doMainPackageAnalysis(final Document document) {
    subtitleHelper(getResourceBundle().getString("report.javancss.package.text"));
    getSink().table();//from w w  w  . j  a  v  a2s . com
    getSink().tableRow();
    // HEADER
    headerCellHelper(getResourceBundle().getString("report.javancss.header.package"));
    headerCellHelper(getResourceBundle().getString("report.javancss.header.classe"));
    headerCellHelper(getResourceBundle().getString("report.javancss.header.function"));
    headerCellHelper(getResourceBundle().getString("report.javancss.header.ncss"));
    headerCellHelper(getResourceBundle().getString("report.javancss.header.javadoc"));
    headerCellHelper(getResourceBundle().getString("report.javancss.header.javadoc_line"));
    headerCellHelper(getResourceBundle().getString("report.javancss.header.single_comment"));
    headerCellHelper(getResourceBundle().getString("report.javancss.header.multi_comment"));
    getSink().tableRow_();
    // DATA
    final List list = document.selectNodes("//javancss/packages/package");
    Collections.sort(list, new NumericNodeComparator("ncss"));
    final Iterator nodeIterator = list.iterator();
    while (nodeIterator.hasNext()) {
        final Node node = (Node) nodeIterator.next();
        getSink().tableRow();
        tableCellHelper(node.valueOf("name"));
        tableCellHelper(node.valueOf("classes"));
        tableCellHelper(node.valueOf("functions"));
        tableCellHelper(node.valueOf("ncss"));
        tableCellHelper(node.valueOf("javadocs"));
        tableCellHelper(node.valueOf("javadoc_lines"));
        tableCellHelper(node.valueOf("single_comment_lines"));
        tableCellHelper(node.valueOf("multi_comment_lines"));
        getSink().tableRow_();
    }
    getSink().table_();
}

From source file:com.adobe.ac.maven.ncss.NcssReportGenerator.java

License:Apache License

private void doTotalPackageAnalysis(final Document document) {
    getSink().table();//from  ww w  .j  av a  2  s . c  o m
    getSink().tableRow();
    headerCellHelper(getResourceBundle().getString("report.javancss.header.classetotal"));
    headerCellHelper(getResourceBundle().getString("report.javancss.header.functiontotal"));
    headerCellHelper(getResourceBundle().getString("report.javancss.header.ncsstotal"));
    headerCellHelper(getResourceBundle().getString("report.javancss.header.javadoc"));
    headerCellHelper(getResourceBundle().getString("report.javancss.header.javadoc_line"));
    headerCellHelper(getResourceBundle().getString("report.javancss.header.single_comment"));
    headerCellHelper(getResourceBundle().getString("report.javancss.header.multi_comment"));
    getSink().tableRow_();
    final Node node = document.selectSingleNode("//javancss/packages/total");
    getSink().tableRow();
    tableCellHelper(node.valueOf("classes"));
    tableCellHelper(node.valueOf("functions"));
    tableCellHelper(node.valueOf("ncss"));
    tableCellHelper(node.valueOf("javadocs"));
    tableCellHelper(node.valueOf("javadoc_lines"));
    tableCellHelper(node.valueOf("single_comment_lines"));
    tableCellHelper(node.valueOf("multi_comment_lines"));
    getSink().tableRow_();
    getSink().table_();
}

From source file:com.adobe.ac.maven.ncss.NcssReportGenerator.java

License:Apache License

private void doTopObjectGeneric(final List nodeList) {
    getSink().table();/*from   w  w  w. j a v  a 2s .  c o m*/
    getSink().tableRow();
    headerCellHelper(getResourceBundle().getString("report.javancss.header.object"));
    headerCellHelper(getResourceBundle().getString("report.javancss.header.ncss"));
    headerCellHelper(getResourceBundle().getString("report.javancss.header.function"));
    headerCellHelper(getResourceBundle().getString("report.javancss.header.classe"));
    headerCellHelper(getResourceBundle().getString("report.javancss.header.javadoc"));
    getSink().tableRow_();
    final Iterator nodeIterator = nodeList.iterator();
    int i = 0;
    while (nodeIterator.hasNext() && (i++ < lineThreshold)) {
        final Node node = (Node) nodeIterator.next();
        getSink().tableRow();
        getSink().tableCell();
        getSink().tableCell_();
        tableCellHelper(node.valueOf("ncss"));
        tableCellHelper(node.valueOf("functions"));
        tableCellHelper(node.valueOf("classes"));
        tableCellHelper(node.valueOf("javadocs"));
        getSink().tableRow_();
    }
    getSink().table_();
}

From source file:com.adobe.ac.maven.ncss.NcssReportGenerator.java

License:Apache License

private void doObjectAverage(final Document document) {
    subtitleHelper(getResourceBundle().getString("report.javancss.averages"));
    getSink().table();/*  ww w.  j ava 2 s .com*/
    getSink().tableRow();
    headerCellHelper(getResourceBundle().getString("report.javancss.header.ncssaverage"));
    headerCellHelper(getResourceBundle().getString("report.javancss.header.programncss"));
    headerCellHelper(getResourceBundle().getString("report.javancss.header.classeaverage"));
    headerCellHelper(getResourceBundle().getString("report.javancss.header.functionaverage"));
    headerCellHelper(getResourceBundle().getString("report.javancss.header.javadocaverage"));
    getSink().tableRow_();
    final Node node = document.selectSingleNode("//javancss/objects/averages");
    final String totalNcss = document.selectSingleNode("//javancss/objects/ncss").getText();
    getSink().tableRow();
    tableCellHelper(node.valueOf("ncss"));
    tableCellHelper(totalNcss);
    tableCellHelper(node.valueOf("classes"));
    tableCellHelper(node.valueOf("functions"));
    tableCellHelper(node.valueOf("javadocs"));
    getSink().tableRow_();
    getSink().table_();
}