001: // FancyFrame.java
002: // $Id: FancyFrame.java,v 1.4 2000/08/16 21:37:48 ylafon Exp $
003: // (c) COPYRIGHT MIT and INRIA, 1998.
004: // Please first read the full copyright statement in file COPYRIGHT.html
005:
006: package org.w3c.jigsaw.tutorials;
007:
008: import java.util.Date;
009: import org.w3c.tools.resources.Attribute;
010: import org.w3c.tools.resources.AttributeRegistry;
011: import org.w3c.tools.resources.DirectoryResource;
012: import org.w3c.tools.resources.FileResource;
013: import org.w3c.tools.resources.FramedResource;
014: import org.w3c.tools.resources.ProtocolException;
015: import org.w3c.tools.resources.ResourceException;
016: import org.w3c.tools.resources.StringAttribute;
017: import org.w3c.jigsaw.frames.HTTPFrame;
018: import org.w3c.jigsaw.html.HtmlGenerator;
019: import org.w3c.jigsaw.http.Reply;
020: import org.w3c.jigsaw.http.Request;
021: import org.w3c.www.http.HTTP;
022:
023: /**
024: * @version $Revision: 1.4 $
025: * @author Benoît Mahé (bmahe@w3.org)
026: */
027: public class FancyFrame extends HTTPFrame {
028:
029: /**
030: * Attribute index - Message to display
031: */
032: protected static int ATTR_MESSAGE = -1;
033:
034: static {
035: Attribute a = null;
036: Class cls = null;
037:
038: try {
039: cls = Class.forName("org.w3c.jigsaw.tutorials.FancyFrame");
040: } catch (Exception ex) {
041: ex.printStackTrace();
042: System.exit(1);
043: }
044:
045: // The message attribute
046: a = new StringAttribute("message", "Hello", Attribute.EDITABLE);
047: ATTR_MESSAGE = AttributeRegistry.registerAttribute(cls, a);
048: }
049:
050: /**
051: * Get the message.
052: * @return A String instance.
053: */
054: public String getMessage() {
055: return getString(ATTR_MESSAGE, null);
056: }
057:
058: /**
059: * Display the Frame message and some attributes of our
060: * associated FileResource. This method is called only if
061: * our associated resource *is* a FileResource.
062: * @param request The request to handle.
063: * @return A Reply instance.
064: * @exception ProtocolException if processing the request failed
065: * @exception ResourceException if an internal error occurs
066: */
067: protected Reply getFileResource(Request request)
068: throws ProtocolException, ResourceException {
069: // get our associated FileResource
070: FileResource fres = getFileResource();
071: // Create the HTML generator, and set titles:
072: HtmlGenerator g = new HtmlGenerator("FancyFrame");
073: g.append("<h1>FancyFrame output</h1>");
074: // emit the message
075: g.append("<p>", getMessage(), "</p>");
076: // display information about our FileResource
077: g.append("<h2> FileResource associated : </h2>");
078: g.append("<ul><li>Identifier : ", fres.getIdentifier());
079: g.append("<li>File : " + fres.getFile());
080: g.append("<li>Last Modified Time : ", new Date(fres
081: .getLastModified()).toString(), "</ul>");
082: // now emit the reply
083: Reply reply = createDefaultReply(request, HTTP.OK);
084: reply.setStream(g);
085: return reply;
086: }
087:
088: /**
089: * Display the Frame message and some attributes of our
090: * associated DirectoryResource. This method is called only if
091: * our associated resource *is* a DirectoryResource.
092: * @param request The request to handle.
093: * @return A Reply instance.
094: * @exception ProtocolException if processing the request failed
095: * @exception ResourceException if an internal error occurs
096: */
097: protected Reply getDirectoryResource(Request request)
098: throws ProtocolException, ResourceException {
099: // get our associated DirectoryResource
100: DirectoryResource dres = getDirectoryResource();
101: // Create the HTML generator, and set titles:
102: HtmlGenerator g = new HtmlGenerator("FancyFrame");
103: g.append("<h1>FancyFrame output</h1>");
104: // emit the message
105: g.append("<p>", getMessage(), "</p>");
106: // display information about our DirectoryResource
107: g.append("<h2> DirectoryResource associated : </h2>");
108: g.append("<ul><li>Identifier : ", dres.getIdentifier());
109: g.append("<li>Directory : " + dres.getDirectory());
110: g.append("<li>Last Modified Time : ", new Date(dres
111: .getLastModified()).toString(), "</ul>");
112: // now emit the reply
113: Reply reply = createDefaultReply(request, HTTP.OK);
114: reply.setStream(g);
115: return reply;
116: }
117:
118: /**
119: * Display the Frame message and some attributes of our
120: * associated Resource. This method is called if the associated
121: * resource has been registered with <strong>registerOtherResource</strong>
122: * or if it's not a usual resource (FileResource, DirectoryResource)
123: * @param request The request to handle.
124: * @return A Reply instance.
125: * @exception ProtocolException if processing the request failed
126: * @exception ResourceException if an internal error occurs
127: */
128: protected Reply getOtherResource(Request request)
129: throws ProtocolException, ResourceException { // get our associated Resource
130: FramedResource res = getResource();
131: // Create the HTML generator, and set titles:
132: HtmlGenerator g = new HtmlGenerator("FancyFrame");
133: g.append("<h1>FancyFrame output</h1>");
134: // emit the message
135: g.append("<p>", getMessage(), "</p>");
136: // display information about our Resource
137: g.append("<h2> Resource associated : </h2>");
138: g.append("<ul><li>Identifier : ", res.getIdentifier());
139: g.append("<li>Last Modified Time : ", new Date(res
140: .getLastModified()).toString(), "</ul>");
141: // now emit the reply
142: Reply reply = createDefaultReply(request, HTTP.OK);
143: reply.setStream(g);
144: return reply;
145:
146: }
147:
148: }
|