01: /*
02: * Copyright 1999,2004 The Apache Software Foundation.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
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 Dan Sandberg
25: * @version $Revision: 1.2 $, $Date: 2004/02/27 14:58:47 $
26: */
27: public class SSISet implements SSICommand {
28: /**
29: * @see SSICommand
30: */
31: public void process(SSIMediator ssiMediator, String[] paramNames,
32: String[] paramValues, PrintWriter writer)
33: throws SSIStopProcessingException {
34:
35: String errorMessage = ssiMediator.getConfigErrMsg();
36: String variableName = null;
37: for (int i = 0; i < paramNames.length; i++) {
38: String paramName = paramNames[i];
39: String paramValue = paramValues[i];
40:
41: if (paramName.equalsIgnoreCase("var")) {
42: variableName = paramValue;
43: } else if (paramName.equalsIgnoreCase("value")) {
44: if (variableName != null) {
45: ssiMediator.setVariableValue(variableName,
46: paramValue);
47: } else {
48: ssiMediator.log("#set--no variable specified");
49: writer.write(errorMessage);
50: throw new SSIStopProcessingException();
51: }
52: } else {
53: ssiMediator
54: .log("#set--Invalid attribute: " + paramName);
55: writer.write(errorMessage);
56: throw new SSIStopProcessingException();
57: }
58: }
59: }
60: }
|