1 2 3 7 package com.hp.hpl.jena.shared.wg; 8 import com.hp.hpl.jena.rdf.arp.MalformedURIException; 9 10 17 public class URI extends com.hp.hpl.jena.rdf.arp.URI { 18 private String relative; 19 public static URI create(String s) { 20 try { 21 return new URI(s); 22 } 23 catch (MalformedURIException e) { 24 if ( e.toString().indexOf("No scheme")!= -1) { 25 try { 26 return new URI(s,false); 27 } 28 catch (MalformedURIException ee) { 29 } 30 } 31 throw new IllegalArgumentException (e.toString()); 32 } 33 } 34 35 private URI(String s,boolean x) throws MalformedURIException { 36 super("http://foo"); 37 relative = s; 38 } 39 private URI(String s) throws MalformedURIException { 40 super(s); 41 } 42 43 private URI(URI x, URI y) throws MalformedURIException { 44 super(x, y.toString()); 45 } 46 public boolean isAbsolute() { 47 return relative == null; 48 } 49 public URI resolve(URI rel) { 50 try { 51 return new URI(this,rel); 52 } 53 catch (MalformedURIException e) { 54 throw new IllegalArgumentException (e.toString()); 55 } 56 } 57 58 public java.net.URL toURL() throws java.net.MalformedURLException { 59 return new java.net.URL (getURIString()); 60 } 61 62 public URI relativize(URI x) { 63 String me = toString(); 64 String xx = x.toString(); 65 if ( !xx.startsWith(me) ) { 66 throw new IllegalArgumentException (xx + " is not relative to " + me); 67 } 68 String sub = xx.substring( me.length() ); 69 return create( sub.charAt(0) == '/' ? sub.substring( 1 ) : sub ); 70 } 71 72 public String getURIString() 73 { return relative == null ? super.getURIString() : relative; } 74 75 public String toString() 76 { return getURIString(); } 77 } 78 104 | Popular Tags |