--- /dev/null
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> \r
+<HTML>\r
+<HEAD>\r
+ <TITLE>Jigsaw 2.0 Internal design</TITLE>\r
+ <link rel="stylesheet" type="text/css" href="../style/doc.css">\r
+ <LINK rel="Stylesheet" media="screen" type="text/css"\r
+ href="style-font-lock.css"> \r
+ </HEAD>\r
+<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#0000EE" VLINK="#551A8B" ALINK="#FF0000">\r
+ <div class="icons-w3c">\r
+ <a href="../../../">\r
+ <img src="/Icons/w3c_home" \r
+ border="0" \r
+ alt="W3C logo"\r
+ height="48" \r
+ width="72">\r
+ </a>\r
+ </div>\r
+ <div class="icons-jigsaw">\r
+ <a href="../../">\r
+ <img src="/Icons/jigsaw" \r
+ border="0"\r
+ alt="Jigsaw"\r
+ height="49"\r
+ width="212">\r
+ </a>\r
+ </div>\r
+\r
+ <div class="title">\r
+ <H1 class="title">\r
+ Jigsaw<br>\r
+ <span class="subtitle">Frame tutorial</span>\r
+ </H1>\r
+ <hr NOSHADE width="70%" align="left">\r
+ <a href="../../Overview.html">Jigsaw Home</a> /\r
+ <a href="../Overview.html">Documentation Overview</a> /\r
+ <a href="Tutorials.html">Tutorials</a>\r
+ </div>\r
+ <div class="body">\r
+<P>\r
+ This tutorial explains you how to write a new frame, by walking through\r
+a complete example. It is assumed that you are familiar with\r
+<A HREF="../User/architecture.html">Jigsaw architecture</A>, and that you\r
+have understand the <A HREF="../User/configuration.html">configuration\r
+tutorial.</A>\r
+<P>\r
+The frame we will write here will display a message describing its attribute\r
+and its associated resource. The tutorial will go through the following steps:\r
+<p>\r
+<OL>\r
+ <LI>\r
+ <A HREF="#writing-frame-class">writing the frame class,</A>\r
+ <LI>\r
+ <A HREF="#installing">installing and configuring it.</A>\r
+</OL>\r
+<H1>\r
+ <A NAME="writing-frame-class"></A>Writing the frame class\r
+</H1>\r
+<P>\r
+Before actually writing a new frame, some decisions must be made about:\r
+<p>\r
+<OL>\r
+ <LI>\r
+ <A HREF="#super-class">What will be its super class</A>\r
+ <LI>\r
+ <A HREF="#package">In what package should it go</A>\r
+ <LI>\r
+ <A HREF="#attributes">What attribute should it define</A>\r
+ <LI>\r
+ <A HREF="#redefining">What method should it redefine</A>\r
+</OL>\r
+<H2>\r
+ <A NAME="super-class"></A>Picking a super class\r
+</H2>\r
+<P>\r
+Deciding for the super class of your frame is a pretty simple process right\r
+now. Here are the rule of thumbs:\r
+<UL>\r
+ <LI>\r
+ If your frame is supposed to handle forms, then you have to choose\r
+ <A HREF="http://jigsaw.w3.org/Doc/Programmer/api/org/w3c/jigsaw/frames/PostableFrame.html">PostableFrame</A>\r
+ as your super class. This will give you the form arguments decoding for free.\r
+ <LI>\r
+ If not, you need to pick a sub-class of\r
+ <A HREF="http://jigsaw.w3.org/Doc/Programmer/api/org/w3c/jigsaw/frames/HTTPFrame.html">HTTPFrame</A> as your\r
+ super class (see\r
+ <A HREF="http://jigsaw.w3.org/Doc/Programmer/api/org/w3c/jigsaw/frames/NegotiatedFrame.html">NegotiatedFrame</A>,\r
+ <A HREF="http://jigsaw.w3.org/Doc/Programmer/api/org/w3c/jigsaw/frames/RelocateFrame.html">RelocateFrame</A>,\r
+ <A HREF="http://jigsaw.w3.org/Doc/Programmer/api/org/w3c/jigsaw/frames/CgiFrame.html">CgiFrame</A>,\r
+ <A HREF="http://jigsaw.w3.org/Doc/Programmer/api/org/w3c/jigsaw/frames/VirtualHostFrame.html">VirtualHostFrame</A>)\r
+</UL>\r
+<P>\r
+Given these short rules, it should be obvious that for our sample frame,\r
+what we want to do is subclass the HTTPFrame. So right now, we can start\r
+writing the following piece of code (we will keep in bold the additional\r
+code we add as we walk through the example):\r
+<DIV CLASS="box">\r
+ <PRE><SPAN class="keyword">import</SPAN> <SPAN class="reference">java</SPAN>.<SPAN class="reference">util</SPAN>.*;\r
+\r
+<SPAN class="keyword">import</SPAN> <SPAN class="reference">org</SPAN>.<SPAN class="reference">w3c</SPAN>.<SPAN class="reference">tools</SPAN>.<SPAN class="reference">resources</SPAN>.*;\r
+<SPAN class="keyword">import</SPAN> <SPAN class="reference">org</SPAN>.<SPAN class="reference">w3c</SPAN>.<SPAN class="reference">jigsaw</SPAN>.<SPAN class="reference">frames</SPAN>.*;\r
+<SPAN class="keyword">import</SPAN> <SPAN class="reference">org</SPAN>.<SPAN class="reference">w3c</SPAN>.<SPAN class="reference">jigsaw</SPAN>.<SPAN class="reference">html</SPAN>.*;\r
+<SPAN class="keyword">import</SPAN> <SPAN class="reference">org</SPAN>.<SPAN class="reference">w3c</SPAN>.<SPAN class="reference">jigsaw</SPAN>.<SPAN class="reference">http</SPAN>.* ;\r
+<SPAN class="keyword">import</SPAN> <SPAN class="reference">org</SPAN>.<SPAN class="reference">w3c</SPAN>.<SPAN class="reference">www</SPAN>.<SPAN class="reference">http</SPAN>.* ;\r
+\r
+<SPAN class="reference">public</SPAN> <SPAN class="keyword">class</SPAN> <SPAN class="function-name">FancyFrame</SPAN> <SPAN class="keyword">extends</SPAN> <SPAN class="type">HTTPFrame</SPAN> {\r
+\r
+}\r
+</PRE>\r
+</DIV>\r
+<P>\r
+Note that we don't know yet were to put this file until we have selected\r
+an appropriate package for our frame.\r
+<H2>\r
+ <A NAME="package"></A>Selecting a package\r
+</H2>\r
+<P>\r
+There is no particular problem with regard to the package your frame belong\r
+to: <B>Jigsaw </B>impose no constraint on this. The only thing you should\r
+be aware of is your CLASSPATH environment variable. This variable setting\r
+is particularly crucial in <B>Jigsaw</B> since it may impact its security:\r
+you don't want anyone to be able to plug new resource classes in the server\r
+!\r
+<P>\r
+For our sample frame, we can create a new package, let's call it tutorial,\r
+under the Jigsaw classes directory. We want this package to be under the\r
+w3c.jigsaw package. We can now create the appropriate directory\r
+(<TT>src/classes/w3c/jigsaw/tutorial</TT>), and write in it the following\r
+FancyFrame.java file:\r
+<DIV CLASS="box">\r
+ <PRE><SPAN class="keyword">package</SPAN> <SPAN class="reference">org</SPAN>.<SPAN class="reference">w3c</SPAN>.<SPAN class="reference">jigsaw</SPAN>.<SPAN class="type">tutorials</SPAN>;\r
+\r
+<SPAN class="keyword">import</SPAN> <SPAN class="reference">java</SPAN>.<SPAN class="reference">util</SPAN>.*;\r
+\r
+<SPAN class="keyword">import</SPAN> <SPAN class="reference">org</SPAN>.<SPAN class="reference">w3c</SPAN>.<SPAN class="reference">tools</SPAN>.<SPAN class="reference">resources</SPAN>.*;\r
+<SPAN class="keyword">import</SPAN> <SPAN class="reference">org</SPAN>.<SPAN class="reference">w3c</SPAN>.<SPAN class="reference">jigsaw</SPAN>.<SPAN class="reference">frames</SPAN>.*;\r
+<SPAN class="keyword">import</SPAN> <SPAN class="reference">org</SPAN>.<SPAN class="reference">w3c</SPAN>.<SPAN class="reference">jigsaw</SPAN>.<SPAN class="reference">html</SPAN>.*;\r
+<SPAN class="keyword">import</SPAN> <SPAN class="reference">org</SPAN>.<SPAN class="reference">w3c</SPAN>.<SPAN class="reference">jigsaw</SPAN>.<SPAN class="reference">http</SPAN>.* ;\r
+<SPAN class="keyword">import</SPAN> <SPAN class="reference">org</SPAN>.<SPAN class="reference">w3c</SPAN>.<SPAN class="reference">www</SPAN>.<SPAN class="reference">http</SPAN>.* ;\r
+\r
+<SPAN class="reference">public</SPAN> <SPAN class="keyword">class</SPAN> <SPAN class="function-name">FancyFrame</SPAN> <SPAN class="keyword">extends</SPAN> <SPAN class="type">HTTPFrame</SPAN> {\r
+\r
+}\r
+</PRE>\r
+</DIV>\r
+<H2>\r
+ <A NAME="attributes"></A>Defining the attributes\r
+</H2>\r
+<P>\r
+The next thing we have to figure out, is the list of attributes for our new\r
+frame. The\r
+<A HREF="http://jigsaw.w3.org/Doc/Programmer/api/org/w3c/jigsaw/frames/HTTPFrame.html">HTTPFrame</A> already\r
+defines a number of attributes (see the\r
+<A HREF="../Reference/Overview.html">reference manual</A>). Defining the\r
+set of attributes of a frame also defines the way the frame will be configured\r
+(since a frame is configured by editing its attribute values). Here, we want\r
+to be able to configure the message that will be emitted by the frame.\r
+<P>\r
+The message emitted by the frame can be described as an editable\r
+<A HREF="http://jigsaw.w3.org/Doc/Programmer/api/org/w3c/tools/resources/StringAttribute.html">StringAttribute</A>,\r
+which defaults to Hello.\r
+<P>\r
+Now that we now the attribute our frame is to have, we should declare it\r
+to the AttributeRegistry. This Registry keeps track of all the attributes\r
+of all resource classes. For each class it knows of, it maintains an ordered\r
+list of the attribute it defines. The fact that this list is ordered is\r
+important, since it allows for fast attribute value access (through a simple\r
+indirection in the attribute value array of each frame instance). Attribute\r
+declaration should be done at class initialization time, so we introduce\r
+a static statement in the class, whose purpose is to declare our attribute:\r
+<DIV CLASS="box">\r
+ <PRE><SPAN class="keyword">package</SPAN> <SPAN class="reference">org</SPAN>.<SPAN class="reference">w3c</SPAN>.<SPAN class="reference">jigsaw</SPAN>.<SPAN class="type">tutorials</SPAN>;\r
+\r
+<SPAN class="keyword">import</SPAN> <SPAN class="reference">java</SPAN>.<SPAN class="reference">util</SPAN>.*;\r
+\r
+<SPAN class="keyword">import</SPAN> <SPAN class="reference">org</SPAN>.<SPAN class="reference">w3c</SPAN>.<SPAN class="reference">tools</SPAN>.<SPAN class="reference">resources</SPAN>.*;\r
+<SPAN class="keyword">import</SPAN> <SPAN class="reference">org</SPAN>.<SPAN class="reference">w3c</SPAN>.<SPAN class="reference">jigsaw</SPAN>.<SPAN class="reference">frames</SPAN>.*;\r
+<SPAN class="keyword">import</SPAN> <SPAN class="reference">org</SPAN>.<SPAN class="reference">w3c</SPAN>.<SPAN class="reference">jigsaw</SPAN>.<SPAN class="reference">html</SPAN>.*;\r
+<SPAN class="keyword">import</SPAN> <SPAN class="reference">org</SPAN>.<SPAN class="reference">w3c</SPAN>.<SPAN class="reference">jigsaw</SPAN>.<SPAN class="reference">http</SPAN>.* ;\r
+<SPAN class="keyword">import</SPAN> <SPAN class="reference">org</SPAN>.<SPAN class="reference">w3c</SPAN>.<SPAN class="reference">www</SPAN>.<SPAN class="reference">http</SPAN>.* ;\r
+\r
+<SPAN class="reference">public</SPAN> <SPAN class="keyword">class</SPAN> <SPAN class="function-name">FancyFrame</SPAN> <SPAN class="keyword">extends</SPAN> <SPAN class="type">HTTPFrame</SPAN> {\r
+\r
+ <SPAN class="comment">/**</SPAN>\r
+<SPAN class="comment"> * Attribute index - Message to display</SPAN>\r
+<SPAN class="comment"> */</SPAN>\r
+ <SPAN class="preprocessor">protected</SPAN> <SPAN class="type">static</SPAN> <SPAN class="type">int</SPAN> <SPAN class="variable-name">ATTR_MESSAGE</SPAN> = -1 ;\r
+\r
+ <SPAN class="type">static</SPAN> {\r
+ <SPAN class="type">Attribute</SPAN> <SPAN class="variable-name">a</SPAN> = <SPAN class="keyword">null</SPAN> ;\r
+ <SPAN class="type">Class</SPAN> <SPAN class="variable-name">cls</SPAN> = <SPAN class="keyword">null</SPAN> ;\r
+\r
+ <SPAN class="keyword">try</SPAN> {\r
+ cls = Class.forName("<SPAN class="string">org.w3c.jigsaw.tutorials.FancyFrame</SPAN>");\r
+ } <SPAN class="keyword">catch</SPAN> (<SPAN class="type">Exception</SPAN> <SPAN class="variable-name">ex</SPAN>) {\r
+ ex.printStackTrace() ;\r
+ System.exit(1) ;\r
+ }\r
+\r
+ <SPAN class="comment">// The message attribute</SPAN>\r
+ a = <SPAN class="keyword">new</SPAN> <SPAN class="type">StringAttribute</SPAN>("<SPAN class="string">message</SPAN>", "<SPAN class="string">Hello</SPAN>", Attribute.EDITABLE) ;\r
+ ATTR_MESSAGE = AttributeRegistry.registerAttribute(cls, a) ;\r
+ }\r
+\r
+ <SPAN class="comment">/**</SPAN>\r
+<SPAN class="comment"> * Get the message.</SPAN>\r
+<SPAN class="comment"> * </SPAN><SPAN class="keyword">@return </SPAN><SPAN class="comment">A String instance.</SPAN>\r
+<SPAN class="comment"> */</SPAN>\r
+ <SPAN class="reference">public</SPAN> <SPAN class="type">String</SPAN> <SPAN class="function-name">getMessage</SPAN>() {\r
+ <SPAN class="keyword">return</SPAN> getString(ATTR_MESSAGE, <SPAN class="keyword">null</SPAN>);\r
+ }\r
+}\r
+</PRE>\r
+</DIV>\r
+<H2>\r
+ <A NAME="redefining"></A>Redefining some methods\r
+</H2>\r
+<P>\r
+At this point, we have declared the set of attributes that our frame defines,\r
+the attribute Registry knows about it, we can now focus on the actual behavior\r
+of the frame. The only HTTP method that our frame will redefine is the GET\r
+method, which will synthesize a reply on the fly for each specific request.\r
+Jigsaw comes with a simple\r
+<A HREF="http://jigsaw.w3.org/Doc/Programmer/api/org/w3c/jigsaw/html/HtmlGenerator.html">HtmlGenerator</A> class\r
+for generating HTML that we want to use for this purpose. Our FancyFrame\r
+could be associated with many kinds of resources,\r
+<A HREF="http://jigsaw.w3.org/Doc/Programmer/api/org/w3c/tools/resources/FileResource.html">FileResource</A>,\r
+<A HREF="http://jigsaw.w3.org/Doc/Programmer/api/org/w3c/tools/resources/DirectoryResource.html">DirectoryResource</A>,\r
+any subclass of\r
+<A HREF="http://jigsaw.w3.org/Doc/Programmer/api/org/w3c/tools/resources/FramedResource.html">FramedResource</A>\r
+or FramedResource itself. <BR>\r
+In this particular case, we want to deal with all these resources, so we\r
+have to redefine the followings method of\r
+<A HREF="http://jigsaw.w3.org/Doc/Programmer/api/org/w3c/jigsaw/frames/HTTPFrame.html">HTTPFrame</A>:\r
+<UL>\r
+ <LI>\r
+ <TT>protected Reply getFileResource(Request request) </TT>which is called\r
+ when the associated resource is a FileResource and the request method is\r
+ GET.\r
+ <LI>\r
+ <TT>protected Reply getDirectoryResource(Request request) </TT>which is called\r
+ when the associated resource is a DirectoryResource and the request method\r
+ is GET.\r
+ <LI>\r
+ <TT>protected Reply getOtherResource(Request request) </TT>which is called\r
+ when the associated resource is not a usual resource (FileResource,\r
+ DirectoryResource) and the request method is GET.\r
+</UL>\r
+<P>\r
+The actual implementation of these methods is the following:\r
+<DIV CLASS="box">\r
+ <PRE><SPAN class="keyword">package</SPAN> <SPAN class="reference">org</SPAN>.<SPAN class="reference">w3c</SPAN>.<SPAN class="reference">jigsaw</SPAN>.<SPAN class="type">tutorials</SPAN>;\r
+\r
+<SPAN class="keyword">import</SPAN> <SPAN class="reference">java</SPAN>.<SPAN class="reference">util</SPAN>.*;\r
+\r
+<SPAN class="keyword">import</SPAN> <SPAN class="reference">org</SPAN>.<SPAN class="reference">w3c</SPAN>.<SPAN class="reference">tools</SPAN>.<SPAN class="reference">resources</SPAN>.*;\r
+<SPAN class="keyword">import</SPAN> <SPAN class="reference">org</SPAN>.<SPAN class="reference">w3c</SPAN>.<SPAN class="reference">jigsaw</SPAN>.<SPAN class="reference">frames</SPAN>.*;\r
+<SPAN class="keyword">import</SPAN> <SPAN class="reference">org</SPAN>.<SPAN class="reference">w3c</SPAN>.<SPAN class="reference">jigsaw</SPAN>.<SPAN class="reference">html</SPAN>.*;\r
+<SPAN class="keyword">import</SPAN> <SPAN class="reference">org</SPAN>.<SPAN class="reference">w3c</SPAN>.<SPAN class="reference">jigsaw</SPAN>.<SPAN class="reference">http</SPAN>.* ;\r
+<SPAN class="keyword">import</SPAN> <SPAN class="reference">org</SPAN>.<SPAN class="reference">w3c</SPAN>.<SPAN class="reference">www</SPAN>.<SPAN class="reference">http</SPAN>.* ;\r
+\r
+<SPAN class="reference">public</SPAN> <SPAN class="keyword">class</SPAN> <SPAN class="function-name">FancyFrame</SPAN> <SPAN class="keyword">extends</SPAN> <SPAN class="type">HTTPFrame</SPAN> {\r
+\r
+ <SPAN class="comment">/**</SPAN>\r
+<SPAN class="comment"> * Attribute index - Message to display</SPAN>\r
+<SPAN class="comment"> */</SPAN>\r
+ <SPAN class="preprocessor">protected</SPAN> <SPAN class="type">static</SPAN> <SPAN class="type">int</SPAN> <SPAN class="variable-name">ATTR_MESSAGE</SPAN> = -1 ;\r
+\r
+ <SPAN class="type">static</SPAN> {\r
+ <SPAN class="type">Attribute</SPAN> <SPAN class="variable-name">a</SPAN> = <SPAN class="keyword">null</SPAN> ;\r
+ <SPAN class="type">Class</SPAN> <SPAN class="variable-name">cls</SPAN> = <SPAN class="keyword">null</SPAN> ;\r
+\r
+ <SPAN class="keyword">try</SPAN> {\r
+ cls = Class.forName("<SPAN class="string">org.w3c.jigsaw.tutorials.FancyFrame</SPAN>");\r
+ } <SPAN class="keyword">catch</SPAN> (<SPAN class="type">Exception</SPAN> <SPAN class="variable-name">ex</SPAN>) {\r
+ ex.printStackTrace() ;\r
+ System.exit(1) ;\r
+ }\r
+\r
+ <SPAN class="comment">// The message attribute</SPAN>\r
+ a = <SPAN class="keyword">new</SPAN> <SPAN class="type">StringAttribute</SPAN>("<SPAN class="string">message</SPAN>", "<SPAN class="string">Hello</SPAN>", Attribute.EDITABLE) ;\r
+ ATTR_MESSAGE = AttributeRegistry.registerAttribute(cls, a) ;\r
+ }\r
+\r
+ <SPAN class="comment">/**</SPAN>\r
+<SPAN class="comment"> * Get the message.</SPAN>\r
+<SPAN class="comment"> * </SPAN><SPAN class="keyword">@return </SPAN><SPAN class="comment">A String instance.</SPAN>\r
+<SPAN class="comment"> */</SPAN>\r
+ <SPAN class="reference">public</SPAN> <SPAN class="type">String</SPAN> <SPAN class="function-name">getMessage</SPAN>() {\r
+ <SPAN class="keyword">return</SPAN> getString(ATTR_MESSAGE, <SPAN class="keyword">null</SPAN>);\r
+ }\r
+\r
+ <SPAN class="comment">/**</SPAN>\r
+<SPAN class="comment"> * Display the Frame message and some attributes of our</SPAN>\r
+<SPAN class="comment"> * associated FileResource. This method is called only if</SPAN>\r
+<SPAN class="comment"> * our associated resource *is* a FileResource.</SPAN>\r
+<SPAN class="comment"> * </SPAN><SPAN class="keyword">@param </SPAN><SPAN class="variable-name">request</SPAN><SPAN class="comment"> The request to handle.</SPAN>\r
+<SPAN class="comment"> * </SPAN><SPAN class="keyword">@return </SPAN><SPAN class="comment">A Reply instance.</SPAN>\r
+<SPAN class="comment"> * </SPAN><SPAN class="keyword">@exception </SPAN><SPAN class="type">ProtocolException</SPAN><SPAN class="comment"> if processing the request failed</SPAN>\r
+<SPAN class="comment"> * </SPAN><SPAN class="keyword">@exception </SPAN><SPAN class="type">NotAProtocolException</SPAN><SPAN class="comment"> if an internal error occurs</SPAN>\r
+<SPAN class="comment"> */</SPAN>\r
+ <SPAN class="preprocessor">protected</SPAN> <SPAN class="type">Reply</SPAN> <SPAN class="function-name">getFileResource</SPAN>(<SPAN class="type">Request</SPAN> <SPAN class="variable-name">request</SPAN>) \r
+ <SPAN class="keyword">throws</SPAN> <SPAN class="type">ProtocolException</SPAN>, <SPAN class="type">NotAProtocolException</SPAN>\r
+ {\r
+ <SPAN class="comment">// get our associated FileResource</SPAN>\r
+ <SPAN class="type">FileResource</SPAN> <SPAN class="variable-name">fres</SPAN> = getFileResource();\r
+ <SPAN class="comment">// Create the HTML generator, and set titles:</SPAN>\r
+ <SPAN class="type">HtmlGenerator</SPAN> <SPAN class="variable-name">g</SPAN> = <SPAN class="keyword">new</SPAN> <SPAN class="type">HtmlGenerator</SPAN>("<SPAN class="string">FancyFrame</SPAN>");\r
+ g.append("<SPAN class="string"><h1>FancyFrame output</h1></SPAN>");\r
+ <SPAN class="comment">// emit the message</SPAN>\r
+ g.append("<SPAN class="string"><p></SPAN>",getMessage(),"<SPAN class="string"></p></SPAN>");\r
+ <SPAN class="comment">// display information about our FileResource</SPAN>\r
+ g.append("<SPAN class="string"><h2> FileResource associated : </h2></SPAN>");\r
+ g.append("<SPAN class="string"><ul><li>Identifier : </SPAN>",fres.getIdentifier());\r
+ g.append("<SPAN class="string"><li>File : </SPAN>"+fres.getFile());\r
+ g.append("<SPAN class="string"><li>Last Modified Time : </SPAN>",\r
+ <SPAN class="keyword">new</SPAN> <SPAN class="type">Date</SPAN>(fres.getLastModified()).toString(),\r
+ "<SPAN class="string"></ul></SPAN>");\r
+ <SPAN class="comment">// now emit the reply</SPAN>\r
+ <SPAN class="type">Reply</SPAN> <SPAN class="variable-name">reply</SPAN> = createDefaultReply(request, HTTP.OK) ;\r
+ reply.setStream(g) ;\r
+ <SPAN class="keyword">return</SPAN> reply ;\r
+ }\r
+\r
+ <SPAN class="comment">/**</SPAN>\r
+<SPAN class="comment"> * Display the Frame message and some attributes of our</SPAN>\r
+<SPAN class="comment"> * associated DirectoryResource. This method is called only if</SPAN>\r
+<SPAN class="comment"> * our associated resource *is* a DirectoryResource.</SPAN>\r
+<SPAN class="comment"> * </SPAN><SPAN class="keyword">@param </SPAN><SPAN class="variable-name">request</SPAN><SPAN class="comment"> The request to handle.</SPAN>\r
+<SPAN class="comment"> * </SPAN><SPAN class="keyword">@return </SPAN><SPAN class="comment">A Reply instance.</SPAN>\r
+<SPAN class="comment"> * </SPAN><SPAN class="keyword">@exception </SPAN><SPAN class="type">ProtocolException</SPAN><SPAN class="comment"> if processing the request failed</SPAN>\r
+<SPAN class="comment"> * </SPAN><SPAN class="keyword">@exception </SPAN><SPAN class="type">NotAProtocolException</SPAN><SPAN class="comment"> if an internal error occurs</SPAN>\r
+<SPAN class="comment"> */</SPAN>\r
+ <SPAN class="preprocessor">protected</SPAN> <SPAN class="type">Reply</SPAN> <SPAN class="function-name">getDirectoryResource</SPAN>(<SPAN class="type">Request</SPAN> <SPAN class="variable-name">request</SPAN>) \r
+ <SPAN class="keyword">throws</SPAN> <SPAN class="type">ProtocolException</SPAN>, <SPAN class="type">NotAProtocolException</SPAN>\r
+ {\r
+ <SPAN class="comment">// get our associated DirectoryResource</SPAN>\r
+ <SPAN class="type">DirectoryResource</SPAN> <SPAN class="variable-name">dres</SPAN> = getDirectoryResource();\r
+ <SPAN class="comment">// Create the HTML generator, and set titles:</SPAN>\r
+ <SPAN class="type">HtmlGenerator</SPAN> <SPAN class="variable-name">g</SPAN> = <SPAN class="keyword">new</SPAN> <SPAN class="type">HtmlGenerator</SPAN>("<SPAN class="string">FancyFrame</SPAN>");\r
+ g.append("<SPAN class="string"><h1>FancyFrame output</h1></SPAN>");\r
+ <SPAN class="comment">// emit the message</SPAN>\r
+ g.append("<SPAN class="string"><p></SPAN>",getMessage(),"<SPAN class="string"></p></SPAN>");\r
+ <SPAN class="comment">// display information about our DirectoryResource</SPAN>\r
+ g.append("<SPAN class="string"><h2> DirectoryResource associated : </h2></SPAN>");\r
+ g.append("<SPAN class="string"><ul><li>Identifier : </SPAN>",dres.getIdentifier());\r
+ g.append("<SPAN class="string"><li>Directory : </SPAN>"+dres.getDirectory());\r
+ g.append("<SPAN class="string"><li>Last Modified Time : </SPAN>",\r
+ <SPAN class="keyword">new</SPAN> <SPAN class="type">Date</SPAN>(dres.getLastModified()).toString(),\r
+ "<SPAN class="string"></ul></SPAN>");\r
+ <SPAN class="comment">// now emit the reply</SPAN>\r
+ <SPAN class="type">Reply</SPAN> <SPAN class="variable-name">reply</SPAN> = createDefaultReply(request, HTTP.OK) ;\r
+ reply.setStream(g) ;\r
+ <SPAN class="keyword">return</SPAN> reply ;\r
+ }\r
+\r
+ <SPAN class="comment">/**</SPAN>\r
+<SPAN class="comment"> * Display the Frame message and some attributes of our</SPAN>\r
+<SPAN class="comment"> * associated Resource. This method is called if the associated</SPAN>\r
+<SPAN class="comment"> * resource has been registered with <strong>registerOtherResource</strong></SPAN>\r
+<SPAN class="comment"> * or if it's not a usual resource (FileResource, DirectoryResource)</SPAN>\r
+<SPAN class="comment"> * </SPAN><SPAN class="keyword">@param </SPAN><SPAN class="variable-name">request</SPAN><SPAN class="comment"> The request to handle.</SPAN>\r
+<SPAN class="comment"> * </SPAN><SPAN class="keyword">@return </SPAN><SPAN class="comment">A Reply instance.</SPAN>\r
+<SPAN class="comment"> * </SPAN><SPAN class="keyword">@exception </SPAN><SPAN class="type">ProtocolException</SPAN><SPAN class="comment"> if processing the request failed</SPAN>\r
+<SPAN class="comment"> * </SPAN><SPAN class="keyword">@exception </SPAN><SPAN class="type">NotAProtocolException</SPAN><SPAN class="comment"> if an internal error occurs</SPAN>\r
+<SPAN class="comment"> */</SPAN>\r
+ <SPAN class="preprocessor">protected</SPAN> <SPAN class="type">Reply</SPAN> <SPAN class="function-name">getOtherResource</SPAN>(<SPAN class="type">Request</SPAN> <SPAN class="variable-name">request</SPAN>) \r
+ <SPAN class="keyword">throws</SPAN> <SPAN class="type">ProtocolException</SPAN>, <SPAN class="type">NotAProtocolException</SPAN>\r
+ { <SPAN class="comment">// get our associated Resource</SPAN>\r
+ <SPAN class="type">FramedResource</SPAN> <SPAN class="variable-name">res</SPAN> = getResource();\r
+ <SPAN class="comment">// Create the HTML generator, and set titles:</SPAN>\r
+ <SPAN class="type">HtmlGenerator</SPAN> <SPAN class="variable-name">g</SPAN> = <SPAN class="keyword">new</SPAN> <SPAN class="type">HtmlGenerator</SPAN>("<SPAN class="string">FancyFrame</SPAN>");\r
+ g.append("<SPAN class="string"><h1>FancyFrame output</h1></SPAN>");\r
+ <SPAN class="comment">// emit the message</SPAN>\r
+ g.append("<SPAN class="string"><p></SPAN>",getMessage(),"<SPAN class="string"></p></SPAN>");\r
+ <SPAN class="comment">// display information about our Resource</SPAN>\r
+ g.append("<SPAN class="string"><h2> Resource associated : </h2></SPAN>");\r
+ g.append("<SPAN class="string"><ul><li>Identifier : </SPAN>",res.getIdentifier());\r
+ g.append("<SPAN class="string"><li>Last Modified Time : </SPAN>",\r
+ <SPAN class="keyword">new</SPAN> <SPAN class="type">Date</SPAN>(res.getLastModified()).toString(),\r
+ "<SPAN class="string"></ul></SPAN>");\r
+ <SPAN class="comment">// now emit the reply</SPAN>\r
+ <SPAN class="type">Reply</SPAN> <SPAN class="variable-name">reply</SPAN> = createDefaultReply(request, HTTP.OK) ;\r
+ reply.setStream(g) ;\r
+ <SPAN class="keyword">return</SPAN> reply ;\r
+ }\r
+}\r
+</PRE>\r
+</DIV>\r
+<H2>\r
+ Note:\r
+</H2>\r
+<P>\r
+Sometimes we don't need to know what kind of resource is associated with\r
+our frame, or we are sure to be associated with a resource which is not a\r
+FileResource neither a DirectoryResource. In that case we could redefine\r
+the following method like this:\r
+<DIV CLASS="box">\r
+ <PRE> <SPAN class="comment">/**</SPAN>\r
+<SPAN class="comment"> * register our associated resource as an "other" resource.</SPAN>\r
+<SPAN class="comment"> */</SPAN>\r
+ <SPAN class="reference">public</SPAN> <SPAN class="type">void</SPAN> <SPAN class="function-name">registerResource</SPAN>(<SPAN class="type">FramedResource</SPAN> <SPAN class="variable-name">resource</SPAN>) {\r
+ <SPAN class="reference">super</SPAN>.registerOtherResource(resource);\r
+ }\r
+</PRE>\r
+</DIV>\r
+<P>\r
+So, we just have to redefine getOtherResource.\r
+<H1>\r
+ <A NAME="installing"></A>Installing the frame\r
+</H1>\r
+<P>\r
+After reading the <A HREF="../User/resource.html">Resource configuration\r
+tutorial</A> you will be able to install the FancyFrame. Here is what I get\r
+with my configuration:\r
+<H3>\r
+ FancyFrame associated with a FileResource\r
+</H3>\r
+<CENTER>\r
+ <IMG SRC="file-output.gif" ALT="FileResource" HEIGHT=186 WIDTH=426>\r
+</CENTER>\r
+<CENTER>\r
+ \r
+</CENTER>\r
+<H3>\r
+ FancyFrame associated with a DirectoryResource\r
+</H3>\r
+<CENTER>\r
+ <IMG SRC="dir-output.gif" ALT="DirectoryResource" HEIGHT=179 WIDTH=444>\r
+</CENTER>\r
+<CENTER>\r
+ \r
+</CENTER>\r
+<H3>\r
+ FancyFrame associated with a FramedResource\r
+</H3>\r
+<CENTER>\r
+ <IMG SRC="framed-output.gif" ALT="FramedResource" HEIGHT=173 WIDTH=416>\r
+</CENTER>\r
+<P>\r
+ <BR>\r
+ <BR>\r
+The example we have been walking through is probably one of the simplest\r
+one, however, by now, you should be able to read and understand the basic\r
+Frame classes provided by Jigsaw. I would recommend reading them in the following\r
+order:\r
+<OL>\r
+ <LI>\r
+ You can start by going through the code of the\r
+ <A HREF="samples/HTTPFrame.html">HTTPFrame</A> , which is more complex then\r
+ our <A HREF="samples/FancyFrame.html">FancyFrame</A>. Every frame relative\r
+ to the HTTP protocol must be a subclass of it.\r
+ <LI>\r
+ You can then continue by browsing the\r
+ <A HREF="samples/RelocateFrame.html">RelocateFrame</A>, which emit an HTTP\r
+ redirect reply.\r
+ <LI>\r
+ If you still have more courage, then try reading the\r
+ <A HREF="samples/NegotiatedFrame.html">NegotiatedFrame,</A> which manage\r
+ content negotiation. There is a significant increase in complexity here.\r
+ <LI>\r
+ Take a look at the <A HREF="samples/Overview.html">Sample code page</A>.\r
+</OL>\r
+<P>\r
+Enjoy !\r
+ </div> <!-- body -->\r
+ <div class="footer">\r
+<P>\r
+<hr noshade>\r
+ <a href="mailto:jigsaw@w3.org">Jigsaw Team</a><br>\r
+ <span class="mini">\r
+ $Id: writing-frames.html,v 1.1 2010/06/15 12:22:19 smhuang Exp $\r
+ </span>\r
+ <p class="policyfooter">\r
+ <font size=-1>\r
+ <a href="/Consortium/Legal/ipr-notice.html#Copyright">Copyright</a>\r
+ © 1999 <a href="http://www.w3.org">W3C</a> \r
+ (<a href="http://www.lcs.mit.edu">MIT</a>, \r
+ <a href="http://www.inria.fr/">INRIA</a>, \r
+ <a href="http://www.keio.ac.jp/">Keio</a> ), \r
+ All Rights Reserved. W3C \r
+ <a href="/Consortium/Legal/ipr-notice.html#Legal Disclaimer">\r
+ liability,\r
+ </a>\r
+ <a href="/Consortium/Legal/ipr-notice.html#W3C Trademarks">\r
+ trademark\r
+ </a>, \r
+ <a href="/Consortium/Legal/copyright-documents.html">\r
+ document use \r
+ </a>\r
+ and\r
+ <a href="/Consortium/Legal/copyright-software.html">\r
+ software licensing\r
+ </a> rules apply. Your interactions with this site are in\r
+ accordance with our \r
+ <a href="/Consortium/Legal/privacy-statement.html#Public">\r
+ public\r
+ </a> and \r
+ <a href="/Consortium/Legal/privacy-statement.html#Members">\r
+ Member\r
+ </a>\r
+ privacy statements.</font>\r
+ </div>\r
+</BODY></HTML>\r