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;
15 import org.eclipse.core.runtime.Platform;
16 import org.eclipse.jface.preference.IPreferenceStore;
18 * Preferences for the Web browser.
20 public class WebBrowserPreference {
21 protected static final String PREF_BROWSER_HISTORY = "webBrowserHistory";
22 protected static final String PREF_INTERNAL_WEB_BROWSER_HISTORY = "internalWebBrowserHistory";
23 protected static final String PREF_INTERNAL_WEB_BROWSER_FAVORITES = "internalWebBrowserFavorites";
24 protected static final String PREF_INTERNAL_WEB_BROWSER_OLD_FAVORITES = "internalWebBrowserOldFavorites";
25 protected static final String URL_PARAMETER = "%URL%";
28 * WebBrowserPreference constructor comment.
30 private WebBrowserPreference() {
35 * Returns the URL to the homepage.
37 * @return java.lang.String
39 public static String getHomePageURL() {
41 // get the default home page
42 URL url = WebBrowserUIPlugin.getInstance().getBundle().getEntry("home/home.html");
43 url = Platform.resolve(url);
44 return url.toExternalForm();
45 } catch (Exception e) {
46 return "http://www.eclipse.org";
51 * Returns the preference store.
53 * @return org.eclipse.jface.preference.IPreferenceStore
55 protected static IPreferenceStore getPreferenceStore() {
56 return WebBrowserUIPlugin.getInstance().getPreferenceStore();
60 * Returns the Web browser history list.
62 * @return java.util.List
64 public static List getInternalWebBrowserHistory() {
65 String temp = getPreferenceStore().getString(PREF_INTERNAL_WEB_BROWSER_HISTORY);
66 StringTokenizer st = new StringTokenizer(temp, "|*|");
67 List l = new ArrayList();
68 while (st.hasMoreTokens()) {
69 String s = st.nextToken();
76 * Returns the Web browser favorites.
78 * @return java.util.List
80 public static List getInternalWebBrowserFavorites() {
81 String temp = getPreferenceStore().getString(PREF_INTERNAL_WEB_BROWSER_FAVORITES);
82 StringTokenizer st = new StringTokenizer(temp, "|*|");
83 List l = new ArrayList();
84 while (st.hasMoreTokens()) {
85 l.add(new Favorite(st.nextToken(), st.nextToken()));
91 * Initialize the default preferences.
93 public static void initializeDefaultPreferences() {
94 IPreferenceStore store = getPreferenceStore();
96 String temp = store.getString(PREF_INTERNAL_WEB_BROWSER_OLD_FAVORITES);
97 StringTokenizer st = new StringTokenizer(temp, "|*|");
98 List def = new ArrayList();
99 while (st.hasMoreTokens()) {
100 def.add(new Favorite(st.nextToken(), st.nextToken()));
103 List list = getInternalWebBrowserFavorites();
104 Iterator iterator = WebBrowserUtil.getUnlockedFavorites().iterator();
105 while (iterator.hasNext()) {
106 Favorite f = (Favorite) iterator.next();
107 if (!def.contains(f))
110 setInternalWebBrowserFavorites(list);
112 StringBuffer sb = new StringBuffer();
113 iterator = WebBrowserUtil.getUnlockedFavorites().iterator();
114 while (iterator.hasNext()) {
115 Favorite f = (Favorite) iterator.next();
116 sb.append(f.getName());
118 sb.append(f.getURL());
121 store.setValue(PREF_INTERNAL_WEB_BROWSER_OLD_FAVORITES, sb.toString());
122 WebBrowserUIPlugin.getInstance().savePluginPreferences();
126 * Sets the Web browser history.
128 * @param java.util.List
130 public static void setInternalWebBrowserHistory(List list) {
131 StringBuffer sb = new StringBuffer();
133 Iterator iterator = list.iterator();
134 while (iterator.hasNext()) {
135 String s = (String) iterator.next();
140 getPreferenceStore().setValue(PREF_INTERNAL_WEB_BROWSER_HISTORY, sb.toString());
141 WebBrowserUIPlugin.getInstance().savePluginPreferences();
145 * Sets the Web browser favorites.
147 * @param java.util.List
149 public static void setInternalWebBrowserFavorites(List list) {
150 StringBuffer sb = new StringBuffer();
152 Iterator iterator = list.iterator();
153 while (iterator.hasNext()) {
154 Favorite f = (Favorite) iterator.next();
155 sb.append(f.getName());
157 sb.append(f.getURL());
161 getPreferenceStore().setValue(PREF_INTERNAL_WEB_BROWSER_FAVORITES, sb.toString());
162 WebBrowserUIPlugin.getInstance().savePluginPreferences();