Example usage for org.dom4j DocumentHelper createText

List of usage examples for org.dom4j DocumentHelper createText

Introduction

In this page you can find the example usage for org.dom4j DocumentHelper createText.

Prototype

public static Text createText(String text) 

Source Link

Usage

From source file:com.liferay.portal.xml.SAXReaderImpl.java

License:Open Source License

public Text createText(String text) {
    return new TextImpl(DocumentHelper.createText(text));
}

From source file:com.xebia.mojo.dashboard.reports.html.CheckstyleDashboardReport.java

License:Apache License

/** {@inheritDoc} */
protected Node postProcess(MavenProject subProject, Node node, int column) throws MojoExecutionException {
    Node n = xmlUtil.getChild(node, column);

    if (n instanceof Element) {
        n = DocumentHelper.createText(((Element) n).getText());
    }/*  w  w  w .j ava  2 s.co  m*/

    return n;
}

From source file:com.xebia.mojo.dashboard.reports.html.CoberturaDashboardReport.java

License:Apache License

/** {@inheritDoc} */
protected Node postProcess(MavenProject subProject, Node contentNode, int column)
        throws MojoExecutionException {
    switch (column) {
    case 0:/*from www. j a  v  a  2 s  .c  o  m*/
    case 1:

        Element graph = xmlUtil.findElement(contentNode, ".//div[@class='percentgraph']");

        // Need to distinguish between plugin versions. If no graph found, try to locate
        // alternate location.
        if (graph != null) {
            HtmlUtil.addStyles(graph,
                    "background-color:#F02020; border:1px solid #808080; height:1.3em; padding:0px; width:100px; border-collapse:collapse;");

            Element bar = xmlUtil.findElement(graph, "div[@class='greenbar']");

            // Possibly no green bar, because no coverage.
            Element text = null;

            if (bar != null) {
                HtmlUtil.addStyles(bar,
                        "background-color:#00F000; height:1.3em; padding:0px; border-collapse:collapse; ");
                text = xmlUtil.findElement(bar, "span[@class='text']");
            } else {
                text = xmlUtil.findElement(graph, "span[@class='text']");
            }

            HtmlUtil.addStyles(text,
                    "display:block; position:absolute; text-align:center; width:100px; border-collapse:collapse;");
            HtmlUtil.removeClassAttributes(contentNode);

            break;
        } else {
            log.info("Old version Cobertura report plugin used.");
            graph = xmlUtil.findElement(contentNode, ".//table[@class='percentGraph']");

            if (graph != null) {
                HtmlUtil.addStyles(graph, "width: 100px;");

                Element greenBar = xmlUtil.findElement(graph, ".//td[@class='covered']");
                HtmlUtil.addStyles(greenBar,
                        "background-color:#00F000; height:1.3em; padding:0px; border-collapse:collapse; ");

                Element redBar = xmlUtil.findElement(graph, ".//td[@class='uncovered']");
                HtmlUtil.addStyles(redBar,
                        "background-color:#F02020; border:1px solid #808080; height:1.3em; padding:0px; border-collapse:collapse;");
                HtmlUtil.removeClassAttributes(contentNode);

                break;
            } else {
                log.error("Cobertura report found, but cannot extract data from it.");
            }
        }

    default:
        return DocumentHelper.createText(XmlUtil.NBSP);
    }

    return contentNode;
}

From source file:com.xebia.mojo.dashboard.reports.html.CpdDashboardReport.java

License:Apache License

/**
 * Method overridden because the super findNode cannot be used, we use a xpath function. The super class uses
 * {@link TidyXmlUtil#findElement(Node, String)} which cannot handle xpath functions.
 *///from  w  w w . ja  va2s . c o  m
protected Node findNode(MavenProject subProject, String xpath) throws MojoExecutionException {
    Document document = xmlUtil.readXhtmlDocument(getReportFile(subProject));

    return DocumentHelper.createText(DashboardUtil.executeXpathFunctionOnDocument(document, xpath));
}

From source file:com.xebia.mojo.dashboard.reports.html.TaglistDashboardReport.java

License:Apache License

/** {@inheritDoc} */
protected Node postProcess(MavenProject subProject, Node contentNode, int column)
        throws MojoExecutionException {
    List rows = contentNode.selectNodes("tr");
    int count = 0;

    for (Iterator it = rows.iterator(); it.hasNext();) {
        Node row = (Element) it.next();
        List cells = row.selectNodes("td");

        if (!cells.isEmpty() && (cells.size() > 1)) {
            String text = ((Element) cells.get(1)).getText();
            count += Integer.parseInt(text);
        }//from w  ww .ja  v  a 2s.  co m
    }

    return DocumentHelper.createText(String.valueOf(count));
}

