Example usage for org.dom4j Element addText

List of usage examples for org.dom4j Element addText

Introduction

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

Prototype

Element addText(String text);

Source Link

Document

Adds a new Text node with the given text to this element.

Usage

From source file:itensil.workflow.track.TrackingXML.java

License:Open Source License

public void appendStepCounts(Branch parent) throws StateException {
    Element setElem = parent.addElement("step-counts");
    for (Map.Entry<String, Integer> sc : stateReport.countBySteps().entrySet()) {
        Element elem = setElem.addElement("count");
        elem.addAttribute("id", sc.getKey());
        elem.addText(sc.getValue().toString());
    }//from w  w w  .j a va  2 s.  co  m
}

From source file:jetsennet.orm.tableinfo.mapping.XmlReader.java

License:Apache License

@Override
public Element read(String itemname, ResultSet result, ResultSetMetaData rsmd) throws Exception {
    Element dataElement = DocumentHelper.createElement(itemname);
    int count = rsmd.getColumnCount();
    for (int i = 1; i <= count; i++) {
        String columnName = rsmd.getColumnLabel(i);
        if (null == columnName || 0 == columnName.length()) {
            columnName = rsmd.getColumnName(i);
        }//from  w ww  .  j  av a 2  s  . c  om
        int columnType = rsmd.getColumnType(i);
        Element curElement = dataElement.addElement(columnName);
        String val = getValue(result, i, columnType);
        if (val != null) {
            curElement.addText(val);
        }
    }
    return dataElement;
}

From source file:jt56.comm.code.util.WolfXmlUtil.java

License:Open Source License

private void getAddStrutsElemant(String filePath, String nodexPath) throws Exception {
    Document document = getPath(filePath, "utf-8");
    Element element = document.getRootElement();
    Element nextElement = element.element("package");
    Element newElement = nextElement.addElement("action");
    newElement.addComment("");
    newElement.addAttribute("name", "test");
    newElement.addAttribute("class", "");
    newElement.addAttribute("method", "");
    newElement.addText("hello");
}

From source file:jt56.comm.code.util.WolfXmlUtil.java

License:Open Source License

public void getAddNode(String filePath, String xPath, String newNode, Map<String, String> attrMap, String text)
        throws Exception {
    if (getQueryNode(filePath, xPath, newNode, attrMap, text) < 1) {
        Document document = getPath(filePath, "UTF-8");
        List list = document.selectNodes(xPath);
        System.out.println(xPath);
        Element element = (Element) list.get(0);
        Element newElement = element.addElement(newNode);
        for (Map.Entry entry : attrMap.entrySet()) {
            newElement.addAttribute((String) entry.getKey(), (String) entry.getValue());
        }/*from   w  ww.  j ava 2 s.  com*/
        if ((text != null) && (text.trim().length() > 0)) {
            newElement.addText(text);
        }
        getXMLWrite(document, filePath);
        System.out.println("" + xPath + "?");
    } else {
        System.out.println("");
    }
}

From source file:lost.tok.Author.java

License:Open Source License

/**
 * Creating an author XML element/*  www .  j av a2s.  co  m*/
 * 
 * @return Element of Author
 */
public Element toXML() {
    Element e = DocumentHelper.createElement("author"); //$NON-NLS-1$
    e.addText(getName());

    return e;
}

From source file:lost.tok.html.DiscConflictPage.java

License:Open Source License

