1 16 package org.outerj.daisy.frontend.components.skinsource; 17 18 import org.apache.excalibur.source.Source; 19 import org.apache.excalibur.source.SourceNotFoundException; 20 import org.apache.excalibur.source.SourceValidity; 21 22 import java.io.*; 23 import java.net.URLConnection ; 24 25 public class SkinSource implements Source { 26 private File file; 27 private String uri; 28 29 public SkinSource(File file, String uri) { 30 this.file = file; 31 this.uri = uri; 32 } 33 34 public boolean exists() { 35 return file.exists(); 36 } 37 38 public InputStream getInputStream() throws IOException, SourceNotFoundException { 39 try { 40 return new FileInputStream(file); 41 } catch (FileNotFoundException fnfe) { 42 throw new SourceNotFoundException(uri + " doesn't exist.", fnfe); 43 } 44 } 45 46 public String getURI() { 47 return uri; 48 } 49 50 public String getScheme() { 51 return "daisyskin"; 52 } 53 54 public SourceValidity getValidity() { 55 if (file.exists()) { 56 return new SkinSourceValidity(file); 57 } else { 58 return null; 59 } 60 } 61 62 public void refresh() { 63 } 65 66 public String getMimeType() { 67 return URLConnection.getFileNameMap().getContentTypeFor(file.getName()); 68 } 69 70 public long getContentLength() { 71 return file.length(); 72 } 73 74 public long getLastModified() { 75 return file.lastModified(); 76 } 77 } 78 | Popular Tags |