| 89 | | (defgeneric publish-handler (website handler)) |
|---|
| 90 | | (defgeneric handler-matches (handler)) |
|---|
| 91 | | (defgeneric publish-site (website)) |
|---|
| | 93 | (defgeneric publish-handler (website handler) |
|---|
| | 94 | (:documentation "Publish HANDLER on WEBSITE, thereby adding it to |
|---|
| | 95 | the chain of handlers that is searched to handle an incoming |
|---|
| | 96 | request.")) |
|---|
| | 97 | |
|---|
| | 98 | (defgeneric handler-matches-p (handler) |
|---|
| | 99 | (:documentation "Determine whether HANDLER is willing to handle the |
|---|
| | 100 | current request. Returns non-NIL if the HANDLER wants to handle the request |
|---|
| | 101 | NIL otherwise.")) |
|---|
| | 102 | |
|---|
| | 103 | (defgeneric publish-site (website) |
|---|
| | 104 | (:documentation "Publish all handlers defined in WEBSITE. |
|---|
| | 105 | |
|---|
| | 106 | XXX When is this called?")) |
|---|
| 194 | | (defgeneric handle (page-handler)) |
|---|
| 195 | | (defgeneric authorized-p (page-handler)) |
|---|
| 196 | | (defgeneric page-handler-url (page-handler)) |
|---|
| | 209 | (defgeneric handle (page-handler) |
|---|
| | 210 | (:documentation "Handle an incoming HTTP request, returning either a |
|---|
| | 211 | string or an (array (unsigned-byte 8) (*)) with the response |
|---|
| | 212 | contents. Alternatively, the handler may call (SEND-HEADERS) to |
|---|
| | 213 | get access to the response stream and output the data to it.")) |
|---|
| | 214 | |
|---|
| | 215 | (defgeneric authorized-p (page-handler) |
|---|
| | 216 | (:documentation "Return non-nil if the request is authorized to be |
|---|
| | 217 | executed on PAGE-HANDLER |
|---|
| | 218 | |
|---|
| | 219 | XXX wouldn't it be better if handler-matches-p checked |
|---|
| | 220 | authorization?")) |
|---|
| | 221 | |
|---|
| | 222 | (defgeneric page-handler-url (page-handler) |
|---|
| | 223 | (:documentation "Return the full base URL for PAGE-HANDLER.")) |
|---|
| 343 | | :reader page-handler-destination))) |
|---|
| 344 | | |
|---|
| 345 | | (defmethod request-pathname ((handler directory-handler)) |
|---|
| 346 | | (or (aux-request-value 'request-pathname) |
|---|
| 347 | | (setf (aux-request-value 'request-pathname) |
|---|
| 348 | | (subseq (script-name) (1+ (length (page-handler-prefix handler))))))) |
|---|
| 349 | | |
|---|
| 350 | | (defmethod handler-matches ((handler directory-handler)) |
|---|
| | 382 | :reader page-handler-destination)) |
|---|
| | 383 | (:documentation |
|---|
| | 384 | "Handler for a directory in the file system. Publishes all files |
|---|
| | 385 | in the directory DESTINATION under their relative path name.")) |
|---|
| | 386 | |
|---|
| | 387 | (defgeneric request-relative-pathname (directory-handler) |
|---|
| | 388 | (:documentation "Return the relative pathname for the current |
|---|
| | 389 | request as determined by DIRECTORY-HANDLER.") |
|---|
| | 390 | (:method ((handler directory-handler)) |
|---|
| | 391 | (or (aux-request-value 'request-relative-pathname) |
|---|
| | 392 | (setf (aux-request-value 'request-relative-pathname) |
|---|
| | 393 | (pathname (subseq (script-name) (1+ (length (page-handler-prefix handler))))))))) |
|---|
| | 394 | |
|---|
| | 395 | (defmethod handler-matches-p ((handler directory-handler)) |
|---|
| 372 | | (:default-initargs :object-class t :query-function nil)) |
|---|
| 373 | | |
|---|
| 374 | | (defgeneric object-handler-get-object (object-handler)) |
|---|
| 375 | | (defgeneric handle-object (object-handler object)) |
|---|
| 376 | | |
|---|
| 377 | | (defmethod object-handler-get-object ((handler object-handler)) |
|---|
| 378 | | (let ((id (parse-url))) |
|---|
| 379 | | (when id |
|---|
| 380 | | (find-store-object id |
|---|
| 381 | | :class (object-handler-object-class handler) |
|---|
| 382 | | :query-function (object-handler-query-function handler))))) |
|---|
| | 420 | (:default-initargs :object-class t :query-function nil) |
|---|
| | 421 | (:documentation "An OBJECT-HANDLER handles requests for a persistent |
|---|
| | 422 | object in the BKNR datastore. The first component of the relative |
|---|
| | 423 | path of the request is used as the key to locate the object. The |
|---|
| | 424 | object is looked up using the OBJECT-HANDLER-GET-OBJECT generic |
|---|
| | 425 | function, which will, by default, call FIND-STORE-OBJECT with the key |
|---|
| | 426 | as argument. |
|---|
| | 427 | |
|---|
| | 428 | The :QUERY-FUNCTION initarg may be supplied to set up a query function |
|---|
| | 429 | that maps from the key to an object. It is typically used to |
|---|
| | 430 | implement lookup by name. |
|---|
| | 431 | |
|---|
| | 432 | The :OBJECT-CLASS initarg may be supplied to restrict the handler to |
|---|
| | 433 | operate on objects of that class or its subclass. If the key |
|---|
| | 434 | specifies the ID of an object that has a different class or if the |
|---|
| | 435 | QUERY-FUNCTION returns an object of a different class, a run-time |
|---|
| | 436 | error is signaled.")) |
|---|
| | 437 | |
|---|
| | 438 | (defgeneric object-handler-get-object (object-handler) |
|---|
| | 439 | (:documentation "Implement object lookup. Methods return the object |
|---|
| | 440 | that the current request should operate upon. The default method for |
|---|
| | 441 | the OBJECT handler class performs a lookup using FIND-STORE-OBJECT.") |
|---|
| | 442 | (:method ((handler object-handler)) |
|---|
| | 443 | (let ((id (parse-url))) |
|---|
| | 444 | (when id |
|---|
| | 445 | (find-store-object id |
|---|
| | 446 | :class (object-handler-object-class handler) |
|---|
| | 447 | :query-function (object-handler-query-function handler)))))) |
|---|
| | 448 | |
|---|
| | 449 | (defgeneric handle-object (object-handler object) |
|---|
| | 450 | (:documentation "Handle the current to the OBJECT-HANDLER. OBJECT |
|---|
| | 451 | is the object as looked up by OBJECT-HANDLER-GET-OBJECT.")) |
|---|
| 389 | | ()) |
|---|
| 390 | | |
|---|
| 391 | | (defgeneric handle-object-form (handler action object)) |
|---|
| | 458 | () |
|---|
| | 459 | (:documentation "Combined FORM-HANDLER and OBJECT-HANDLER class that |
|---|
| | 460 | is used as a base class for handlers that edit an object using a HTML |
|---|
| | 461 | form.")) |
|---|
| | 462 | |
|---|
| | 463 | (defgeneric handle-object-form (handler action object) |
|---|
| | 464 | (:documentation "Perform ACTION, a keyword that has been determined by |
|---|
| | 465 | parsing the \"action\" input element of the current HTML form, on |
|---|
| | 466 | OBJECT, which is parsed using the mechanism of an OBJECT-HANDLER.")) |
|---|