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:org.ballproject.knime.base.config.GalaxyNodeConfigurationReader.java

License:Open Source License

private void processParameter(Node n) throws Exception {
    Parameter<?> ret = null;
    String type = n.valueOf("@type");
    if (type.equals(""))
        throw new Exception("type information for parameter not set");

    String key = n.valueOf("@name");
    String val = n.valueOf("@value");

    System.out.println("processing param " + key + " type:" + type);

    if (type.equals("integer"))
        ret = new IntegerParameter(key, val);
    if (type.equals("float"))
        ret = new DoubleParameter(key, val);
    if (type.equals("boolean"))
        ret = new BoolParameter(key, val);
    if (type.equals("text"))
        ret = new StringParameter(key, val);
    if (type.equals("select")) {
        List<Node> options = DOMHelper.selectNodes(n, "option");
        List<String> opts = new ArrayList<String>();
        List<String> labs = new ArrayList<String>();
        for (Node option : options) {
            String optval = option.valueOf("@value");
            String label = option.valueOf("text()");
            opts.add(optval);//from   w  w w  .ja v a 2s  . c  om
            labs.add(label);
        }
        ret = new StringChoiceParameter(key, opts, labs);
    }
    String descr = n.valueOf("label/text()");

    if (ret != null) {
        ret.setKey(key);
        ret.setDescription(descr);
    }

    config.addParameter(key, ret);
}

From source file:org.ballproject.knime.base.config.GalaxyNodeConfigurationReader.java

License:Open Source License

private Port readInPort(Node portnode) throws Exception {
    Port port = new Port();

    port.setOptional(true);/*from  w w  w.j a v  a2 s .co m*/

    Node n = DOMHelper.selectSingleNode(portnode, "label");

    String portdescr = n.valueOf("text()");
    port.setDescription(portdescr);

    String extension = DOMHelper.valueOf(portnode, "@format");
    port.addMimeType(new MIMEtype(extension));

    String portname = DOMHelper.valueOf(portnode, "@name");
    port.setName(portname);

    String optional = DOMHelper.valueOf(portnode, "@optional");
    if (optional.equals("false"))
        port.setOptional(false);

    return port;
}

From source file:org.codehaus.mojo.javancss.NcssAggregateReportGenerator.java

License:Apache License

