001: // DirectoryResource.java
002: // $Id: ExitloopCommand.java,v 1.4 2000/08/16 21:37:47 ylafon Exp $
003: // (c) COPYRIGHT MIT and INRIA, 1996.
004: // Please first read the full copyright statement in file COPYRIGHT.html
005:
006: package org.w3c.jigsaw.ssi.commands;
007:
008: import java.util.Dictionary;
009: import java.util.Hashtable;
010:
011: import org.w3c.www.http.HTTP;
012:
013: import org.w3c.jigsaw.http.Reply;
014: import org.w3c.jigsaw.http.Request;
015:
016: import org.w3c.tools.resources.FramedResource;
017: import org.w3c.tools.resources.Resource;
018: import org.w3c.tools.resources.ResourceFrame;
019:
020: import org.w3c.util.ArrayDictionary;
021:
022: import org.w3c.jigsaw.ssi.SSIFrame;
023:
024: /**
025: * Implementation of the SSI <code>exitloop</code> command.
026: * @author Benoit Mahe <bmahe@sophia.inria.fr>
027: */
028: public class ExitloopCommand implements ControlCommand {
029: private final static String NAME = "exitloop";
030: private final static boolean debug = true;
031:
032: private static final String keys[] = { "name", "command", "var",
033: "equals" };
034:
035: protected static Hashtable exitloops = null;
036:
037: static {
038: exitloops = new Hashtable(23);
039: }
040:
041: public String getValue(Dictionary variables, String var,
042: Request request) {
043: return null;
044: }
045:
046: /**
047: * return true if reply can be cached.
048: * @return a boolean.
049: */
050: public boolean acceptCaching() {
051: return false;
052: }
053:
054: protected static int getPosition(String name)
055: throws ControlCommandException {
056: Integer pos = (Integer) exitloops.get(name);
057: if (pos == null)
058: throw new ControlCommandException(NAME, "Position unknown.");
059: else
060: return pos.intValue();
061: }
062:
063: public void setPosition(SSIFrame ssiframe, Request request,
064: CommandRegistry registry, ArrayDictionary parameters,
065: Dictionary variables, int position) {
066: Object values[] = parameters.getMany(keys);
067: String name = (String) values[0];
068: if (name != null)
069: exitloops.put(ssiframe.getResource().getURLPath() + ":"
070: + name, new Integer(position));
071: }
072:
073: public Reply execute(SSIFrame ssiframe, Request request,
074: ArrayDictionary parameters, Dictionary variables) {
075: return ssiframe.createCommandReply(request, HTTP.OK);
076: }
077:
078: protected boolean check(CommandRegistry registry,
079: ArrayDictionary parameters, Dictionary variables,
080: Request request) {
081: Object values[] = parameters.getMany(keys);
082: String name = (String) values[0];
083: String command = (String) values[1];
084: String var = (String) values[2];
085: String equals = (String) values[3];
086:
087: if ((command == null) || (var == null) || (equals == null))
088: return true;
089: Command cmd = registry.lookupCommand(command);
090: String value = cmd.getValue(variables, var, request);
091: return value.equals(equals);
092: }
093:
094: public int jumpTo(SSIFrame ssiframe, Request request,
095: CommandRegistry registry, ArrayDictionary parameters,
096: Dictionary variables) throws ControlCommandException {
097: Object values[] = parameters.getMany(keys);
098: String name = (String) values[0];
099: if (name != null) {
100: if (!check(registry, parameters, variables, request))
101: return (getPosition(ssiframe.getResource().getURLPath()
102: + ":" + name) + 1);
103: return (EndloopCommand.getPosition(ssiframe.getResource()
104: .getURLPath()
105: + ":" + name) + 1);
106: }
107: throw new ControlCommandException(NAME, "name not initialized.");
108: }
109:
110: public String getName() {
111: return NAME;
112: }
113:
114: }
|