![]() ![]() |
Sie sind hier: ZWikiSeiten > ZPublisher ZPublisherEine grundlegende Komponente bei der Auslieferung (publishing) von Webseiten. �bersetzt von http://www.dieter.handshake.de/pyprojects/zope/book/chap3.html#ZPublisher Der ZPublisher ist f�r die folgenden Aufgaben verantwortlich:
Nun etwas detaillierter zu diesen Aufgaben:
Der REquest?(ANfrage?) kann Argumente enthalten, die n�her bestimmen was getan werden soll bzw. Daten f�r die Aktion bereitstellen. Bei [GET]? und [HEAD]? requests sind die Argumente im AbfrageString? enthalten, bei anderen RequestMethod?-s sind sie im RequestBody?. Die Parameter sind oft verschiedenartig verschl�sselt und k�nnen auf verschiedene Art und Weise serialisiert werden. Der ZPublisher holt sie und entschl�sselt sie falls n�tig.
PAckager?-s packen mehrere Parameter-Definitionen mit gleichem oder mit verwandten Namen in gr��ere Strukturen um sie einfacher zugreifbar zu machen. Zope unterst�tzt folgende PAckager?:
Normalerweise ruft ZPublisher das beim TRaversal? ausgew�hlte Objekt auf um die HTTPResponse? zu erzeugen. Wenn aber der REquest? eine ACtions? k�nnen zwei Formen haben: Es gibt zwei verschiedene ACtions?-Typen:
ConTroller?-s steuern wie ZPublisher die gegebenen ParameterDefinition?-en. ZPublisher nutzt folgende ConTroller?-s:
W�hrend dem traversal, �berquert der ZPublisher die Webseite gem�� dem PathComponent? im ResourceLocator? des REquest?-s. (Ein [URI]? Pfad ist eine Folge von PfadAbschnitt?-en (PathSegment?-s). ZPublisher traversiert dies in Schritten, einen f�r jeden PfadAbschnitt?. Bei jedem Schritt beginnt er mit dem aktuellen Objekt und hat eine Folge von PfadAbschnitt?-en zum Traversieren �brig. Er interpretiert den ersten Abschnitt als den accessor (Wegbereiter?) im KOntext? des aktuellen Objekts um zum n�chsten Objekt zu gelangen. Normalerweise wird der n�chste Schritt der �berschreitung dieses folgende Objekt als aktuelles Objekt nehmen und der erste Abschnitt des vorher restlichen Abschnitts wird verworfen. Der Prozess stoppt wenn der entweder alle PfadSegment?-e bearbeitet wurden oder wenn das aktuelle PfadSegment? auf kein neues Objekt zugreifen kann[26]?. Der zweite Fall zeigt f�r gew�hnlich einen Fehler an[27]?. ZPublisher beginnt die Traversierung beim RootObject und mit dem vollst�ndigen RequestLocatorPath?. Wenn ein 'index_html'-Objekt im KOntext? des Objektes verf�gbar ist, das durch eine erfolgreiche �berquerung lokalisiert wurde, so wird ZPublisher diese Die weiteren Teile dieser Seite sind nur f�r ProduktEntwickler? relevant. Andere Leser k�nnen sie �berspringen. The remaining parts of this section are relevant only for product developers. Other readers may skip them. ZPublisher provides two traversal hooks. As we said in the introduction, a hook is a step in a procedure where the application can take over control when the normal framework implementation does not fit its needs. The first hook is called __before_publishing_traverse__. If defined, it is called at the start of a traversal step. It is defined when the step's current object has such an attribute. The attribute will be called with two arguments, the current object and the request object. Its return value is discarded, thus only its side effects are essential. Usually, it will modify the request object. The modification may be as simple as defining additional parameters or providing defaults. However, the request object also provides methods that change the path segments still to be traversed. Therefore, the hook can drastically change the traversal. This is used for example to implement virtual hosting or to facilitate internationalization. Products that use this hook are for example SiteAccess2? (for virtual hosting) and Localizer (a localization tool). The second hook is called __bobo_traverse__. If defined, it customizes the "accessor" notion. As we have seen, during a traversal step, ZPublisher uses the first path segment as an accessor to find the next object in the current object's context. Its default behavior is to first check for an attribute of the given name, then for a (mapping) key, then fails. However, if the current object has an attribute __bobo_traverse__, then this function is called with the request object and the segment as parameters to determine the next object. It can even return a tuple of objects. In this case, the last element defines the next object while the preceeding objects define the path to this object replacing the current object. This hook is used, for example, to implement advanced features of ZSQL methods such as direct traversal. During traversal, ZPublisher builds a sequence of objects visited during traversal to the final selected object. It makes the reverse list accessible as the request member PARENTS. PARENTS[0]? is the object's parent, the object visited before this object; PARENTS[1]? is the object's grand parent, and so on. The object itself is made available via the member PUBLISHED. 2.6.5. Initiate Authentication Once ZPublisher has determined the object to be called during the traversal, it initiates authentication. It does not authenticate the user itself, but cooperates with other Zope objects, so called UserFolders? to fulfill this task. First, ZPublisher determines which roles can call the object. Then, ZPublisher goes back along the chain of nodes it had visited during traversal (but in reverse order). It checks each node, whether it contains a UserFolder? instance and if it does, whether this user folder can authenticate a user with the required roles. If authentication is successful, ZPublisher places the resulting user object as AUTHENTICATED_USER into the REQUEST object. Otherwise, ZPublisher continues its search towards the site root. The highest UserFolder? will return the Anonymous user, if it cannot authenticate the user and calling the object does not require special roles. If ZPublisher has reached the site root without being able to find a user folder that authenticated the user with sufficient privileges to call the object, it raises an Unauthorized exception. If not overridden by application specific code (e.g. special user folders), such an exception is turned into an "Unauthorized" HTTP response. Such an HTTP response causes the browser to pop up a login dialog. 2.6.6. Call object/method Now, that traversal has determined the object to call and the necessary authorization is checked, ZPublisher can call the object. ZPublisher looks into the object and determines what parameters are mandatory or optional for the call. It then looks into the REQUEST object and then the objects context, in this order, to find such parameters. It then calls the object with the parameters found, raising an exception if a mandatory parameter has not been found. ZPublisher calls the object inside a transaction. This makes is possible to undo most types of side effects of the call in case it should fail[28]?. If the call raises an exception, the transaction is aborted. When the call returns without exception, the transaction is committed and other requests can see potential effects by this call. 2.6.7. Handle errors ZPublisher handles all errors that occur during its proper operation or exceptions raised during the object call. It turns them into appropriate HTTP responses. ----------- Usually, the next traversal step will use this object as current object and the segment sequence with the first segment removed. |