Updated news reader to use ProxyUtils class from com.nokia.cpp.utils.core plugin to retrieve proxy data.
authorstechong
Thu, 13 Aug 2009 12:52:54 -0500
changeset 433 93ea4941aeb5
parent 432 f0a3eb120614
child 434 da3780c8afe3
Updated news reader to use ProxyUtils class from com.nokia.cpp.utils.core plugin to retrieve proxy data.
core/com.nokia.carbide.cpp.news.reader/src/com/nokia/carbide/cpp/internal/news/reader/CarbideNewsReaderPlugin.java
core/com.nokia.carbide.cpp.news.reader/src/com/nokia/carbide/cpp/internal/news/reader/feed/CarbideFeedFetcher.java
core/com.nokia.carbide.cpp.news.reader/src/com/nokia/carbide/cpp/internal/news/reader/gen/FeedInfo/FeedInfoManager.java
--- a/core/com.nokia.carbide.cpp.news.reader/src/com/nokia/carbide/cpp/internal/news/reader/CarbideNewsReaderPlugin.java	Thu Aug 13 00:06:53 2009 -0500
+++ b/core/com.nokia.carbide.cpp.news.reader/src/com/nokia/carbide/cpp/internal/news/reader/CarbideNewsReaderPlugin.java	Thu Aug 13 12:52:54 2009 -0500
@@ -18,11 +18,8 @@
 package com.nokia.carbide.cpp.internal.news.reader;
 
 import java.io.IOException;
-import java.net.URISyntaxException;
 import java.net.URL;
 
-import org.eclipse.core.net.proxy.IProxyData;
-import org.eclipse.core.net.proxy.IProxyService;
 import org.eclipse.core.runtime.FileLocator;
 import org.eclipse.core.runtime.IPath;
 import org.eclipse.core.runtime.IProgressMonitor;
@@ -37,7 +34,6 @@
 import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.plugin.AbstractUIPlugin;
 import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
 
 import com.nokia.carbide.cpp.internal.news.reader.editor.NewsEditor;
 import com.nokia.carbide.cpp.internal.news.reader.feed.FeedManager;
@@ -125,32 +121,6 @@
 	}
 
 	/**
-	 * Retrieve proxy data for a given URL.
-	 * @param url - URL in question
-	 * @return proxy data associated with the URL if one is available, null otherwise
-	 */
-	public static IProxyData getProxyData(URL url) {
-		BundleContext context = getDefault().getBundle().getBundleContext();
-		if (context != null) {
-			ServiceReference reference = context.getServiceReference(IProxyService.class.getName());
-			if (reference != null) {
-				IProxyService proxyService = (IProxyService) context.getService(reference);
-				if (proxyService != null) {
-					try {
-						IProxyData[] proxyData = proxyService.select(url.toURI());
-						if (proxyData != null && proxyData.length > 0) {
-							return proxyData[0];
-						}
-					} catch (URISyntaxException e) {
-						return null;
-					}
-				}
-			}
-		}
-		return null;
-	}
-
-	/**
 	 * Launch the Carbide.c++ news page.
 	 */
 	public static void launchNewsPage() {
--- a/core/com.nokia.carbide.cpp.news.reader/src/com/nokia/carbide/cpp/internal/news/reader/feed/CarbideFeedFetcher.java	Thu Aug 13 00:06:53 2009 -0500
+++ b/core/com.nokia.carbide.cpp.news.reader/src/com/nokia/carbide/cpp/internal/news/reader/feed/CarbideFeedFetcher.java	Thu Aug 13 12:52:54 2009 -0500
@@ -18,12 +18,14 @@
 package com.nokia.carbide.cpp.internal.news.reader.feed;
 
 import java.io.IOException;
+import java.net.URISyntaxException;
 import java.net.URL;
 import java.net.URLConnection;
 
 import org.eclipse.core.net.proxy.IProxyData;
 
 import com.nokia.carbide.cpp.internal.news.reader.CarbideNewsReaderPlugin;
+import com.nokia.cpp.internal.api.utils.core.ProxyUtils;
 import com.sun.syndication.feed.synd.SyndFeed;
 import com.sun.syndication.fetcher.FetcherException;
 import com.sun.syndication.fetcher.impl.FeedFetcherCache;
@@ -49,10 +51,14 @@
 	 * @see com.sun.syndication.fetcher.impl.HttpURLFeedFetcher#retrieveFeed(java.net.URL)
 	 */
 	public SyndFeed retrieveFeed(URL feedUrl) throws IllegalArgumentException, IOException, FeedException, FetcherException {
-		IProxyData data = CarbideNewsReaderPlugin.getProxyData(feedUrl);
-		if (data != null) {
-			System.setProperty("http.proxyHost", data.getHost());
-			System.setProperty("http.proxyPort", Integer.toString(data.getPort()));
+		try {
+			IProxyData data = ProxyUtils.getProxyData(feedUrl.toURI());
+			if (data != null) {
+				System.setProperty("http.proxyHost", data.getHost());
+				System.setProperty("http.proxyPort", Integer.toString(data.getPort()));
+			}
+		} catch (URISyntaxException e) {
+			CarbideNewsReaderPlugin.log(e);
 		}
 		return super.retrieveFeed(feedUrl);
 	}
--- a/core/com.nokia.carbide.cpp.news.reader/src/com/nokia/carbide/cpp/internal/news/reader/gen/FeedInfo/FeedInfoManager.java	Thu Aug 13 00:06:53 2009 -0500
+++ b/core/com.nokia.carbide.cpp.news.reader/src/com/nokia/carbide/cpp/internal/news/reader/gen/FeedInfo/FeedInfoManager.java	Thu Aug 13 12:52:54 2009 -0500
@@ -34,6 +34,7 @@
 
 import com.nokia.carbide.cpp.internal.news.reader.CarbideNewsReaderPlugin;
 import com.nokia.cpp.internal.api.utils.core.FileUtils;
+import com.nokia.cpp.internal.api.utils.core.ProxyUtils;
 
 /**
  * A class for managing feed information.
@@ -138,7 +139,7 @@
 				InputStream inputStream = null;
 				try {
 					Proxy proxy = null;
-					IProxyData data = CarbideNewsReaderPlugin.getProxyData(fileUrl);
+					IProxyData data = ProxyUtils.getProxyData(fileUrl.toURI());
 					if (data != null) {
 						String host = data.getHost();
 						int port = data.getPort();