01: /*
02: * Copyright 1999,2004 The Apache Software Foundation.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.apache.catalina.ssi;
18:
19: import java.io.IOException;
20: import java.io.PrintWriter;
21: import java.util.Date;
22:
23: import org.apache.catalina.util.DateTool;
24: import org.apache.catalina.util.Strftime;
25:
26: /**
27: * Implements the Server-side #flastmod command
28: *
29: * @author Bip Thelin
30: * @author Dan Sandberg
31: * @version $Revision: 1.3 $, $Date: 2004/02/27 14:58:47 $
32: */
33: public final class SSIFlastmod implements SSICommand {
34: /**
35: * @see SSICommand
36: */
37: public void process(SSIMediator ssiMediator, String[] paramNames,
38: String[] paramValues, PrintWriter writer) {
39:
40: String configErrMsg = ssiMediator.getConfigErrMsg();
41: StringBuffer buf = new StringBuffer();
42:
43: for (int i = 0; i < paramNames.length; i++) {
44: String paramName = paramNames[i];
45: String paramValue = paramValues[i];
46:
47: try {
48: if (paramName.equalsIgnoreCase("file")
49: || paramName.equalsIgnoreCase("virtual")) {
50: boolean virtual = paramName
51: .equalsIgnoreCase("virtual");
52: long lastModified = ssiMediator
53: .getFileLastModified(paramValue, virtual);
54: Date date = new Date(lastModified);
55: String configTimeFmt = ssiMediator
56: .getConfigTimeFmt();
57: writer.write(formatDate(date, configTimeFmt));
58: } else {
59: ssiMediator.log("#flastmod--Invalid attribute: "
60: + paramName);
61: writer.write(configErrMsg);
62: }
63: } catch (IOException e) {
64: ssiMediator.log(
65: "#flastmod--Couldn't get last modified for file: "
66: + paramValue, e);
67: writer.write(configErrMsg);
68: }
69: }
70: }
71:
72: protected String formatDate(Date date, String configTimeFmt) {
73: Strftime strftime = new Strftime(configTimeFmt,
74: DateTool.LOCALE_US);
75: return strftime.format(date);
76: }
77: }
|