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