All prefs for xampp administrated in external tools plugin.
[phpeclipse.git] / net.sourceforge.phpeclipse.webbrowser / src / net / sourceforge / phpeclipse / webbrowser / internal / WebBrowserPreference.java
1 /**
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
7  *
8  * Contributors:
9  *    IBM - Initial API and implementation
10  */
11 package net.sourceforge.phpeclipse.webbrowser.internal;
12
13 import java.net.URL;
14 import java.util.ArrayList;
15 import java.util.Iterator;
16 import java.util.List;
17 import java.util.StringTokenizer;
18
19 import org.eclipse.core.runtime.Platform;
20 import org.eclipse.jface.preference.IPreferenceStore;
21 /**
22  * Preferences for the Web browser.
23  */
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%";
30         
31         /**
32          * WebBrowserPreference constructor comment.
33          */
34         private WebBrowserPreference() {
35                 super();
36         }
37
38         /**
39          * Returns the URL to the homepage.
40          * 
41          * @return java.lang.String
42          */
43         public static String getHomePageURL() {
44                 try {
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";
51                 }
52         }
53
54         /**
55          * Returns the preference store.
56          *
57          * @return org.eclipse.jface.preference.IPreferenceStore
58          */
59         protected static IPreferenceStore getPreferenceStore() {
60                 return WebBrowserUIPlugin.getInstance().getPreferenceStore();
61         }
62         
63         /**
64          * Returns the Web browser history list.
65          * 
66          * @return java.util.List
67          */
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();
74                         l.add(s);
75                 }
76                 return l;
77         }
78         
79         /**
80          * Returns the Web browser favorites.
81          * 
82          * @return java.util.List
83          */
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()));
90                 }
91                 return l;
92         }
93
94         /**
95          * Initialize the default preferences.
96          */
97         public static void initializeDefaultPreferences() {
98                 IPreferenceStore store = getPreferenceStore();
99                 
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()));
105                 }
106                 
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))
112                                 list.add(f);
113                 }
114                 setInternalWebBrowserFavorites(list);
115                 
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());
121                         sb.append("|*|");
122                         sb.append(f.getURL());
123                         sb.append("|*|");
124                 }
125                 store.setValue(PREF_INTERNAL_WEB_BROWSER_OLD_FAVORITES, sb.toString());
126                 WebBrowserUIPlugin.getInstance().savePluginPreferences();
127         }
128         
129         /**
130          * Sets the Web browser history.
131          *
132          * @param java.util.List
133          */
134         public static void setInternalWebBrowserHistory(List list) {
135                 StringBuffer sb = new StringBuffer();
136                 if (list != null) {
137                         Iterator iterator = list.iterator();
138                         while (iterator.hasNext()) {
139                                 String s = (String) iterator.next();
140                                 sb.append(s);
141                                 sb.append("|*|");
142                         }
143                 }
144                 getPreferenceStore().setValue(PREF_INTERNAL_WEB_BROWSER_HISTORY, sb.toString());
145                 WebBrowserUIPlugin.getInstance().savePluginPreferences();
146         }
147         
148         /**
149          * Sets the Web browser favorites.
150          *
151          * @param java.util.List
152          */
153         public static void setInternalWebBrowserFavorites(List list) {
154                 StringBuffer sb = new StringBuffer();
155                 if (list != null) {
156                         Iterator iterator = list.iterator();
157                         while (iterator.hasNext()) {
158                                 Favorite f = (Favorite) iterator.next();
159                                 sb.append(f.getName());
160                                 sb.append("|*|");
161                                 sb.append(f.getURL());
162                                 sb.append("|*|");
163                         }
164                 }
165                 getPreferenceStore().setValue(PREF_INTERNAL_WEB_BROWSER_FAVORITES, sb.toString());
166                 WebBrowserUIPlugin.getInstance().savePluginPreferences();
167         }
168 }