01: // DirectoryResource.java
02: // $Id: ElseCommand.java,v 1.4 2000/08/16 21:37:47 ylafon Exp $
03: // (c) COPYRIGHT MIT and INRIA, 1996.
04: // Please first read the full copyright statement in file COPYRIGHT.html
05:
06: package org.w3c.jigsaw.ssi.commands;
07:
08: import java.util.Dictionary;
09: import java.util.Hashtable;
10:
11: import org.w3c.www.http.HTTP;
12:
13: import org.w3c.jigsaw.http.Reply;
14: import org.w3c.jigsaw.http.Request;
15:
16: import org.w3c.tools.resources.Resource;
17: import org.w3c.tools.resources.ResourceFrame;
18:
19: import org.w3c.util.ArrayDictionary;
20:
21: import org.w3c.jigsaw.ssi.SSIFrame;
22:
23: /**
24: * Implementation of the SSI <code>else</code> command.
25: * @author Benoit Mahe <bmahe@sophia.inria.fr>
26: */
27:
28: public class ElseCommand implements ControlCommand {
29: private final static String NAME = "else";
30: private final static boolean debug = true;
31:
32: private static final String keys[] = { "name" };
33:
34: protected static Hashtable elsestore = null;
35:
36: static {
37: elsestore = new Hashtable(23);
38: }
39:
40: protected static int getPosition(String name)
41: throws ControlCommandException {
42: Integer pos = (Integer) elsestore.get(name);
43: if (pos == null)
44: throw new ControlCommandException(NAME, "Position unknown.");
45: else
46: return pos.intValue();
47: }
48:
49: public void setPosition(SSIFrame ssiframe, Request request,
50: CommandRegistry registry, ArrayDictionary parameters,
51: Dictionary variables, int position) {
52: Object values[] = parameters.getMany(keys);
53: String name = (String) values[0];
54: if (name != null)
55: elsestore.put(ssiframe.getURLPath() + ":" + name,
56: new Integer(position));
57: }
58:
59: public String getValue(Dictionary variables, String var,
60: Request request) {
61: return null;
62: }
63:
64: public Reply execute(SSIFrame ssiframe, Request request,
65: ArrayDictionary parameters, Dictionary variables) {
66: return ssiframe.createCommandReply(request, HTTP.OK);
67: }
68:
69: public int jumpTo(SSIFrame ssiframe, Request request,
70: CommandRegistry registry, ArrayDictionary parameters,
71: Dictionary variables) throws ControlCommandException {
72: Object values[] = parameters.getMany(keys);
73: String name = (String) values[0];
74: if (name != null)
75: return (EndifCommand.getPosition(ssiframe.getResource()
76: .getURLPath()
77: + ":" + name) + 1);
78: throw new ControlCommandException(NAME, "name not initialized.");
79: }
80:
81: public String getName() {
82: return NAME;
83: }
84:
85: /**
86: * return true if reply can be cached.
87: * @return a boolean.
88: */
89: public boolean acceptCaching() {
90: return false;
91: }
92:
93: }
|