private void doModuleAnalysis(List reports) {
    getSink().table();//from  www  .ja v  a  2  s . co m
    getSink().tableRow();
    headerCellHelper(getString("report.javancss.header.module"));
    headerCellHelper(getString("report.javancss.header.packages"));
    headerCellHelper(getString("report.javancss.header.classetotal"));
    headerCellHelper(getString("report.javancss.header.functiontotal"));
    headerCellHelper(getString("report.javancss.header.ncsstotal"));
    headerCellHelper(getString("report.javancss.header.javadoc"));
    headerCellHelper(getString("report.javancss.header.javadoc_line"));
    headerCellHelper(getString("report.javancss.header.single_comment"));
    headerCellHelper(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 (Iterator it = reports.iterator(); it.hasNext();) {
        ModuleReport report = (ModuleReport) it.next();
        Document document = report.getJavancssDocument();
        getSink().tableRow();
        getLog().debug("Aggregating " + report.getModule().getArtifactId());
        tableCellHelper(report.getModule().getArtifactId());
        int packageSize = document.selectNodes("//javancss/packages/package").size();
        packages += packageSize;
        tableCellHelper(String.valueOf(packageSize));

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

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

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

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

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

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

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

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

        getSink().tableRow_();
    }

    // Totals row
    getSink().tableRow();
    tableCellHelper(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:org.codehaus.mojo.javancss.NcssReportGenerator.java

License:Apache License

private void doMainPackageAnalysis(Document document) {
    subtitleHelper(getString("report.javancss.package.text"));
    getSink().table();/*from   w  w  w  . j a  v  a2 s.  co  m*/
    getSink().tableRow();
    // HEADER
    headerCellHelper(getString("report.javancss.header.package"));
    headerCellHelper(getString("report.javancss.header.classe"));
    headerCellHelper(getString("report.javancss.header.function"));
    headerCellHelper(getString("report.javancss.header.ncss"));
    headerCellHelper(getString("report.javancss.header.javadoc"));
    headerCellHelper(getString("report.javancss.header.javadoc_line"));
    headerCellHelper(getString("report.javancss.header.single_comment"));
    headerCellHelper(getString("report.javancss.header.multi_comment"));
    getSink().tableRow_();
    // DATA
    List list = document.selectNodes("//javancss/packages/package");
    Collections.sort(list, new NumericNodeComparator("ncss"));
    Iterator nodeIterator = list.iterator();
    while (nodeIterator.hasNext()) {
        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:org.codehaus.mojo.javancss.NcssReportGenerator.java

License:Apache License

private void doTotalPackageAnalysis(Document document) {
    getSink().table();// w  w w.  j a  va  2  s  . com
    getSink().tableRow();
    headerCellHelper(getString("report.javancss.header.classetotal"));
    headerCellHelper(getString("report.javancss.header.functiontotal"));
    headerCellHelper(getString("report.javancss.header.ncsstotal"));
    headerCellHelper(getString("report.javancss.header.javadoc"));
    headerCellHelper(getString("report.javancss.header.javadoc_line"));
    headerCellHelper(getString("report.javancss.header.single_comment"));
    headerCellHelper(getString("report.javancss.header.multi_comment"));
    getSink().tableRow_();
    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:org.codehaus.mojo.javancss.NcssReportGenerator.java

License:Apache License

private void doTopObjectGeneric(List nodeList) {
    getSink().table();/*from  w  w w.  ja  va  2  s .co  m*/
    getSink().tableRow();
    headerCellHelper(getString("report.javancss.header.object"));
    headerCellHelper(getString("report.javancss.header.ncss"));
    headerCellHelper(getString("report.javancss.header.function"));
    headerCellHelper(getString("report.javancss.header.classe"));
    headerCellHelper(getString("report.javancss.header.javadoc"));
    getSink().tableRow_();
    Iterator nodeIterator = nodeList.iterator();
    int i = 0;
    while (nodeIterator.hasNext() && (i++ < lineThreshold)) {
        Node node = (Node) nodeIterator.next();
        getSink().tableRow();
        getSink().tableCell();
        jxrLink(node.valueOf("name"));
        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:org.codehaus.mojo.javancss.NcssReportGenerator.java

License:Apache License

private void doObjectAverage(Document document) {
    subtitleHelper(getString("report.javancss.averages"));
    getSink().table();//from w  ww .  j  a va 2  s . c  o m
    getSink().tableRow();
    headerCellHelper(getString("report.javancss.header.ncssaverage"));
    headerCellHelper(getString("report.javancss.header.programncss"));
    headerCellHelper(getString("report.javancss.header.classeaverage"));
    headerCellHelper(getString("report.javancss.header.functionaverage"));
    headerCellHelper(getString("report.javancss.header.javadocaverage"));
    getSink().tableRow_();
    Node node = document.selectSingleNode("//javancss/objects/averages");
    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_();
}

From source file:org.codehaus.mojo.javancss.NcssReportGenerator.java

License:Apache License

private void doFunctionAnalysis(Document document) {
    subtitleHelper(getString("report.javancss.top") + " " + lineThreshold + " "
            + getString("report.javancss.function.byncss"));
    getSink().table();/*from w ww.ja  v  a  2  s.c  o m*/
    getSink().tableRow();
    headerCellHelper(getString("report.javancss.header.function"));
    headerCellHelper(getString("report.javancss.header.ncss"));
    headerCellHelper(getString("report.javancss.header.ccn"));
    headerCellHelper(getString("report.javancss.header.javadoc"));
    getSink().tableRow_();
    List list = document.selectNodes("//javancss/functions/function");
    Collections.sort(list, new NumericNodeComparator("ncss"));
    Iterator nodeIterator = list.iterator();
    int i = 0;
    while (nodeIterator.hasNext() && (i++ < lineThreshold)) {
        Node node = (Node) nodeIterator.next();
        getSink().tableRow();
        getSink().tableCell();
        jxrFunctionLink(node.valueOf("name"));
        getSink().tableCell_();
        tableCellHelper(node.valueOf("ncss"));
        tableCellHelper(node.valueOf("ccn"));
        tableCellHelper(node.valueOf("javadocs"));
        getSink().tableRow_();
    }
    getSink().table_();
}

From source file:org.codehaus.mojo.javancss.NcssReportGenerator.java

License:Apache License

private void doFunctionAverage(Document document) {
    subtitleHelper(getString("report.javancss.averages"));
    getSink().table();//ww  w . j a v a  2s . c  o m
    getSink().tableRow();
    headerCellHelper(getString("report.javancss.header.programncss"));
    headerCellHelper(getString("report.javancss.header.ncssaverage"));
    headerCellHelper(getString("report.javancss.header.ccnaverage"));
    headerCellHelper(getString("report.javancss.header.javadocaverage"));
    getSink().tableRow_();
    Node node = document.selectSingleNode("//javancss/functions/function_averages");
    String totalNcss = document.selectSingleNode("//javancss/functions/ncss").getText();
    getSink().tableRow();
    tableCellHelper(totalNcss);
    tableCellHelper(node.valueOf("ncss"));
    tableCellHelper(node.valueOf("ccn"));
    tableCellHelper(node.valueOf("javadocs"));
    getSink().tableRow_();
    getSink().table_();
}

From source file:org.codehaus.mojo.javancss.NcssViolationCheckMojo.java

License:Apache License

public void execute() throws MojoExecutionException, MojoFailureException {
    if (sourceDirectory == null || !sourceDirectory.exists()) {
        return;/*www. j  av a  2 s . c o  m*/
    }
    Set ccnViolation = new HashSet();
    Set ncssViolation = new HashSet();
    List methodList = loadDocument().selectNodes("//javancss/functions/function");
    // Count ccn & ncss violations
    Iterator nodeIterator = methodList.iterator();
    while (nodeIterator.hasNext()) {
        Node node = (Node) nodeIterator.next();
        // count ccn violation
        int ccn = new Integer(node.valueOf("ccn")).intValue();
        if (ccn > ccnLimit) {
            ccnViolation.add(node.valueOf("name"));
        }
        // count ncss violation
        int ncss = new Integer(node.valueOf("ncss")).intValue();
        if (ncss > ncssLimit) {
            ncssViolation.add(node.valueOf("name"));
        }
    }
    // crappy....
    reportViolation("ccn", ccnViolation, ccnLimit);
    reportViolation("ncss", ncssViolation, ncssLimit);
}