1.1 --- a/docs/path-info.html Mon Nov 06 23:38:12 2006 +0000
1.2 +++ b/docs/path-info.html Mon Nov 06 23:39:49 2006 +0000
1.3 @@ -1,22 +1,20 @@
1.4 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
1.5 -<html xmlns="http://www.w3.org/1999/xhtml"><head>
1.6 - <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type" />
1.7 -
1.8 - <title>Paths To and Within Applications</title><meta name="generator" content="amaya 8.1a, see http://www.w3.org/Amaya/" />
1.9 - <link href="styles.css" rel="stylesheet" type="text/css" /></head>
1.10 -<body>
1.11 -<h1>Paths To and
1.12 +<html xmlns="http://www.w3.org/1999/xhtml"><head> <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type" /><title>Paths To and Within Applications</title>
1.13 +<meta name="generator" content="amaya 8.1a, see http://www.w3.org/Amaya/" /> <link href="styles.css" rel="stylesheet" type="text/css" /></head>
1.14 +<body><h1>Paths
1.15 +To and
1.16 Within Applications</h1>
1.17 <p>One thing to be aware of, in the
1.18 code of an application, is which part
1.19 of
1.20 a
1.21 -path refers to the location of the application in a server environment, and
1.22 +path refers to the location of the application in a server environment,
1.23 +and
1.24 which refers to some resource within the application itself. Consider
1.25 this
1.26 path:</p>
1.27 -<pre>/folder/application/resource</pre>
1.28 -<p>Let us say that the application
1.29 +<pre>/folder/application/resource/operation</pre><p>Let us say
1.30 +that the application
1.31 was deployed in a Zope server
1.32 instance
1.33 inside
1.34 @@ -25,48 +23,50 @@
1.35 We may
1.36 then
1.37 say that the path to the application is this:
1.38 -</p>
1.39 -<pre>/folder/application</pre>
1.40 -<p>Meanwhile, the path <span style="font-style: italic;">within</span> the
1.41 +</p><pre>/folder/application</pre><p>Meanwhile,
1.42 +the path <span style="font-style: italic;">within</span>
1.43 +the
1.44 application is just this:
1.45 -</p>
1.46 -<pre>/resource</pre>
1.47 -<p>In WebStack, we refer to this latter case - the path within the
1.48 +</p><pre>/resource/operation</pre><p>In WebStack, we
1.49 +refer to this latter case - the path within
1.50 +the
1.51 application - as the "path info".</p>
1.52 -<div class="WebStack">
1.53 -<h3>WebStack API - Paths To
1.54 +<div class="WebStack"><h3>WebStack API - Paths To
1.55 Resources Within Applications</h3>
1.56 <p>On transaction objects, the
1.57 following methods exist to inspect paths
1.58 to
1.59 resources within applications.</p>
1.60 -<dl>
1.61 - <dt><code>get_path_info</code></dt>
1.62 - <dd>This gets the path of a
1.63 +<dl> <dt><code>get_path_info</code></dt>
1.64 +<dd>This gets the path of a
1.65 resource within an application. The path should always contain a
1.66 leading <code>/</code> character at the very least.<br />
1.67 -An optional <code>encoding</code> parameter may be used to assist the process of converting the path to a Unicode object - see <a href="encodings.html">"Character Encodings"</a> for more information.</dd>
1.68 - <dt><code>get_virtual_path_info</code></dt>
1.69 - <dd>This gets the path of a
1.70 +An optional <code>encoding</code> parameter may be
1.71 +used to assist the process of converting the path to a Unicode object -
1.72 +see <a href="encodings.html">"Character Encodings"</a>
1.73 +for more information.</dd> <dt><code>get_virtual_path_info</code></dt>
1.74 +<dd>This gets the path of a
1.75 resource within a part of an application
1.76 - the application itself decides the scope of the path and can set the
1.77 "virtual path info" using the <code>set_virtual_path_info</code>
1.78 method. The path should either contain a leading <code>/</code>
1.79 character optionally followed by other characters, or an empty string.<br />
1.80 -
1.81 -An optional <code>encoding</code> parameter may be used to assist the process of converting the path to a Unicode object - see <a href="encodings.html">"Character Encodings"</a> for more information.</dd><dt><code>get_processed_virtual_path_info</code></dt>
1.82 - <dd>This gets the virtual path information which is considered to
1.83 +An optional <code>encoding</code> parameter may be
1.84 +used to assist the process of converting the path to a Unicode object -
1.85 +see <a href="encodings.html">"Character Encodings"</a>
1.86 +for more information.</dd><dt><code>get_processed_virtual_path_info</code></dt>
1.87 +<dd>This gets the virtual path information which is considered to
1.88 have been processed or traversed, and consists of the part of the path
1.89 info which does not appear in the virtual path info. In other words,
1.90 when components at the start of the virtual path info are removed, such
1.91 components will appear at the end of the processed virtual path info.<br />
1.92 -
1.93 -An optional <code>encoding</code> parameter may be used to assist the process of converting the path to a Unicode object - see <a href="encodings.html">"Character Encodings"</a> for more information.</dd>
1.94 -
1.95 -</dl>
1.96 -</div>
1.97 -<h2>Choosing the Right Path Value</h2>
1.98 -<p>Given that the path may change depending on where an
1.99 +An optional <code>encoding</code> parameter may be
1.100 +used to assist the process of converting the path to a Unicode object -
1.101 +see <a href="encodings.html">"Character Encodings"</a>
1.102 +for more information.</dd>
1.103 +</dl></div><h2>Choosing the Right Path Value</h2>
1.104 +<p>Given that the path may change depending on
1.105 +where an
1.106 application is deployed in a server environment, it may not be very
1.107 easy to use when determining which resources are being requested or
1.108 accessed within your application. Conversely, given that the "path
1.109 @@ -74,33 +74,27 @@
1.110 it may be difficult to use that to provide references or links to those
1.111 resources. Here is a summary of how you might use the different path
1.112 values:</p>
1.113 -<table style="text-align: left; width: 80%;" align="center" border="1" cellpadding="5" cellspacing="0" width="80%">
1.114 - <tbody>
1.115 - <tr>
1.116 - <th style="text-align: center;">Type of information</th>
1.117 - <th style="text-align: center;">Possible uses</th>
1.118 - </tr>
1.119 - <tr>
1.120 - <td align="undefined" valign="undefined">Path</td>
1.121 - <td align="undefined" valign="undefined">Building links to
1.122 -resources within an application.</td>
1.123 - </tr>
1.124 - <tr><td align="undefined" valign="undefined">Path without path info</td><td align="undefined" valign="undefined">Finding the location of the application in a server environment. (This is the path with the "path info" subtracted from
1.125 -the end.)</td></tr><tr>
1.126 - <td align="undefined" valign="undefined">Path info</td>
1.127 - <td align="undefined" valign="undefined">Determining which
1.128 -resources are being accessed within an application.</td>
1.129 - </tr>
1.130 - <tr>
1.131 - <td align="undefined" valign="undefined">Virtual path info</td>
1.132 - <td align="undefined" valign="undefined">This is an
1.133 +<table style="text-align: left; width: 80%;" align="center" border="1" cellpadding="5" cellspacing="0" width="80%"> <tbody> <tr> <th style="text-align: center;">Type of information</th> <th style="text-align: center;">Possible uses</th> </tr>
1.134 +<tr> <td align="undefined" valign="undefined">Path</td>
1.135 +<td align="undefined" valign="undefined">Building
1.136 +links to
1.137 +resources within an application.</td> </tr> <tr><td align="undefined" valign="undefined">Path without
1.138 +path info</td><td align="undefined" valign="undefined">Finding
1.139 +the location of the application in a server environment. (This is the
1.140 +path with the "path info" subtracted from
1.141 +the end.)</td></tr><tr> <td align="undefined" valign="undefined">Path info</td> <td align="undefined" valign="undefined">Determining
1.142 +which
1.143 +resources are being accessed within an application.</td> </tr>
1.144 +<tr> <td align="undefined" valign="undefined">Virtual
1.145 +path info</td> <td align="undefined" valign="undefined">This
1.146 +is an
1.147 application-defined version of "path info" and is discussed below.</td>
1.148 - </tr>
1.149 - </tbody>
1.150 -</table>
1.151 -<h2>Using the Virtual Path</h2>
1.152 -<p>Although WebStack sets the "path info" so that applications
1.153 -know which part of themselves are being accessed, you may decide
1.154 +</tr> </tbody></table><h2>Using the Virtual
1.155 +Path</h2>
1.156 +<p>Although WebStack sets the "path info" so that
1.157 +applications
1.158 +know which part of themselves are being accessed, you may
1.159 +decide
1.160 that upon
1.161 processing the request, these different parts of your application
1.162 should be
1.163 @@ -112,19 +106,22 @@
1.164 part they used, passing on a modified path to the other resources. For
1.165 such approaches, the "virtual path info" may be used instead, since it
1.166 permits modification within an application.</p>
1.167 -<p>So starting with a virtual path like this (which would be the same
1.168 +<p>So starting with a virtual path like this (which would be the
1.169 +same
1.170 as the "path info")...</p>
1.171 -<pre>/company/department/employee</pre>
1.172 -<p>...a resource might extract <code>company</code> from the start
1.173 +<pre>/company/department/employee</pre><p>...a
1.174 +resource might extract <code>company</code> from
1.175 +the start
1.176 of the path as follows:</p>
1.177 -<pre> # Inside a respond method...<br /> path = trans.get_virtual_path_info() # get the virtual path<br /> parts = path.split("/") # split the path into components - the first will be empty</pre>
1.178 -<p>Then, having processed the first non-empty part (remembering that
1.179 +<pre> # Inside a respond method...<br /> path = trans.get_virtual_path_info() # get the virtual path<br /> parts = path.split("/") # split the path into components - the first will be empty</pre><p>Then,
1.180 +having processed the first non-empty part (remembering that
1.181 the first part will be an empty string)...</p>
1.182 -<pre> if len(parts) > 1: # check to see how deep we are in the path<br /> process_something(parts[1]) # process the first non-empty part</pre>
1.183 -<p>...it will reconstruct the path, removing the processed part (but
1.184 -remembering to preserve a leading <code>/</code> character)...</p>
1.185 -<pre> trans.set_virtual_path_info("/" + "/".join(parts[2:]))</pre>
1.186 -<p>...and hand over control to another resource which would do the same
1.187 +<pre> if len(parts) > 1: # check to see how deep we are in the path<br /> process_something(parts[1]) # process the first non-empty part</pre><p>...it
1.188 +will reconstruct the path, removing the processed part (but
1.189 +remembering to preserve a leading <code>/</code>
1.190 +character)...</p>
1.191 +<pre> trans.set_virtual_path_info("/" + "/".join(parts[2:]))</pre><p>...and
1.192 +hand over control to another resource which would do the same
1.193 thing with the first of the other path components (<code>department</code>
1.194 and <code>employee</code>), and so on.</p>
1.195 <p>The compelling thing about this strategy is the way that each
1.196 @@ -133,17 +130,46 @@
1.197 independently from any "parent" resource. Moreover, such resources
1.198 could be deployed independently and still operate in the same way
1.199 without being "hardcoded" into assuming that they always reside at a
1.200 -particular level in a resource hierarchy.</p>
1.201 -<div class="WebStack">
1.202 +particular level in a resource hierarchy.</p><div class="WebStack">
1.203 <h3>WebStack API - Paths To
1.204 Resources Within Applications</h3>
1.205 <p>On transaction objects, the
1.206 following method exists to set virtual paths within applications.</p>
1.207 -<dl>
1.208 - <dt><code>set_virtual_path_info</code></dt>
1.209 - <dd>This sets the virtual path, affecting subsequent calls to the <code>get_virtual_path_info</code>
1.210 +<dl><dt><code>set_virtual_path_info</code></dt><dd>This
1.211 +sets the virtual path, affecting subsequent calls to the <code>get_virtual_path_info</code>
1.212 method. The path should either contain a leading <code>/</code>
1.213 -character optionally followed by other characters, or an empty string.</dd>
1.214 -</dl>
1.215 -</div>
1.216 +character optionally followed by other characters, or an empty string.</dd></dl>
1.217 +</div><h2>Summary</h2><p>The following illustration hopefully provides a more memorable way of representing the structure of paths:</p>
1.218 +<table style="text-align: left; width: 80%;" align="center" border="1" cellpadding="5" cellspacing="0" width="80%">
1.219 + <tbody>
1.220 + <tr>
1.221 + <th colspan="6" rowspan="1">URL</th>
1.222 + </tr>
1.223 + <tr>
1.224 + <th colspan="1" rowspan="4">Protocol, host, port</th>
1.225 + <th colspan="5" rowspan="1">Path</th>
1.226 + </tr>
1.227 + <tr>
1.228 + <th colspan="3" rowspan="1">Path without query</th>
1.229 + <th rowspan="3"></th>
1.230 + <th colspan="1" rowspan="3">Query</th>
1.231 + </tr>
1.232 + <tr>
1.233 + <th colspan="1" rowspan="2">Path without path info</th>
1.234 + <th colspan="2">Path info</th>
1.235 + </tr>
1.236 + <tr>
1.237 + <th>Processed virtual path info</th>
1.238 + <th>Virtual path info</th>
1.239 + </tr>
1.240 + <tr>
1.241 + <td>http://www.python.org</td>
1.242 + <td>/folder/application</td>
1.243 + <td>/resource</td>
1.244 + <td>/operation</td>
1.245 + <td>?</td>
1.246 + <td>a=1&b=2</td>
1.247 + </tr>
1.248 + </tbody>
1.249 +</table>
1.250 </body></html>
1.251 \ No newline at end of file