01: // EndloopCommand.java
02: // $Id: EndloopCommand.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>endloop</code> command.
25: * @author Benoit Mahe <bmahe@sophia.inria.fr>
26: */
27: public class EndloopCommand implements ControlCommand {
28: private final static String NAME = "endloop";
29: private final static boolean debug = true;
30:
31: private static final String keys[] = { "name" };
32:
33: protected static Hashtable endloops = null;
34:
35: static {
36: endloops = new Hashtable(23);
37: }
38:
39: /**
40: * return true if reply can be cached.
41: * @return a boolean.
42: */
43: public boolean acceptCaching() {
44: return false;
45: }
46:
47: protected static int getPosition(String name)
48: throws ControlCommandException {
49: Integer pos = (Integer) endloops.get(name);
50: if (pos == null)
51: throw new ControlCommandException(NAME, "Position unknown.");
52: else
53: return pos.intValue();
54: }
55:
56: public void setPosition(SSIFrame ssiframe, Request request,
57: CommandRegistry registry, ArrayDictionary parameters,
58: Dictionary variables, int position) {
59: Object values[] = parameters.getMany(keys);
60: String name = (String) values[0];
61: if (name != null)
62: endloops.put(ssiframe.getResource().getURLPath() + ":"
63: + name, new Integer(position));
64: }
65:
66: public String getValue(Dictionary variables, String var,
67: Request request) {
68: return null;
69: }
70:
71: public Reply execute(SSIFrame ssiframe, Request request,
72: ArrayDictionary parameters, Dictionary variables) {
73: return ssiframe.createCommandReply(request, HTTP.OK);
74: }
75:
76: public int jumpTo(SSIFrame ssiframe, Request request,
77: CommandRegistry registry, ArrayDictionary parameters,
78: Dictionary variables) throws ControlCommandException {
79: Object values[] = parameters.getMany(keys);
80: String name = (String) values[0];
81: if (name != null)
82: return LoopCommand.getPosition(ssiframe.getResource()
83: .getURLPath()
84: + ":" + name);
85: throw new ControlCommandException(NAME, "name not initialized.");
86: }
87:
88: public String getName() {
89: return NAME;
90: }
91:
92: }
|