author | redestad |
Thu, 21 Apr 2016 13:39:53 +0200 | |
changeset 37593 | 824750ada3d6 |
parent 25859 | 3317bb8137f4 |
child 37781 | 71ed5645f17c |
permissions | -rw-r--r-- |
2 | 1 |
/* |
5506 | 2 |
* Copyright (c) 1996, 1998, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
/*- |
|
27 |
* netdoc urls point either into the local filesystem or externally |
|
28 |
* through an http url, with network documents being preferred. Useful for |
|
29 |
* FAQs & other documents which are likely to be changing over time at the |
|
30 |
* central site, and where the user will want the most recent edition. |
|
31 |
* |
|
32 |
* @author Steven B. Byrne |
|
33 |
*/ |
|
34 |
||
35 |
package sun.net.www.protocol.netdoc; |
|
36 |
||
37 |
import java.net.URL; |
|
38 |
import java.net.URLConnection; |
|
39 |
import java.net.MalformedURLException; |
|
40 |
import java.net.URLStreamHandler; |
|
41 |
import java.io.InputStream; |
|
42 |
import java.io.IOException; |
|
37593
824750ada3d6
8154231: Simplify access to System properties from JDK code
redestad
parents:
25859
diff
changeset
|
43 |
import sun.security.action.GetPropertyAction; |
2 | 44 |
|
45 |
public class Handler extends URLStreamHandler { |
|
46 |
static URL base; |
|
47 |
||
48 |
/* |
|
49 |
* Attempt to find a load the given url using the default (network) |
|
50 |
* documentation location. If that fails, use the local copy |
|
51 |
*/ |
|
52 |
public synchronized URLConnection openConnection(URL u) |
|
53 |
throws IOException |
|
54 |
{ |
|
55 |
URLConnection uc = null; |
|
56 |
URL ru; |
|
57 |
||
37593
824750ada3d6
8154231: Simplify access to System properties from JDK code
redestad
parents:
25859
diff
changeset
|
58 |
boolean localonly = Boolean.parseBoolean( |
824750ada3d6
8154231: Simplify access to System properties from JDK code
redestad
parents:
25859
diff
changeset
|
59 |
GetPropertyAction.getProperty("newdoc.localonly")); |
2 | 60 |
|
37593
824750ada3d6
8154231: Simplify access to System properties from JDK code
redestad
parents:
25859
diff
changeset
|
61 |
String docurl = GetPropertyAction.getProperty("doc.url"); |
2 | 62 |
|
63 |
String file = u.getFile(); |
|
64 |
if (!localonly) { |
|
65 |
try { |
|
66 |
if (base == null) { |
|
67 |
base = new URL(docurl); |
|
68 |
} |
|
69 |
ru = new URL(base, file); |
|
70 |
} catch (MalformedURLException e) { |
|
71 |
ru = null; |
|
72 |
} |
|
73 |
if (ru != null) { |
|
74 |
uc = ru.openConnection(); |
|
75 |
} |
|
76 |
} |
|
77 |
||
78 |
if (uc == null) { |
|
79 |
try { |
|
80 |
ru = new URL("file", "~", file); |
|
81 |
||
82 |
uc = ru.openConnection(); |
|
83 |
InputStream is = uc.getInputStream(); // Check for success. |
|
84 |
} catch (MalformedURLException e) { |
|
85 |
uc = null; |
|
86 |
} catch (IOException e) { |
|
87 |
uc = null; |
|
88 |
} |
|
89 |
} |
|
90 |
||
91 |
if (uc == null) { |
|
92 |
throw new IOException("Can't find file for URL: " |
|
93 |
+u.toExternalForm()); |
|
94 |
} |
|
95 |
return uc; |
|
96 |
} |
|
97 |
} |