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.39 2003/05/14 06:54:04 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")
164 (defun write-ho-value (obj name type formatter cdata strm)
165 (declare (ignorable type))
166 (let* ((slot-data (slot-value obj name))
167 (fmt-data (if formatter
168 (funcall formatter slot-data)
171 (kmrcl:xml-cdata fmt-data)
175 (write-string data strm))
177 (write-string (write-to-string data) strm))
179 (format strm "~A" data)))))
181 (defun ppfc-html (title name type formatter cdata print-func)
182 (vector-push-extend '(write-string "<span class=\"" s) print-func)
183 (vector-push-extend `(write-string ,title s) print-func)
184 (vector-push-extend '(write-string "\">" s) print-func)
185 (vector-push-extend `(write-ho-value x ',name ',type ',formatter ,cdata s) print-func)
186 (vector-push-extend '(write-string "</span>" s) print-func))
188 (defun ppfc-xml (tag name type formatter cdata print-func)
189 (vector-push-extend '(write-char #\< s) print-func)
190 (vector-push-extend `(write-string ,tag s) print-func)
191 (vector-push-extend '(write-char #\> s) print-func)
192 (vector-push-extend `(write-ho-value x ',name ',type ',formatter ,cdata s) print-func)
193 (vector-push-extend '(write-string "</" s) print-func)
194 (vector-push-extend `(write-string ,tag s) print-func)
195 (vector-push-extend '(write-char #\> s) print-func))
197 (defun ppfc-html-labels (label name type formatter cdata print-func)
198 (vector-push-extend '(write-string "<span class=\"label\">" s) print-func)
199 (vector-push-extend `(write-string ,label s) print-func)
200 (vector-push-extend '(write-string "</span> " s) print-func)
201 (ppfc-html label name type formatter cdata print-func))
203 (defun ppfc-xhtml-labels (label tag name type formatter cdata print-func)
204 (vector-push-extend '(write-string "<span class=\"label\">" s) print-func)
205 (vector-push-extend `(write-string ,label s) print-func)
206 (vector-push-extend '(write-string "</span> " s) print-func)
207 (ppfc-html tag name type formatter cdata print-func))
209 (defun ppfc-xml-labels (label tag name type formatter cdata print-func)
210 (vector-push-extend '(write-string "<label>" s) print-func)
211 (vector-push-extend `(write-string ,label s) print-func)
212 (vector-push-extend '(write-string "</label> " s) print-func)
213 (ppfc-xml tag name type formatter cdata print-func))
215 (defun ppfc-html-link (name type formatter cdata nlink print-func)
216 (declare (fixnum nlink))
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 (when (plusp (length print-func))
326 (setf (obj-data-print-code view) `(lambda (x s links)
327 (declare (ignorable links))
328 ,@(map 'list #'identity print-func)))
329 (setf (obj-data-func view)
330 (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 write-user-name-maybe-plural (obj nitems strm)
517 (hyperobject-class-user-name-plural obj)
518 (hyperobject-class-user-name obj))
521 (defun initialize-text-view (view)
522 (setf (list-start-str-or-func view)
524 (eval '(lambda (obj nitems strm)
525 (write-user-name-maybe-plural obj nitems strm)
526 (write-char #\: strm)
527 (write-char #\Newline strm)))))
528 (setf (list-start-indent view) t)
529 (setf (obj-data-indent view) t)
530 (setf (obj-data-end-str view) +newline-string+))
532 (defun html-list-start-func (obj nitems strm)
533 (write-string "<p><b>" strm)
534 (write-user-name-maybe-plural obj nitems strm)
535 (write-string ":</b></p><div class=\"" strm)
536 (write-string (class-name-of obj) strm)
537 (write-string "\"><ul>" strm)
538 (write-char #\newline strm))
540 (defun initialize-html-view (view)
541 (initialize-text-view view)
542 (setf (file-start-str view) (format nil "<html><body>~%"))
543 (setf (file-end-str view) (format nil "</body><html>~%"))
544 (setf (list-start-indent view) t)
545 (setf (list-start-str-or-func view) #'html-list-start-func)
546 (setf (list-end-str-or-func view) (format nil "</ul></div>~%"))
547 (setf (list-end-indent view) t)
548 (setf (obj-start-indent view) t)
549 (setf (obj-start-str-or-func view) "<li>")
550 (setf (obj-end-indent view) t)
551 (setf (obj-end-str-or-func view) (format nil "</li>~%"))
552 (setf (obj-data-indent view) t))
554 (defun initialize-xhtml-view (view)
555 (initialize-text-view view)
556 (setf (file-start-str view) (format nil "<html><body>~%"))
557 (setf (file-end-str view) (format nil "</body><html>~%"))
558 (setf (list-start-indent view) t)
559 (setf (list-start-str-or-func view) #'html-list-start-func)
560 (setf (list-end-str-or-func view) (format nil "</ul></div>~%"))
561 (setf (list-end-indent view) t)
562 (setf (obj-start-indent view) t)
563 (setf (obj-start-str-or-func view) "<li>")
564 (setf (obj-end-indent view) t)
565 (setf (obj-end-str-or-func view) (format nil "</li>~%"))
566 (setf (obj-data-indent view) t))
568 (defun xmlformat-list-end-func (x strm)
569 (write-string "</" strm)
570 (write-string (class-name-of x) strm)
571 (write-string "list" strm)
572 (write-string ">" strm)
573 (write-char #\newline strm))
575 (defun xmlformat-list-start-func (x nitems strm)
576 (write-char #\< strm)
577 (write-string (class-name-of x) strm)
578 (write-string "list><title>" strm)
579 (write-user-name-maybe-plural x nitems strm)
580 (write-string ":</title>" strm)
581 (write-char #\newline strm))
583 (defun initialize-xml-view (view)
584 (initialize-text-view view)
585 (setf (file-start-str view) "") ; (std-xml-header)
586 (setf (list-start-indent view) t)
587 (setf (list-start-str-or-func view) #'xmlformat-list-start-func)
588 (setf (list-end-indent view) t)
589 (setf (list-end-str-or-func view) #'xmlformat-list-end-func)
590 (setf (obj-start-str-or-func view) (format nil "<~(~a~)>" (object-class-name view)))
591 (setf (obj-start-indent view) t)
592 (setf (obj-end-str-or-func view) (format nil "</~(~a~)>~%" (object-class-name view)))
593 (setf (obj-end-indent view) nil)
594 (setf (obj-data-indent view) nil))
597 ;;; File Start and Ends
599 (defun fmt-file-start (view strm)
600 (awhen (file-start-str view)
601 (write-string it strm)))
603 (defun fmt-file-end (view strm)
604 (awhen (file-end-str view)
605 (write-string it strm)))
607 ;;; List Start and Ends
609 (defun fmt-list-start (obj view strm indent num-items)
610 (when (list-start-indent view)
611 (indent-spaces indent strm))
612 (awhen (list-start-str-or-func view)
614 (write-string it strm)
615 (funcall it obj num-items strm))))
617 (defun fmt-list-end (obj view strm indent num-items)
618 (declare (ignore num-items))
619 (when (list-end-indent view)
620 (indent-spaces indent strm))
621 (awhen (list-end-str-or-func view)
623 (write-string it strm)
624 (funcall it obj strm))))
626 ;;; Object Start and Ends
628 (defun fmt-obj-start (obj view strm indent)
629 (when (obj-start-indent view)
630 (indent-spaces indent strm))
631 (awhen (obj-start-str-or-func view)
633 (write-string it strm)
634 (funcall it obj strm))))
636 (defun fmt-obj-end (obj view strm indent)
637 (when (obj-end-indent view)
638 (indent-spaces indent strm))
639 (awhen (obj-end-str-or-func view)
641 (write-string it strm)
642 (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-string fieldfunc s)
653 (write-string (link-ampersand view) s)
654 (write-string "key=" s)
655 (write-string fieldvalue s)
656 (dolist (var refvars)
657 (write-string (link-ampersand view) s)
658 (write-string (car var) s)
660 (write-string (cdr var) s))
664 (defun make-link-start-old (view fieldfunc fieldvalue refvars)
665 (format nil "~a\"~a?func=~a~akey=~a~a\""
666 (link-href-start view)
667 (make-url (link-page-name view))
669 (link-ampersand view) fieldvalue
672 (dolist (var refvars)
674 varstr (link-ampersand view)
675 (format nil "~a=~a" (car var) (cdr var))))
679 (defun make-link-end (obj view fieldname)
680 (declare (ignore obj fieldname))
681 (link-href-end view))
683 (defun fmt-obj-data (obj view strm indent refvars)
684 (when (obj-data-indent view)
685 (indent-spaces indent strm))
686 (if (link-slots view)
687 (fmt-obj-data-with-link obj view strm refvars)
688 (fmt-obj-data-plain obj view strm))
689 (awhen (obj-data-end-str view)
690 (write-string it strm)))
692 (defun fmt-obj-data-plain (obj view strm)
693 (awhen (obj-data-func view)
694 (funcall it obj strm nil)))
696 (defun fmt-obj-data-with-link (obj view strm refvars)
697 (let ((refvalues '()))
698 ;; make list of hyperlink link fields for printing to refstr template
699 (dolist (name (link-slots view))
700 (awhen (find name (hyperobject-class-hyperlinks obj) :key #'name)
701 (push (make-link-start view (lookup it) (slot-value obj name)
702 (append (link-parameters it) refvars))
704 (push (make-link-end obj view name) refvalues)))
705 (funcall (obj-data-func view) obj strm (nreverse refvalues))))
707 (defun obj-data (obj view)
708 "Returns the objects data as a string. Used by common-graphics outline function"
709 (with-output-to-string (s) (fmt-obj-data-plain obj view s)))
711 ;;; Display method for objects
714 (defun load-all-subobjects (objs)
715 "Load all subobjects if they have not already been loaded."
716 (dolist (obj (mklist objs))
717 (dolist (subobj (hyperobject-class-subobjects obj))
718 (awhen (slot-value obj (name-slot subobj))
719 (load-all-subobjects it))))
722 (defun view-hyperobject (objs view category strm &optional (indent 0) filter
724 "Display a single or list of hyperobject-class instances and their subobjects"
725 (declare (fixnum indent))
726 (let-when (objlist (mklist objs))
727 (let ((nobjs (length objlist))
731 (*print-readably* nil)
734 (fmt-list-start (car objlist) view strm indent nobjs)
735 (dolist (obj objlist)
736 (unless (and filter (not (funcall filter obj)))
737 (fmt-obj-start obj view strm indent)
738 (fmt-obj-data obj view strm (1+ indent) refvars)
739 (when (and subobjects (hyperobject-class-subobjects obj))
740 (dolist (subobj (hyperobject-class-subobjects obj))
741 (aif (slot-value obj (name-slot subobj))
742 (view-hyperobject it (get-category-view (car (mklist it)) category)
743 category strm (1+ indent) filter
744 subobjects refvars))))
745 (fmt-obj-end obj view strm indent)))
746 (fmt-list-end (car objlist) view strm indent nobjs)))
750 (defun view (objs &key (stream *standard-output*) category view
751 filter subobjects refvars file-wrapper)
752 "EXPORTED Function: prints hyperobject-class objects. Simplies call to view-hyperobject"
753 (let-when (objlist (mklist objs))
755 (setq view (get-category-view (car objlist) category)))
757 (setq view (default-view (class-of (car objlist)))))
759 (fmt-file-start view stream))
760 (view-hyperobject objlist view category stream 0 filter subobjects refvars)
762 (fmt-file-end view stream)))
768 (defun fmt-comma-integer (i)
769 (format nil "~:d" i))