KickJava   Java API By Example, From Geeks To Geeks.

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


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

23 public class SSISet implements SSICommand {
24     /**
25      * @see SSICommand
26      */

27     public long process(SSIMediator ssiMediator, String JavaDoc commandName,
28             String JavaDoc[] paramNames, String JavaDoc[] paramValues, PrintWriter JavaDoc writer)
29             throws SSIStopProcessingException {
30         long lastModified = 0;
31         String JavaDoc errorMessage = ssiMediator.getConfigErrMsg();
32         String JavaDoc variableName = null;
33         for (int i = 0; i < paramNames.length; i++) {
34             String JavaDoc paramName = paramNames[i];
35             String JavaDoc paramValue = paramValues[i];
36             if (paramName.equalsIgnoreCase("var")) {
37                 variableName = paramValue;
38             } else if (paramName.equalsIgnoreCase("value")) {
39                 if (variableName != null) {
40                     String JavaDoc substitutedValue = ssiMediator
41                             .substituteVariables(paramValue);
42                     ssiMediator.setVariableValue(variableName,
43                             substitutedValue);
44                     lastModified = System.currentTimeMillis();
45                 } else {
46                     ssiMediator.log("#set--no variable specified");
47                     writer.write(errorMessage);
48                     throw new SSIStopProcessingException();
49                 }
50             } else {
51                 ssiMediator.log("#set--Invalid attribute: " + paramName);
52                 writer.write(errorMessage);
53                 throw new SSIStopProcessingException();
54             }
55         }
56         return lastModified;
57     }
58 }
Popular Tags