1 6 7 package com.quikj.client.framework; 8 9 import java.net.*; 10 import java.applet.*; 11 12 16 public class URLUtils 17 { 18 19 public URLUtils() 20 { 21 } 22 23 public static URL formatURL(Applet applet, String loc) 24 { 25 URL url = null; 26 try 27 { 28 url = new URL(loc); 29 } 30 catch (MalformedURLException ex) 31 { 32 URL docbase = applet.getDocumentBase(); 33 if (loc.startsWith("/") == true) 34 { 35 StringBuffer buffer = new StringBuffer (docbase.getProtocol() 36 + "://" 37 + docbase.getHost()); 38 39 if (docbase.getPort() > 0) 40 { 41 buffer.append(":" + docbase.getPort()); 42 } 43 44 buffer.append(loc); 45 46 try 47 { 48 url = new URL(buffer.toString()); 49 } 50 catch (MalformedURLException ex1) 51 { 52 ; 53 } 54 } 55 else { 57 String path = docbase.toString(); 58 59 int last = path.lastIndexOf('/'); 61 62 path = path.substring(0, last+1); 63 64 try 65 { 66 url = new URL(path + loc); 68 } 69 catch (MalformedURLException ex1) 70 { 71 ; 72 } 73 } 74 } 75 76 return url; 77 } 78 } 79 | Popular Tags |