KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > help > internal > webapp > data > BookmarksData


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.help.internal.webapp.data;
12
13 import javax.servlet.ServletContext JavaDoc;
14 import javax.servlet.http.*;
15
16 import org.eclipse.help.IHelpResource;
17 import org.eclipse.help.internal.base.*;
18
19 /**
20  * This class manages bookmarks.
21  */

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 JavaDoc 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 JavaDoc bookmarkURL = request.getParameter("bookmark"); //$NON-NLS-1$
49
if (bookmarkURL != null && bookmarkURL.length() > 0
50                 && !bookmarkURL.equals("about:blank")) { //$NON-NLS-1$
51
String JavaDoc title = request.getParameter("title"); //$NON-NLS-1$
52
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 JavaDoc bookmarkURL = request.getParameter("bookmark"); //$NON-NLS-1$
62
if (bookmarkURL != null && bookmarkURL.length() > 0
63                 && !bookmarkURL.equals("about:blank")) { //$NON-NLS-1$
64
String JavaDoc title = request.getParameter("title"); //$NON-NLS-1$
65
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         // sanity test for infocenter, but this could not work anyway...
80
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 JavaDoc op = request.getParameter("operation"); //$NON-NLS-1$
95
if ("add".equals(op)) //$NON-NLS-1$
96
return ADD;
97         else if ("remove".equals(op)) //$NON-NLS-1$
98
return REMOVE;
99         else if ("removeAll".equals(op)) //$NON-NLS-1$
100
return REMOVE_ALL;
101         else
102             return NONE;
103     }
104 }
105
Popular Tags