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.33 2003/05/14 04:28:09 kevin Exp $
12 ;;;; This file is Copyright (c) 2000-2002 by Kevin M. Rosenberg
14 ;;;; *************************************************************************
16 (in-package :hyperobject)
18 (eval-when (:compile-toplevel :execute)
19 (declaim (optimize (speed 2) (safety 2) (compilation-speed 0) (debug 2))))
22 (defclass object-view ()
23 ((object-class-name :initform nil :initarg :object-class-name
24 :accessor object-class-name
25 :documentation "Name of class of object to be viewed.")
26 (object-class :initform nil :initarg :object-class
27 :accessor object-class
28 :documentation "Class of object to be viewed.")
29 (slots :initform nil :initarg :slots :accessor slots
30 :documentation "List of effective slots for object to be viewed.")
31 (name :initform nil :initarg :name :accessor name
32 :documentation "Name for this view.")
33 (category :initform nil :initarg :category :accessor category
34 :documentation "Category for view. Helpful when want to find a view corresponding to a particular category.")
35 (source-code :initform nil :initarg :source-code :accessor source-code
36 :documentation "Source code for generating view.")
37 (country-language :initform :en :initarg :country-language
38 :documentation "Country's Language for this view.")
40 (file-start-str :type (or string null) :initform nil :initarg :file-start-str
41 :accessor file-start-str)
42 (file-end-str :type (or string null) :initform nil :initarg :file-end-str
43 :accessor file-end-str)
44 (list-start-str-or-func :type (or string function null) :initform nil
45 :initarg :list-start-str-or-func
46 :accessor list-start-str-or-func)
47 (list-start-indent :initform nil :initarg :list-start-indent
48 :accessor list-start-indent)
49 (list-end-str-or-func :type (or string function null) :initform nil
50 :initarg :list-end-str-or-func
51 :accessor list-end-str-or-func)
52 (list-end-indent :initform nil :initarg :list-end-indent
53 :accessor list-end-indent)
54 (obj-start-str-or-func :type (or string function null) :initform nil :initarg :obj-start-str-or-func
55 :accessor obj-start-str-or-func)
56 (obj-start-indent :initform nil :initarg :obj-start-indent
57 :accessor obj-start-indent)
58 (obj-end-str-or-func :type (or string function null) :initform nil :initarg :obj-end-str-or-func
59 :accessor obj-end-str-or-func)
60 (obj-end-indent :initform nil :initarg :obj-end-indent
61 :accessor obj-end-indent)
62 (obj-data-indent :initform nil :initarg :obj-data-indent
63 :accessor obj-data-indent)
64 (obj-data-func :type (or function null) :initform nil
65 :initarg :obj-data-func
66 :accessor obj-data-func)
67 (obj-data-print-code :type (or function null) :initform nil
68 :initarg :obj-data-print-code
69 :accessor obj-data-print-code)
70 (obj-data-end-str :type (or string null) :initform nil
71 :initarg :obj-data-end-str
72 :accessor obj-data-end-str)
73 (link-slots :type list :initform nil
74 :documentation "List of slot names that have hyperlinks"
76 (link-page-name :type (or string null) :initform nil :initarg :link-page-name
77 :accessor link-page-name)
78 (link-href-start :type (or string null) :initform nil :initarg :link-href-start
79 :accessor link-href-start)
80 (link-href-end :type (or string null) :initform nil :initarg :link-href-end
81 :accessor link-href-end)
82 (link-ampersand :type (or string null) :initform nil :initarg :link-ampersand
83 :accessor link-ampersand))
84 (:default-initargs :link-page-name "disp-func1")
85 (:documentation "View class for a hyperobject"))
88 (defun get-category-view (obj category &optional slots)
89 "Find or make a category view for an object"
90 (let ((obj-class (class-of obj)))
92 (default-view obj-class)
93 (aif (find category (views obj-class) :key #'category)
96 (make-instance 'object-view
97 :object-class-name (class-name obj-class)
98 :object-class obj-class
101 (push view (views obj-class))
104 ;;;; *************************************************************************
105 ;;;; Metaclass Intialization
106 ;;;; *************************************************************************
108 (defun finalize-views (cl)
109 "Finalize all views that are given on a objects initialization"
110 (unless (default-print-slots cl)
111 (setf (default-print-slots cl)
112 (mapcar #'slot-definition-name (class-slots cl))))
114 (dolist (view-def (views cl))
115 (push (make-object-view cl view-def) views))
116 (setf (views cl) (nreverse views)))
119 (setf (default-view cl) (make-object-view cl (default-view cl))))
121 (setf (default-view cl) (make-object-view cl (car (views cl)))))
123 (setf (default-view cl) (make-object-view cl :default)))))
125 (defun make-object-view (cl view-def)
126 "Make an object view from a definition. Do nothing if a class is passed so that reinitialization will be a no-op"
128 ((typep view-def 'object-view)
130 ((eq view-def :default)
131 (let* ((name (class-name cl))
132 (view (make-instance 'object-view :name "automatic"
133 :object-class-name name
135 :category :compact-text)))
138 (eval `(make-instance ,view-def)))
140 (error "Invalid parameter to make-object-view: ~S" view-def))))
142 (defmethod initialize-instance :after ((view object-view)
143 &rest initargs &key &allow-other-keys)
144 (initialize-view (object-class view) view))
146 (defun initialize-view (obj-cl view)
147 "Calculate all view slots for a hyperobject class"
150 (initialize-view-by-category obj-cl view))
152 (initialize-view-by-source-code obj-cl view))
154 (setf (category view) :compact-text)
155 (initialize-view-by-category obj-cl view))))
157 (defun initialize-view-by-source-code (obj-cl view)
158 "Initialize a view based upon a source code"
159 (let ((source-code (source-code view)))
160 (error "not implemented")
165 (defun write-ho-value (obj name type formatter cdata strm)
166 (declare (ignorable type))
167 (let* ((slot-data (slot-value obj name))
168 (fmt-data (if formatter
169 (funcall formatter slot-data)
172 (kmrcl:xml-cdata fmt-data)
176 (write-string data strm))
178 (write-string (write-to-string data) strm))
180 (format strm "~A" data)))))
182 (defun ppfc-html (title name type formatter cdata print-func)
183 (vector-push-extend '(write-string "<span class=\"" s) print-func)
184 (vector-push-extend `(write-string ,title s) print-func)
185 (vector-push-extend '(write-string "\">" s) print-func)
186 (vector-push-extend `(write-ho-value x ',name ',type ',formatter ,cdata s) print-func)
187 (vector-push-extend '(write-string "</span>" s) print-func))
189 (defun ppfc-xml (tag name type formatter cdata print-func)
190 (vector-push-extend '(write-char #\< s) print-func)
191 (vector-push-extend `(write-string ,tag s) print-func)
192 (vector-push-extend '(write-char #\> s) print-func)
193 (vector-push-extend `(write-ho-value x ',name ',type ',formatter ,cdata s) print-func)
194 (vector-push-extend '(write-string "</" s) print-func)
195 (vector-push-extend `(write-string ,tag s) print-func)
196 (vector-push-extend '(write-char #\> s) print-func))
198 (defun ppfc-html-labels (label name type formatter cdata print-func)
199 (vector-push-extend '(write-string "<span class=\"label\">" s) print-func)
200 (vector-push-extend `(write-string ,label s) print-func)
201 (vector-push-extend '(write-string "</span> " s) print-func)
202 (ppfc-html label name type formatter cdata print-func))
204 (defun ppfc-xhtml-labels (label tag name type formatter cdata print-func)
205 (vector-push-extend '(write-string "<span class=\"label\">" s) print-func)
206 (vector-push-extend `(write-string ,label s) print-func)
207 (vector-push-extend '(write-string "</span> " s) print-func)
208 (ppfc-html tag name type formatter cdata print-func))
210 (defun ppfc-xml-labels (label tag name type formatter cdata print-func)
211 (vector-push-extend '(write-string "<label>" s) print-func)
212 (vector-push-extend `(write-string ,label s) print-func)
213 (vector-push-extend '(write-string "</label> " s) print-func)
214 (ppfc-xml tag name type formatter cdata print-func))
216 (defun ppfc-html-link (name type formatter cdata nlink print-func)
217 (vector-push-extend '(write-char #\< s) print-func)
218 (vector-push-extend `(write-string (nth ,(+ nlink nlink) links) s) print-func)
219 (vector-push-extend '(write-char #\> s) print-func)
220 (vector-push-extend `(write-ho-value x ',name ',type ',formatter ,cdata s) print-func)
221 (vector-push-extend '(write-string "</" s) print-func)
222 (vector-push-extend `(write-string (nth ,(+ nlink nlink 1) links) s) print-func)
223 (vector-push-extend '(write-char #\> s) print-func))
225 (defun ppfc-html-link-labels (label name type formatter cdata nlink print-func)
226 (vector-push-extend '(write-string "<label>" s) print-func)
227 (vector-push-extend `(write-string ,label s) print-func)
228 (vector-push-extend '(write-string "</label> " s) print-func)
229 (ppfc-html-link name type formatter cdata nlink print-func))
231 (defun push-print-fun-code (category slot nlink print-func)
232 (let* ((formatter (esd-print-formatter slot))
233 (name (slot-definition-name slot))
234 (namestr-lower (string-downcase (symbol-name name)))
235 (xml-namestr (escape-xml-string namestr-lower))
236 (xml-tag (escape-xml-string namestr-lower))
237 (type (slot-value slot 'type))
239 (and (in category :xml :xhtml :xml-link :xhtml-link
240 :xml-labels :ie-xml-labels
241 :xhtml-link-labels :xml-link-labels :ie-xml-link
244 (lisp-type-is-a-string type))))))
245 (hyperlink (esd-hyperlink slot)))
250 `(write-ho-value x ',name ',type ',formatter ,cdata s) print-func))
251 (:compact-text-labels
252 (vector-push-extend `(write-string ,namestr-lower s) print-func)
253 (vector-push-extend '(write-char #\space s) print-func)
255 `(write-ho-value x ',name ',type ',formatter ,cdata s) print-func))
257 (ppfc-html namestr-lower name type formatter cdata print-func))
259 (ppfc-xml xml-tag name type formatter cdata print-func))
261 (ppfc-html-labels namestr-lower name type formatter cdata print-func))
263 (ppfc-xhtml-labels xml-namestr namestr-lower name type formatter cdata print-func))
265 (ppfc-xml-labels xml-namestr xml-tag name type formatter cdata print-func))
266 ((or :html-link :xhtml-link)
268 (ppfc-html-link name type formatter cdata nlink print-func)
269 (ppfc-html namestr-lower name type formatter cdata print-func)))
270 ((or :xml-link :ie-xml-link)
272 (ppfc-html-link name type formatter cdata nlink print-func)
273 (ppfc-xml xml-tag name type formatter cdata print-func)))
276 (ppfc-html-labels namestr-lower name type formatter cdata print-func)))
279 (ppfc-html-link-labels xml-namestr name type formatter cdata nlink
281 (ppfc-xhtml-labels xml-tag namestr-lower name type formatter cdata
283 ((or :xml-link-labels :ie-xml-link-labels)
285 (ppfc-html-link-labels xml-namestr name type formatter cdata nlink
287 (ppfc-xml-labels xml-tag namestr-lower name type formatter cdata
291 (defun view-has-links-p (view)
292 (in (category view) :html-link :xhtml-link :xml-link :ie-xml-link
293 :html-link-labels :xhtml-links-labels :xml-link-labels
294 :ie-xml-link-labels))
296 (defun initialize-view-by-category (obj-cl view)
297 "Initialize a view based upon a preset category"
298 (unless (in (category view) :compact-text :compact-text-labels
299 :html :html-labels :html-link-labels
300 :xhtml :xhtml-labels :xhtml-link-labels
301 :xml :xml-labels :xml-link :ie-xml-link
302 :xml-link-labels :ie-xml-link-labels)
303 (error "Unknown view category ~A" (category view)))
305 (unless (slots view) (setf (slots view) (default-print-slots obj-cl)))
308 (print-func (make-array 10 :fill-pointer 0 :adjustable t)))
310 (do* ((slots (slots view) (cdr slots))
311 (slot-name (car slots) (car slots))
312 (slot (find-slot-by-name obj-cl slot-name)
313 (find-slot-by-name obj-cl slot-name)))
316 (error "Slot ~A is not found in class ~S" slot-name obj-cl))
318 (push-print-fun-code (category view) slot (length links) print-func)
319 (when (> (length slots) 1)
320 (vector-push-extend '(write-char #\space s) print-func))
322 (when (and (view-has-links-p view) (esd-hyperlink slot))
323 (push (slot-definition-name slot) links)))
325 (setf (obj-data-print-code view) `(lambda (x s links)
326 (declare (ignorable links))
327 ,@(map 'list #'identity print-func)))
329 (setf (obj-data-func view)
330 (when print-func (compile nil (eval (obj-data-print-code view)))))
332 (setf (link-slots view) (nreverse links)))
334 (finalize-view-by-category view)
337 (defun finalize-view-by-category (view)
338 (case (category view)
339 ((or :compact-text :compact-text-labels)
340 (initialize-text-view view))
341 ((or :html :xhtml :html-labels :xhtml-labels)
342 (initialize-html-view view))
343 ((or :xml :xml-labels)
344 (initialize-xml-view view))
345 ((or :html-link :html-link-labels)
346 (initialize-html-view view)
347 (setf (link-href-start view) "a href=")
348 (setf (link-href-end view) "a")
349 (setf (link-ampersand view) "&"))
350 ((or :xhtml-link :xhtml-link-labels)
351 (initialize-html-view view)
352 (setf (link-href-start view) "a href=")
353 (setf (link-href-end view) "a")
354 (setf (link-ampersand view) "&"))
355 ((or :xml-link :xml-link-labels)
356 (initialize-xml-view view)
357 (setf (link-href-start view)
358 "xmllink xlink:type=\"simple\" xlink:href=")
359 (setf (link-href-end view) "xmllink")
360 (setf (link-ampersand view) "&"))
361 ((or :ie-xml-link :ie-xml-link-labels)
362 (initialize-xml-view view)
363 (setf (link-href-start view) "html:a href=")
364 (setf (link-href-end view) "html:a")
365 (setf (link-ampersand view) "&"))))
368 (defun initialize-view-by-category (obj-cl view)
369 "Initialize a view based upon a preset category"
374 (category (category view)))
376 (unless (in category :compact-text :compact-text-labels
377 :html :html-labels :html-link-labels
378 :xhtml :xhtml-labels :xhtml-link-labels
379 :xml :xml-labels :xml-link :ie-xml-link
380 :xml-link-labels :ie-xml-link-labels)
381 (error "Unknown view category ~A" category))
384 (setf (slots view) (default-print-slots obj-cl)))
385 (dolist (slot-name (slots view))
386 (let ((slot (find-slot-by-name obj-cl slot-name)))
388 (error "Slot ~A is not found in class ~S" slot-name obj-cl))
389 (let* ((name (slot-definition-name slot))
390 (namestr-lower (string-downcase (symbol-name name)))
391 (xml-namestr (escape-xml-string namestr-lower))
392 (xml-tag (escape-xml-string namestr-lower))
393 (type (slot-value slot 'type))
394 (print-formatter (esd-print-formatter slot)))
399 (setq first-field nil))
401 (string-append fmtstr " ")))
405 ((or :integer :fixnum)
413 (string-append fmtstr value-fmt))
414 (:compact-text-labels
415 (string-append fmtstr namestr-lower " " value-fmt))
417 (string-append fmtstr (concatenate 'string "<span class=\"" namestr-lower "\">" value-fmt "</span>")))
419 (string-append fmtstr (concatenate 'string "<" namestr-lower ">" value-fmt "</" namestr-lower ">")))
421 (string-append fmtstr (concatenate 'string "<span class=\"label\">" namestr-lower "</span> <span class=\"" namestr-lower "\">" value-fmt "</span>")))
423 (string-append fmtstr (concatenate 'string "<span class=\"label\">" xml-namestr "</span> <span class=\"" namestr-lower "\">" value-fmt "</span>")))
425 (string-append fmtstr (concatenate 'string "<label>" xml-namestr "</label> <" xml-tag ">" value-fmt "</" xml-tag ">")))
426 ((or :html-link :xhtml-link)
428 (if (esd-hyperlink slot)
429 (string-append fmtstr "<~~a>" value-fmt "</~~a>")
430 (string-append fmtstr (concatenate 'string "<span class=\"" namestr-lower "\">" value-fmt "</span>"))))
431 ((or :xml-link :ie-xml-link)
433 (if (esd-hyperlink slot)
434 (string-append fmtstr "<~~a>" value-fmt "</~~a>")
435 (string-append fmtstr (concatenate 'string "<" xml-tag ">" value-fmt "</" xml-tag ">"))))
438 (if (esd-hyperlink slot)
439 (string-append fmtstr "<span class=\"label\">" namestr-lower "</span> <~~a>" value-fmt "</~~a>")
440 (string-append fmtstr (concatenate 'string "<span class=\"label\">" namestr-lower "</span> <span class=\"" namestr-lower "\">" value-fmt "</span>"))))
443 (if (esd-hyperlink slot)
444 (string-append fmtstr "<span class=\"label\">" xml-namestr "</span> <~~a>" value-fmt "</~~a>")
445 (string-append fmtstr (concatenate 'string "<span class=\"label\">" xml-namestr "</span> <span class=\"" namestr-lower "\">" value-fmt "</span>"))))
446 ((or :xml-link-labels :ie-xml-link-labels)
448 (if (esd-hyperlink slot)
449 (string-append fmtstr "<label>" xml-namestr "</label> <~~a>" value-fmt "</~~a>")
450 (string-append fmtstr (concatenate 'string "<label>" xml-namestr "</label> <" xml-tag ">" value-fmt "</" xml-tag ">")))))
453 (let ((func (if print-formatter
454 `(,print-formatter (slot-value x (quote ,name)))
455 `(slot-value x (quote ,name)))))
456 (when (and (in category :xml :xhtml :xml-link :xhtml-link
457 :xml-labels :ie-xml-labels
458 :xhtml-link-labels :xml-link-labels :ie-xml-link
461 (lisp-type-is-a-string type)))
462 (setq func `(kmrcl:xml-cdata ,func)))
463 (push func value-func))
468 (compile nil (eval `(lambda (x) (values ,@(nreverse value-func)))))))
470 (setf (obj-data-fmtstr view) fmtstr)
471 (setf (obj-data-value-func view) value-func)
472 (setf (link-slots view) (nreverse links))
475 ((or :compact-text :compact-text-labels)
476 (initialize-text-view view))
477 ((or :html :xhtml :html-labels :xhtml-labels)
478 (initialize-html-view view))
479 ((or :xml :xml-labels)
480 (initialize-xml-view view))
481 ((or :html-link :html-link-labels)
482 (initialize-html-view view)
483 (setf (link-href-start view) "a href=")
484 (setf (link-href-end view) "a")
485 (setf (link-ampersand view) "&"))
486 ((or :xhtml-link :xhtml-link-labels)
487 (initialize-html-view view)
488 (setf (link-href-start view) "a href=")
489 (setf (link-href-end view) "a")
490 (setf (link-ampersand view) "&"))
491 ((or :xml-link :xml-link-labels)
492 (initialize-xml-view view)
493 (setf (link-href-start view)
494 "xmllink xlink:type=\"simple\" xlink:href=")
495 (setf (link-href-end view) "xmllink")
496 (setf (link-ampersand view) "&"))
497 ((or :ie-xml-link :ie-xml-link-labels)
498 (initialize-xml-view view)
499 (setf (link-href-start view) "html:a href=")
500 (setf (link-href-end view) "html:a")
501 (setf (link-ampersand view) "&"))))
505 ;;;; *************************************************************************
506 ;;;; View Data Format Section
507 ;;;; *************************************************************************
509 (defun class-name-of (obj)
510 (string-downcase (class-name (class-of obj))))
512 (defvar +newline-string+ (format nil "~%"))
514 (defun initialize-text-view (view)
515 (setf (list-start-str-or-func view)
517 #'(lambda (obj nitems strm)
518 (format strm "~a~P:~%"
519 (hyperobject-class-user-name obj) nitems))))
520 (setf (list-start-indent view) t)
521 (setf (obj-data-indent view) t)
522 (setf (obj-data-end-str view) +newline-string+))
524 (defun html-list-start-func (obj nitems strm)
525 (format strm "<p><b>~a~p:</b></p><div class=\""
526 (hyperobject-class-user-name obj) nitems)
527 (write-string (class-name-of obj) strm)
528 (write-string "\"><ul>" strm)
529 (write-char #\newline strm))
531 (defun initialize-html-view (view)
532 (initialize-text-view view)
533 (setf (file-start-str view) (format nil "<html><body>~%"))
534 (setf (file-end-str view) (format nil "</body><html>~%"))
535 (setf (list-start-indent view) t)
536 (setf (list-start-str-or-func view) #'html-list-start-func)
537 (setf (list-end-str-or-func view) (format nil "</ul></div>~%"))
538 (setf (list-end-indent view) t)
539 (setf (obj-start-indent view) t)
540 (setf (obj-start-str-or-func view) "<li>")
541 (setf (obj-end-indent view) t)
542 (setf (obj-end-str-or-func view) (format nil "</li>~%"))
543 (setf (obj-data-indent view) t))
545 (defun initialize-xhtml-view (view)
546 (initialize-text-view view)
547 (setf (file-start-str view) (format nil "<html><body>~%"))
548 (setf (file-end-str view) (format nil "</body><html>~%"))
549 (setf (list-start-indent view) t)
550 (setf (list-start-str-or-func view) #'html-list-start-func)
551 (setf (list-end-str-or-func view) (format nil "</ul></div>~%"))
552 (setf (list-end-indent view) t)
553 (setf (obj-start-indent view) t)
554 (setf (obj-start-str-or-func view) "<li>")
555 (setf (obj-end-indent view) t)
556 (setf (obj-end-str-or-func view) (format nil "</li>~%"))
557 (setf (obj-data-indent view) t))
559 (defun xmlformat-list-end-func (x strm)
560 (write-string "</" strm)
561 (write-string (class-name-of x) strm)
562 (write-string "list" strm)
563 (write-string ">" strm)
564 (write-char #\newline strm))
566 (defun xmlformat-list-start-func (x nitems strm)
567 (write-char #\< strm)
568 (write-string (class-name-of x) strm)
569 (write-string "list><title>" strm)
570 (format strm "~A~P:</title> ~%"
571 (hyperobject-class-user-name x) nitems))
573 (defun initialize-xml-view (view)
574 (initialize-text-view view)
575 (setf (file-start-str view) "") ; (std-xml-header)
576 (setf (list-start-indent view) t)
577 (setf (list-start-str-or-func view) #'xmlformat-list-start-func)
578 (setf (list-end-indent view) t)
579 (setf (list-end-str-or-func view) #'xmlformat-list-end-func)
580 (setf (obj-start-str-or-func view) (format nil "<~(~a~)>" (object-class-name view)))
581 (setf (obj-start-indent view) t)
582 (setf (obj-end-str-or-func view) (format nil "</~(~a~)>~%" (object-class-name view)))
583 (setf (obj-end-indent view) nil)
584 (setf (obj-data-indent view) nil))
587 ;;; File Start and Ends
589 (defun fmt-file-start (view strm)
590 (awhen (file-start-str view)
591 (write-string it strm)))
593 (defun fmt-file-end (view strm)
594 (awhen (file-end-str view)
595 (write-string it strm)))
597 ;;; List Start and Ends
599 (defun fmt-list-start (obj view strm indent num-items)
600 (when (list-start-indent view)
601 (indent-spaces indent strm))
602 (awhen (list-start-str-or-func view)
604 (write-string it strm)
605 (funcall it obj num-items strm))))
607 (defun fmt-list-end (obj view strm indent num-items)
608 (declare (ignore num-items))
609 (when (list-end-indent view)
610 (indent-spaces indent strm))
611 (awhen (list-end-str-or-func view)
613 (write-string it strm)
614 (funcall it obj strm))))
616 ;;; Object Start and Ends
618 (defun fmt-obj-start (obj view strm indent)
619 (when (obj-start-indent view)
620 (indent-spaces indent strm))
621 (awhen (obj-start-str-or-func view)
623 (write-string it strm)
624 (funcall it obj strm))))
626 (defun fmt-obj-end (obj view strm indent)
627 (when (obj-end-indent view)
628 (indent-spaces indent strm))
629 (awhen (obj-end-str-or-func view)
631 (write-string it strm)
632 (funcall it obj strm))))
636 (defun make-link-start (view fieldfunc fieldvalue refvars)
637 (format nil "~a\"~a?func=~a~akey=~a~a\""
638 (link-href-start view)
639 (make-url (link-page-name view))
641 (link-ampersand view) fieldvalue
644 (dolist (var refvars)
646 varstr (link-ampersand view)
647 (format nil "~a=~a" (car var) (cadr var))))
651 (defun make-link-end (obj view fieldname)
652 (declare (ignore obj fieldname))
653 (link-href-end view))
655 (defun fmt-obj-data (obj view strm indent refvars)
656 (when (obj-data-indent view)
657 (indent-spaces indent strm))
658 (if (link-slots view)
659 (fmt-obj-data-with-link obj view strm refvars)
660 (fmt-obj-data-plain obj view strm))
661 (awhen (obj-data-end-str view)
662 (write-string it strm)))
664 (defun fmt-obj-data-plain (obj view strm)
665 (awhen (obj-data-func view)
666 (funcall it obj strm nil)))
668 (defun fmt-obj-data-with-link (obj view strm refvars)
669 (let ((refvalues '()))
670 ;; make list of hyperlink link fields for printing to refstr template
671 (dolist (name (link-slots view))
672 (awhen (find name (hyperobject-class-hyperlinks obj) :key #'name)
673 (push (make-link-start view (lookup it) (slot-value obj name)
674 (append (link-parameters it) refvars))
676 (push (make-link-end obj view name) refvalues)))
677 (funcall (obj-data-func view) obj strm (nreverse refvalues))))
679 (defun obj-data (obj view)
680 "Returns the objects data as a string. Used by common-graphics outline function"
681 (with-output-to-string (s) (fmt-obj-data-plain obj view s)))
683 ;;; Display method for objects
686 (defun load-all-subobjects (objs)
687 "Load all subobjects if they have not already been loaded."
688 (dolist (obj (mklist objs))
689 (dolist (subobj (hyperobject-class-subobjects obj))
690 (awhen (slot-value obj (name-slot subobj))
691 (load-all-subobjects it))))
694 (defun view-hyperobject (objs view category strm &optional (indent 0) filter
696 "Display a single or list of hyperobject-class instances and their subobjects"
697 (let-when (objlist (mklist objs))
698 (let ((nobjs (length objlist))
702 (*print-readably* nil)
705 (fmt-list-start (car objlist) view strm indent nobjs)
706 (dolist (obj objlist)
707 (unless (and filter (not (funcall filter obj)))
708 (fmt-obj-start obj view strm indent)
709 (fmt-obj-data obj view strm (1+ indent) refvars)
710 (when (and subobjects (hyperobject-class-subobjects obj))
711 (dolist (subobj (hyperobject-class-subobjects obj))
712 (aif (slot-value obj (name-slot subobj))
713 (view-hyperobject it (get-category-view (car (mklist it)) category)
714 category strm (1+ indent) filter
715 subobjects refvars))))
716 (fmt-obj-end obj view strm indent)))
717 (fmt-list-end (car objlist) view strm indent nobjs)))
721 (defun view (objs &key (stream *standard-output*) category view
722 filter subobjects refvars file-wrapper)
723 "EXPORTED Function: prints hyperobject-class objects. Simplies call to view-hyperobject"
724 (let-when (objlist (mklist objs))
726 (setq view (get-category-view (car objlist) category)))
728 (setq view (default-view (class-of (car objlist)))))
730 (fmt-file-start view stream))
731 (view-hyperobject objlist view category stream 0 filter subobjects refvars)
733 (fmt-file-end view stream)))
739 (defun fmt-comma-integer (i)
740 (format nil "~:d" i))