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

/**
 * //w  ww.  ja v a 2s.com
 * @param matches
 * @param userName
 * @param labels
 */
// @SuppressWarnings("unused")
public void constructViewLinks(ArrayList<Bookmark> matches, String userName, ArrayList<String> labels) {
    if (!userName.equals("SessionDummy") && !userName.equals("SessionDummyChanged")) {
        Element root = xmlDoc.addElement(XML);

        Element loggedInAs = root.addElement("LoggedInAs").addText(userName);

        Element allLabelList = root.addElement("AllLabelList");

        Iterator<String> labelsIter = labels.iterator();
        while (labelsIter.hasNext()) {
            String curLabel = labelsIter.next();
            Element label = allLabelList.addElement("Label").addAttribute("name", curLabel);
        }

        Element bookmarkList = root.addElement("BookmarkList");

        for (Iterator<Bookmark> it = matches.iterator(); it.hasNext();) {
            Bookmark x = it.next();

            Integer bookmarkID = new Integer(x.getLinkID());
            Element bookmark = bookmarkList.addElement("Bookmark").addAttribute("id", bookmarkID.toString())
                    .addAttribute("permission", x.getLinkPermission());

            Element title = bookmark.addElement("Title").addText(x.getLinkName());

            Element url = bookmark.addElement("Link").addText(x.getLinkURL());

            Element description = bookmark.addElement("Description").addText(x.getLinkDescription());

            Element labelList = bookmark.addElement("LabelList");

            labelsIter = x.getLabels();
            while (labelsIter.hasNext()) {
                String curLabel = (String) labelsIter.next();
                Element label = labelList.addElement("Label").addAttribute("name", curLabel);
            }

            Element toolbarPosition = bookmark.addElement("ToolbarPosition")
                    .addText(String.valueOf(x.getToolbarPosition()));
        }
    }
}

From source file:bookmarks.BookmarkXML.java

License:Open Source License

/**
 * /*from   w  ww.  j av a 2 s.c  o m*/
 * @param matches
 * @param userName
 * @param labels
 * @param msg
 * @param rejects
 * @param search
 */
public void constructSearchUser(ArrayList<Bookmark> matches, String userName, String search) {
    if (!userName.equals("SessionDummy") && !userName.equals("SessionDummyChanged")) {
        Element root = xmlDoc.addElement(XML);

        root.addElement("LoggedInAs").addText(userName);

        root.addElement("SearchString").addText(search);

        if (matches.size() > 0) {
            root.addElement("Message").addText("");
        }

        else {
            root.addElement("Message").addText("Your search for '" + search + "' yielded no results.");
        }

        // Element allLabelList = root.addElement("AllLabelList");

        Iterator labelsIter;// = labels.iterator();
        /*
         * while(labelsIter.hasNext()){ String curLabel =
         * (String)labelsIter.next();
         * allLabelList.addElement("Label").addAttribute("name", curLabel);
         * }
         */

        Element bookmarkList = root.addElement("BookmarkList");

        for (Iterator<Bookmark> it = matches.iterator(); it.hasNext();) {
            Bookmark x = it.next();

            Integer bookmarkID = new Integer(x.getLinkID());
            Element bookmark = bookmarkList.addElement("Bookmark").addAttribute("id", bookmarkID.toString())
                    .addAttribute("permission", x.getLinkPermission());

            bookmark.addElement("Title").addText(x.getLinkName());

            bookmark.addElement("Link").addText(x.getLinkURL());

            bookmark.addElement("Description").addText(x.getLinkDescription());

            Element labelList = bookmark.addElement("LabelList");

            labelsIter = x.getLabels();
            while (labelsIter.hasNext()) {
                String curLabel = (String) labelsIter.next();
                labelList.addElement("Label").addAttribute("name", curLabel);
            }

            bookmark.addElement("ToolbarPosition").addText(String.valueOf(x.getToolbarPosition()));
        }

    }
}

From source file:bookmarks.BookmarkXML.java

License:Open Source License

/**
 * /*from   w w  w  .j a  v a2 s  .c o m*/
 * @param userName
 * @param numberOfUsers
 * @param matches
 */
@SuppressWarnings("unused")
public void constructTop10Bookmarked(String userName, int numberOfUsers, ArrayList<TopBookmarkInfo> matches) {
    Element root = xmlDoc.addElement(XML);

    if (numberOfUsers == 0) {
        numberOfUsers = 1;
    }

    int length = String.valueOf(numberOfUsers).length();

    Element loggedInAs = root.addElement("LoggedInAs").addText(userName);

    Element bookmarkList = root.addElement("BookmarkList");

    for (Iterator<TopBookmarkInfo> it = matches.iterator(); it.hasNext();) {
        TopBookmarkInfo x = it.next();

        Element bookmark = bookmarkList.addElement("Bookmark");

        if (!userName.equals("")) {
            bookmark.addElement("LoggedIn");
        }

        Element url = bookmark.addElement("Link").addText(x.getLinkURL());

        Element encodedUrl = bookmark.addElement("EncodedLink")
                .addText(Utilities.encodeURIComponent(x.getLinkURL()));

        Element hitcount = bookmark.addElement("HitCount").addText(String.valueOf(x.getRepetitions()));

        Element hitcountsort = bookmark.addElement("HitCountToSortBy")
                .addText(paddedValueOf(x.getRepetitions(), length, '0'));

        Element rank = bookmark.addElement("Rank").addText(String.valueOf(x.getRank()));

        Element numberOfUsers_e = bookmark.addElement("NumberOfUsers").addText(String.valueOf(numberOfUsers));

        Element percentage = bookmark.addElement("Percentage")
                .addText(String.valueOf((x.getRepetitions() * 100) / numberOfUsers));

    }
}

