1.1 --- a/docs/paths-filesystem.html Sun Apr 24 15:43:10 2005 +0000
1.2 +++ b/docs/paths-filesystem.html Sun Apr 24 22:47:22 2005 +0000
1.3 @@ -1,70 +1,117 @@
1.4 -<?xml version="1.0" encoding="iso-8859-1"?>
1.5 -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
1.6 - "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
1.7 +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
1.8 <html xmlns="http://www.w3.org/1999/xhtml">
1.9 <head>
1.10 - <title>Treating the Path Like a Filesystem</title>
1.11 - <meta name="generator" content="amaya 8.1a, see http://www.w3.org/Amaya/" />
1.12 + <title>Treating the Path Like a
1.13 +Filesystem</title>
1.14 + <meta name="generator"
1.15 + content="amaya 8.1a, see http://www.w3.org/Amaya/" />
1.16 <link href="styles.css" rel="stylesheet" type="text/css" />
1.17 </head>
1.18 -
1.19 <body>
1.20 -<h1>Treating the Path Like a Filesystem</h1>
1.21 -
1.22 -<p>...or as a reference into deeply categorized resources. In this approach,
1.23 +<h1>Treating the Path Like a
1.24 +Filesystem</h1>
1.25 +<p>...or as a reference into
1.26 +deeply categorized resources. In this approach,
1.27 we take a path like this...</p>
1.28 <pre>/documents/news/2005/article.html</pre>
1.29 -
1.30 -<p>...and we consider <code>documents</code>, <code>news</code>, and
1.31 -<code>2005</code> as directories, and <code>article.html</code> as a
1.32 +<p>...and we consider <code>documents</code>,
1.33 +<code>news</code>,
1.34 +and
1.35 +<code>2005</code>
1.36 +as directories, and <code>article.html</code>
1.37 +as a
1.38 file-like resource. If we ask for the following path...</p>
1.39 <pre>/documents/news/2005</pre>
1.40 -
1.41 -<p>...we may decide to provide a listing of files within that directory, or
1.42 -we may decide to refuse such a request. Indeed some approaches will insist
1.43 -that such a listing may only be produced with the following path instead:</p>
1.44 +<p>...we may decide to provide a
1.45 +listing of files within that directory, or
1.46 +we may decide to refuse such a request. Indeed some kinds of
1.47 +applications insist
1.48 +that such a listing may only be produced with the following path
1.49 +instead:</p>
1.50 <pre>/documents/news/2005/</pre>
1.51 -
1.52 -<p>Applications of this kind are quite common since the publishing of files
1.53 -on a Web server often just involves exposing parts of a real filesystem to
1.54 +<p>Applications of this kind are
1.55 +quite common since the publishing of files
1.56 +on a Web server often just involves exposing parts of a real filesystem
1.57 +to
1.58 requests through the server.</p>
1.59 -
1.60 -<h2>Resource Hierarchies in WebStack</h2>
1.61 -
1.62 -<p>We might decide to represent components in these kinds of paths using
1.63 -different resource classes, so that folders or directories are represented by
1.64 -one kind of resource class and files or documents are represented by other
1.65 -kinds of resource classes. We might then predefine a hierarchy of resources
1.66 -so that when a request arrives for a resource, we can check it against the
1.67 -hierarchy and process the request according to whichever type of resource is
1.68 -being accessed.</p>
1.69 -
1.70 -<p>Consider the above hierarchy; we would implement such a hierarchy with a
1.71 -resource object mapped to <code>documents</code>, and that resource object
1.72 +<h2>Resource Hierarchies in
1.73 +WebStack</h2>
1.74 +<p>There are a number of different
1.75 +ways that paths can be interpreted and handled in WebStack
1.76 +applications, including...</p>
1.77 +<ul>
1.78 + <li>Using predefined hierarchies
1.79 +of resources.</li>
1.80 + <li>By inspecting the path in a
1.81 +top-level resource and then creating resources to deal with different
1.82 +cases.</li>
1.83 + <li>By handling all kinds of
1.84 +paths in the same resource.</li>
1.85 +</ul>
1.86 +<h3>Predefining Resource
1.87 +Hierarchies</h3>
1.88 +<p>We might decide to represent
1.89 +components in these kinds of paths using
1.90 +different resource classes; for example:</p>
1.91 +<ul>
1.92 + <li>Folders or directories are
1.93 +represented by a special resource class which contains other
1.94 +folders and possibly some files.</li>
1.95 + <li>Files or documents are
1.96 +represented by special resource classes which provide access
1.97 +to the content of such files.</li>
1.98 +</ul>
1.99 +We might then predefine a hierarchy of resources
1.100 +so that when a request arrives for a resource, we can check it against
1.101 +the
1.102 +hierarchy and process the request according to whichever type of
1.103 +resource is
1.104 +being accessed. For example:<br />
1.105 +<ul>
1.106 + <li><code>documents</code>
1.107 + <ul>
1.108 + <li><code>news</code>
1.109 + <ul>
1.110 + <li><code>2005</code>
1.111 + <ul>
1.112 + <li><code>article.html</code></li>
1.113 + <li><code>another.html</code></li>
1.114 + </ul>
1.115 + </li>
1.116 + <li><code>2004</code>
1.117 + <ul>
1.118 + <li><code>document.html</code></li>
1.119 + </ul>
1.120 + </li>
1.121 + </ul>
1.122 + </li>
1.123 + </ul>
1.124 + </li>
1.125 +</ul>
1.126 +<p>Consider the above hierarchy;
1.127 +we would implement such a hierarchy with a
1.128 +resource object mapped to <code>documents</code>,
1.129 +and that resource object
1.130 would contain a mapping of years to other resources. Eventually, at the
1.131 -bottom of the hierarchy, individual resources would represent articles and be
1.132 +bottom of the hierarchy, individual resources would represent articles
1.133 +and be
1.134 mapped to names such as <code>article.html</code>.</p>
1.135 -
1.136 <div class="WebStack">
1.137 -<h3>WebStack API - Predefining Resource Hierarchies in Adapter Code</h3>
1.138 -
1.139 -<p>WebStack provides a resource class for convenient mapping of path
1.140 +<h3>WebStack API - Predefining
1.141 +Resource Hierarchies in Adapter Code</h3>
1.142 +<p>WebStack provides a resource
1.143 +class for convenient mapping of path
1.144 components (ie. names) to resource objects:
1.145 <code>WebStack.Resources.ResourceMap.MapResource</code></p>
1.146 -
1.147 -<p>This class can be used in adapter or "glue" code to initialise an
1.148 +<p>This class can be used in <a href="deploying.html">adapter code</a>
1.149 +to initialise an
1.150 application as follows:</p>
1.151 -<pre>from WebStack.Resources.ResourceMap import MapResource
1.152 -article_resource = [some resource representing the article]
1.153 -year_2004_resource = [a MapResource with definitions]
1.154 -year_2005_resource = MapResource({"article.html" : article_resource})
1.155 -news_resource = MapResource({"2005" : year_2005_resource, "2004" : year_2004_resource})
1.156 -documents_resource = MapResource({"news" : news_resource})
1.157 -top_resource = MapResource({"documents" : documents_resource})</pre>
1.158 +<pre>from WebStack.Resources.ResourceMap import MapResource<br />from MyApplication import FileResource # import some resource class<br /><br />article_resource = FileResource(...) # make a resource representing the article<br />document_resource = FileResource(...) # make a resource representing the document<br />year_2004_resource = MapResource({"document.html" : document_resource})<br />year_2005_resource = MapResource({"article.html" : article_resource})<br />news_resource = MapResource({"2005" : year_2005_resource, "2004" : year_2004_resource})<br />documents_resource = MapResource({"news" : news_resource})<br />top_resource = MapResource({"documents" : documents_resource})</pre>
1.159 </div>
1.160 -
1.161 -<p>Of course, predefining hierarchies is not the only way to support such
1.162 +<p>Of course, predefining resource
1.163 +objects is not the only way to support such
1.164 hierarchies. We could inspect paths and act dynamically on the supplied
1.165 -information.</p>
1.166 +information, either choosing to create resources or choosing to handle
1.167 +such paths in the same resource.</p>
1.168 </body>
1.169 </html>