1 18 19 package org.apache.batik.apps.rasterizer; 20 21 import java.io.IOException ; 22 import java.io.InputStream ; 23 24 import org.apache.batik.util.ParsedURL; 25 26 30 public class SVGConverterURLSource implements SVGConverterSource { 31 34 protected static final String SVG_EXTENSION = ".svg"; 35 protected static final String SVGZ_EXTENSION = ".svgz"; 36 37 public static final String ERROR_INVALID_URL 45 = "SVGConverterURLSource.error.invalid.url"; 46 47 ParsedURL purl; 48 String name; 49 50 public SVGConverterURLSource(String url) throws SVGConverterException{ 51 this.purl = new ParsedURL(url); 52 53 String path = this.purl.getPath(); 55 if (path == null || 56 !(path.toLowerCase().endsWith(SVG_EXTENSION) || 57 path.toLowerCase().endsWith(SVGZ_EXTENSION))){ 58 throw new SVGConverterException(ERROR_INVALID_URL, 59 new Object []{url}); 60 } 61 62 int n = path.lastIndexOf("/"); 63 if (n != -1){ 64 path = path.substring(n+1); 67 } 68 69 name = path; 70 71 String ref = this.purl.getRef(); 76 if (ref != null && (ref.length()!=0)) { 77 name += "" + ref.hashCode(); 78 } 79 } 80 81 public String toString(){ 82 return purl.toString(); 83 } 84 85 public String getURI(){ 86 return toString(); 87 } 88 89 public boolean equals(Object o){ 90 if (o == null || !(o instanceof SVGConverterURLSource)){ 91 return false; 92 } 93 94 return purl.equals(((SVGConverterURLSource)o).purl); 95 } 96 97 public InputStream openStream() throws IOException { 98 return purl.openStream(); 99 } 100 101 public boolean isSameAs(String srcStr){ 102 return toString().equals(srcStr); 103 } 104 105 public boolean isReadable(){ 106 return true; 107 } 108 109 public String getName(){ 110 return name; 111 } 112 } 113 | Popular Tags |