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.PrintWriter;
20: import java.util.Collection;
21: import java.util.Iterator;
22:
23: /**
24: * Implements the Server-side #printenv command
25: *
26: * @author Dan Sandberg
27: * @author David Becker
28: * @version $Revision: 531303 $, $Date: 2007-04-23 02:24:01 +0200 (lun., 23 avr. 2007) $
29: */
30: public class SSIPrintenv implements SSICommand {
31: /**
32: * @see SSICommand
33: */
34: public long process(SSIMediator ssiMediator, String commandName,
35: String[] paramNames, String[] paramValues,
36: PrintWriter writer) {
37: long lastModified = 0;
38: //any arguments should produce an error
39: if (paramNames.length > 0) {
40: String errorMessage = ssiMediator.getConfigErrMsg();
41: writer.write(errorMessage);
42: } else {
43: Collection variableNames = ssiMediator.getVariableNames();
44: Iterator iter = variableNames.iterator();
45: while (iter.hasNext()) {
46: String variableName = (String) iter.next();
47: String variableValue = ssiMediator
48: .getVariableValue(variableName);
49: //This shouldn't happen, since all the variable names must
50: // have values
51: if (variableValue == null) {
52: variableValue = "(none)";
53: }
54: writer.write(variableName);
55: writer.write('=');
56: writer.write(variableValue);
57: writer.write('\n');
58: lastModified = System.currentTimeMillis();
59: }
60: }
61: return lastModified;
62: }
63: }
|