Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 161458
Collapse All | Expand All

(-)src/org/eclipse/mylar/tests/misc/AllMiscTests.java (+1 lines)
Lines 26-31 Link Here
26
		// suite.addTestSuite(BugzillaSearchPluginTest.class);
26
		// suite.addTestSuite(BugzillaSearchPluginTest.class);
27
		suite.addTestSuite(AssertionsEnabledTest.class);
27
		suite.addTestSuite(AssertionsEnabledTest.class);
28
		suite.addTestSuite(HypertextStructureBridgeTest.class);
28
		suite.addTestSuite(HypertextStructureBridgeTest.class);
29
		suite.addTestSuite(GetFaviconForUrlTest.class);
29
		//suite.addTestSuite(BugzillaStackTraceTest.class);
30
		//suite.addTestSuite(BugzillaStackTraceTest.class);
30
		// $JUnit-END$
31
		// $JUnit-END$
31
		return suite;
32
		return suite;
(-).refactorings/2007/3/12/refactorings.history (+5 lines)
Added Link Here
1
<?xml version="1.0" encoding="utf-8" standalone="no"?>
2
<session version="1.0">
3
<refactoring comment="Rename type 'org.eclipse.mylar.tests.misc.GetFaviconsForUrlText' to 'GetFaviconsForUrlTest'&#10;- Original project: 'org.eclipse.mylar.tests'&#10;- Original element: 'org.eclipse.mylar.tests.misc.GetFaviconsForUrlText'&#10;- Renamed element: 'org.eclipse.mylar.tests.misc.GetFaviconsForUrlTest'&#10;- Update references to refactored element&#10;- Update textual occurrences in comments and strings" description="Rename type 'GetFaviconsForUrlText'" flags="589830" id="org.eclipse.jdt.ui.rename.type" input="/src&lt;org.eclipse.mylar.tests.misc{GetFaviconsForUrlText.java[GetFaviconsForUrlText" matchStrategy="1" name="GetFaviconsForUrlTest" qualified="false" references="true" similarDeclarations="false" stamp="1174496407717" textual="false" version="1.0"/>
4
<refactoring comment="Rename compilation unit 'org.eclipse.mylar.tests.misc.GetFaviconsForUrlTest.java' to 'GetFaviconForUrlTest.java'&#10;- Original project: 'org.eclipse.mylar.tests'&#10;- Original element: 'org.eclipse.mylar.tests.misc.GetFaviconsForUrlTest.java'&#10;- Renamed element: 'org.eclipse.mylar.tests.misc.GetFaviconForUrlTest.java'" description="Rename compilation unit 'GetFaviconsForUrlTest.java'" flags="2" id="org.eclipse.jdt.ui.rename.compilationunit" input="/src&lt;org.eclipse.mylar.tests.misc{GetFaviconsForUrlTest.java" name="GetFaviconForUrlTest.java" references="false" stamp="1174496520152" version="1.0"/>
5
</session>
(-).refactorings/2007/3/12/refactorings.index (+2 lines)
Added Link Here
1
1174496407717	Rename type 'GetFaviconsForUrlText'
2
1174496520152	Rename compilation unit 'GetFaviconsForUrlTest.java'
(-)src/org/eclipse/mylar/tests/misc/GetFaviconForUrlTest.java (+60 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 - 2006 University Of British Columbia and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     University Of British Columbia - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylar.tests.misc;
13
14
import java.net.MalformedURLException;
15
16
import org.eclipse.mylar.core.net.WebClientUtil;
17
import org.eclipse.swt.graphics.Image;
18
import org.eclipse.swt.graphics.ImageData;
19
20
import junit.framework.TestCase;
21
22
/**
23
 * @author Leo Dos Santos
24
 */
25
public class GetFaviconForUrlTest extends TestCase {
26
	
27
	public void testMalformedUrl() {
28
		boolean exceptionThrown = false;
29
		try {
30
			WebClientUtil.getFaviconForUrl("www.eclipse.org");
31
		} catch (MalformedURLException e) {
32
			exceptionThrown = true;
33
		} 
34
		assertTrue(exceptionThrown);
35
	}
36
	
37
	public void testEclipseDotOrg() {
38
		Image img = null;
39
		try {
40
			img = WebClientUtil.getFaviconForUrl("http://www.eclipse.org");
41
		} catch (MalformedURLException e) {
42
			fail();
43
		}
44
		assertNotNull(img);
45
		ImageData data = img.getImageData();
46
		assertEquals(data.height, 16);
47
		assertEquals(data.width, 16);
48
	}
49
	
50
	public void testNoFavicon() {
51
		Image img = null;
52
		try {
53
			img = WebClientUtil.getFaviconForUrl("http://help.eclipse.org/help32/index.jsp");
54
		} catch (MalformedURLException e) {
55
			fail();
56
		}
57
		assertNull(img);
58
	}
59
	
60
}
(-)src/org/eclipse/mylar/core/net/WebClientUtil.java (-1 / +36 lines)
Lines 12-18 Link Here
12
package org.eclipse.mylar.core.net;
12
package org.eclipse.mylar.core.net;
13
13
14
import java.net.InetSocketAddress;
14
import java.net.InetSocketAddress;
15
import java.net.MalformedURLException;
15
import java.net.Proxy;
16
import java.net.Proxy;
17
import java.net.URL;
16
import java.net.Proxy.Type;
18
import java.net.Proxy.Type;
17
19
18
import org.apache.commons.httpclient.Credentials;
20
import org.apache.commons.httpclient.Credentials;
Lines 23-32 Link Here
23
import org.apache.commons.httpclient.params.HttpClientParams;
25
import org.apache.commons.httpclient.params.HttpClientParams;
24
import org.apache.commons.httpclient.protocol.Protocol;
26
import org.apache.commons.httpclient.protocol.Protocol;
25
import org.apache.commons.httpclient.protocol.ProtocolSocketFactory;
27
import org.apache.commons.httpclient.protocol.ProtocolSocketFactory;
28
import org.eclipse.jface.resource.ImageDescriptor;
29
import org.eclipse.swt.SWTException;
30
import org.eclipse.swt.graphics.Image;
31
import org.eclipse.swt.graphics.ImageData;
26
32
27
/**
33
/**
28
 * @author Mik Kersten
34
 * @author Mik Kersten
29
 * @author Steffen Pingel
35
 * @author Steffen Pingel
36
 * @author Leo Dos Santos - getFaviconForUrl
30
 */
37
 */
31
public class WebClientUtil {
38
public class WebClientUtil {
32
39
Lines 147-153 Link Here
147
					.getInstance(), WebClientUtil.getPort(repositoryUrl));
154
					.getInstance(), WebClientUtil.getPort(repositoryUrl));
148
			client.getHostConfiguration().setHost(WebClientUtil.getDomain(repositoryUrl),
155
			client.getHostConfiguration().setHost(WebClientUtil.getDomain(repositoryUrl),
149
					WebClientUtil.getPort(repositoryUrl), acceptAllSsl);
156
					WebClientUtil.getPort(repositoryUrl), acceptAllSsl);
150
			// Protocol.registerProtocol("https", acceptAllSsl);
157
			Protocol.registerProtocol("https", acceptAllSsl);
151
		} else {
158
		} else {
152
			client.getHostConfiguration().setHost(WebClientUtil.getDomain(repositoryUrl),
159
			client.getHostConfiguration().setHost(WebClientUtil.getDomain(repositoryUrl),
153
					WebClientUtil.getPort(repositoryUrl));
160
					WebClientUtil.getPort(repositoryUrl));
Lines 180-184 Link Here
180
		}
