]>
Commit | Line | Data |
---|---|---|
1b2798f6 EK |
1 | /******************************************************************************* |
2 | * Copyright (c) 2008, 2009 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 | * Ferenc Hechler - initial API and implementation | |
10 | * Ferenc Hechler, ferenc_hechler@users.sourceforge.net - 219530 [jar application] add Jar-in-Jar ClassLoader option | |
11 | * Ferenc Hechler, ferenc_hechler@users.sourceforge.net - 262746 [jar exporter] Create a builder for jar-in-jar-loader.zip | |
12 | * Ferenc Hechler, ferenc_hechler@users.sourceforge.net - 262748 [jar exporter] extract constants for string literals in JarRsrcLoader et al. | |
13 | *******************************************************************************/ | |
14 | package org.eclipse.jdt.internal.jarinjarloader; | |
15 | ||
16 | import java.io.IOException; | |
17 | import java.net.URL; | |
18 | ||
19 | /** | |
20 | * This class will be compiled into the binary jar-in-jar-loader.zip. This ZIP is used for the | |
21 | * "Runnable JAR File Exporter" | |
22 | * | |
23 | * Handle URLs with protocol "rsrc". "rsrc:path/file.ext" identifies the content accessible as | |
24 | * classLoader.getResourceAsStream("path/file.ext"). "rsrc:path/" identifies a base-path for | |
25 | * resources to be searched. The spec "file.ext" is combined to "rsrc:path/file.ext". | |
26 | * | |
27 | * @since 3.5 | |
28 | */ | |
29 | public class RsrcURLStreamHandler extends java.net.URLStreamHandler { | |
30 | ||
31 | private ClassLoader classLoader; | |
32 | ||
33 | public RsrcURLStreamHandler(ClassLoader classLoader) { | |
34 | this.classLoader = classLoader; | |
35 | } | |
36 | ||
37 | protected java.net.URLConnection openConnection(URL u) throws IOException { | |
38 | return new RsrcURLConnection(u, classLoader); | |
39 | } | |
40 | ||
41 | protected void parseURL(URL url, String spec, int start, int limit) { | |
42 | String file; | |
43 | if (spec.startsWith(JIJConstants.INTERNAL_URL_PROTOCOL_WITH_COLON)) | |
44 | file = spec.substring(5); | |
45 | else if (url.getFile().equals(JIJConstants.CURRENT_DIR)) | |
46 | file = spec; | |
47 | else if (url.getFile().endsWith(JIJConstants.PATH_SEPARATOR)) | |
48 | file = url.getFile() + spec; | |
49 | else | |
50 | file = spec; | |
51 | setURL(url, JIJConstants.INTERNAL_URL_PROTOCOL, "", -1, null, null, file, null, null); //$NON-NLS-1$ | |
52 | } | |
53 | ||
54 | } |