@Override
protected String getBody() {
    Element body = DocumentHelper.createElement("div"); //$NON-NLS-1$
    body.addAttribute("id", "conflict"); //$NON-NLS-1$ //$NON-NLS-2$
    body.addAttribute("class", "main_content"); //$NON-NLS-1$ //$NON-NLS-2$

    // main title of Discussion conflict page
    body.addElement("h1").addText(Messages.getString("DiscConflictPage.ChooseDiscussion")); //$NON-NLS-1$ //$NON-NLS-2$

    for (int i = 0; i < info.size(); i++) {
        // 1. extract information from the info object
        DiscussionPage dPage = info.getDPage(i);
        Link link = info.getLink(i);//from w  w w  . jav  a 2s.  c o  m
        Discussion disc = link.getLinkedDiscussion();
        String text = info.getLinkText(i);

        // 2. Add the i'th discussion title
        Element div = body.addElement("div"); //$NON-NLS-1$
        div.addElement("h2").addText(link.getDisplayLinkType() + ": " + link.getSubject()); //$NON-NLS-1$ //$NON-NLS-2$

        // 3. Add the i'th excerption's text
        Element quoteElm = div.addElement("blockquote"); //$NON-NLS-1$
        quoteElm.addAttribute("class", "sublink"); //$NON-NLS-1$ //$NON-NLS-2$
        quoteElm.addAttribute("cite", getPathTo(dPage)); //$NON-NLS-1$
        quoteElm.addElement("p").addText(text); //$NON-NLS-1$

        // 4. Add the link to the discussion + creator's name
        Element p = div.addElement("p"); //$NON-NLS-1$
        Element linkElm = p.addElement("a"); //$NON-NLS-1$
        linkElm.addAttribute("href", getPathTo(dPage)); //$NON-NLS-1$
        linkElm.addText(disc.getDiscName());
        p.addText(Messages.getString("DiscConflictPage.CreatedBy")); //$NON-NLS-1$
        p.addElement("em").addText(disc.getCreatorName()); //$NON-NLS-1$
    }

    return GeneralFunctions.elementToString(body);
}

From source file:lost.tok.html.DiscussionPage.java

License:Open Source License

@Override
protected String getBody() {
    Element body = DocumentHelper.createElement("div"); //$NON-NLS-1$
    body.addAttribute("id", "discussion"); //$NON-NLS-1$ //$NON-NLS-2$
    body.addAttribute("class", "main_content"); //$NON-NLS-1$ //$NON-NLS-2$

    body.addElement("h1").addText(disc.getDiscName()); //$NON-NLS-1$

    body.addText(Messages.getString("DiscussionPage.CreatedBy")); //$NON-NLS-1$
    body.addElement("em").addText(disc.getCreatorName()); //$NON-NLS-1$
    body.addElement("p").addText(disc.getDescription()); //$NON-NLS-1$

    if (disc.getLink() != null)
        body.add(getLinkInfoElement());//from  w w  w . ja va  2 s  . c o  m

    Element opinionList = body.addElement("ol"); //$NON-NLS-1$
    for (Opinion o : disc.getOpinions()) {
        Element listItem = opinionList.addElement("li"); //$NON-NLS-1$
        listItem.add(getOpinionElement(o));
    }

    // TODO(Shay, low): Consider adding related root and source files

    return GeneralFunctions.elementToString(body);
}

From source file:lost.tok.html.DiscussionPage.java

License:Open Source License

/**
 * Returns a div element containing all the information related to the discussion's link
 *///  w  ww. ja v a  2s.c o m
private Element getLinkInfoElement() {
    Element div = DocumentHelper.createElement("div"); //$NON-NLS-1$

    Link l = disc.getLink();

    div.addAttribute("class", "linkInfo"); //$NON-NLS-1$ //$NON-NLS-2$
    div.addElement("h2").addText(l.getSubject()); //$NON-NLS-1$
    Element typeElement = div.addElement("p"); //$NON-NLS-1$

    typeElement.addText(Messages.getString("DiscussionPage.linkType")); //$NON-NLS-1$
    typeElement.addElement("em").addText(l.getDisplayLinkType()); //$NON-NLS-1$

    Element sublinksList = div.addElement("ul"); //$NON-NLS-1$
    for (SubLink sl : l.getSubLinkList()) {
        LinkedList<Excerption> excerptions = new LinkedList<Excerption>();
        for (Excerption e : sl.getExcerption())
            excerptions.add(e);

        String eText = Excerption.concat(excerptions);
        Source src = sl.getLinkedSource();

        Element listItem = sublinksList.addElement("li"); //$NON-NLS-1$

        Element quoteElm = listItem.addElement("blockquote"); //$NON-NLS-1$
        quoteElm.addAttribute("class", "sublink"); //$NON-NLS-1$ //$NON-NLS-2$
        quoteElm.addAttribute("cite", getPathToSrc(src)); //$NON-NLS-1$
        quoteElm.addElement("p").addText(eText); //$NON-NLS-1$

        Element srcLinkParagraph = listItem.addElement("p"); //$NON-NLS-1$
        srcLinkParagraph.addText(Messages.getString("DiscussionPage.Source")).add(getLinkSrcElm(src)); //$NON-NLS-1$
    }

    return div;
}

