refactory whole plugin
[phpeclipse.git] / net.sourceforge.phpeclipse.webbrowser / src / net / sourceforge / phpeclipse / webbrowser / internal / WebBrowserPreference.java
index 2198585..5c83893 100644 (file)
@@ -1,29 +1,38 @@
 /**
  * Copyright (c) 2003 IBM Corporation and others.
- * All rights reserved.   This program and the accompanying materials
+ * All rights reserved. � This program and the accompanying materials
  * are made available under the terms of the Common Public License v1.0
  * which accompanies this distribution, and is available at
  * http://www.eclipse.org/legal/cpl-v10.html
- *
+ �*
  * Contributors:
  *    IBM - Initial API and implementation
  */
 package net.sourceforge.phpeclipse.webbrowser.internal;
 
-import java.util.*;
 import java.net.URL;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.StringTokenizer;
+
 import org.eclipse.core.runtime.Platform;
 import org.eclipse.jface.preference.IPreferenceStore;
+
 /**
  * Preferences for the Web browser.
  */
 public class WebBrowserPreference {
        protected static final String PREF_BROWSER_HISTORY = "webBrowserHistory";
+
        protected static final String PREF_INTERNAL_WEB_BROWSER_HISTORY = "internalWebBrowserHistory";
+
        protected static final String PREF_INTERNAL_WEB_BROWSER_FAVORITES = "internalWebBrowserFavorites";
+
        protected static final String PREF_INTERNAL_WEB_BROWSER_OLD_FAVORITES = "internalWebBrowserOldFavorites";
+
        protected static final String URL_PARAMETER = "%URL%";
-       
+
        /**
         * WebBrowserPreference constructor comment.
         */
@@ -39,7 +48,8 @@ public class WebBrowserPreference {
        public static String getHomePageURL() {
                try {
                        // get the default home page
-                       URL url = WebBrowserUIPlugin.getInstance().getBundle().getEntry("home/home.html");
+                       URL url = WebBrowserUIPlugin.getInstance().getBundle().getEntry(
+                                       "home/home.html");
                        url = Platform.resolve(url);
                        return url.toExternalForm();
                } catch (Exception e) {
@@ -49,20 +59,21 @@ public class WebBrowserPreference {
 
        /**
         * Returns the preference store.
-        *
+        * 
         * @return org.eclipse.jface.preference.IPreferenceStore
         */
        protected static IPreferenceStore getPreferenceStore() {
                return WebBrowserUIPlugin.getInstance().getPreferenceStore();
        }
-       
+
        /**
         * Returns the Web browser history list.
         * 
         * @return java.util.List
         */
        public static List getInternalWebBrowserHistory() {
-               String temp = getPreferenceStore().getString(PREF_INTERNAL_WEB_BROWSER_HISTORY);
+               String temp = getPreferenceStore().getString(
+                               PREF_INTERNAL_WEB_BROWSER_HISTORY);
                StringTokenizer st = new StringTokenizer(temp, "|*|");
                List l = new ArrayList();
                while (st.hasMoreTokens()) {
@@ -71,18 +82,23 @@ public class WebBrowserPreference {
                }
                return l;
        }
-       
+
        /**
         * Returns the Web browser favorites.
         * 
         * @return java.util.List
         */
        public static List getInternalWebBrowserFavorites() {
-               String temp = getPreferenceStore().getString(PREF_INTERNAL_WEB_BROWSER_FAVORITES);
+               String temp = getPreferenceStore().getString(
+                               PREF_INTERNAL_WEB_BROWSER_FAVORITES);
                StringTokenizer st = new StringTokenizer(temp, "|*|");
                List l = new ArrayList();
-               while (st.hasMoreTokens()) {
-                       l.add(new Favorite(st.nextToken(), st.nextToken()));
+               try {
+                       while (st.hasMoreTokens()) {
+                               l.add(new Favorite(st.nextToken(), st.nextToken()));
+                       }
+               } catch (Exception e) {
+                       // ignore
                }
                return l;
        }
@@ -92,15 +108,18 @@ public class WebBrowserPreference {
         */
        public static void initializeDefaultPreferences() {
                IPreferenceStore store = getPreferenceStore();
-               
+
                String temp = store.getString(PREF_INTERNAL_WEB_BROWSER_OLD_FAVORITES);
                StringTokenizer st = new StringTokenizer(temp, "|*|");
                List def = new ArrayList();
-               while (st.hasMoreTokens()) {
-                       def.add(new Favorite(st.nextToken(), st.nextToken()));
+               try {
+                       while (st.hasMoreTokens()) {
+                               def.add(new Favorite(st.nextToken(), st.nextToken()));
+                       }
+               } catch (Exception e) {
+                       // ignore
                }
-               
-               List list = getInternalWebBrowserFavorites(); 
+               List list = getInternalWebBrowserFavorites();
                Iterator iterator = WebBrowserUtil.getUnlockedFavorites().iterator();
                while (iterator.hasNext()) {
                        Favorite f = (Favorite) iterator.next();
@@ -108,7 +127,7 @@ public class WebBrowserPreference {
                                list.add(f);
                }
                setInternalWebBrowserFavorites(list);
-               
+
                StringBuffer sb = new StringBuffer();
                iterator = WebBrowserUtil.getUnlockedFavorites().iterator();
                while (iterator.hasNext()) {
@@ -121,10 +140,10 @@ public class WebBrowserPreference {
                store.setValue(PREF_INTERNAL_WEB_BROWSER_OLD_FAVORITES, sb.toString());
                WebBrowserUIPlugin.getInstance().savePluginPreferences();
        }
-       
+
        /**
         * Sets the Web browser history.
-        *
+        * 
         * @param java.util.List
         */
        public static void setInternalWebBrowserHistory(List list) {
@@ -137,13 +156,14 @@ public class WebBrowserPreference {
                                sb.append("|*|");
                        }
                }
-               getPreferenceStore().setValue(PREF_INTERNAL_WEB_BROWSER_HISTORY, sb.toString());
+               getPreferenceStore().setValue(PREF_INTERNAL_WEB_BROWSER_HISTORY,
+                               sb.toString());
                WebBrowserUIPlugin.getInstance().savePluginPreferences();
        }
-       
+
        /**
         * Sets the Web browser favorites.
-        *
+        * 
         * @param java.util.List
         */
        public static void setInternalWebBrowserFavorites(List list) {
@@ -158,7 +178,8 @@ public class WebBrowserPreference {
                                sb.append("|*|");
                        }
                }
-               getPreferenceStore().setValue(PREF_INTERNAL_WEB_BROWSER_FAVORITES, sb.toString());
+               getPreferenceStore().setValue(PREF_INTERNAL_WEB_BROWSER_FAVORITES,
+                               sb.toString());
                WebBrowserUIPlugin.getInstance().savePluginPreferences();
        }
 }
\ No newline at end of file