JAL-1807 Bob's first commit -- Applet loaded; needs image
[jalview.git] / src / javajs / util / AjaxURLStreamHandler.java
1 package javajs.util;
2
3 import java.io.IOException;
4 import java.net.URL;
5 import java.net.URLConnection;
6 import java.net.URLStreamHandler;
7
8
9
10 /**
11  * 
12  * A method to allow a JavaScript AJAX adapter to 
13  * deliver web content to JSmol. This handler is just a formality.
14  * 
15  */
16 public class AjaxURLStreamHandler extends URLStreamHandler {
17
18         String protocol;
19
20         public AjaxURLStreamHandler(String protocol) {
21                 this.protocol = protocol;
22         }
23
24         @Override
25         protected URLConnection openConnection(URL url) throws IOException {
26                 return new AjaxURLConnection(url);
27         }
28
29
30   @Override
31   protected String toExternalForm(URL u) {
32     SB result = new SB();
33     result.append(u.getProtocol());
34     result.append(":");
35     if (u.getAuthority() != null && u.getAuthority().length() > 0) {
36       result.append("//");
37       result.append(u.getAuthority());
38     }
39     if (u.getPath() != null) {
40       result.append(u.getPath());
41     }
42     if (u.getQuery() != null) {
43       result.append("?");
44       result.append(u.getQuery());
45     }
46     if (u.getRef() != null) {
47       result.append("#");
48       result.append(u.getRef());
49     }
50     return result.toString();
51   }
52
53 }