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:
22: /**
23: * Implements the Server-side #include command
24: *
25: * @author Bip Thelin
26: * @author Paul Speed
27: * @author Dan Sandberg
28: * @author David Becker
29: * @version $Revision: 531303 $, $Date: 2007-04-23 02:24:01 +0200 (lun., 23 avr. 2007) $
30: */
31: public final class SSIInclude implements SSICommand {
32: /**
33: * @see SSICommand
34: */
35: public long process(SSIMediator ssiMediator, String commandName,
36: String[] paramNames, String[] paramValues,
37: PrintWriter writer) {
38: long lastModified = 0;
39: String configErrMsg = ssiMediator.getConfigErrMsg();
40: for (int i = 0; i < paramNames.length; i++) {
41: String paramName = paramNames[i];
42: String paramValue = paramValues[i];
43: String substitutedValue = ssiMediator
44: .substituteVariables(paramValue);
45: try {
46: if (paramName.equalsIgnoreCase("file")
47: || paramName.equalsIgnoreCase("virtual")) {
48: boolean virtual = paramName
49: .equalsIgnoreCase("virtual");
50: lastModified = ssiMediator.getFileLastModified(
51: substitutedValue, virtual);
52: String text = ssiMediator.getFileText(
53: substitutedValue, virtual);
54: writer.write(text);
55: } else {
56: ssiMediator.log("#include--Invalid attribute: "
57: + paramName);
58: writer.write(configErrMsg);
59: }
60: } catch (IOException e) {
61: ssiMediator.log("#include--Couldn't include file: "
62: + substitutedValue, e);
63: writer.write(configErrMsg);
64: }
65: }
66: return lastModified;
67: }
68: }
|