1 48 49 package org.jpublish.repository; 50 51 import java.io.IOException ; 52 import java.io.InputStream ; 53 import java.io.InputStreamReader ; 54 import java.io.Reader ; 55 56 import org.apache.commons.logging.Log; 57 import org.apache.commons.logging.LogFactory; 58 import org.jpublish.view.ContentSource; 59 60 65 66 public class RepositoryContentSource implements ContentSource { 67 68 private static Log log = LogFactory.getLog(RepositoryContentSource.class); 69 70 private Repository repository = null; 71 private String path = null; 72 73 public RepositoryContentSource(Repository repository, String path) { 74 this.repository = repository; 75 this.path = path; 76 } 77 78 84 85 public long getLastModified() throws IOException { 86 return repository.getLastModified(path); 87 } 88 89 95 96 public InputStream getInputStream() throws IOException { 97 try { 98 if (log.isDebugEnabled()) { 99 log.debug("getInputStream():path=" + path); 100 log.debug("Repository class: " + repository.getClass()); 101 } 102 Content content = repository.getContent(path); 103 return content.getContentInputStream(); 104 } catch (Exception e) { 105 throw new IOException ("Error getting stream: " + e); 106 } 107 } 108 109 115 116 public Reader getReader() throws IOException { 117 try { 118 if (log.isDebugEnabled()) { 119 log.debug("getInputStream():path=" + path); 120 } 121 Content content = repository.getContent(path); 122 return new InputStreamReader (content.getContentInputStream()); 123 } catch (Exception e) { 124 throw new IOException ("Error getting reader: " + e); 125 } 126 } 127 128 136 137 public Reader getReader(String encoding) throws IOException { 138 try { 139 if (log.isDebugEnabled()) { 140 log.debug("getInputStream(encoding=" + encoding + "):path=" + path); 141 } 142 Content content = repository.getContent(path); 143 return new InputStreamReader (content.getContentInputStream(), 144 encoding); 145 } catch (Exception e) { 146 throw new IOException ("Error getting reader: " + e); 147 } 148 } 149 150 } 151 | Popular Tags |