r3518: *** empty log message ***
[hyperobject.git] / views.lisp
1 ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
4 ;;;;
5 ;;;; Name:          views.lisp
6 ;;;; Purpose:       View methods for Hyperobjects
7 ;;;; Programmer:    Kevin M. Rosenberg
8 ;;;; Date Started:  Apr 2000
9 ;;;;
10 ;;;; $Id: views.lisp,v 1.3 2002/11/29 05:05:29 kevin Exp $
11 ;;;;
12 ;;;; This file is Copyright (c) 2000-2002 by Kevin M. Rosenberg
13 ;;;;
14 ;;;; *************************************************************************
15  
16 (in-package :hyperobject)
17
18 (eval-when (:compile-toplevel :execute)
19   (declaim (optimize (speed 3) (safety 1) (compilation-speed 0) (debug 3))))
20
21
22 ;;;; *************************************************************************
23 ;;;;  Metaclass Intialization
24 ;;;; *************************************************************************
25
26 (defun process-views (cl)
27   "Calculate all view slots for a hyperobject class"
28   (let ((fmtstr-text "")
29         (fmtstr-html "")
30         (fmtstr-xml "")
31         (fmtstr-text-labels "")
32         (fmtstr-html-labels "")
33         (fmtstr-xml-labels "")
34         (fmtstr-html-ref "")
35         (fmtstr-xml-ref "")
36         (fmtstr-html-ref-labels "")
37         (fmtstr-xml-ref-labels "")
38         (first-field t)
39         (value-func '())
40         (xmlvalue-func '())
41         (classname (class-name cl))
42         (package (symbol-package (class-name cl)))
43         (references nil))
44     (declare (ignore classname))
45     (check-type (slot-value cl 'print-slots) list)
46     (dolist (slot-name (slot-value cl 'print-slots))
47       (let ((slot (find-slot-by-name cl slot-name)))
48         (unless slot
49           (error "Slot ~A is not found in class ~S" slot-name cl))
50         (let ((name (slot-definition-name slot))
51               (namestr (symbol-name (slot-definition-name slot)))
52               (namestr-lower (string-downcase (symbol-name (slot-definition-name slot))))
53               (type (slot-value slot 'ho-type))
54               (print-formatter (slot-value slot 'print-formatter))
55               (value-fmt "~a")
56               (plain-value-func nil)
57               html-str xml-str html-label-str xml-label-str)
58           
59           (when (or (eql type :integer) (eql type :fixnum))
60             (setq value-fmt "~d"))
61           
62           (when (eql type :boolean)
63             (setq value-fmt "~a"))
64           
65           (if first-field
66               (setq first-field nil)
67               (progn
68                 (string-append fmtstr-text " ")
69                 (string-append fmtstr-html " ")
70                 (string-append fmtstr-xml " ")
71                 (string-append fmtstr-text-labels " ")
72                 (string-append fmtstr-html-labels " ")
73                 (string-append fmtstr-xml-labels " ")
74                 (string-append fmtstr-html-ref " ")
75                 (string-append fmtstr-xml-ref " ")
76                 (string-append fmtstr-html-ref-labels " ")
77                 (string-append fmtstr-xml-ref-labels " ")))
78           
79           (setq html-str (concatenate 'string "<span class=\"" namestr-lower "\">" value-fmt "</span>"))
80           (setq xml-str (concatenate 'string "<" namestr-lower ">" value-fmt "</" namestr-lower ">"))
81           (setq html-label-str (concatenate 'string "<span class=\"label\">" namestr-lower "</span> <span class=\"" namestr-lower "\">" value-fmt "</span>"))
82           (setq xml-label-str (concatenate 'string "<label>" namestr-lower "</label> <" namestr-lower ">" value-fmt "</" namestr-lower ">"))
83           
84           (string-append fmtstr-text value-fmt)
85           (string-append fmtstr-html html-str)
86           (string-append fmtstr-xml xml-str)
87           (string-append fmtstr-text-labels namestr-lower " " value-fmt)
88           (string-append fmtstr-html-labels html-label-str)
89           (string-append fmtstr-xml-labels xml-label-str)
90           
91           (if (slot-value slot 'reference)
92               (progn
93                 (string-append fmtstr-html-ref "<~~a>" value-fmt "</~~a>")
94                 (string-append fmtstr-xml-ref "<~~a>" value-fmt "</~~a>")
95                 (string-append fmtstr-html-ref-labels "<span class=\"label\">" namestr-lower "</span> <~~a>" value-fmt "</~~a>")
96                 (string-append fmtstr-xml-ref-labels "<label>" namestr-lower "</label> <~~a>" value-fmt "</~~a>")
97                 (push (make-instance 'reference :name name
98                                      :lookup (slot-value slot 'reference))
99                       references))
100               (progn
101                 (string-append fmtstr-html-ref html-str)
102                 (string-append fmtstr-xml-ref xml-str)
103                 (string-append fmtstr-html-ref-labels html-label-str)
104                 (string-append fmtstr-xml-ref-labels xml-label-str)))
105           
106           (if print-formatter
107               (setq plain-value-func 
108                     (list `(,print-formatter (slot-value x ',(intern namestr package)))))
109               (setq plain-value-func 
110                     (list `(slot-value x ',(intern namestr package)))))
111           (setq value-func (append value-func plain-value-func))
112           
113           (if (eql type :cdata)
114               (setq xmlvalue-func (append xmlvalue-func (list `(xml-cdata ,@plain-value-func))))
115               (setq xmlvalue-func (append xmlvalue-func plain-value-func)))
116           )))
117     
118     (setf (slot-value cl 'references) references)
119     
120     (if value-func
121         (setq value-func `(lambda (x) (values ,@value-func)))
122         (setq value-func `(lambda () (values))))
123     (setq value-func (compile nil (eval value-func)))
124     
125     (if xmlvalue-func
126         (setq xmlvalue-func `(lambda (x) (values ,@xmlvalue-func)))
127         (setq xmlvalue-func `(lambda () (values))))
128     (setq xmlvalue-func (compile nil (eval xmlvalue-func)))
129     
130     (setf (slot-value cl 'fmtstr-text) fmtstr-text)
131     (setf (slot-value cl 'fmtstr-html) fmtstr-html)
132     (setf (slot-value cl 'fmtstr-xml) fmtstr-xml)
133     (setf (slot-value cl 'fmtstr-text-labels) fmtstr-text-labels)
134     (setf (slot-value cl 'fmtstr-html-labels) fmtstr-html-labels)
135     (setf (slot-value cl 'fmtstr-xml-labels) fmtstr-xml-labels)
136     (setf (slot-value cl 'fmtstr-html-ref) fmtstr-html-ref)
137     (setf (slot-value cl 'fmtstr-xml-ref) fmtstr-xml-ref)
138     (setf (slot-value cl 'fmtstr-html-ref-labels) fmtstr-html-ref-labels)
139     (setf (slot-value cl 'fmtstr-xml-ref-labels) fmtstr-xml-ref-labels)
140     (setf (slot-value cl 'value-func) value-func)
141     (setf (slot-value cl 'xmlvalue-func) xmlvalue-func))
142   (values))
143
144
145 ;;;; *************************************************************************
146 ;;;;  View Data Format Section
147 ;;;; *************************************************************************
148
149 (defparameter *default-textformat* nil)
150 (defparameter *default-htmlformat* nil)
151 (defparameter *default-htmlrefformat* nil)
152 (defparameter *default-xhtmlformat* nil)
153 (defparameter *default-xhtmlrefformat* nil)
154 (defparameter *default-xmlformat* nil)
155 (defparameter *default-xmlrefformat* nil)
156 (defparameter *default-ie-xmlrefformat* nil)
157 (defparameter *default-nullformat* nil)
158 (defparameter *default-init-format?* nil)
159
160 (defun make-format-instance (fmt)
161   (unless *default-init-format?*
162     (setq *default-textformat* (make-instance 'textformat))
163     (setq *default-htmlformat* (make-instance 'htmlformat))
164     (setq *default-htmlrefformat* (make-instance 'htmlrefformat))
165     (setq *default-xhtmlformat* (make-instance 'xhtmlformat))
166     (setq *default-xhtmlrefformat* (make-instance 'xhtmlrefformat))
167     (setq *default-xmlformat* (make-instance 'xmlformat))
168     (setq *default-xmlrefformat* (make-instance 'xmlrefformat))
169     (setq *default-ie-xmlrefformat* (make-instance 'ie-xmlrefformat))
170     (setq *default-nullformat* (make-instance 'nullformat))
171     (setq *default-init-format?* t))
172   
173   (case fmt
174       (:text *default-textformat*)
175       (:html *default-htmlformat*)
176       (:htmlref *default-htmlrefformat*)
177       (:xhtml  *default-xhtmlformat*)
178       (:xhtmlref *default-xhtmlrefformat*)
179       (:xml  *default-xmlformat*)
180       (:xmlref *default-xmlrefformat*)
181       (:ie-xmlref *default-ie-xmlrefformat*)
182       (:null *default-nullformat*)
183       (otherwise *default-textformat*)))
184     
185 ;;;; Output format classes for print hyperobject-classes
186
187 (defclass dataformat ()
188   ((file-start-str :type string :initarg :file-start-str :reader file-start-str)
189    (file-end-str :type string :initarg :file-end-str :reader file-end-str)
190    (list-start-fmtstr :type string :initarg :list-start-fmtstr :reader list-start-fmtstr)
191    (list-start-value-func :type function :initarg :list-start-value-func :reader list-start-value-func)
192    (list-start-indent :initarg :list-start-indent :reader list-start-indent)
193    (list-end-fmtstr :type string :initarg :list-end-fmtstr :reader list-end-fmtstr)
194    (list-end-value-func :type function :initarg :list-end-value-func :reader list-end-value-func)
195    (list-end-indent :initarg :list-end-indent :reader list-end-indent)
196    (obj-start-fmtstr :type string :initarg :obj-start-fmtstr :reader obj-start-fmtstr)
197    (obj-start-value-func :initarg :obj-start-value-func :reader obj-start-value-func)
198    (obj-start-indent :initarg :obj-start-indent :reader obj-start-indent)
199    (obj-end-fmtstr :type string :initarg :obj-end-fmtstr :reader obj-end-fmtstr)
200    (obj-end-value-func :initarg :obj-end-value-func :reader obj-end-value-func)
201    (obj-end-indent :initarg :obj-end-indent :reader obj-end-indent)
202    (obj-data-indent :initarg :obj-data-indent :reader obj-data-indent)
203    (obj-data-fmtstr :initarg :obj-data-fmtstr :reader  obj-data-fmtstr)
204    (obj-data-fmtstr-labels :initarg :obj-data-fmtstr-labels :reader  obj-data-fmtstr-labels)
205    (obj-data-end-fmtstr :initarg :obj-data-end-fmtstr :reader obj-data-end-fmtstr)
206    (obj-data-value-func :initarg :obj-data-value-func :reader obj-data-value-func)
207    (link-ref :initarg :link-ref :reader link-ref))
208   (:default-initargs :file-start-str nil :file-end-str nil :list-start-fmtstr nil :list-start-value-func nil
209                      :list-start-indent nil :list-end-fmtstr nil :list-end-value-func nil :list-end-indent nil
210                      :obj-start-fmtstr nil :obj-start-value-func nil :obj-start-indent nil
211                      :obj-end-fmtstr nil :obj-end-value-func nil :obj-end-indent nil
212                      :obj-data-indent nil :obj-data-fmtstr nil :obj-data-fmtstr-labels nil :obj-data-end-fmtstr nil
213                      :obj-data-value-func nil :link-ref nil)
214   (:documentation "Parent for all dataformat objects"))
215
216 (defclass binaryformat (dataformat)
217   ())
218
219 (defclass nullformat (dataformat)
220   ())
221
222 (defun text-list-start-value-func (obj nitems)
223   (values (hyperobject-class-title obj) nitems))
224
225 (defclass textformat (dataformat) 
226   ()    
227   (:default-initargs :list-start-fmtstr "~a~P:~%"
228     :list-start-value-func #'text-list-start-value-func
229     :list-start-indent t
230     :obj-data-indent t
231     :obj-data-fmtstr #'hyperobject-class-fmtstr-text
232     :obj-data-fmtstr-labels #'hyperobject-class-fmtstr-text-labels
233     :obj-data-end-fmtstr "~%"
234     :obj-data-value-func #'hyperobject-class-value-func))
235
236
237 (defun class-name-of (obj)
238   (string-downcase (class-name (class-of obj))))
239
240 (defun htmlformat-list-start-value-func (x nitems) 
241   (values (hyperobject-class-title x) nitems (class-name-of x)))
242
243 (defclass htmlformat (textformat) 
244   ()
245   (:default-initargs :file-start-str "<html><body>~%"
246     :file-end-str "</body><html>~%"
247     :list-start-indent t
248     :list-start-fmtstr "<p><b>~a~p:</b></p><div class=\"~A\"><ul>~%"
249     :list-start-value-func #'htmlformat-list-start-value-func
250     :list-end-fmtstr "</ul></div>~%"
251     :list-end-indent t
252     :list-end-value-func #'identity
253     :obj-start-indent t
254     :obj-start-fmtstr "<li>"
255     :obj-start-value-func #'identity
256     :obj-end-indent  t
257     :obj-end-fmtstr  "</li>~%"
258     :obj-end-value-func #'identity
259     :obj-data-indent t
260     :obj-data-fmtstr #'hyperobject-class-fmtstr-html-labels
261     :obj-data-fmtstr-labels #'hyperobject-class-fmtstr-html-labels
262     :obj-data-value-func #'hyperobject-class-value-func))
263
264 (defclass xhtmlformat (textformat) 
265   ()
266   (:default-initargs :file-start-str "<html><body>~%"
267     :file-end-str "</body><html>~%"
268     :list-start-indent t
269     :list-start-fmtstr "<p><b>~a~p:</b></p><div class=\"~A\"><ul>~%"
270     :list-start-value-func #'htmlformat-list-start-value-func
271     :list-end-fmtstr "</ul></div>~%"
272     :list-end-indent t
273     :list-end-value-func #'identity
274     :obj-start-indent t
275     :obj-start-fmtstr "<li>"
276     :obj-start-value-func #'identity
277     :obj-end-indent  t
278     :obj-end-fmtstr  "</li>~%"
279     :obj-end-value-func #'identity
280     :obj-data-indent t
281     :obj-data-fmtstr #'hyperobject-class-fmtstr-html-labels
282     :obj-data-fmtstr-labels #'hyperobject-class-fmtstr-html-labels
283     :obj-data-value-func #'hyperobject-class-xmlvalue-func))
284
285
286 (defun xmlformat-list-end-value-func (x)
287   (format nil "~alist" (class-name-of x)))
288
289 (defun xmlformat-list-start-value-func (x nitems) 
290   (values (format nil "~alist" (class-name-of x)) (hyperobject-class-title x) nitems))
291
292 (defclass xmlformat (textformat) 
293   ()
294   (:default-initargs :file-start-str "" ; (std-xml-header)
295     :list-start-indent  t
296     :list-start-fmtstr "<~a><title>~a~p:</title> ~%"
297     :list-start-value-func #'xmlformat-list-start-value-func
298     :list-end-indent  t
299     :list-end-fmtstr "</~a>~%"
300     :list-end-value-func #'xmlformat-list-end-value-func
301     :obj-start-fmtstr "<~a>"
302     :obj-start-value-func #'class-name-of
303     :obj-start-indent t
304     :obj-end-fmtstr "</~a>~%"
305     :obj-end-value-func #'class-name-of
306     :obj-end-indent nil
307     :obj-data-indent nil
308     :obj-data-fmtstr #'hyperobject-class-fmtstr-xml
309     :obj-data-fmtstr-labels #'hyperobject-class-fmtstr-xml-labels
310     :obj-data-value-func #'hyperobject-class-xmlvalue-func))
311
312 (defclass link-ref ()
313   ((fmtstr :type function :initarg :fmtstr :accessor fmtstr)
314    (fmtstr-labels :type function :initarg :fmtstr-labels :accessor fmtstr-labels)
315    (page-name :type string :initarg :page-name :accessor page-name)
316    (href-head :type string :initarg :href-head :accessor href-head)
317    (href-end :type string :initarg :href-end :accessor href-end)
318    (ampersand :type string :initarg :ampersand :accessor ampersand))
319   (:default-initargs :fmtstr nil 
320     :fmtstr-labels nil 
321     :page-name "disp-func1" 
322     :href-head nil :href-end nil :ampersand nil)
323   (:documentation "Formatting for a linked reference"))
324
325 (defclass html-link-ref (link-ref)
326   ()
327   (:default-initargs :fmtstr #'hyperobject-class-fmtstr-html-ref  
328     :fmtstr-labels #'hyperobject-class-fmtstr-html-ref-labels
329     :href-head "a href=" 
330     :href-end "a" 
331     :ampersand "&"))
332
333 (defclass xhtml-link-ref (link-ref)
334   ()
335   (:default-initargs :fmtstr #'hyperobject-class-fmtstr-html-ref  
336     :fmtstr-labels #'hyperobject-class-fmtstr-html-ref-labels
337     :href-head "a href=" 
338     :href-end "a" 
339     :ampersand "&amp;"))
340
341 (defclass xml-link-ref (link-ref)
342   ()
343   (:default-initargs :fmtstr #'hyperobject-class-fmtstr-xml-ref 
344                      :fmtstr-labels #'hyperobject-class-fmtstr-xml-ref-labels
345                      :href-head "xmllink xlink:type=\"simple\" xlink:href=" 
346                      :href-end "xmllink" 
347                      :ampersand "&amp;")
348   (:documentation "Mozilla's and W3's idea of a link with XML"))
349
350 (defclass ie-xml-link-ref (xml-link-ref)
351   ()
352   (:default-initargs :href-head "html:a href=" 
353                      :href-end "html:a" )
354   (:documentation "Internet Explorer's idea of a link with XML"))
355
356
357 (defclass htmlrefformat (htmlformat)
358   ()
359   (:default-initargs :link-ref (make-instance 'html-link-ref)))
360
361 (defclass xhtmlrefformat (xhtmlformat)
362   ()
363   (:default-initargs :link-ref (make-instance 'xhtml-link-ref)))
364
365 (defclass xmlrefformat (xmlformat)
366   ()
367   (:default-initargs :link-ref (make-instance 'xml-link-ref)))
368
369 (defclass ie-xmlrefformat (xmlformat)
370   ()
371   (:default-initargs :link-ref (make-instance 'ie-xml-link-ref)))
372
373
374 ;;; File Start and Ends
375
376 (defgeneric fmt-file-start (fmt s))
377 (defmethod fmt-file-start ((fmt dataformat) (s stream)))
378
379 (defmethod fmt-file-start ((fmt textformat) (s stream))
380   (aif (file-start-str fmt)
381       (format s it)))
382
383 (defgeneric fmt-file-end (fmt s))
384 (defmethod fmt-file-end ((fmt textformat) (s stream))
385   (aif (file-end-str fmt)
386           (format s it)))
387
388 ;;; List Start and Ends
389
390 (defgeneric fmt-list-start (obj fmt s &optional indent num-items))
391 (defmethod fmt-list-start (x (fmt textformat) (s stream) &optional (indent 0) (num-items 1))
392   (if (list-start-indent fmt)
393       (indent-spaces indent s))
394   (aif (list-start-fmtstr fmt)
395           (apply #'format s it
396                  (multiple-value-list
397                   (funcall (list-start-value-func fmt) x num-items)))))
398
399 (defgeneric fmt-list-end (obj fmt s &optional indent num-items))
400 (defmethod fmt-list-end (x (fmt textformat) (s stream) &optional (indent 0) (num-items 1))
401   (declare (ignore num-items))
402   (if (list-end-indent fmt)
403       (indent-spaces indent s))
404   (aif (list-end-fmtstr fmt)
405           (apply #'format s it
406                  (multiple-value-list
407                   (funcall (list-end-value-func fmt) x)))))
408
409 ;;; Object Start and Ends
410
411 (defgeneric fmt-obj-start (obj fmt s &optional indent))
412 (defmethod fmt-obj-start (x (fmt textformat) (s stream) &optional (indent 0))
413   (if (obj-start-indent fmt)
414       (indent-spaces indent s))
415   (aif (obj-start-fmtstr fmt)
416           (apply #'format s it
417                  (multiple-value-list
418                   (funcall (obj-start-value-func fmt) x)))))
419
420 (defgeneric fmt-obj-end (obj fmt s &optional indent))
421 (defmethod fmt-obj-end (x (fmt textformat) (s stream) &optional (indent 0))
422   (if (obj-end-indent fmt)
423       (indent-spaces indent s))
424   (aif (obj-end-fmtstr fmt)
425           (apply #'format s it
426                  (multiple-value-list
427                   (funcall (obj-end-value-func fmt) x)))))
428   
429 ;;; Object Data 
430
431 (defgeneric make-link-start (obj ref fieldname fieldfunc fieldvalue refvars))
432 (defmethod make-link-start (obj (ref link-ref) fieldname fieldfunc fieldvalue refvars)
433   (declare (ignore obj fieldname))
434   (format nil "~a\"~a?func=~a~akey=~a~a\"" 
435           (href-head ref) (make-url (page-name ref)) fieldfunc 
436           (ampersand ref) fieldvalue
437           (if refvars
438               (let ((varstr ""))
439                 (dolist (var refvars)
440                   (string-append varstr (format nil "~a~a=~a" 
441                                                 (ampersand ref) (car var) (cadr var))))
442                 varstr)
443             "")))
444
445 (defgeneric make-link-end (obj ref fieldname)) 
446 (defmethod make-link-end (obj (ref link-ref) fieldname)
447   (declare (ignore obj fieldname))
448   (format nil "~a" (href-end ref))
449   )
450
451 (defgeneric fmt-obj-data (obj fmt s &optional indent label refvars))
452 (defmethod fmt-obj-data (x (fmt textformat) s
453                          &optional (indent 0) (label nil) (refvars nil))
454   (if (obj-data-indent fmt)
455       (indent-spaces indent s))
456   (if (link-ref fmt)
457       (fmt-obj-data-with-ref x fmt s label refvars)
458     (fmt-obj-data-plain x fmt s label))
459   (aif (obj-data-end-fmtstr fmt)
460        (format s it)))
461
462 (defgeneric fmt-obj-data-plain (obj fmt s label))
463 (defmethod fmt-obj-data-plain (x (fmt textformat) s label)
464   (if label
465       (apply #'format s
466              (funcall (obj-data-fmtstr-labels fmt) x)
467              (multiple-value-list 
468               (funcall (funcall (obj-data-value-func fmt) x) x)))
469     (apply #'format s (funcall (obj-data-fmtstr fmt) x)
470            (multiple-value-list
471             (funcall (funcall (obj-data-value-func fmt) x) x)))))
472
473 (defgeneric fmt-obj-data-with-ref (obj fmt s label refvars))
474 (defmethod fmt-obj-data-with-ref (x (fmt textformat) s label refvars)
475   (let ((refstr (make-ref-data-str x fmt label))
476         (refvalues nil)
477         (field-values 
478          (multiple-value-list
479           (funcall (funcall (obj-data-value-func fmt) x) x))))
480     
481     ;; make list of reference link fields for printing to refstr template
482     (dolist (ref (hyperobject-class-references x))
483       (let ((link-start 
484              (make-link-start x (link-ref fmt) (name ref) (lookup ref)
485                               (nth (position (name ref)
486                                              (hyperobject-class-fields x)
487                                              :key #'(lambda (x)
488                                                       (slot-definition-name x)))
489                                    field-values)  
490                               (append (link-parameters ref) refvars)))
491             (link-end (make-link-end x (link-ref fmt) (name ref))))
492         (push link-start refvalues)
493         (push link-end refvalues)))
494     (setq refvalues (nreverse refvalues))
495     
496     (apply #'format s refstr refvalues)))
497
498 (defgeneric obj-data (obj))
499 (defmethod obj-data (x)
500   "Returns the objects data as a string. Used by common-graphics outline function"
501   (let ((fmt (make-format-instance :text)))
502     (apply #'format nil (funcall (obj-data-fmtstr fmt) x)
503            (multiple-value-list 
504             (funcall (funcall (obj-data-value-func fmt) x) x)))))
505
506 (defgeneric make-ref-data-str (obj fmt &optional label))
507 (defmethod make-ref-data-str (x (fmt textformat) &optional (label nil))
508   "Return fmt string for that contains ~a slots for reference link start and end"
509   (unless (link-ref fmt)
510     (error "fmt does not contain a link-ref"))
511   (let ((refstr 
512          (if label
513              (apply #'format nil (funcall (fmtstr-labels (link-ref fmt)) x)
514                     (multiple-value-list
515                       (funcall (funcall (obj-data-value-func fmt) x) x)))
516            (apply #'format nil (funcall (fmtstr (link-ref fmt)) x)
517                   (multiple-value-list (funcall (funcall (obj-data-value-func fmt) x) x))))))
518     refstr))
519   
520 ;;; Display method for objects
521
522
523 (defgeneric load-all-subobjects (objs))
524 (defmethod load-all-subobjects (objs)
525   "Load all subobjects if they have not already been loaded."
526   (when objs
527     (let ((objlist (mklist objs)))
528       (dolist (obj objlist)
529         (awhen (hyperobject-class-subobjects obj)  ;; access list of functions
530           (dolist (child-obj it)   ;; for each child function
531             (awhen (funcall (reader child-obj) obj)
532               (load-all-subobjects it))))))
533     objs))
534
535 (defgeneric view-hyperobject (objs fmt strm
536                                   &optional label english-only-function
537                                   indent subobjects refvars))
538
539 (defmethod view-hyperobject (objs (fmt dataformat) (strm stream) 
540                                  &optional (label nil) (indent 0)
541                                  (english-only-function nil)
542                                  (subobjects nil) (refvars nil))
543 "Display a single or list of hyperobject-class instances and their subobjects"
544   (when objs
545     (setq objs (mklist objs))
546     (let ((nobjs (length objs)))
547       (fmt-list-start (car objs) fmt strm indent nobjs)
548       (dolist (obj objs)
549         (unless (and english-only-function
550                   (multiple-value-bind (eng term) (funcall english-only-function obj)
551                     (and term (not eng))))
552           (fmt-obj-start obj fmt strm indent)
553           (fmt-obj-data obj fmt strm (1+ indent) label refvars)
554           (if subobjects
555               (awhen (hyperobject-class-subobjects obj)  ;; access list of functions
556                         (dolist (child-obj it)   ;; for each child function
557                           (awhen (funcall (reader child-obj) obj) ;; access set of child objects
558                                     (view-hyperobject it fmt strm label 
559                                                      (1+ indent) english-only-function
560                                                      subobjects refvars)))))
561           (fmt-obj-end obj fmt strm indent)))
562       (fmt-list-end (car objs) fmt strm indent nobjs))
563     t))
564
565
566 (defun view (objs &key (os *standard-output*) (format :text)
567                       (label nil) (english-only-function nil)
568                       (subobjects nil) (file-wrapper t) (refvars nil))
569   "EXPORTED Function: prints hyperobject-class objects. Simplies call to view-hyperobject"
570   (let ((fmt (make-format-instance format)))
571     (if file-wrapper
572         (fmt-file-start fmt os))
573     (when objs
574       (view-hyperobject objs fmt os label 0 english-only-function subobjects refvars))
575     (if file-wrapper
576         (fmt-file-end fmt os)))
577   objs)
578