From source file:bookmarks.BookmarkXML.java

License:Open Source License

/**
 * /*www .j a v  a 2s. c om*/
 * @param links
 * @param folders
 * @param labels
 */
@SuppressWarnings("unused")
public void constructFoldersAndLinks(ArrayList<Bookmark> links, ArrayList<Folder> folders,
        ArrayList<String> labels) {
    Element root = xmlDoc.addElement(XML);

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

    Element allLabelList = root.addElement("AllLabelList");

    Iterator<String> labelsIter = labels.iterator();
    while (labelsIter.hasNext()) {
        String curLabel = labelsIter.next();
        Element label = allLabelList.addElement("Label").addAttribute("name", curLabel);
    }

    Element bookmarkList = root.addElement("BookmarkList");

    for (Iterator<Bookmark> it = links.iterator(); it.hasNext();) {
        Bookmark x = it.next();

        Integer bookmarkID = new Integer(x.getLinkID());
        Element bookmark = bookmarkList.addElement("Bookmark").addAttribute("id", bookmarkID.toString())
                .addAttribute("permission", x.getLinkPermission());

        Element title = bookmark.addElement("Title").addText(stripNonValidXMLCharacters(x.getLinkName()));

        Element url = bookmark.addElement("Link").addText(x.getLinkURL());

        Element description = bookmark.addElement("Description")
                .addText(stripNonValidXMLCharacters(x.getLinkDescription()));

        Element labelList = bookmark.addElement("LabelList");

        labelsIter = x.getLabels();
        while (labelsIter.hasNext()) {
            String curLabel = labelsIter.next();
            Element label = labelList.addElement("Label").addAttribute("name", curLabel);
        }

        Element linkFolderParentID = bookmark.addElement("linkFolderParentID")
                .addText(String.valueOf(x.getLinkFolderParentID()));

        Element icon = bookmark.addElement("Icon").addText("");

        Element toolbarPosition = bookmark.addElement("ToolbarPosition")
                .addText(stripNonValidXMLCharacters(String.valueOf(x.getToolbarPosition())));
    }

    Element folderList = root.addElement("FolderList");

    for (Iterator<Folder> it = folders.iterator(); it.hasNext();) {
        Folder x = it.next();

        Element folder = folderList.addElement("Folder").addAttribute("id", String.valueOf(x.getFolderID()))
                .addAttribute("parent", String.valueOf(x.getFolderParentID()))
                .addAttribute("type", x.getFolderType());

        Element folderID = folder.addElement("FolderName").addText(Utilities.eliminateNull(x.getFolderName()));
        Element subbedUsers = folder.addElement("SubscribedUsers");
        if (x.subscribedUsers != null) {
            for (int i = 0; i < x.subscribedUsers.length; i++) {
                subbedUsers.addElement("username").addText(x.subscribedUsers[i]);
            }
        }
        Element toolbarPosition = folder.addElement("ToolbarPosition")
                .addText(Utilities.eliminateNull(String.valueOf(x.getToolbarPosition())));
    }
}

From source file:bookmarks.BookmarkXML.java

License:Open Source License

/**
 * /*  w  ww.  j a  v  a  2 s. c  o  m*/
 * @param result
 * @param message
 */
@SuppressWarnings("unused")
public void constructNodeAction(String result, String message) {
    Element root = xmlDoc.getRootElement();

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

    root = xmlDoc.addElement(XML);
    Element resultE = root.addElement("Result").addText(result);
    Element messageE = root.addElement("Message").addText(message);
}

From source file:bookmarks.BookmarkXML.java

License:Open Source License

/**
 * Constructs a Node Action success//w ww  .j a v  a 2 s . com
 */
@SuppressWarnings("unused")
public void constructNodeActionSuccess() {
    Element root = xmlDoc.getRootElement();

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

    root = xmlDoc.addElement(XML);
    Element resultE = root.addElement("Result").addText(SUCCESS);
    Element messageE = root.addElement("Message").addText("");
}

From source file:bookmarks.BookmarkXML.java

License:Open Source License

/**
 * /*from www  .  j a  v  a 2 s .c  o m*/
 * Constructs a Node Action failure
 * 
 * @param message
 */
@SuppressWarnings("unused")
public void constructNodeActionFailure(String message) {
    Element root = xmlDoc.getRootElement();

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

    root = xmlDoc.addElement(XML);
    Element resultE = root.addElement("Result").addText(FAILURE);
    Element messageE = root.addElement("Message").addText(message);
}

From source file:bookmarks.BookmarkXML.java

License:Open Source License

/**
 * This will create an generic success message.
 *///from  www .jav a 2 s . c  o  m
public void constructGenericSuccess() {
    Document document = this.xmlDoc;
    Element root = document.addElement(XML);
    Element status = root.addElement("result");

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

From source file:bookmarks.BookmarkXML.java

License:Open Source License

/**
 * //from   w  w  w. j a va 2s  .  com
 * This will create an generic failure message.
 * 
 * @param message
 */
public void constructGenericFailure(String errMessage) {
    Document document = this.xmlDoc;
    Element root = document.addElement(XML);
    Element status = root.addElement("result");

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

From source file:bookmarks.BookmarkXML.java

License:Open Source License

/**
 * //ww w  .j ava  2s .c  om
 * @param userName
 */
@SuppressWarnings("unused")
public void constructExport(String userName) {
    if (!userName.equals("SessionDummy") && !userName.equals("SessionDummyChanged")) {
        Element root = xmlDoc.addElement(XML);

        Element loggedInAs = root.addElement("LoggedInAs").addText(userName);
    }
}