1 11 package org.eclipse.help.internal.webapp.data; 12 13 import javax.servlet.ServletContext ; 14 import javax.servlet.http.*; 15 16 import org.eclipse.help.IHelpResource; 17 import org.eclipse.help.internal.base.*; 18 19 22 public class BookmarksData extends RequestData { 23 public final static int NONE = 0; 24 public final static int ADD = 1; 25 public final static int REMOVE = 2; 26 public final static int REMOVE_ALL = 3; 27 28 public BookmarksData(ServletContext context, HttpServletRequest request, 29 HttpServletResponse response) { 30 super(context, request, response); 31 32 switch (getOperation()) { 33 case ADD : 34 addBookmark(); 35 break; 36 case REMOVE : 37 removeBookmark(); 38 break; 39 case REMOVE_ALL : 40 removeAllBookmarks(); 41 break; 42 default : 43 break; 44 } 45 } 46 47 public void addBookmark() { 48 String bookmarkURL = request.getParameter("bookmark"); if (bookmarkURL != null && bookmarkURL.length() > 0 50 && !bookmarkURL.equals("about:blank")) { String title = request.getParameter("title"); if (title == null) { 53 return; 54 } 55 BookmarkManager manager = BaseHelpSystem.getBookmarkManager(); 56 manager.addBookmark(bookmarkURL, title); 57 } 58 } 59 60 public void removeBookmark() { 61 String bookmarkURL = request.getParameter("bookmark"); if (bookmarkURL != null && bookmarkURL.length() > 0 63 && !bookmarkURL.equals("about:blank")) { String title = request.getParameter("title"); if (title == null) { 66 return; 67 } 68 BookmarkManager manager = BaseHelpSystem.getBookmarkManager(); 69 manager.removeBookmark(bookmarkURL, title); 70 } 71 } 72 73 public void removeAllBookmarks() { 74 BookmarkManager manager = BaseHelpSystem.getBookmarkManager(); 75 manager.removeAllBookmarks(); 76 } 77 78 public Topic[] getBookmarks() { 79 if (BaseHelpSystem.getMode() != BaseHelpSystem.MODE_INFOCENTER) { 81 BookmarkManager manager = BaseHelpSystem.getBookmarkManager(); 82 IHelpResource [] bookmarks = manager.getBookmarks(); 83 Topic [] topics = new Topic[bookmarks.length]; 84 for (int i=0; i<bookmarks.length; i++) { 85 IHelpResource bookmark = bookmarks[i]; 86 topics[i] = new Topic(bookmark.getLabel(), bookmark.getHref()); 87 } 88 return topics; 89 } 90 return new Topic[0]; 91 } 92 93 private int getOperation() { 94 String op = request.getParameter("operation"); if ("add".equals(op)) return ADD; 97 else if ("remove".equals(op)) return REMOVE; 99 else if ("removeAll".equals(op)) return REMOVE_ALL; 101 else 102 return NONE; 103 } 104 } 105 | Popular Tags |