/** * $Revision$ * $Date$ * * Copyright 2003-2007 Jive Software. * * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jivesoftware.smackx.bookmark; import org.jivesoftware.smackx.packet.PrivateData; import org.jivesoftware.smackx.provider.PrivateDataProvider; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; import java.io.IOException; import java.util.ArrayList; import java.util.Iterator; import java.util.List; /** * Bookmarks is used for storing and retrieving URLS and Conference rooms. * Bookmark Storage (JEP-0048) defined a protocol for the storage of bookmarks to conference rooms and other entities * in a Jabber user's account. * See the following code sample for saving Bookmarks: *
*
* XMPPConnection con = new XMPPConnection("jabber.org");
* con.login("john", "doe");
* Bookmarks bookmarks = new Bookmarks();
*
* // Bookmark a URL
* BookmarkedURL url = new BookmarkedURL();
* url.setName("Google");
* url.setURL("http://www.jivesoftware.com");
* bookmarks.addURL(url);
* // Bookmark a Conference room.
* BookmarkedConference conference = new BookmarkedConference();
* conference.setName("My Favorite Room");
* conference.setAutoJoin("true");
* conference.setJID("dev@conference.jivesoftware.com");
* bookmarks.addConference(conference);
* // Save Bookmarks using PrivateDataManager.
* PrivateDataManager manager = new PrivateDataManager(con);
* manager.setPrivateData(bookmarks);
*
*
* LastActivity activity = LastActivity.getLastActivity(con, "xray@jabber.org");
*
*
* @author Derek DeMoro
*/
public class Bookmarks implements PrivateData {
private List bookmarkedURLS;
private List bookmarkedConferences;
/**
* Required Empty Constructor to use Bookmarks.
*/
public Bookmarks() {
bookmarkedURLS = new ArrayList();
bookmarkedConferences = new ArrayList();
}
/**
* Adds a BookmarkedURL.
*
* @param bookmarkedURL the bookmarked bookmarkedURL.
*/
public void addBookmarkedURL(BookmarkedURL bookmarkedURL) {
bookmarkedURLS.add(bookmarkedURL);
}
/**
* Removes a bookmarked bookmarkedURL.
*
* @param bookmarkedURL the bookmarked bookmarkedURL to remove.
*/
public void removeBookmarkedURL(BookmarkedURL bookmarkedURL) {
bookmarkedURLS.remove(bookmarkedURL);
}
/**
* Removes all BookmarkedURLs from user's bookmarks.
*/
public void clearBookmarkedURLS() {
bookmarkedURLS.clear();
}
/**
* Add a BookmarkedConference to bookmarks.
*
* @param bookmarkedConference the conference to remove.
*/
public void addBookmarkedConference(BookmarkedConference bookmarkedConference) {
bookmarkedConferences.add(bookmarkedConference);
}
/**
* Removes a BookmarkedConference.
*
* @param bookmarkedConference the BookmarkedConference to remove.
*/
public void removeBookmarkedConference(BookmarkedConference bookmarkedConference) {
bookmarkedConferences.remove(bookmarkedConference);
}
/**
* Removes all BookmarkedConferences from Bookmarks.
*/
public void clearBookmarkedConferences() {
bookmarkedConferences.clear();
}
/**
* Returns a Collection of all Bookmarked URLs for this user.
*
* @return a collection of all Bookmarked URLs.
*/
public List getBookmarkedURLS() {
return bookmarkedURLS;
}
/**
* Returns a Collection of all Bookmarked Conference for this user.
*
* @return a collection of all Bookmarked Conferences.
*/
public List getBookmarkedConferences() {
return bookmarkedConferences;
}
/**
* Returns the root element name.
*
* @return the element name.
*/
public String getElementName() {
return "storage";
}
/**
* Returns the root element XML namespace.
*
* @return the namespace.
*/
public String getNamespace() {
return "storage:bookmarks";
}
/**
* Returns the XML reppresentation of the PrivateData.
*
* @return the private data as XML.
*/
public String toXML() {
StringBuilder buf = new StringBuilder();
buf.append("