2 * Copyright (c) 2003 IBM Corporation and others.
3 * All rights reserved. � This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM - Initial API and implementation
11 package net.sourceforge.phpeclipse.webbrowser.internal;
14 import java.util.ArrayList;
15 import java.util.Iterator;
16 import java.util.List;
17 import java.util.StringTokenizer;
19 import org.eclipse.core.runtime.Platform;
20 import org.eclipse.jface.preference.IPreferenceStore;
23 * Preferences for the Web browser.
25 public class WebBrowserPreference {
26 protected static final String PREF_BROWSER_HISTORY = "webBrowserHistory";
28 protected static final String PREF_INTERNAL_WEB_BROWSER_HISTORY = "internalWebBrowserHistory";
30 protected static final String PREF_INTERNAL_WEB_BROWSER_FAVORITES = "internalWebBrowserFavorites";
32 protected static final String PREF_INTERNAL_WEB_BROWSER_OLD_FAVORITES = "internalWebBrowserOldFavorites";
34 protected static final String URL_PARAMETER = "%URL%";
37 * WebBrowserPreference constructor comment.
39 private WebBrowserPreference() {
44 * Returns the URL to the homepage.
46 * @return java.lang.String
48 public static String getHomePageURL() {
50 // get the default home page
51 URL url = WebBrowserUIPlugin.getInstance().getBundle().getEntry(
53 url = Platform.resolve(url);
54 return url.toExternalForm();
55 } catch (Exception e) {
56 return "http://www.eclipse.org";
61 * Returns the preference store.
63 * @return org.eclipse.jface.preference.IPreferenceStore
65 protected static IPreferenceStore getPreferenceStore() {
66 return WebBrowserUIPlugin.getInstance().getPreferenceStore();
70 * Returns the Web browser history list.
72 * @return java.util.List
74 public static List getInternalWebBrowserHistory() {
75 String temp = getPreferenceStore().getString(
76 PREF_INTERNAL_WEB_BROWSER_HISTORY);
77 StringTokenizer st = new StringTokenizer(temp, "|*|");
78 List l = new ArrayList();
79 while (st.hasMoreTokens()) {
80 String s = st.nextToken();
87 * Returns the Web browser favorites.
89 * @return java.util.List
91 public static List getInternalWebBrowserFavorites() {
92 String temp = getPreferenceStore().getString(
93 PREF_INTERNAL_WEB_BROWSER_FAVORITES);
94 StringTokenizer st = new StringTokenizer(temp, "|*|");
95 List l = new ArrayList();
97 while (st.hasMoreTokens()) {
98 l.add(new Favorite(st.nextToken(), st.nextToken()));
100 } catch (Exception e) {
107 * Initialize the default preferences.
109 public static void initializeDefaultPreferences() {
110 IPreferenceStore store = getPreferenceStore();
112 String temp = store.getString(PREF_INTERNAL_WEB_BROWSER_OLD_FAVORITES);
113 StringTokenizer st = new StringTokenizer(temp, "|*|");
114 List def = new ArrayList();
116 while (st.hasMoreTokens()) {
117 def.add(new Favorite(st.nextToken(), st.nextToken()));
119 } catch (Exception e) {
122 List list = getInternalWebBrowserFavorites();
123 Iterator iterator = WebBrowserUtil.getUnlockedFavorites().iterator();
124 while (iterator.hasNext()) {
125 Favorite f = (Favorite) iterator.next();
126 if (!def.contains(f))
129 setInternalWebBrowserFavorites(list);
131 StringBuffer sb = new StringBuffer();
132 iterator = WebBrowserUtil.getUnlockedFavorites().iterator();
133 while (iterator.hasNext()) {
134 Favorite f = (Favorite) iterator.next();
135 sb.append(f.getName());
137 sb.append(f.getURL());
140 store.setValue(PREF_INTERNAL_WEB_BROWSER_OLD_FAVORITES, sb.toString());
141 WebBrowserUIPlugin.getInstance().savePluginPreferences();
145 * Sets the Web browser history.
147 * @param java.util.List
149 public static void setInternalWebBrowserHistory(List list) {
150 StringBuffer sb = new StringBuffer();
152 Iterator iterator = list.iterator();
153 while (iterator.hasNext()) {
154 String s = (String) iterator.next();
159 getPreferenceStore().setValue(PREF_INTERNAL_WEB_BROWSER_HISTORY,
161 WebBrowserUIPlugin.getInstance().savePluginPreferences();
165 * Sets the Web browser favorites.
167 * @param java.util.List
169 public static void setInternalWebBrowserFavorites(List list) {
170 StringBuffer sb = new StringBuffer();
172 Iterator iterator = list.iterator();
173 while (iterator.hasNext()) {
174 Favorite f = (Favorite) iterator.next();
175 sb.append(f.getName());
177 sb.append(f.getURL());
181 getPreferenceStore().setValue(PREF_INTERNAL_WEB_BROWSER_FAVORITES,
183 WebBrowserUIPlugin.getInstance().savePluginPreferences();