1 ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
6 ;;;; Purpose: View methods for Hyperobjects
7 ;;;; Programmer: Kevin M. Rosenberg
8 ;;;; Date Started: Apr 2000
10 ;;;; $Id: views.lisp,v 1.41 2003/05/14 07:05:24 kevin Exp $
12 ;;;; This file is Copyright (c) 2000-2003 by Kevin M. Rosenberg
13 ;;;; *************************************************************************
15 (in-package :hyperobject)
17 (eval-when (:compile-toplevel :execute)
18 (declaim (optimize (speed 2) (safety 2) (compilation-speed 0) (debug 2))))
21 (defclass object-view ()
22 ((object-class-name :initform nil :initarg :object-class-name
23 :accessor object-class-name
24 :documentation "Name of class of object to be viewed.")
25 (object-class :initform nil :initarg :object-class
26 :accessor object-class
27 :documentation "Class of object to be viewed.")
28 (slots :initform nil :initarg :slots :accessor slots
29 :documentation "List of effective slots for object to be viewed.")
30 (name :initform nil :initarg :name :accessor name
31 :documentation "Name for this view.")
32 (category :initform nil :initarg :category :accessor category
33 :documentation "Category for view. Helpful when want to find a view corresponding to a particular category.")
34 (source-code :initform nil :initarg :source-code :accessor source-code
35 :documentation "Source code for generating view.")
36 (country-language :initform :en :initarg :country-language
37 :documentation "Country's Language for this view.")
39 (file-start-str :type (or string null) :initform nil :initarg :file-start-str
40 :accessor file-start-str)
41 (file-end-str :type (or string null) :initform nil :initarg :file-end-str
42 :accessor file-end-str)
43 (list-start-str-or-func :type (or string function null) :initform nil
44 :initarg :list-start-str-or-func
45 :accessor list-start-str-or-func)
46 (list-start-indent :initform nil :initarg :list-start-indent
47 :accessor list-start-indent)
48 (list-end-str-or-func :type (or string function null) :initform nil
49 :initarg :list-end-str-or-func
50 :accessor list-end-str-or-func)
51 (list-end-indent :initform nil :initarg :list-end-indent
52 :accessor list-end-indent)
53 (obj-start-str-or-func :type (or string function null) :initform nil :initarg :obj-start-str-or-func
54 :accessor obj-start-str-or-func)
55 (obj-start-indent :initform nil :initarg :obj-start-indent
56 :accessor obj-start-indent)
57 (obj-end-str-or-func :type (or string function null) :initform nil :initarg :obj-end-str-or-func
58 :accessor obj-end-str-or-func)
59 (obj-end-indent :initform nil :initarg :obj-end-indent
60 :accessor obj-end-indent)
61 (obj-data-indent :initform nil :initarg :obj-data-indent
62 :accessor obj-data-indent)
63 (obj-data-func :type (or function null) :initform nil
64 :initarg :obj-data-func
65 :accessor obj-data-func)
66 (obj-data-print-code :type (or function null) :initform nil
67 :initarg :obj-data-print-code
68 :accessor obj-data-print-code)
69 (obj-data-end-str :type (or string null) :initform nil
70 :initarg :obj-data-end-str
71 :accessor obj-data-end-str)
72 (link-slots :type list :initform nil
73 :documentation "List of slot names that have hyperlinks"
75 (link-page-name :type (or string null) :initform nil :initarg :link-page-name
76 :accessor link-page-name)
77 (link-href-start :type (or string null) :initform nil :initarg :link-href-start
78 :accessor link-href-start)
79 (link-href-end :type (or string null) :initform nil :initarg :link-href-end
80 :accessor link-href-end)
81 (link-ampersand :type (or string null) :initform nil :initarg :link-ampersand
82 :accessor link-ampersand))
83 (:default-initargs :link-page-name "disp-func1")
84 (:documentation "View class for a hyperobject"))
87 (defun get-category-view (obj category &optional slots)
88 "Find or make a category view for an object"
89 (let ((obj-class (class-of obj)))
91 (default-view obj-class)
92 (aif (find category (views obj-class) :key #'category)
95 (make-instance 'object-view
96 :object-class-name (class-name obj-class)
97 :object-class obj-class
100 (push view (views obj-class))
103 ;;;; *************************************************************************
104 ;;;; Metaclass Intialization
105 ;;;; *************************************************************************
107 (defun finalize-views (cl)
108 "Finalize all views that are given on a objects initialization"
109 (unless (default-print-slots cl)
110 (setf (default-print-slots cl)
111 (mapcar #'slot-definition-name (class-slots cl))))
113 (dolist (view-def (views cl))
114 (push (make-object-view cl view-def) views))
115 (setf (views cl) (nreverse views)))
118 (setf (default-view cl) (make-object-view cl (default-view cl))))
120 (setf (default-view cl) (make-object-view cl (car (views cl)))))
122 (setf (default-view cl) (make-object-view cl :default)))))
124 (defun make-object-view (cl view-def)
125 "Make an object view from a definition. Do nothing if a class is passed so that reinitialization will be a no-op"
127 ((typep view-def 'object-view)
129 ((eq view-def :default)
130 (let* ((name (class-name cl))
131 (view (make-instance 'object-view :name "automatic"
132 :object-class-name name
134 :category :compact-text)))
137 (eval `(make-instance ,view-def)))
139 (error "Invalid parameter to make-object-view: ~S" view-def))))
141 (defmethod initialize-instance :after ((view object-view)
142 &rest initargs &key &allow-other-keys)
143 (initialize-view (object-class view) view))
145 (defun initialize-view (obj-cl view)
146 "Calculate all view slots for a hyperobject class"
149 (initialize-view-by-category obj-cl view))
151 (initialize-view-by-source-code obj-cl view))
153 (setf (category view) :compact-text)
154 (initialize-view-by-category obj-cl view))))
156 (defun initialize-view-by-source-code (obj-cl view)
157 "Initialize a view based upon a source code"
158 (let ((source-code (source-code view)))
159 (error "not implemented")
163 (defmacro write-simple (v s)
166 (write-string (write-to-string ,v) ,s)))
168 (defun write-ho-value (obj name type formatter cdata strm)
169 (declare (ignorable type))
170 (let* ((slot-data (slot-value obj name))
171 (fmt-data (if formatter
172 (funcall formatter slot-data)
175 (kmrcl:xml-cdata fmt-data)
177 (write-simple data strm)))
180 (defun ppfc-html (title name type formatter cdata print-func)
181 (vector-push-extend '(write-string "<span class=\"" s) print-func)
182 (vector-push-extend `(write-string ,title s) print-func)
183 (vector-push-extend '(write-string "\">" s) print-func)
184 (vector-push-extend `(write-ho-value x ',name ',type ',formatter ,cdata s) print-func)
185 (vector-push-extend '(write-string "</span>" s) print-func))
187 (defun ppfc-xml (tag name type formatter cdata print-func)
188 (vector-push-extend '(write-char #\< s) print-func)
189 (vector-push-extend `(write-string ,tag s) print-func)
190 (vector-push-extend '(write-char #\> s) print-func)
191 (vector-push-extend `(write-ho-value x ',name ',type ',formatter ,cdata s) print-func)
192 (vector-push-extend '(write-string "</" s) print-func)
193 (vector-push-extend `(write-string ,tag s) print-func)
194 (vector-push-extend '(write-char #\> s) print-func))
196 (defun ppfc-html-labels (label name type formatter cdata print-func)
197 (vector-push-extend '(write-string "<span class=\"label\">" s) print-func)
198 (vector-push-extend `(write-string ,label s) print-func)
199 (vector-push-extend '(write-string "</span> " s) print-func)
200 (ppfc-html label name type formatter cdata print-func))
202 (defun ppfc-xhtml-labels (label tag name type formatter cdata print-func)
203 (vector-push-extend '(write-string "<span class=\"label\">" s) print-func)
204 (vector-push-extend `(write-string ,label s) print-func)
205 (vector-push-extend '(write-string "</span> " s) print-func)
206 (ppfc-html tag name type formatter cdata print-func))
208 (defun ppfc-xml-labels (label tag name type formatter cdata print-func)
209 (vector-push-extend '(write-string "<label>" s) print-func)
210 (vector-push-extend `(write-string ,label s) print-func)
211 (vector-push-extend '(write-string "</label> " s) print-func)
212 (ppfc-xml tag name type formatter cdata print-func))
214 (defun ppfc-html-link (name type formatter cdata nlink print-func)
215 (declare (fixnum nlink))
216 (vector-push-extend '(write-char #\< s) print-func)
217 (vector-push-extend `(write-string (nth ,(+ nlink nlink) links) s) print-func)
218 (vector-push-extend '(write-char #\> s) print-func)
219 (vector-push-extend `(write-ho-value x ',name ',type ',formatter ,cdata s) print-func)
220 (vector-push-extend '(write-string "</" s) print-func)
221 (vector-push-extend `(write-string (nth ,(+ nlink nlink 1) links) s) print-func)
222 (vector-push-extend '(write-char #\> s) print-func))
224 (defun ppfc-html-link-labels (label name type formatter cdata nlink print-func)
225 (vector-push-extend '(write-string "<label>" s) print-func)
226 (vector-push-extend `(write-string ,label s) print-func)
227 (vector-push-extend '(write-string "</label> " s) print-func)
228 (ppfc-html-link name type formatter cdata nlink print-func))
230 (defun push-print-fun-code (category slot nlink print-func)
231 (let* ((formatter (esd-print-formatter slot))
232 (name (slot-definition-name slot))
233 (namestr-lower (string-downcase (symbol-name name)))
234 (xml-namestr (escape-xml-string namestr-lower))
235 (xml-tag (escape-xml-string namestr-lower))
236 (type (slot-value slot 'type))
238 (and (in category :xml :xhtml :xml-link :xhtml-link
239 :xml-labels :ie-xml-labels
240 :xhtml-link-labels :xml-link-labels :ie-xml-link
243 (lisp-type-is-a-string type))))))
244 (hyperlink (esd-hyperlink slot)))
249 `(write-ho-value x ',name ',type ',formatter ,cdata s) print-func))
250 (:compact-text-labels
251 (vector-push-extend `(write-string ,namestr-lower s) print-func)
252 (vector-push-extend '(write-char #\space s) print-func)
254 `(write-ho-value x ',name ',type ',formatter ,cdata s) print-func))
256 (ppfc-html namestr-lower name type formatter cdata print-func))
258 (ppfc-xml xml-tag name type formatter cdata print-func))
260 (ppfc-html-labels namestr-lower name type formatter cdata print-func))
262 (ppfc-xhtml-labels xml-namestr namestr-lower name type formatter cdata print-func))
264 (ppfc-xml-labels xml-namestr xml-tag name type formatter cdata print-func))
265 ((or :html-link :xhtml-link)
267 (ppfc-html-link name type formatter cdata nlink print-func)
268 (ppfc-html namestr-lower name type formatter cdata print-func)))
269 ((or :xml-link :ie-xml-link)
271 (ppfc-html-link name type formatter cdata nlink print-func)
272 (ppfc-xml xml-tag name type formatter cdata print-func)))
275 (ppfc-html-labels namestr-lower name type formatter cdata print-func)))
278 (ppfc-html-link-labels xml-namestr name type formatter cdata nlink
280 (ppfc-xhtml-labels xml-tag namestr-lower name type formatter cdata
282 ((or :xml-link-labels :ie-xml-link-labels)
284 (ppfc-html-link-labels xml-namestr name type formatter cdata nlink
286 (ppfc-xml-labels xml-tag namestr-lower name type formatter cdata
290 (defun view-has-links-p (view)
291 (in (category view) :html-link :xhtml-link :xml-link :ie-xml-link
292 :html-link-labels :xhtml-links-labels :xml-link-labels
293 :ie-xml-link-labels))
295 (defun initialize-view-by-category (obj-cl view)
296 "Initialize a view based upon a preset category"
297 (unless (in (category view) :compact-text :compact-text-labels
298 :html :html-labels :html-link-labels
299 :xhtml :xhtml-labels :xhtml-link-labels
300 :xml :xml-labels :xml-link :ie-xml-link
301 :xml-link-labels :ie-xml-link-labels)
302 (error "Unknown view category ~A" (category view)))
304 (unless (slots view) (setf (slots view) (default-print-slots obj-cl)))
307 (print-func (make-array 10 :fill-pointer 0 :adjustable t)))
309 (do* ((slots (slots view) (cdr slots))
310 (slot-name (car slots) (car slots))
311 (slot (find-slot-by-name obj-cl slot-name)
312 (find-slot-by-name obj-cl slot-name)))
315 (error "Slot ~A is not found in class ~S" slot-name obj-cl))
317 (push-print-fun-code (category view) slot (length links) print-func)
318 (when (> (length slots) 1)
319 (vector-push-extend '(write-char #\space s) print-func))
321 (when (and (view-has-links-p view) (esd-hyperlink slot))
322 (push (slot-definition-name slot) links)))
324 (when (plusp (length print-func))
325 (setf (obj-data-print-code view) `(lambda (x s links)
326 (declare (ignorable links))
327 ,@(map 'list #'identity print-func)))
328 (setf (obj-data-func view)
329 (compile nil (eval (obj-data-print-code view)))))
331 (setf (link-slots view) (nreverse links)))
333 (finalize-view-by-category view)
336 (defun finalize-view-by-category (view)
337 (case (category view)
338 ((or :compact-text :compact-text-labels)
339 (initialize-text-view view))
340 ((or :html :xhtml :html-labels :xhtml-labels)
341 (initialize-html-view view))
342 ((or :xml :xml-labels)
343 (initialize-xml-view view))
344 ((or :html-link :html-link-labels)
345 (initialize-html-view view)
346 (setf (link-href-start view) "a href=")
347 (setf (link-href-end view) "a")
348 (setf (link-ampersand view) "&"))
349 ((or :xhtml-link :xhtml-link-labels)
350 (initialize-html-view view)
351 (setf (link-href-start view) "a href=")
352 (setf (link-href-end view) "a")
353 (setf (link-ampersand view) "&"))
354 ((or :xml-link :xml-link-labels)
355 (initialize-xml-view view)
356 (setf (link-href-start view)
357 "xmllink xlink:type=\"simple\" xlink:href=")
358 (setf (link-href-end view) "xmllink")
359 (setf (link-ampersand view) "&"))
360 ((or :ie-xml-link :ie-xml-link-labels)
361 (initialize-xml-view view)
362 (setf (link-href-start view) "html:a href=")
363 (setf (link-href-end view) "html:a")
364 (setf (link-ampersand view) "&"))))
367 (defun initialize-view-by-category (obj-cl view)
368 "Initialize a view based upon a preset category"
373 (category (category view)))
375 (unless (in category :compact-text :compact-text-labels
376 :html :html-labels :html-link-labels
377 :xhtml :xhtml-labels :xhtml-link-labels
378 :xml :xml-labels :xml-link :ie-xml-link
379 :xml-link-labels :ie-xml-link-labels)
380 (error "Unknown view category ~A" category))
383 (setf (slots view) (default-print-slots obj-cl)))
384 (dolist (slot-name (slots view))
385 (let ((slot (find-slot-by-name obj-cl slot-name)))
387 (error "Slot ~A is not found in class ~S" slot-name obj-cl))
388 (let* ((name (slot-definition-name slot))
389 (namestr-lower (string-downcase (symbol-name name)))
390 (xml-namestr (escape-xml-string namestr-lower))
391 (xml-tag (escape-xml-string namestr-lower))
392 (type (slot-value slot 'type))
393 (print-formatter (esd-print-formatter slot)))
398 (setq first-field nil))
400 (string-append fmtstr " ")))
404 ((or :integer :fixnum)
412 (string-append fmtstr value-fmt))
413 (:compact-text-labels
414 (string-append fmtstr namestr-lower " " value-fmt))
416 (string-append fmtstr (concatenate 'string "<span class=\"" namestr-lower "\">" value-fmt "</span>")))
418 (string-append fmtstr (concatenate 'string "<" namestr-lower ">" value-fmt "</" namestr-lower ">")))
420 (string-append fmtstr (concatenate 'string "<span class=\"label\">" namestr-lower "</span> <span class=\"" namestr-lower "\">" value-fmt "</span>")))
422 (string-append fmtstr (concatenate 'string "<span class=\"label\">" xml-namestr "</span> <span class=\"" namestr-lower "\">" value-fmt "</span>")))
424 (string-append fmtstr (concatenate 'string "<label>" xml-namestr "</label> <" xml-tag ">" value-fmt "</" xml-tag ">")))
425 ((or :html-link :xhtml-link)
427 (if (esd-hyperlink slot)
428 (string-append fmtstr "<~~a>" value-fmt "</~~a>")
429 (string-append fmtstr (concatenate 'string "<span class=\"" namestr-lower "\">" value-fmt "</span>"))))
430 ((or :xml-link :ie-xml-link)
432 (if (esd-hyperlink slot)
433 (string-append fmtstr "<~~a>" value-fmt "</~~a>")
434 (string-append fmtstr (concatenate 'string "<" xml-tag ">" value-fmt "</" xml-tag ">"))))
437 (if (esd-hyperlink slot)
438 (string-append fmtstr "<span class=\"label\">" namestr-lower "</span> <~~a>" value-fmt "</~~a>")
439 (string-append fmtstr (concatenate 'string "<span class=\"label\">" namestr-lower "</span> <span class=\"" namestr-lower "\">" value-fmt "</span>"))))
442 (if (esd-hyperlink slot)
443 (string-append fmtstr "<span class=\"label\">" xml-namestr "</span> <~~a>" value-fmt "</~~a>")
444 (string-append fmtstr (concatenate 'string "<span class=\"label\">" xml-namestr "</span> <span class=\"" namestr-lower "\">" value-fmt "</span>"))))
445 ((or :xml-link-labels :ie-xml-link-labels)
447 (if (esd-hyperlink slot)
448 (string-append fmtstr "<label>" xml-namestr "</label> <~~a>" value-fmt "</~~a>")
449 (string-append fmtstr (concatenate 'string "<label>" xml-namestr "</label> <" xml-tag ">" value-fmt "</" xml-tag ">")))))
452 (let ((func (if print-formatter
453 `(,print-formatter (slot-value x (quote ,name)))
454 `(slot-value x (quote ,name)))))
455 (when (and (in category :xml :xhtml :xml-link :xhtml-link
456 :xml-labels :ie-xml-labels
457 :xhtml-link-labels :xml-link-labels :ie-xml-link
460 (lisp-type-is-a-string type)))
461 (setq func `(kmrcl:xml-cdata ,func)))
462 (push func value-func))
467 (compile nil (eval `(lambda (x) (values ,@(nreverse value-func)))))))
469 (setf (obj-data-fmtstr view) fmtstr)
470 (setf (obj-data-value-func view) value-func)
471 (setf (link-slots view) (nreverse links))
474 ((or :compact-text :compact-text-labels)
475 (initialize-text-view view))
476 ((or :html :xhtml :html-labels :xhtml-labels)
477 (initialize-html-view view))
478 ((or :xml :xml-labels)
479 (initialize-xml-view view))
480 ((or :html-link :html-link-labels)
481 (initialize-html-view view)
482 (setf (link-href-start view) "a href=")
483 (setf (link-href-end view) "a")
484 (setf (link-ampersand view) "&"))
485 ((or :xhtml-link :xhtml-link-labels)
486 (initialize-html-view view)
487 (setf (link-href-start view) "a href=")
488 (setf (link-href-end view) "a")
489 (setf (link-ampersand view) "&"))
490 ((or :xml-link :xml-link-labels)
491 (initialize-xml-view view)
492 (setf (link-href-start view)
493 "xmllink xlink:type=\"simple\" xlink:href=")
494 (setf (link-href-end view) "xmllink")
495 (setf (link-ampersand view) "&"))
496 ((or :ie-xml-link :ie-xml-link-labels)
497 (initialize-xml-view view)
498 (setf (link-href-start view) "html:a href=")
499 (setf (link-href-end view) "html:a")
500 (setf (link-ampersand view) "&"))))
504 ;;;; *************************************************************************
505 ;;;; View Data Format Section
506 ;;;; *************************************************************************
508 (defun class-name-of (obj)
509 (string-downcase (class-name (class-of obj))))
511 (defvar +newline-string+ (format nil "~%"))
513 (defun write-user-name-maybe-plural (obj nitems strm)
516 (hyperobject-class-user-name-plural obj)
517 (hyperobject-class-user-name obj))
520 (defun initialize-text-view (view)
521 (setf (list-start-str-or-func view)
523 (eval '(lambda (obj nitems strm)
524 (write-user-name-maybe-plural obj nitems strm)
525 (write-char #\: strm)
526 (write-char #\Newline strm)))))
527 (setf (list-start-indent view) t)
528 (setf (obj-data-indent view) t)
529 (setf (obj-data-end-str view) +newline-string+))
531 (defun html-list-start-func (obj nitems strm)
532 (write-string "<p><b>" strm)
533 (write-user-name-maybe-plural obj nitems strm)
534 (write-string ":</b></p><div class=\"" strm)
535 (write-string (class-name-of obj) strm)
536 (write-string "\"><ul>" strm)
537 (write-char #\newline strm))
539 (defun initialize-html-view (view)
540 (initialize-text-view view)
541 (setf (file-start-str view) (format nil "<html><body>~%"))
542 (setf (file-end-str view) (format nil "</body><html>~%"))
543 (setf (list-start-indent view) t)
544 (setf (list-start-str-or-func view) #'html-list-start-func)
545 (setf (list-end-str-or-func view) (format nil "</ul></div>~%"))
546 (setf (list-end-indent view) t)
547 (setf (obj-start-indent view) t)
548 (setf (obj-start-str-or-func view) "<li>")
549 (setf (obj-end-indent view) t)
550 (setf (obj-end-str-or-func view) (format nil "</li>~%"))
551 (setf (obj-data-indent view) t))
553 (defun initialize-xhtml-view (view)
554 (initialize-text-view view)
555 (setf (file-start-str view) (format nil "<html><body>~%"))
556 (setf (file-end-str view) (format nil "</body><html>~%"))
557 (setf (list-start-indent view) t)
558 (setf (list-start-str-or-func view) #'html-list-start-func)
559 (setf (list-end-str-or-func view) (format nil "</ul></div>~%"))
560 (setf (list-end-indent view) t)
561 (setf (obj-start-indent view) t)
562 (setf (obj-start-str-or-func view) "<li>")
563 (setf (obj-end-indent view) t)
564 (setf (obj-end-str-or-func view) (format nil "</li>~%"))
565 (setf (obj-data-indent view) t))
567 (defun xmlformat-list-end-func (x strm)
568 (write-string "</" strm)
569 (write-string (class-name-of x) strm)
570 (write-string "list" strm)
571 (write-string ">" strm)
572 (write-char #\newline strm))
574 (defun xmlformat-list-start-func (x nitems strm)
575 (write-char #\< strm)
576 (write-string (class-name-of x) strm)
577 (write-string "list><title>" strm)
578 (write-user-name-maybe-plural x nitems strm)
579 (write-string ":</title>" strm)
580 (write-char #\newline strm))
582 (defun initialize-xml-view (view)
583 (initialize-text-view view)
584 (setf (file-start-str view) "") ; (std-xml-header)
585 (setf (list-start-indent view) t)
586 (setf (list-start-str-or-func view) #'xmlformat-list-start-func)
587 (setf (list-end-indent view) t)
588 (setf (list-end-str-or-func view) #'xmlformat-list-end-func)
589 (setf (obj-start-str-or-func view) (format nil "<~(~a~)>" (object-class-name view)))
590 (setf (obj-start-indent view) t)
591 (setf (obj-end-str-or-func view) (format nil "</~(~a~)>~%" (object-class-name view)))
592 (setf (obj-end-indent view) nil)
593 (setf (obj-data-indent view) nil))
596 ;;; File Start and Ends
598 (defun fmt-file-start (view strm)
599 (awhen (file-start-str view)
600 (write-string it strm)))
602 (defun fmt-file-end (view strm)
603 (awhen (file-end-str view)
604 (write-string it strm)))
606 ;;; List Start and Ends
608 (defun fmt-list-start (obj view strm indent num-items)
609 (when (list-start-indent view)
610 (indent-spaces indent strm))
611 (awhen (list-start-str-or-func view)
613 (write-string it strm)
614 (funcall it obj num-items strm))))
616 (defun fmt-list-end (obj view strm indent num-items)
617 (declare (ignore num-items))
618 (when (list-end-indent view)
619 (indent-spaces indent strm))
620 (awhen (list-end-str-or-func view)
622 (write-string it strm)
623 (funcall it obj strm))))
625 ;;; Object Start and Ends
627 (defun fmt-obj-start (obj view strm indent)
628 (when (obj-start-indent view)
629 (indent-spaces indent strm))
630 (awhen (obj-start-str-or-func view)
632 (write-string it strm)
633 (funcall it obj strm))))
635 (defun fmt-obj-end (obj view strm indent)
636 (when (obj-end-indent view)
637 (indent-spaces indent strm))
638 (awhen (obj-end-str-or-func view)
640 (write-string it strm)
641 (funcall it obj strm))))
646 (defun make-link-start (view fieldfunc fieldvalue refvars)
647 (with-output-to-string (s)
648 (write-string (link-href-start view) s)
650 (write-string (make-url (link-page-name view)) s)
651 (write-string "?func=" s)
652 (write-simple fieldfunc s)
653 (write-string (link-ampersand view) s)
654 (write-string "key=" s)
655 (write-simple fieldvalue s)
656 (dolist (var refvars)
657 (write-string (link-ampersand view) s)
658 (write-simple (car var) s)
660 (write-simple (cdr var) s))
663 (defun make-link-end (obj view fieldname)
664 (declare (ignore obj fieldname))
665 (link-href-end view))
667 (defun fmt-obj-data (obj view strm indent refvars)
668 (when (obj-data-indent view)
669 (indent-spaces indent strm))
670 (if (link-slots view)
671 (fmt-obj-data-with-link obj view strm refvars)
672 (fmt-obj-data-plain obj view strm))
673 (awhen (obj-data-end-str view)
674 (write-string it strm)))
676 (defun fmt-obj-data-plain (obj view strm)
677 (awhen (obj-data-func view)
678 (funcall it obj strm nil)))
680 (defun fmt-obj-data-with-link (obj view strm refvars)
681 (let ((refvalues '()))
682 ;; make list of hyperlink link fields for printing to refstr template
683 (dolist (name (link-slots view))
684 (awhen (find name (hyperobject-class-hyperlinks obj) :key #'name)
685 (push (make-link-start view (lookup it) (slot-value obj name)
686 (append (link-parameters it) refvars))
688 (push (make-link-end obj view name) refvalues)))
689 (funcall (obj-data-func view) obj strm (nreverse refvalues))))
691 (defun obj-data (obj view)
692 "Returns the objects data as a string. Used by common-graphics outline function"
693 (with-output-to-string (s) (fmt-obj-data-plain obj view s)))
695 ;;; Display method for objects
698 (defun load-all-subobjects (objs)
699 "Load all subobjects if they have not already been loaded."
700 (dolist (obj (mklist objs))
701 (dolist (subobj (hyperobject-class-subobjects obj))
702 (awhen (slot-value obj (name-slot subobj))
703 (load-all-subobjects it))))
706 (defun view-hyperobject (objs view category strm &optional (indent 0) filter
708 "Display a single or list of hyperobject-class instances and their subobjects"
709 (declare (fixnum indent))
710 (let-when (objlist (mklist objs))
711 (let ((nobjs (length objlist))
715 (*print-readably* nil)
718 (fmt-list-start (car objlist) view strm indent nobjs)
719 (dolist (obj objlist)
720 (unless (and filter (not (funcall filter obj)))
721 (fmt-obj-start obj view strm indent)
722 (fmt-obj-data obj view strm (1+ indent) refvars)
723 (when (and subobjects (hyperobject-class-subobjects obj))
724 (dolist (subobj (hyperobject-class-subobjects obj))
725 (aif (slot-value obj (name-slot subobj))
726 (view-hyperobject it (get-category-view (car (mklist it)) category)
727 category strm (1+ indent) filter
728 subobjects refvars))))
729 (fmt-obj-end obj view strm indent)))
730 (fmt-list-end (car objlist) view strm indent nobjs)))
734 (defun view (objs &key (stream *standard-output*) category view
735 filter subobjects refvars file-wrapper)
736 "EXPORTED Function: prints hyperobject-class objects. Simplies call to view-hyperobject"
737 (let-when (objlist (mklist objs))
739 (setq view (get-category-view (car objlist) category)))
741 (setq view (default-view (class-of (car objlist)))))
743 (fmt-file-start view stream))
744 (view-hyperobject objlist view category stream 0 filter subobjects refvars)
746 (fmt-file-end view stream)))
752 (defun fmt-comma-integer (i)
753 (format nil "~:d" i))