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;
22 * Preferences for the Web browser.
24 public class WebBrowserPreference {
25 protected static final String PREF_BROWSER_HISTORY = "webBrowserHistory";
26 protected static final String PREF_INTERNAL_WEB_BROWSER_HISTORY = "internalWebBrowserHistory";
27 protected static final String PREF_INTERNAL_WEB_BROWSER_FAVORITES = "internalWebBrowserFavorites";
28 protected static final String PREF_INTERNAL_WEB_BROWSER_OLD_FAVORITES = "internalWebBrowserOldFavorites";
29 protected static final String URL_PARAMETER = "%URL%";
32 * WebBrowserPreference constructor comment.
34 private WebBrowserPreference() {
39 * Returns the URL to the homepage.
41 * @return java.lang.String
43 public static String getHomePageURL() {
45 // get the default home page
46 URL url = WebBrowserUIPlugin.getInstance().getBundle().getEntry("home/home.html");
47 url = Platform.resolve(url);
48 return url.toExternalForm();
49 } catch (Exception e) {
50 return "http://www.eclipse.org";
55 * Returns the preference store.
57 * @return org.eclipse.jface.preference.IPreferenceStore
59 protected static IPreferenceStore getPreferenceStore() {
60 return WebBrowserUIPlugin.getInstance().getPreferenceStore();
64 * Returns the Web browser history list.
66 * @return java.util.List
68 public static List getInternalWebBrowserHistory() {
69 String temp = getPreferenceStore().getString(PREF_INTERNAL_WEB_BROWSER_HISTORY);
70 StringTokenizer st = new StringTokenizer(temp, "|*|");
71 List l = new ArrayList();
72 while (st.hasMoreTokens()) {
73 String s = st.nextToken();
80 * Returns the Web browser favorites.
82 * @return java.util.List
84 public static List getInternalWebBrowserFavorites() {
85 String temp = getPreferenceStore().getString(PREF_INTERNAL_WEB_BROWSER_FAVORITES);
86 StringTokenizer st = new StringTokenizer(temp, "|*|");
87 List l = new ArrayList();
88 while (st.hasMoreTokens()) {
89 l.add(new Favorite(st.nextToken(), st.nextToken()));
95 * Initialize the default preferences.
97 public static void initializeDefaultPreferences() {
98 IPreferenceStore store = getPreferenceStore();
100 String temp = store.getString(PREF_INTERNAL_WEB_BROWSER_OLD_FAVORITES);
101 StringTokenizer st = new StringTokenizer(temp, "|*|");
102 List def = new ArrayList();
103 while (st.hasMoreTokens()) {
104 def.add(new Favorite(st.nextToken(), st.nextToken()));
107 List list = getInternalWebBrowserFavorites();
108 Iterator iterator = WebBrowserUtil.getUnlockedFavorites().iterator();
109 while (iterator.hasNext()) {
110 Favorite f = (Favorite) iterator.next();
111 if (!def.contains(f))
114 setInternalWebBrowserFavorites(list);
116 StringBuffer sb = new StringBuffer();
117 iterator = WebBrowserUtil.getUnlockedFavorites().iterator();
118 while (iterator.hasNext()) {
119 Favorite f = (Favorite) iterator.next();
120 sb.append(f.getName());
122 sb.append(f.getURL());
125 store.setValue(PREF_INTERNAL_WEB_BROWSER_OLD_FAVORITES, sb.toString());
126 WebBrowserUIPlugin.getInstance().savePluginPreferences();
130 * Sets the Web browser history.
132 * @param java.util.List
134 public static void setInternalWebBrowserHistory(List list) {
135 StringBuffer sb = new StringBuffer();
137 Iterator iterator = list.iterator();
138 while (iterator.hasNext()) {
139 String s = (String) iterator.next();
144 getPreferenceStore().setValue(PREF_INTERNAL_WEB_BROWSER_HISTORY, sb.toString());
145 WebBrowserUIPlugin.getInstance().savePluginPreferences();
149 * Sets the Web browser favorites.
151 * @param java.util.List
153 public static void setInternalWebBrowserFavorites(List list) {
154 StringBuffer sb = new StringBuffer();
156 Iterator iterator = list.iterator();
157 while (iterator.hasNext()) {
158 Favorite f = (Favorite) iterator.next();
159 sb.append(f.getName());
161 sb.append(f.getURL());
165 getPreferenceStore().setValue(PREF_INTERNAL_WEB_BROWSER_FAVORITES, sb.toString());
166 WebBrowserUIPlugin.getInstance().savePluginPreferences();