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:
21: /**
22: * Implements the Server-side #set command
23: *
24: * @author Paul Speed
25: * @author Dan Sandberg
26: * @author David Becker
27: * @version $Revision: 531303 $, $Date: 2007-04-23 02:24:01 +0200 (lun., 23 avr. 2007) $
28: */
29: public class SSISet implements SSICommand {
30: /**
31: * @see SSICommand
32: */
33: public long process(SSIMediator ssiMediator, String commandName,
34: String[] paramNames, String[] paramValues,
35: PrintWriter writer) throws SSIStopProcessingException {
36: long lastModified = 0;
37: String errorMessage = ssiMediator.getConfigErrMsg();
38: String variableName = null;
39: for (int i = 0; i < paramNames.length; i++) {
40: String paramName = paramNames[i];
41: String paramValue = paramValues[i];
42: if (paramName.equalsIgnoreCase("var")) {
43: variableName = paramValue;
44: } else if (paramName.equalsIgnoreCase("value")) {
45: if (variableName != null) {
46: String substitutedValue = ssiMediator
47: .substituteVariables(paramValue);
48: ssiMediator.setVariableValue(variableName,
49: substitutedValue);
50: lastModified = System.currentTimeMillis();
51: } else {
52: ssiMediator.log("#set--no variable specified");
53: writer.write(errorMessage);
54: throw new SSIStopProcessingException();
55: }
56: } else {
57: ssiMediator
58: .log("#set--Invalid attribute: " + paramName);
59: writer.write(errorMessage);
60: throw new SSIStopProcessingException();
61: }
62: }
63: return lastModified;
64: }
65: }
|