187
		}
181
		return Proxy.NO_PROXY;
188
		return Proxy.NO_PROXY;
182
	}
189
	}
190
	
191
	/**
192
	 * @param repositoryUrl	The URL of the web site including protocol.
193
	 * 				E.g. <code>http://foo.bar</code> or <code>https://foo.bar/baz</code>
194
	 * @return a 16*16 favicon, or null if no favicon found
195
	 * @throws MalformedURLException 
196
	 */
197
	public static Image getFaviconForUrl(String repositoryUrl) throws MalformedURLException {
198
		URL url = new URL(repositoryUrl);
199
		
200
		String host = url.getHost();
201
		String protocol = url.getProtocol();
202
		String favString = protocol + "://" + host + "/favicon.ico";
203
		
204
		URL favUrl = new URL(favString);
205
		try {
206
			ImageDescriptor desc = ImageDescriptor.createFromURL(favUrl);
207
			if (desc.getImageData() != null) {
208
				if ((desc.getImageData().width != 16) && (desc.getImageData().height != 16)) {
209
					ImageData data = desc.getImageData().scaledTo(16, 16);
210
					return ImageDescriptor.createFromImageData(data).createImage(false);
211
				}
212
			}
213
			return ImageDescriptor.createFromURL(favUrl).createImage(false);
214
		} catch (SWTException e) {
215
			return null;
216
		}
217
	}
183
218
184
}
219
}
(-)META-INF/MANIFEST.MF (-1 / +3 lines)
Lines 4-10 Link Here
4
Bundle-SymbolicName: org.eclipse.mylar
4
Bundle-SymbolicName: org.eclipse.mylar
5
Bundle-Version: 2.0.0.v20070316-1930
5
Bundle-Version: 2.0.0.v20070316-1930
6
Bundle-Vendor: Eclipse.org
6
Bundle-Vendor: Eclipse.org
7
Require-Bundle: org.eclipse.core.runtime
7
Require-Bundle: org.eclipse.core.runtime,
8
 org.eclipse.swt,
9
 org.eclipse.jface
8
Bundle-ClassPath: .,
10
Bundle-ClassPath: .,
9
 lib-httpclient/commons-httpclient-3.0.1.jar,
11
 lib-httpclient/commons-httpclient-3.0.1.jar,
10
 lib-httpclient/commons-codec-1.3.jar,
12
 lib-httpclient/commons-codec-1.3.jar,

Return to bug 161458