KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > util > ParsedURLJarProtocolHandler


1 /*
2
3    Copyright 2001-2003 The Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16
17  */

18 package org.apache.batik.util;
19
20 import java.net.MalformedURLException JavaDoc;
21 import java.net.URL JavaDoc;
22
23 /**
24  * Protocol Handler for the 'jar' protocol.
25  * This appears to have the format:
26  * jar:<URL for jar file>!<path in jar file>
27  *
28  * @author <a HREF="mailto:deweese@apache.org">Thomas DeWeese</a>
29  * @version $Id: ParsedURLJarProtocolHandler.java,v 1.7 2004/08/18 07:15:49 vhardy Exp $
30  */

31 public class ParsedURLJarProtocolHandler
32     extends ParsedURLDefaultProtocolHandler {
33
34     public static final String JavaDoc JAR = "jar";
35
36     public ParsedURLJarProtocolHandler() {
37         super(JAR);
38     }
39
40
41     // We mostly use the base class parse methods (that leverage
42
// java.net.URL. But we take care to ignore the baseURL if urlStr
43
// is an absolute URL.
44
public ParsedURLData parseURL(ParsedURL baseURL, String JavaDoc urlStr) {
45         String JavaDoc start = urlStr.substring(0, JAR.length()+1).toLowerCase();
46         
47         // urlStr is absolute...
48
if (start.equals(JAR+":"))
49             return parseURL(urlStr);
50
51         // It's relative so base it off baseURL.
52
try {
53             URL JavaDoc context = new URL JavaDoc(baseURL.toString());
54             URL JavaDoc url = new URL JavaDoc(context, urlStr);
55             return constructParsedURLData(url);
56         } catch (MalformedURLException JavaDoc mue) {
57             return super.parseURL(baseURL, urlStr);
58         }
59     }
60 }
61
62
Popular Tags