1 17 package org.alfresco.config.source; 18 19 import java.io.BufferedInputStream ; 20 import java.io.FileInputStream ; 21 import java.io.IOException ; 22 import java.io.InputStream ; 23 import java.util.Collections ; 24 import java.util.List ; 25 26 import javax.servlet.ServletContext ; 27 28 import org.apache.commons.logging.Log; 29 import org.apache.commons.logging.LogFactory; 30 import org.springframework.web.context.ServletContextAware; 31 32 41 public class WebAppConfigSource extends BaseConfigSource implements ServletContextAware 42 { 43 private static Log logger = LogFactory.getLog(FileConfigSource.class); 44 private ServletContext servletCtx; 45 46 53 public WebAppConfigSource(String filename) 54 { 55 this(Collections.singletonList(filename)); 56 } 57 58 62 public WebAppConfigSource(List <String > sourceStrings) 63 { 64 super(sourceStrings); 65 } 66 67 70 public void setServletContext(ServletContext servletContext) 71 { 72 this.servletCtx = servletContext; 73 } 74 75 78 public InputStream getInputStream(String sourceString) 79 { 80 InputStream is = null; 81 82 try 83 { 84 String fullPath = this.servletCtx.getRealPath(sourceString); 85 is = new BufferedInputStream (new FileInputStream (fullPath)); 86 } 87 catch (IOException ioe) 88 { 89 if (logger.isDebugEnabled()) 90 { 91 logger.debug("Failed to obtain input stream to file: " + sourceString, ioe); 92 } 93 } 94 95 return is; 96 } 97 } 98 | Popular Tags |