KickJava   Java API By Example, From Geeks To Geeks.

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


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 /**
17  * Implements the Server-side #include command
18  *
19  * @author Bip Thelin
20  * @author Paul Speed
21  * @author Dan Sandberg
22  * @author David Becker
23  * @version $Revision: 467222 $, $Date: 2006-10-24 05:17:11 +0200 (mar., 24 oct. 2006) $
24  */

25 public final class SSIInclude implements SSICommand {
26     /**
27      * @see SSICommand
28      */

29     public long process(SSIMediator ssiMediator, String JavaDoc commandName,
30             String JavaDoc[] paramNames, String JavaDoc[] paramValues, PrintWriter JavaDoc writer) {
31         long lastModified = 0;
32         String JavaDoc configErrMsg = ssiMediator.getConfigErrMsg();
33         for (int i = 0; i < paramNames.length; i++) {
34             String JavaDoc paramName = paramNames[i];
35             String JavaDoc paramValue = paramValues[i];
36             String JavaDoc substitutedValue = ssiMediator
37                     .substituteVariables(paramValue);
38             try {
39                 if (paramName.equalsIgnoreCase("file")
40                         || paramName.equalsIgnoreCase("virtual")) {
41                     boolean virtual = paramName.equalsIgnoreCase("virtual");
42                     lastModified = ssiMediator.getFileLastModified(
43                              substitutedValue, virtual);
44                     String JavaDoc text = ssiMediator.getFileText(substitutedValue,
45                             virtual);
46                     writer.write(text);
47                 } else {
48                     ssiMediator.log("#include--Invalid attribute: "
49                             + paramName);
50                     writer.write(configErrMsg);
51                 }
52             } catch (IOException JavaDoc e) {
53                 ssiMediator.log("#include--Couldn't include file: "
54                         + substitutedValue, e);
55                 writer.write(configErrMsg);
56             }
57         }
58         return lastModified;
59     }
60 }
Popular Tags