1 37 package net.sourceforge.cruisecontrol.servlet; 38 39 import javax.servlet.ServletConfig ; 40 import javax.servlet.ServletException ; 41 import java.io.File ; 42 import java.io.IOException ; 43 import java.io.InputStream ; 44 45 import net.sourceforge.cruisecontrol.LogFile; 46 47 48 52 public class LogFileServlet extends FileServlet { 53 54 55 public LogFileServlet() { 56 } 57 58 protected File getRootDir(ServletConfig servletconfig) throws ServletException { 59 File rootDirectory = getLogDir(servletconfig); 60 if (rootDirectory == null) { 61 String message = "LogFileServlet not configured correctly in web.xml.\n" 62 + "logDir must point to existing directory.\n" 63 + "logDir is currently set to <" 64 + getLogDirParameter(servletconfig) + ">"; 65 throw new ServletException (message); 66 } 67 68 return rootDirectory; 69 } 70 71 protected String getMimeType(String filename) { 72 return "application/xml"; 73 } 74 75 LogFile getLogFile(final String subFilePath) { 76 int logIndex = subFilePath.lastIndexOf('/'); 77 String project = subFilePath.substring(0, logIndex); 78 String logName = subFilePath.substring(logIndex + 1); 79 return new LogFile(new File (getRootDir(), project), logName); 80 } 81 protected WebFile getSubWebFile(final String subFilePath) { 82 return new LogWebFile(getLogFile(subFilePath)); 83 } 84 85 private static class LogWebFile extends WebFile { 86 private LogFile logfile; 87 88 public LogWebFile(LogFile file) { 89 super(file.getFile()); 90 logfile = file; 91 } 92 93 protected InputStream getInputStream() throws IOException { 94 return logfile.getInputStream(); 95 } 96 } 97 } 98 | Popular Tags |