KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > internal > boot > PlatformURLBaseConnection


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation 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  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.core.internal.boot;
12
13 import java.io.IOException JavaDoc;
14 import java.net.URL JavaDoc;
15 import org.eclipse.core.internal.runtime.CommonMessages;
16 import org.eclipse.osgi.util.NLS;
17
18 /**
19  * Platform URL support
20  * platform:/base/ maps to platform installation location
21  */

22 public class PlatformURLBaseConnection extends PlatformURLConnection {
23
24     // platform/ protocol
25
public static final String JavaDoc PLATFORM = "base"; //$NON-NLS-1$
26
public static final String JavaDoc PLATFORM_URL_STRING = PlatformURLHandler.PROTOCOL + PlatformURLHandler.PROTOCOL_SEPARATOR + "/" + PLATFORM + "/"; //$NON-NLS-1$ //$NON-NLS-2$
27

28     private static URL JavaDoc installURL;
29
30     /*
31      * Constructor for the class.
32      */

33     public PlatformURLBaseConnection(URL JavaDoc url) {
34         super(url);
35     }
36
37     /* (non-Javadoc)
38      * @see org.eclipse.equinox.internal.url.PlatformURLConnection#allowCaching()
39      */

40     protected boolean allowCaching() {
41         return true;
42     }
43
44     /* (non-Javadoc)
45      * @see org.eclipse.equinox.internal.url.PlatformURLConnection#resolve()
46      */

47     protected URL JavaDoc resolve() throws IOException JavaDoc {
48         String JavaDoc spec = url.getFile().trim();
49         if (spec.startsWith("/")) //$NON-NLS-1$
50
spec = spec.substring(1);
51         if (!spec.startsWith(PLATFORM + "/")) { //$NON-NLS-1$
52
String JavaDoc message = NLS.bind(CommonMessages.url_badVariant, url);
53             throw new IOException JavaDoc(message);
54         }
55         return spec.length() == PLATFORM.length() + 1 ? installURL : new URL JavaDoc(installURL, spec.substring(PLATFORM.length() + 1));
56     }
57
58     public static void startup(URL JavaDoc url) {
59         // register connection type for platform:/base/ handling
60
if (installURL != null)
61             return;
62         installURL = url;
63         PlatformURLHandler.register(PLATFORM, PlatformURLBaseConnection.class);
64     }
65 }
66
Popular Tags