01: // DirectoryListerFrame.java
02: // $Id: DirectoryListerFrame.java,v 1.7 2002/08/08 12:36:51 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.resources;
07:
08: import org.w3c.tools.resources.FramedResource;
09: import org.w3c.tools.resources.InvalidResourceException;
10: import org.w3c.tools.resources.ProtocolException;
11: import org.w3c.tools.resources.Resource;
12: import org.w3c.tools.resources.ResourceException;
13: import org.w3c.tools.resources.ResourceFrame;
14: import org.w3c.tools.resources.ResourceReference;
15:
16: import org.w3c.jigsaw.http.Reply;
17: import org.w3c.jigsaw.http.Request;
18:
19: import org.w3c.jigsaw.frames.HTTPFrame;
20:
21: import org.w3c.www.http.HTTP;
22:
23: /**
24: * Emit the content of its parent directory.
25: */
26: public class DirectoryListerFrame extends HTTPFrame {
27:
28: public void registerResource(FramedResource resource) {
29: super .registerOtherResource(resource);
30: }
31:
32: /**
33: * The default GET method for other king of associated resource
34: * @param request The request to handle.
35: * @exception ProtocolException If processsing the request failed.
36: * @exception ResourceException If the resource got a fatal error.
37: */
38: protected Reply getOtherResource(Request request)
39: throws ProtocolException, ResourceException {
40: ResourceReference rr = getResource().getParent();
41: if (rr != null) {
42: try {
43: FramedResource p = (FramedResource) rr.unsafeLock();
44: // synchronize here to create locks in the right order
45: synchronized (p) {
46: // verify
47: Class http_class = null;
48: try {
49: http_class = Class
50: .forName("org.w3c.jigsaw.frames.HTTPFrame");
51: } catch (ClassNotFoundException ex) {
52: throw new ResourceException(ex.getMessage());
53: }
54: ResourceReference rrf = p
55: .getFrameReference(http_class);
56: if (rrf == null) {
57: throw new ResourceException(
58: "DirectoryResource has "
59: + "no HTTPFrame");
60: }
61: try {
62: HTTPFrame httpframe = (HTTPFrame) rrf
63: .unsafeLock();
64: if (p instanceof DirectoryResource)
65: return httpframe
66: .getDirectoryListing(request);
67: else
68: return httpframe.get(request);
69: } catch (InvalidResourceException ex) {
70: throw new ResourceException(
71: "Invalid parent frame (lister):"
72: + ex.getMessage());
73: } finally {
74: rrf.unlock();
75: }
76: }
77: } catch (InvalidResourceException ex) {
78: throw new ResourceException("Invalid parent (lister):"
79: + ex.getMessage());
80: } finally {
81: rr.unlock();
82: }
83: } else {
84: return createDefaultReply(request, HTTP.NO_CONTENT);
85: }
86: }
87: }
|