1 19 package org.openide.util; 20 21 import org.openide.filesystems.FileObject; 22 import org.openide.util.NbBundle; 23 24 import java.net.InetAddress ; 25 import java.net.MalformedURLException ; 26 import java.net.URL ; 27 import java.net.UnknownHostException ; 28 29 30 37 public abstract class HttpServer { 38 39 private static HttpServer.Impl registeredServer = null; 40 41 private HttpServer() { 42 } 43 44 49 private static HttpServer.Impl getServer() throws UnknownHostException { 50 Object o = Lookup.getDefault().lookup(HttpServer.Impl.class); 51 52 if (o != null) { 53 return (HttpServer.Impl) o; 54 } 55 56 if (registeredServer != null) { 57 return registeredServer; 58 } else { 59 throw new UnknownHostException (NbBundle.getBundle(HttpServer.class).getString("MSG_NoServerRegistered")); 60 } 61 } 62 63 70 public static void registerServer(HttpServer.Impl server) 71 throws SecurityException { 72 if (registeredServer != null) { 73 throw new SecurityException (NbBundle.getBundle(HttpServer.class).getString("SERVER_REGISTERED")); 74 } 75 76 registeredServer = server; 77 } 78 79 85 public static void deregisterServer(HttpServer.Impl server) 86 throws SecurityException { 87 if (registeredServer == null) { 88 return; } 90 91 if (registeredServer != server) { 92 throw new SecurityException (NbBundle.getBundle(HttpServer.class).getString("SERVER_CANNOT_UNREGISTER")); 93 } else { 94 registeredServer = null; 95 } 96 } 97 98 106 public static URL getRepositoryURL(FileObject fo) throws MalformedURLException , UnknownHostException { 107 return getServer().getRepositoryURL(fo); 108 } 109 110 119 public static URL getRepositoryRoot() throws MalformedURLException , UnknownHostException { 120 return getServer().getRepositoryRoot(); 121 } 122 123 132 public static URL getResourceURL(String resourcePath) 133 throws MalformedURLException , UnknownHostException { 134 return getServer().getResourceURL(resourcePath); 135 } 136 137 144 public static URL getResourceRoot() throws MalformedURLException , UnknownHostException { 145 return getServer().getResourceRoot(); 146 } 147 148 157 public static boolean allowAccess(InetAddress addr) 158 throws UnknownHostException { 159 return getServer().allowAccess(addr); 160 } 161 162 176 public interface Impl { 177 184 public URL getRepositoryURL(FileObject fo) throws MalformedURLException , UnknownHostException ; 185 186 193 public URL getRepositoryRoot() throws MalformedURLException , UnknownHostException ; 194 195 203 public URL getResourceURL(String resourcePath) 204 throws MalformedURLException , UnknownHostException ; 205 206 212 public URL getResourceRoot() throws MalformedURLException , UnknownHostException ; 213 214 222 public boolean allowAccess(InetAddress addr) throws UnknownHostException ; 223 } 224 } 225 | Popular Tags |