1 package net.sf.uitags.js; 2 3 import java.io.BufferedReader ; 4 import java.io.IOException ; 5 import java.io.InputStream ; 6 import java.io.InputStreamReader ; 7 8 import javax.servlet.ServletContext ; 9 10 import net.sf.uitags.util.ResourceCloser; 11 12 17 abstract class FileFinder { 18 static FileFinder getInstance( 19 ServletContext context, String containingDirName) { 20 if (containingDirName == null) { 21 return new ClasspathBasedFileFinder(); 22 } 23 24 return new FileSystemBasedFileFinder(context, containingDirName); 25 } 26 27 final String readContents(String fileName) throws IOException { 28 StringBuffer out = new StringBuffer (); 29 30 InputStream in = null; 31 BufferedReader contents = null; 32 try { 33 in = openInputStream(fileName); 34 contents = new BufferedReader (new InputStreamReader (in)); 35 while (contents.ready()) { 36 out.append(contents.readLine()); 37 out.append("\n"); 38 } 39 } 40 finally { 41 ResourceCloser.close(contents); 42 ResourceCloser.close(in); 43 } 44 45 return out.toString(); 46 } 47 48 54 protected abstract InputStream openInputStream(String fileName) 55 throws IOException ; 56 57 61 protected abstract boolean supportsFilesNotFromSuites(); 62 63 66 protected abstract long getLastModified(String fileName) 67 throws IOException ; 68 } 69 | Popular Tags |