1 package net.sf.uitags.js; 2 3 import java.io.IOException ; 4 import java.io.InputStream ; 5 import java.net.URL ; 6 7 import javax.servlet.ServletContext ; 8 9 final class FileSystemBasedFileFinder extends FileFinder { 10 private ServletContext servletContext; 11 private String containingDirName; 12 13 FileSystemBasedFileFinder( 14 ServletContext servletContext, String containingDirName) { 15 this.servletContext = servletContext; 16 this.containingDirName = correctDirName(containingDirName); 17 } 18 19 private String correctDirName(String name) { 20 name = name.trim(); 21 22 if (!name.startsWith("/")) { 24 name = "/" + name; 25 } 26 27 if (!name.endsWith("/")) { 29 name = name + "/"; 30 } 31 32 return name; 33 } 34 35 protected InputStream openInputStream(String fileName) throws IOException { 36 return getUrl(fileName).openStream(); 37 } 38 39 protected boolean supportsFilesNotFromSuites() { 40 return true; 41 } 42 43 protected long getLastModified(String fileName) throws IOException { 44 return getUrl(fileName).openConnection().getLastModified(); 45 } 46 47 private URL getUrl(String fileName) throws IOException { 48 return this.servletContext.getResource(this.containingDirName + fileName); 49 } 50 51 54 String getCorrectedDirName() { 55 return this.containingDirName; 56 } 57 } 58 | Popular Tags |