KickJava   Java API By Example, From Geeks To Geeks.

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


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.PrintWriter JavaDoc;
15 /**
16  * Return the result associated with the supplied Server Variable.
17  *
18  * @author Bip Thelin
19  * @author Paul Speed
20  * @author Dan Sandberg
21  * @author David Becker
22  * @version $Revision: 467222 $, $Date: 2006-10-24 05:17:11 +0200 (mar., 24 oct. 2006) $
23  */

24 public class SSIEcho implements SSICommand {
25     protected final static String JavaDoc DEFAULT_ENCODING = "entity";
26     protected final static String JavaDoc MISSING_VARIABLE_VALUE = "(none)";
27
28
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 encoding = DEFAULT_ENCODING;
36         String JavaDoc errorMessage = ssiMediator.getConfigErrMsg();
37         for (int i = 0; i < paramNames.length; i++) {
38             String JavaDoc paramName = paramNames[i];
39             String JavaDoc paramValue = paramValues[i];
40             if (paramName.equalsIgnoreCase("var")) {
41                 String JavaDoc variableValue = ssiMediator.getVariableValue(
42                         paramValue, encoding);
43                 if (variableValue == null) {
44                     variableValue = MISSING_VARIABLE_VALUE;
45                 }
46                 writer.write(variableValue);
47                 lastModified = System.currentTimeMillis();
48             } else if (paramName.equalsIgnoreCase("encoding")) {
49                 if (isValidEncoding(paramValue)) {
50                     encoding = paramValue;
51                 } else {
52                     ssiMediator.log("#echo--Invalid encoding: " + paramValue);
53                     writer.write(errorMessage);
54                 }
55             } else {
56                 ssiMediator.log("#echo--Invalid attribute: " + paramName);
57                 writer.write(errorMessage);
58             }
59         }
60         return lastModified;
61     }
62
63
64     protected boolean isValidEncoding(String JavaDoc encoding) {
65         return encoding.equalsIgnoreCase("url")
66                 || encoding.equalsIgnoreCase("entity")
67                 || encoding.equalsIgnoreCase("none");
68     }
69 }
Popular Tags