1 16 package org.outerj.daisy.books.store.source; 17 18 import org.apache.excalibur.source.Source; 19 import org.apache.excalibur.source.SourceNotFoundException; 20 import org.apache.excalibur.source.SourceValidity; 21 import org.apache.excalibur.source.impl.validity.TimeStampValidity; 22 import org.outerj.daisy.books.store.BookInstance; 23 import org.outerx.daisy.x10Bookstoremeta.ResourcePropertiesDocument; 24 25 import java.io.InputStream ; 26 import java.io.IOException ; 27 import java.net.URLConnection ; 28 29 public class BookStoreSource implements Source { 30 private BookInstance bookInstance; 31 private String resource; 32 33 public BookStoreSource(BookInstance bookInstance, String resource) { 34 this.bookInstance = bookInstance; 35 this.resource = resource; 36 } 37 38 public boolean exists() { 39 return bookInstance.exists(resource); 40 } 41 42 public InputStream getInputStream() throws IOException , SourceNotFoundException { 43 return bookInstance.getResource(resource); 44 } 45 46 public String getURI() { 47 return "bookstore:" + bookInstance.getName() + "/" + resource; 48 } 49 50 public String getScheme() { 51 return "bookstore"; 52 } 53 54 public SourceValidity getValidity() { 55 return new TimeStampValidity(getLastModified()); 56 } 57 58 public void refresh() { 59 } 60 61 public String getMimeType() { 62 ResourcePropertiesDocument propertiesDocument = bookInstance.getResourceProperties(resource); 63 String mimeType = (propertiesDocument != null && propertiesDocument.getResourceProperties() != null) ? propertiesDocument.getResourceProperties().getMimeType() : null; 64 if (mimeType == null) 65 mimeType = URLConnection.getFileNameMap().getContentTypeFor(resource); 66 return mimeType; 67 } 68 69 public long getContentLength() { 70 return bookInstance.getContentLength(resource); 71 } 72 73 public long getLastModified() { 74 return bookInstance.getLastModified(resource); 75 } 76 } 77 | Popular Tags |