< prev index next >

src/java.base/share/classes/sun/net/www/protocol/netdoc/Handler.java

Print this page
rev 14210 : 8154231: Simplify access to System properties from JDK code
Reviewed-by: rriggs


  23  * questions.
  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;

  43 
  44 public class Handler extends URLStreamHandler {
  45     static URL base;
  46 
  47     /*
  48      * Attempt to find a load the given url using the default (network)
  49      * documentation location.  If that fails, use the local copy
  50      */
  51     public synchronized URLConnection openConnection(URL u)
  52         throws IOException
  53     {
  54         URLConnection uc = null;
  55         URL ru;
  56 
  57         Boolean tmp = java.security.AccessController.doPrivileged(
  58             new sun.security.action.GetBooleanAction("newdoc.localonly"));
  59         boolean localonly = tmp.booleanValue();
  60 
  61         String docurl = java.security.AccessController.doPrivileged(
  62             new sun.security.action.GetPropertyAction("doc.url"));
  63 
  64         String file = u.getFile();
  65         if (!localonly) {
  66             try {
  67                 if (base == null) {
  68                     base = new URL(docurl);
  69                 }
  70                 ru = new URL(base, file);
  71             } catch (MalformedURLException e) {
  72                 ru = null;
  73             }
  74             if (ru != null) {
  75                 uc = ru.openConnection();
  76             }
  77         }
  78 
  79         if (uc == null) {
  80             try {
  81                 ru = new URL("file", "~", file);
  82 


  23  * questions.
  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;
  43 import sun.security.action.GetPropertyAction;
  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 
  58         boolean localonly = Boolean.parseBoolean(
  59                 GetPropertyAction.getProperty("newdoc.localonly"));

  60 
  61         String docurl = GetPropertyAction.getProperty("doc.url");

  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 
< prev index next >