From source file:com.xebia.mojo.dashboard.reports.xml.ChangelogDashboardReport.java

License:Apache License

/** {@inheritDoc} */
public Node getContent(MavenProject subProject, int column) throws MojoExecutionException {
    String xpath = null;/*from  w w w  . ja v  a 2  s.  c  o m*/

    switch (column) {
    case 0:
        xpath = "count(//changelog-entry)";
        break;

    case 1:
        xpath = "count(//file)";
        break;

    default:
        return DocumentHelper.createText(XmlUtil.NBSP);
    }

    Document document = xmlUtil.readXmlDocument(getReportFile(subProject));

    return DocumentHelper.createText(DashboardUtil.executeXpathFunctionOnDocument(document, xpath));
}

From source file:com.xebia.mojo.dashboard.reports.xml.FindBugsDashboardReport.java

License:Apache License

/** {@inheritDoc} */
public Node getContent(MavenProject subProject, int column) throws MojoExecutionException {
    String xpath = null;//from  w  ww.j av a 2  s  .  c  o m

    switch (column) {
    case 0:
        xpath = "count(//file)";
        break;

    case 1:
        xpath = "count(//BugInstance)";
        break;

    default:
        return DocumentHelper.createText(XmlUtil.NBSP);
    }

    Document document = xmlUtil.readXmlDocument(getReportFile(subProject));

    return DocumentHelper.createText(DashboardUtil.executeXpathFunctionOnDocument(document, xpath));
}

From source file:com.xebia.mojo.dashboard.reports.xml.JDependDashboardReport.java

License:Apache License

/** {@inheritDoc} */
public Node getContent(MavenProject subProject, int column) throws MojoExecutionException {
    String xpath = null;//from   w w w .j a  v  a2 s .co  m

    switch (column) {
    case 0:
        xpath = "sum(//Package/Stats/TotalClasses)";
        break;

    case 1:
        xpath = "sum(//Package/Stats/ConcreteClasses)";
        break;

    case 2:
        xpath = "sum(//Package/Stats/AbstractClasses)";
        break;

    case 3:
        xpath = "sum(//Package/Stats/Ca)";
        break;

    case 4:
        xpath = "sum(//Package/Stats/Ce)";
        break;

    case 5:
        xpath = "count(//Cycles/Package)";
        break;

    default:
        return DocumentHelper.createText(XmlUtil.NBSP);
    }

    Document document = xmlUtil.readXmlDocument(getReportFile(subProject));

    return DocumentHelper.createText(DashboardUtil.executeXpathFunctionOnDocument(document, xpath));

}

From source file:com.xebia.mojo.dashboard.reports.xml.NcssDashboardReport.java

License:Apache License

/** {@inheritDoc} */
public Node getContent(MavenProject subProject, int column) throws MojoExecutionException {
    Node value = null;//from  w w w  .ja v a  2s. c  om
    Document document = xmlUtil.readXmlDocument(getReportFile(subProject));

    switch (column) {
    case 0:

        String xpath = "count(//packages/package)";
        value = DocumentHelper.createText(DashboardUtil.executeXpathFunctionOnDocument(document, xpath));
        break;

    case 1:
        value = document.selectSingleNode("//total/classes/text()");
        break;

    case 2:
        value = document.selectSingleNode("//total/functions/text()");
        break;

    case 3:
        value = document.selectSingleNode("//total/ncss/text()");
        break;

    case 4:
        value = document.selectSingleNode("//total/javadocs/text()");
        break;

    default:
        value = DocumentHelper.createText(XmlUtil.NBSP);
    }

    return value;
}

From source file:com.xebia.mojo.dashboard.reports.xml.PmdDashboardReport.java

License:Apache License

/** {@inheritDoc} */
public Node getContent(MavenProject subProject, int column) throws MojoExecutionException {
    String xpath = null;//from www .j a va  2s .c  o m

    switch (column) {
    case 0:
        xpath = "count(//file)";
        break;

    case 1:
        xpath = "count(//violation)";
        break;

    default:
        return DocumentHelper.createText(XmlUtil.NBSP);
    }

    Document document = xmlUtil.readXmlDocument(getReportFile(subProject));

    return DocumentHelper.createText(DashboardUtil.executeXpathFunctionOnDocument(document, xpath));
}