Example usage for org.dom4j Element addElement

List of usage examples for org.dom4j Element addElement

Introduction

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

Prototype

Element addElement(String name);

Source Link

Document

Adds a new Element node with the given name to this branch and returns a reference to the new node.

Usage

From source file:bookmarks.BookmarkXML.java

License:Open Source License

public void constructBuddyRequests(ArrayList<Buddy> buddyRequests) {
    Element root = xmlDoc.getRootElement();

    if (root != null)
        root.detach();// w  w w. ja va 2s. c o  m

    root = xmlDoc.addElement(XML);
    root.addElement("result").addText(SUCCESS);
    for (int i = 0; i < buddyRequests.size(); i++) {
        Element buddy = root.addElement("buddy");
        buddy.addElement("username").addText(buddyRequests.get(i).username);
    }
}

From source file:bookmarks.BookmarkXML.java

License:Open Source License

/**
 * Creates a xml list using the objects in the array.
 * /*from  ww w .  ja va2  s .c  o  m*/
 * @param objects
 *            An array of strings.
 */
@SuppressWarnings("unused")
public void constructNodeActionList(ArrayList<String> objects) {
    Element root = xmlDoc.getRootElement();

    if (root != null)
        root.detach();

    root = xmlDoc.addElement(XML);

    Element resultE = root.addElement("Result").addText(SUCCESS);

    for (Iterator<String> it = objects.iterator(); it.hasNext();) {
        String x = it.next();

        Element icon = root.addElement("Object").addText(x);

    }

}

From source file:bookmarks.buddylist.BuddyList.java

License:Open Source License

/**
 * /*from  w  w  w.  j  av  a2 s .  c o m*/
 * @return
 * @throws SQLException 
 */
public Document toXml() throws SQLException {
    Buddy curBuddy = null;
    Document buddyList = DocumentHelper.createDocument();
    Element root = buddyList.addElement("buddylist");

    for (int i = 0; i < this.buddies.size(); i++) {
        Element buddy = root.addElement("buddy");
        Element username = buddy.addElement("username");
        Element nickname = buddy.addElement("nickname");

        curBuddy = (Buddy) this.buddies.get(i);
        username.addText(curBuddy.username);
        if (curBuddy.nickname != null)
            nickname.addText(curBuddy.nickname);
    }

    return buddyList;

}

From source file:bookmarks.buddylist.BuddyListServlet.java

License:Open Source License

private Document constructSuccess() {
    Document document = DocumentHelper.createDocument();
    Element root = document.addElement("xml");
    Element status = root.addElement("result");

    status.addElement("status").addText("SUCCESS");
    status.addElement("message");
    return document;
}

From source file:bookmarks.buddylist.BuddyListServlet.java

License:Open Source License

private Document constructFailure(String errMessage) {
    Document document = DocumentHelper.createDocument();
    Element root = document.addElement("xml");
    Element status = root.addElement("result");

    status.addElement("status").addText("FAILURE");
    status.addElement("message").addText(errMessage);
    return document;
}

From source file:br.mdarte.exemplo.academico.cd.CursoDAO.java

public Element xmlExportEntity(AbstractEntity entity, Element raiz) throws DAOException {
    try {/*from w  w w. ja  va2  s . c  o m*/

        CursoImpl obj = (CursoImpl) entity;

        if (obj.getCodigo() != null) {
            Element attcodigo = raiz.addElement("codigo");
            attcodigo.addText(obj.getCodigo().toString());
        }
        if (obj.getNome() != null) {
            Element attnome = raiz.addElement("nome");
            attnome.addText(obj.getNome().toString());
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

    return raiz;
}

From source file:br.mdarte.exemplo.academico.cd.EstudanteDAO.java

public Element xmlExportEntity(AbstractEntity entity, Element raiz) throws DAOException {
    try {/* w ww.j  a v a2 s .  co  m*/

        EstudanteImpl obj = (EstudanteImpl) entity;

        if (obj.getMatricula() != null) {
            Element attmatricula = raiz.addElement("matricula");
            attmatricula.addText(obj.getMatricula().toString());
        }
        if (obj.getNome() != null) {
            Element attnome = raiz.addElement("nome");
            attnome.addText(obj.getNome().toString());
        }

        br.mdarte.exemplo.academico.cd.CursoImpl assEntitycurso = (br.mdarte.exemplo.academico.cd.CursoImpl) obj
                .getCurso();
        Element asscurso = raiz.addElement("curso");
        if (assEntitycurso != null) {
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

    return raiz;
}

From source file:cc.warlock.core.client.settings.internal.HighlightConfigurationProvider.java

License:Open Source License

@Override
protected void saveTo(List<Element> elements) {
    //System.out.println("Saving highlights");
    Element highlightsElement = DocumentHelper.createElement("highlights");

    for (IHighlightString string : highlights) {
        Element hElement = highlightsElement.addElement("highlight");
        fillElement(hElement, string);//from  ww  w  . j  a va  2  s.co m

        createStyleElement(hElement, string.getStyle());
    }

    for (Map.Entry<String, IWarlockStyle> entry : namedStyles.entrySet()) {
        highlightsElement.add(createStyleElement(entry.getValue()));
    }

    elements.add(highlightsElement);
}

From source file:cc.warlock.core.client.settings.internal.HighlightConfigurationProvider.java

License:Open Source License

protected Element createStyleElement(Element parent, IWarlockStyle style) {
    Element element = null;//from  w ww .  j  a  v  a  2 s . c  o m
    if (parent != null) {
        element = parent.addElement("style");
    } else {
        element = DocumentHelper.createElement("style");
    }

    if (style.getName() != null)
        element.addAttribute("name", style.getName());

    element.addAttribute("background", colorString(style.getBackgroundColor()));
    element.addAttribute("foreground", colorString(style.getForegroundColor()));

    for (IWarlockStyle.StyleType styleType : style.getStyleTypes()) {
        Element sElement = element.addElement("styleType");
        sElement.setText(styleType.name());
    }

    element.addAttribute("full-line", "" + style.isFullLine());
    //System.out.println("saving sound " + style.getSound());
    element.addAttribute("sound", style.getSound());
    return element;
}

From source file:cc.warlock.core.client.settings.internal.IgnoreConfigurationProvider.java

License:Open Source License

@Override
protected void saveTo(List<Element> elements) {
    Element ignoresElement = DocumentHelper.createElement("ignores");

    for (IIgnore ignore : ignores) {
        Element iElement = ignoresElement.addElement("ignore");
        fillElement(iElement, ignore);/*from ww  w.  j av  a  2s. com*/
    }

    elements.add(ignoresElement);
}