1 |
/* |
/* Handler.java -- "file" protocol handler for java.net |
2 |
Handler.java -- "file" protocol handler for java.net |
Copyright (C) 1998, 2002 Free Software Foundation, Inc. |
|
Copyright (C) 1998 Free Software Foundation, Inc. |
|
|
|
|
|
This file is part of GNU Classpath. |
|
|
|
|
|
GNU Classpath is free software; you can redistribute it and/or modify |
|
|
it under the terms of the GNU General Public License as published by |
|
|
the Free Software Foundation; either version 2, or (at your option) |
|
|
any later version. |
|
|
|
|
|
GNU Classpath is distributed in the hope that it will be useful, but |
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
|
General Public License for more details. |
|
|
|
|
|
You should have received a copy of the GNU General Public License |
|
|
along with GNU Classpath; see the file COPYING. If not, write to the |
|
|
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
|
|
02111-1307 USA. |
|
|
|
|
|
Linking this library statically or dynamically with other modules is |
|
|
making a combined work based on this library. Thus, the terms and |
|
|
conditions of the GNU General Public License cover the whole |
|
|
combination. |
|
|
|
|
|
As a special exception, the copyright holders of this library give you |
|
|
permission to link this library with independent modules to produce an |
|
|
executable, regardless of the license terms of these independent |
|
|
modules, and to copy and distribute the resulting executable under |
|
|
terms of your choice, provided that you also meet, for each linked |
|
|
independent module, the terms and conditions of the license of that |
|
|
module. An independent module is a module which is not derived from |
|
|
or based on this library. If you modify this library, you may extend |
|
|
this exception to your version of the library, but you are not |
|
|
obligated to do so. If you do not wish to do so, delete this |
|
|
exception statement from your version. |
|
|
*/ |
|
3 |
|
|
4 |
|
This file is part of GNU Classpath. |
5 |
|
|
6 |
|
GNU Classpath is free software; you can redistribute it and/or modify |
7 |
|
it under the terms of the GNU General Public License as published by |
8 |
|
the Free Software Foundation; either version 2, or (at your option) |
9 |
|
any later version. |
10 |
|
|
11 |
|
GNU Classpath is distributed in the hope that it will be useful, but |
12 |
|
WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 |
|
General Public License for more details. |
15 |
|
|
16 |
|
You should have received a copy of the GNU General Public License |
17 |
|
along with GNU Classpath; see the file COPYING. If not, write to the |
18 |
|
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
19 |
|
02111-1307 USA. |
20 |
|
|
21 |
|
Linking this library statically or dynamically with other modules is |
22 |
|
making a combined work based on this library. Thus, the terms and |
23 |
|
conditions of the GNU General Public License cover the whole |
24 |
|
combination. |
25 |
|
|
26 |
|
As a special exception, the copyright holders of this library give you |
27 |
|
permission to link this library with independent modules to produce an |
28 |
|
executable, regardless of the license terms of these independent |
29 |
|
modules, and to copy and distribute the resulting executable under |
30 |
|
terms of your choice, provided that you also meet, for each linked |
31 |
|
independent module, the terms and conditions of the license of that |
32 |
|
module. An independent module is a module which is not derived from |
33 |
|
or based on this library. If you modify this library, you may extend |
34 |
|
this exception to your version of the library, but you are not |
35 |
|
obligated to do so. If you do not wish to do so, delete this |
36 |
|
exception statement from your version. */ |
37 |
|
|
38 |
package gnu.java.net.protocol.file; |
package gnu.java.net.protocol.file; |
39 |
|
|
239 |
setURL(url, url.getProtocol(), host, port, file, anchor); |
setURL(url, url.getProtocol(), host, port, file, anchor); |
240 |
} |
} |
241 |
|
|
242 |
|
|
243 |
|
/** |
244 |
|
* This method overrides URLStreamHandler's as a specialized |
245 |
|
* and more efficient toExternalForm |
246 |
|
* |
247 |
|
* @param url The URL object whose external form will be returned |
248 |
|
*/ |
249 |
|
|
250 |
|
protected String |
251 |
|
toExternalForm(URL url) |
252 |
|
{ |
253 |
|
StringBuffer sb = new StringBuffer(PlatformHelper.INITIAL_MAX_PATH); |
254 |
|
sb.append("file://"); |
255 |
|
|
256 |
|
String prefix = url.getHost(); |
257 |
|
if(prefix != null && prefix.length() > 0){ |
258 |
|
sb.append(prefix); |
259 |
|
int port = url.getPort(); |
260 |
|
if (port > 0){ |
261 |
|
sb.append(':'); |
262 |
|
sb.append(port); |
263 |
|
} |
264 |
|
} |
265 |
|
|
266 |
|
String file = url.getFile(); |
267 |
|
if (file != null) |
268 |
|
sb.append(file); |
269 |
|
else |
270 |
|
sb.append('/'); |
271 |
|
|
272 |
|
String anchor = url.getRef(); |
273 |
|
if (anchor != null){ |
274 |
|
sb.append('#'); |
275 |
|
sb.append(anchor); |
276 |
|
} |
277 |
|
|
278 |
|
return sb.toString(); |
279 |
|
} |
280 |
|
|
281 |
} // class Handler |
} // class Handler |
282 |
|
|