KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > catalina > ssi > SSIFlastmod


1 /*
2  * Copyright 1999,2004 The Apache Software Foundation. Licensed under the
3  * Apache License, Version 2.0 (the "License"); you may not use this file
4  * except in compliance with the License. You may obtain a copy of the License
5  * at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable
6  * law or agreed to in writing, software distributed under the License is
7  * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
8  * KIND, either express or implied. See the License for the specific language
9  * governing permissions and limitations under the License.
10  */

11 package org.apache.catalina.ssi;
12
13
14 import java.io.IOException JavaDoc;
15 import java.io.PrintWriter JavaDoc;
16 import java.util.Date JavaDoc;
17 import org.apache.catalina.util.DateTool;
18 import org.apache.catalina.util.Strftime;
19 /**
20  * Implements the Server-side #flastmod command
21  *
22  * @author Bip Thelin
23  * @author Paul Speed
24  * @author Dan Sandberg
25  * @author David Becker
26  * @version $Revision: 467222 $, $Date: 2006-10-24 05:17:11 +0200 (mar., 24 oct. 2006) $
27  */

28 public final class SSIFlastmod implements SSICommand {
29     /**
30      * @see SSICommand
31      */

32     public long process(SSIMediator ssiMediator, String JavaDoc commandName,
33             String JavaDoc[] paramNames, String JavaDoc[] paramValues, PrintWriter JavaDoc writer) {
34         long lastModified = 0;
35         String JavaDoc configErrMsg = ssiMediator.getConfigErrMsg();
36         for (int i = 0; i < paramNames.length; i++) {
37             String JavaDoc paramName = paramNames[i];
38             String JavaDoc paramValue = paramValues[i];
39             String JavaDoc 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 JavaDoc date = new Date JavaDoc(lastModified);
48                     String JavaDoc 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 JavaDoc 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 JavaDoc formatDate(Date JavaDoc date, String JavaDoc configTimeFmt) {
67         Strftime strftime = new Strftime(configTimeFmt, DateTool.LOCALE_US);
68         return strftime.format(date);
69     }
70 }
Popular Tags