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

/**
 * @author Brian Terlson/*  ww  w . j  a  va 2 s. c  o m*/
 * @param folders
 *            Shared Folders
 */
public void constructSharedFolderInvites(ArrayList<SharedFolder> folders) {
    Element root = xmlDoc.addElement(XML);
    root.addElement("Result").addText(SUCCESS);
    Element folderList = root.addElement("folders");
    for (int i = 0; i < folders.size(); i++) {
        Element folder = folderList.addElement("folder");
        folder.addElement("name").addText(folders.get(i).getFolderName());
        folder.addElement("id").addText(String.valueOf(folders.get(i).getFolderID()));
        folder.addElement("ownerName").addText(folders.get(i).getOwnerName());
    }
}

From source file:bookmarks.BookmarkXML.java

License:Open Source License

/**
 * /*from  w w w.j av a  2s.c  o m*/
 * @param userName
 * @param bookmarks
 */
public void constructMostRecentlyAdded(String userName, ArrayList<LinkNameUrlObject> bookmarks) {
    Element root = xmlDoc.addElement(XML);

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

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

    for (int i = 0; i < bookmarks.size(); i++) {
        LinkNameUrlObject temp = bookmarks.get(i);

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

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

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

        bookmark.addElement("URL").addText(temp.getLinkURL());

        bookmark.addElement("Date").addText(temp.getLinkDate());

        bookmark.addElement("EncodedLink").addText(Utilities.encodeURIComponent(temp.getLinkURL()));

        bookmark.addElement("EncodedName").addText(Utilities.encodeURIComponent(temp.getLinkName()));

    }
}

From source file:bookmarks.BookmarkXML.java

License:Open Source License

/**
 * //from  w ww  . j av a2s.c o  m
 * @param userName
 * @param bookmarks
 */
public void constructRecommendations(String userName, ArrayList<LinkNameUrlObject> bookmarks) {
    if (!userName.equals("SessionDummy") && !userName.equals("SessionDummyChanged")) {
        Element root = xmlDoc.addElement(XML);

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

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

        for (int i = 0; i < bookmarks.size(); i++) {
            LinkNameUrlObject temp = bookmarks.get(i);

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

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

            if (temp.getLinkName() != null) {
                bookmark.addElement("Title").addText(temp.getLinkName());
            } else {
                bookmark.addElement("Title").addText(temp.getLinkURL());
            }

            bookmark.addElement("URL").addText(temp.getLinkURL());

            bookmark.addElement("EncodedLink").addText(Utilities.encodeURIComponent(temp.getLinkURL()));

            bookmark.addElement("EncodedName").addText(Utilities.encodeURIComponent(temp.getLinkName()));

        }
    }
}

From source file:bookmarks.BookmarkXML.java

License:Open Source License

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

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

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

        String size = "" + bookmarks.size();

        // if (searchString.length() < 3)
        // root.addElement("ResultSize").addText("-1");
        // else
        root.addElement("ResultSize").addText(size);
        root.addElement("SearchString").addText(searchString);

        for (int i = 0; i < bookmarks.size(); i++) {

            Bookmark temp = bookmarks.get(i);

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

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

            bookmark.addElement("URL").addText(temp.getLinkURL());

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

            bookmark.addElement("EncodedLink").addText(Utilities.encodeURIComponent(temp.getLinkURL()));

            bookmark.addElement("EncodedName").addText(Utilities.encodeURIComponent(temp.getLinkName()));

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

    }
}

From source file:bookmarks.BookmarkXML.java

License:Open Source License

public void constructFacebookLogin(String userName) {

    Element root = xmlDoc.addElement(XML);
    root.addElement("ChipmarkUser").addText(userName);

    addXSLTarget("facebookLogin");

}

From source file:bookmarks.BookmarkXML.java

License:Open Source License

/**
 * /*  ww  w  .  ja  v a 2 s. com*/
 * @param userName
 * @param target
 */
public void constructMain(String userName, String target) {
    Element root = xmlDoc.addElement(XML);
    if (userName == null) {
        userName = new String();
    }
    if (!userName.equals("SessionDummy") && !userName.equals("SessionDummyChanged"))
        root.addElement("LoggedInAs").addText(userName);

    if (target != null) {
        root.addElement("Target").addText(target);
    }

}

From source file:bookmarks.BookmarkXML.java

License:Open Source License

/**
 * /* www. j av a  2 s .c om*/
 * @param userName
 * @param count
 * @param target
 */
@SuppressWarnings("unused")
public void constructMainCount(String userName, int count, String target) {
    Element root = xmlDoc.addElement(XML);
    if (userName == null) {
        userName = new String();
    }

    if (!userName.equals("SessionDummy") && !userName.equals("SessionDummyChanged")) {
        Element loggedInAs = root.addElement("LoggedInAs").addText(userName);

        Element userBookmarkCount = root.addElement("userBookmarkCount")
                .addText((new Integer(count)).toString());
    }
    if (target != null) {
        Element targetXml = root.addElement("Target").addText(target);
    }
}

From source file:bookmarks.BookmarkXML.java

License:Open Source License

/**
 * /* w w w.  j av a 2 s. co  m*/
 * @param userName
 * @param errorMsg
 */
@SuppressWarnings("unused")
public void constructLogin(String userName, String errorMsg) {
    Element root = xmlDoc.addElement(XML);

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

    Element errorLog = root.addElement("Error").addText(errorMsg);

}

From source file:bookmarks.BookmarkXML.java

License:Open Source License

/**
 * this is added to fix bug 665/*from   ww  w  .ja va2  s.c o  m*/
 * 
 * @param userName
 * @param linkID
 * @param linkName
 * @param linkURL
 * @param linkPermission
 * @param linkDescription
 * @param linkLabels
 * @param linkToolbarPosition
 * @param error
 */
@SuppressWarnings("unused")
public void constructEditLinkResult(String userName, String linkID, String linkName, String linkURL,
        String linkPermission, String linkDescription, ArrayList linkLabels, String linkToolbarPosition,
        String error) {
    if (!userName.equals("SessionDummy") && !userName.equals("SessionDummyChanged")) {
        Element root = xmlDoc.addElement(XML);

        Element resultError = root.addElement("Result").addText(error);

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

        Element bookmarkElem = root.addElement("Bookmark").addAttribute("id", linkID);

        Element title = bookmarkElem.addElement("Title").addText(linkName);

        Element url = bookmarkElem.addElement("Link").addText(linkURL);

        Element permission = bookmarkElem.addElement("Permission").addText(linkPermission);

        Element description = bookmarkElem.addElement("Description").addText(linkDescription);

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

        if (linkLabels != null) {
            for (int i = 0; i < linkLabels.size(); i++) {
                String curLabel = (String) linkLabels.get(i);
                Element label = labelList.addElement("Label").addAttribute("name", curLabel);
            }
        }

        Element toolbarPosition = bookmarkElem.addElement("ToolbarPosition").addText(linkToolbarPosition);
    }
}

From source file:bookmarks.BookmarkXML.java

License:Open Source License

/**
 * /*from   ww w.jav a 2 s.c  o  m*/
 * @param bookmark
 * @param userName
 */
@SuppressWarnings("unused")
public void constructEditLink(Bookmark bookmark, String userName) {
    if (!userName.equals("SessionDummy") && !userName.equals("SessionDummyChanged")) {
        Element root = xmlDoc.addElement(XML);

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

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

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

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

        Element permission = bookmarkElem.addElement("Permission").addText(bookmark.getLinkPermission());

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

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

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

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