--- /dev/null
+// DirectoryResource.java\r
+// $Id: ElseCommand.java,v 1.1 2010/06/15 12:21:52 smhuang Exp $\r
+// (c) COPYRIGHT MIT and INRIA, 1996.\r
+// Please first read the full copyright statement in file COPYRIGHT.html\r
+\r
+package org.w3c.jigsaw.ssi.commands;\r
+\r
+import java.util.Dictionary;\r
+import java.util.Hashtable;\r
+\r
+import org.w3c.www.http.HTTP;\r
+\r
+import org.w3c.jigsaw.http.Reply;\r
+import org.w3c.jigsaw.http.Request;\r
+\r
+import org.w3c.tools.resources.Resource;\r
+import org.w3c.tools.resources.ResourceFrame;\r
+\r
+import org.w3c.util.ArrayDictionary;\r
+\r
+import org.w3c.jigsaw.ssi.SSIFrame;\r
+\r
+/**\r
+ * Implementation of the SSI <code>else</code> command. \r
+ * @author Benoit Mahe <bmahe@sophia.inria.fr>\r
+ */\r
+\r
+public class ElseCommand implements ControlCommand {\r
+ private final static String NAME = "else";\r
+ private final static boolean debug = true;\r
+\r
+ private static final String keys[] = { "name" };\r
+\r
+ protected static Hashtable elsestore = null;\r
+\r
+ static {\r
+ elsestore = new Hashtable(23);\r
+ }\r
+\r
+ protected static int getPosition(String name) \r
+ throws ControlCommandException \r
+ {\r
+ Integer pos = (Integer)elsestore.get(name);\r
+ if (pos == null)\r
+ throw new ControlCommandException(NAME,"Position unknown.");\r
+ else return pos.intValue();\r
+ }\r
+\r
+ public void setPosition(SSIFrame ssiframe,\r
+ Request request,\r
+ CommandRegistry registry,\r
+ ArrayDictionary parameters,\r
+ Dictionary variables,\r
+ int position) \r
+ {\r
+ Object values[] = parameters.getMany(keys);\r
+ String name = (String) values[0];\r
+ if (name != null)\r
+ elsestore.put(ssiframe.getURLPath()+":"+name, \r
+ new Integer(position));\r
+ }\r
+\r
+ public String getValue(Dictionary variables, String var, Request request) {\r
+ return null;\r
+ }\r
+\r
+ public Reply execute(SSIFrame ssiframe\r
+ , Request request\r
+ , ArrayDictionary parameters\r
+ , Dictionary variables) \r
+ {\r
+ return ssiframe.createCommandReply(request, HTTP.OK);\r
+ }\r
+\r
+ public int jumpTo(SSIFrame ssiframe,\r
+ Request request,\r
+ CommandRegistry registry,\r
+ ArrayDictionary parameters,\r
+ Dictionary variables)\r
+ throws ControlCommandException\r
+ {\r
+ Object values[] = parameters.getMany(keys);\r
+ String name = (String) values[0];\r
+ if (name != null)\r
+ return \r
+ (EndifCommand.getPosition(ssiframe.getResource().getURLPath()+\r
+ ":"+name)+1);\r
+ throw new ControlCommandException(NAME,"name not initialized.");\r
+ }\r
+\r
+ public String getName() {\r
+ return NAME;\r
+ }\r
+\r
+ /**\r
+ * return true if reply can be cached.\r
+ * @return a boolean.\r
+ */\r
+ public boolean acceptCaching() {\r
+ return false;\r
+ }\r
+\r
+}\r
+\r
+\r