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();
89 while (st.hasMoreTokens()) {
90 l.add(new Favorite(st.nextToken(), st.nextToken()));
92 } catch (Exception e) {
99 * Initialize the default preferences.
101 public static void initializeDefaultPreferences() {
102 IPreferenceStore store = getPreferenceStore();
104 String temp = store.getString(PREF_INTERNAL_WEB_BROWSER_OLD_FAVORITES);
105 StringTokenizer st = new StringTokenizer(temp, "|*|");
106 List def = new ArrayList();
108 while (st.hasMoreTokens()) {
109 def.add(new Favorite(st.nextToken(), st.nextToken()));
111 } catch (Exception e) {
114 List list = getInternalWebBrowserFavorites();
115 Iterator iterator = WebBrowserUtil.getUnlockedFavorites().iterator();
116 while (iterator.hasNext()) {
117 Favorite f = (Favorite) iterator.next();
118 if (!def.contains(f))
121 setInternalWebBrowserFavorites(list);
123 StringBuffer sb = new StringBuffer();
124 iterator = WebBrowserUtil.getUnlockedFavorites().iterator();
125 while (iterator.hasNext()) {
126 Favorite f = (Favorite) iterator.next();
127 sb.append(f.getName());
129 sb.append(f.getURL());
132 store.setValue(PREF_INTERNAL_WEB_BROWSER_OLD_FAVORITES, sb.toString());
133 WebBrowserUIPlugin.getInstance().savePluginPreferences();
137 * Sets the Web browser history.
139 * @param java.util.List
141 public static void setInternalWebBrowserHistory(List list) {
142 StringBuffer sb = new StringBuffer();
144 Iterator iterator = list.iterator();
145 while (iterator.hasNext()) {
146 String s = (String) iterator.next();
151 getPreferenceStore().setValue(PREF_INTERNAL_WEB_BROWSER_HISTORY, sb.toString());
152 WebBrowserUIPlugin.getInstance().savePluginPreferences();
156 * Sets the Web browser favorites.
158 * @param java.util.List
160 public static void setInternalWebBrowserFavorites(List list) {
161 StringBuffer sb = new StringBuffer();
163 Iterator iterator = list.iterator();
164 while (iterator.hasNext()) {
165 Favorite f = (Favorite) iterator.next();
166 sb.append(f.getName());
168 sb.append(f.getURL());
172 getPreferenceStore().setValue(PREF_INTERNAL_WEB_BROWSER_FAVORITES, sb.toString());
173 WebBrowserUIPlugin.getInstance().savePluginPreferences();