1 11 package org.apache.catalina.ssi; 12 13 14 import java.io.IOException ; 15 import java.io.PrintWriter ; 16 import java.util.Date ; 17 import org.apache.catalina.util.DateTool; 18 import org.apache.catalina.util.Strftime; 19 28 public final class SSIFlastmod implements SSICommand { 29 32 public long process(SSIMediator ssiMediator, String commandName, 33 String [] paramNames, String [] paramValues, PrintWriter writer) { 34 long lastModified = 0; 35 String configErrMsg = ssiMediator.getConfigErrMsg(); 36 for (int i = 0; i < paramNames.length; i++) { 37 String paramName = paramNames[i]; 38 String paramValue = paramValues[i]; 39 String substitutedValue = ssiMediator 40 .substituteVariables(paramValue); 41 try { 42 if (paramName.equalsIgnoreCase("file") 43 || paramName.equalsIgnoreCase("virtual")) { 44 boolean virtual = paramName.equalsIgnoreCase("virtual"); 45 lastModified = ssiMediator.getFileLastModified( 46 substitutedValue, virtual); 47 Date date = new Date (lastModified); 48 String configTimeFmt = ssiMediator.getConfigTimeFmt(); 49 writer.write(formatDate(date, configTimeFmt)); 50 } else { 51 ssiMediator.log("#flastmod--Invalid attribute: " 52 + paramName); 53 writer.write(configErrMsg); 54 } 55 } catch (IOException e) { 56 ssiMediator.log( 57 "#flastmod--Couldn't get last modified for file: " 58 + substitutedValue, e); 59 writer.write(configErrMsg); 60 } 61 } 62 return lastModified; 63 } 64 65 66 protected String formatDate(Date date, String configTimeFmt) { 67 Strftime strftime = new Strftime(configTimeFmt, DateTool.LOCALE_US); 68 return strftime.format(date); 69 } 70 } | Popular Tags |