From source file:lost.tok.html.DiscussionPage.java

License:Open Source License

/**
 * Creates a div element describing the given opinion
 * @param o the opinion to generate html div for
 * @return a div element that contains all the information relating the opinion
 *//*from   w w w . ja v  a 2  s .  co  m*/
private Element getOpinionElement(Opinion o) {
    Element div = DocumentHelper.createElement("div"); //$NON-NLS-1$

    // 1. Create the title
    Element opTitle = div.addElement("h2"); //$NON-NLS-1$
    opTitle.addText(o.getName());
    opTitle.addAttribute("id", "discItem" + o.getId()); //$NON-NLS-1$ //$NON-NLS-2$

    Quote[] quotes = disc.getSortedQuotes(o.getName());

    // add quotes only if there are any
    if (quotes.length > 0) {
        Element quotesList = div.addElement("ul"); //$NON-NLS-1$

        // 2. Add the quotes
        for (Quote q : quotes) {
            // TODO(Shay, medium-low): Sort the quotes according to author importance

            Element listItem = quotesList.addElement("li"); //$NON-NLS-1$
            listItem.add(getQuoteElement(q));
        }
    }
    // TODO(Shay, low): Consider adding relation data

    return div;
}

From source file:lost.tok.html.DiscussionPage.java

License:Open Source License

/**
 * Creates a div element describing the given quote
 * @param q the quote to generate html div for
 * @return a div element that contains all the information relating the quote
 *///from www . ja  v  a  2s.c  o m
private Element getQuoteElement(Quote q) {
    Element div = DocumentHelper.createElement("div"); //$NON-NLS-1$

    // 1. Get the quote's text and find a good title for it
    String qText = q.getText();
    int actualLen = qText.indexOf(' ', QUOTE_TITLE_LENGTH);
    actualLen = (actualLen != -1) ? actualLen : qText.length();
    String qTitle = qText.substring(0, actualLen);

    // 2. Get the src we should link to
    Source src = q.getSource();

    // 3. Add the title
    Element quoteTitle = div.addElement("h3"); //$NON-NLS-1$
    quoteTitle.addText(qTitle);
    quoteTitle.addAttribute("id", "discItem" + q.getID()); //$NON-NLS-1$ //$NON-NLS-2$

    // 4. Add the quote itself
    Element quoteElm = div.addElement("blockquote"); //$NON-NLS-1$
    quoteElm.addAttribute("class", "quote"); //$NON-NLS-1$ //$NON-NLS-2$
    quoteElm.addAttribute("cite", getPathToSrc(src)); //$NON-NLS-1$
    quoteElm.addElement("p").addText(qText); //$NON-NLS-1$

    // 5. Add a comment, if there is one
    if (!q.getComment().equals("")) //$NON-NLS-1$
    {
        Element pComment = div.addElement("p"); //$NON-NLS-1$
        pComment.addText(Messages.getString("DiscussionPage.Comment")); //$NON-NLS-1$
        pComment.addElement("em").addText(q.getComment()); //$NON-NLS-1$

        quoteElm.addAttribute("title", q.getComment()); //$NON-NLS-1$
    }

    // 6. Add a link to the related source
    Element srcLinkParagraph = div.addElement("p"); //$NON-NLS-1$
    srcLinkParagraph.addText(Messages.getString("DiscussionPage.From")).add(getLinkSrcElm(src)); //$NON-NLS-1$

    // TODO(Shay, low): 7. Consider adding relation data

    return div;
}