--- /dev/null
+// DirectoryListerFrame.java\r
+// $Id: DirectoryListerFrame.java,v 1.2 2010/06/15 17:53:06 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.resources ;\r
+\r
+import org.w3c.tools.resources.FramedResource;\r
+import org.w3c.tools.resources.InvalidResourceException;\r
+import org.w3c.tools.resources.ProtocolException;\r
+import org.w3c.tools.resources.Resource;\r
+import org.w3c.tools.resources.ResourceException;\r
+import org.w3c.tools.resources.ResourceFrame;\r
+import org.w3c.tools.resources.ResourceReference;\r
+\r
+import org.w3c.jigsaw.http.Reply;\r
+import org.w3c.jigsaw.http.Request;\r
+\r
+import org.w3c.jigsaw.frames.HTTPFrame;\r
+\r
+import org.w3c.www.http.HTTP;\r
+\r
+/**\r
+ * Emit the content of its parent directory.\r
+ */\r
+public class DirectoryListerFrame extends HTTPFrame {\r
+\r
+ public void registerResource(FramedResource resource) {\r
+ super.registerOtherResource(resource);\r
+ }\r
+\r
+ /**\r
+ * The default GET method for other king of associated resource\r
+ * @param request The request to handle.\r
+ * @exception ProtocolException If processsing the request failed.\r
+ * @exception ResourceException If the resource got a fatal error.\r
+ */\r
+ protected Reply getOtherResource (Request request)\r
+ throws ProtocolException, ResourceException\r
+ {\r
+ ResourceReference rr = getResource().getParent();\r
+ if (rr != null) {\r
+ try {\r
+ FramedResource p = (FramedResource)rr.unsafeLock();\r
+ // synchronize here to create locks in the right order\r
+ synchronized (p) { \r
+ // verify\r
+ Class http_class = null;\r
+ try {\r
+ http_class = \r
+ Class.forName("org.w3c.jigsaw.frames.HTTPFrame");\r
+ //Added by Jeff Huang\r
+ //TODO: FIXIT\r
+ } catch (ClassNotFoundException ex) {\r
+ throw new ResourceException(ex.getMessage());\r
+ }\r
+ ResourceReference rrf = p.getFrameReference(http_class);\r
+ if (rrf == null) {\r
+ throw new ResourceException("DirectoryResource has "+\r
+ "no HTTPFrame");\r
+ }\r
+ try { \r
+ HTTPFrame httpframe = (HTTPFrame) rrf.unsafeLock();\r
+ if (p instanceof DirectoryResource) \r
+ return httpframe.getDirectoryListing(request);\r
+ else \r
+ return httpframe.get(request);\r
+ } catch (InvalidResourceException ex) {\r
+ throw new ResourceException(\r
+ "Invalid parent frame (lister):"+\r
+ ex.getMessage());\r
+ } finally {\r
+ rrf.unlock();\r
+ }\r
+ }\r
+ } catch (InvalidResourceException ex) {\r
+ throw new ResourceException("Invalid parent (lister):"+\r
+ ex.getMessage());\r
+ } finally {\r
+ rr.unlock();\r
+ }\r
+ } else {\r
+ return createDefaultReply(request, HTTP.NO_CONTENT) ;\r
+ }\r
+ }\r
+}\r