;;;; Programmer: Kevin M. Rosenberg
;;;; Date Started: Apr 2000
;;;;
-;;;; $Id: views.lisp,v 1.40 2003/05/14 07:00:47 kevin Exp $
+;;;; $Id: views.lisp,v 1.45 2003/05/16 07:35:09 kevin Exp $
;;;;
;;;; This file is Copyright (c) 2000-2003 by Kevin M. Rosenberg
;;;; *************************************************************************
)
)
+(defmacro write-simple (v s)
+ `(typecase ,v
+ (string
+ (write-string ,v ,s))
+ #+allegro
+ (fixnum
+ (excl::print-fixnum ,s 10 ,v))
+ (symbol
+ (write-string (symbol-name ,v) ,s))
+ (t
+ (write-string (write-to-string ,v) ,s))))
(defun write-ho-value (obj name type formatter cdata strm)
(declare (ignorable type))
(data (if cdata
(kmrcl:xml-cdata fmt-data)
fmt-data)))
- (typecase data
- (string
- (write-string data strm))
- (t
- (write-string (write-to-string data) strm)))))
+ (write-simple data strm)))
+
(defun ppfc-html (title name type formatter cdata print-func)
(vector-push-extend '(write-string "<span class=\"" s) print-func)
(ppfc-xml xml-tag name type formatter cdata print-func)))
(:html-link-labels
(if hyperlink
+ (ppfc-html-link-labels namestr-lower name type formatter cdata nlink
+ print-func)
(ppfc-html-labels namestr-lower name type formatter cdata print-func)))
(:xhtml-link-labels
(if hyperlink
(defun view-has-links-p (view)
(in (category view) :html-link :xhtml-link :xml-link :ie-xml-link
- :html-link-labels :xhtml-links-labels :xml-link-labels
+ :html-link-labels :xhtml-link-labels :xml-link-labels
:ie-xml-link-labels))
(defun initialize-view-by-category (obj-cl view)
(unless (in (category view) :compact-text :compact-text-labels
:html :html-labels :html-link-labels
:xhtml :xhtml-labels :xhtml-link-labels
+ :xhtml-link :html-link
:xml :xml-labels :xml-link :ie-xml-link
:xml-link-labels :ie-xml-link-labels)
(error "Unknown view category ~A" (category view)))
(setf (link-href-end view) "html:a")
(setf (link-ampersand view) "&"))))
-#+ignore
-(defun initialize-view-by-category (obj-cl view)
- "Initialize a view based upon a preset category"
- (let ((fmtstr nil)
- (first-field t)
- (value-func '())
- (links '())
- (category (category view)))
-
- (unless (in category :compact-text :compact-text-labels
- :html :html-labels :html-link-labels
- :xhtml :xhtml-labels :xhtml-link-labels
- :xml :xml-labels :xml-link :ie-xml-link
- :xml-link-labels :ie-xml-link-labels)
- (error "Unknown view category ~A" category))
-
- (unless (slots view)
- (setf (slots view) (default-print-slots obj-cl)))
- (dolist (slot-name (slots view))
- (let ((slot (find-slot-by-name obj-cl slot-name)))
- (unless slot
- (error "Slot ~A is not found in class ~S" slot-name obj-cl))
- (let* ((name (slot-definition-name slot))
- (namestr-lower (string-downcase (symbol-name name)))
- (xml-namestr (escape-xml-string namestr-lower))
- (xml-tag (escape-xml-string namestr-lower))
- (type (slot-value slot 'type))
- (print-formatter (esd-print-formatter slot)))
-
- (cond
- (first-field
- (setq fmtstr "")
- (setq first-field nil))
- (t
- (string-append fmtstr " ")))
-
- (let ((value-fmt
- (case type
- ((or :integer :fixnum)
- "~d")
- (:boolean
- "~a")
- (otherwise
- "~a"))))
- (case category
- (:compact-text
- (string-append fmtstr value-fmt))
- (:compact-text-labels
- (string-append fmtstr namestr-lower " " value-fmt))
- ((or :html :xhtml)
- (string-append fmtstr (concatenate 'string "<span class=\"" namestr-lower "\">" value-fmt "</span>")))
- (:xml
- (string-append fmtstr (concatenate 'string "<" namestr-lower ">" value-fmt "</" namestr-lower ">")))
- (:html-labels
- (string-append fmtstr (concatenate 'string "<span class=\"label\">" namestr-lower "</span> <span class=\"" namestr-lower "\">" value-fmt "</span>")))
- (:xhtml-labels
- (string-append fmtstr (concatenate 'string "<span class=\"label\">" xml-namestr "</span> <span class=\"" namestr-lower "\">" value-fmt "</span>")))
- (:xml-labels
- (string-append fmtstr (concatenate 'string "<label>" xml-namestr "</label> <" xml-tag ">" value-fmt "</" xml-tag ">")))
- ((or :html-link :xhtml-link)
- (push name links)
- (if (esd-hyperlink slot)
- (string-append fmtstr "<~~a>" value-fmt "</~~a>")
- (string-append fmtstr (concatenate 'string "<span class=\"" namestr-lower "\">" value-fmt "</span>"))))
- ((or :xml-link :ie-xml-link)
- (push name links)
- (if (esd-hyperlink slot)
- (string-append fmtstr "<~~a>" value-fmt "</~~a>")
- (string-append fmtstr (concatenate 'string "<" xml-tag ">" value-fmt "</" xml-tag ">"))))
- (:html-link-labels
- (push name links)
- (if (esd-hyperlink slot)
- (string-append fmtstr "<span class=\"label\">" namestr-lower "</span> <~~a>" value-fmt "</~~a>")
- (string-append fmtstr (concatenate 'string "<span class=\"label\">" namestr-lower "</span> <span class=\"" namestr-lower "\">" value-fmt "</span>"))))
- (:xhtml-link-labels
- (push name links)
- (if (esd-hyperlink slot)
- (string-append fmtstr "<span class=\"label\">" xml-namestr "</span> <~~a>" value-fmt "</~~a>")
- (string-append fmtstr (concatenate 'string "<span class=\"label\">" xml-namestr "</span> <span class=\"" namestr-lower "\">" value-fmt "</span>"))))
- ((or :xml-link-labels :ie-xml-link-labels)
- (push name links)
- (if (esd-hyperlink slot)
- (string-append fmtstr "<label>" xml-namestr "</label> <~~a>" value-fmt "</~~a>")
- (string-append fmtstr (concatenate 'string "<label>" xml-namestr "</label> <" xml-tag ">" value-fmt "</" xml-tag ">")))))
- ) ;; let value-fmt
-
- (let ((func (if print-formatter
- `(,print-formatter (slot-value x (quote ,name)))
- `(slot-value x (quote ,name)))))
- (when (and (in category :xml :xhtml :xml-link :xhtml-link
- :xml-labels :ie-xml-labels
- :xhtml-link-labels :xml-link-labels :ie-xml-link
- :ie-xml-link-labels)
- (or print-formatter
- (lisp-type-is-a-string type)))
- (setq func `(kmrcl:xml-cdata ,func)))
- (push func value-func))
- )))
-
- (when value-func
- (setq value-func
- (compile nil (eval `(lambda (x) (values ,@(nreverse value-func)))))))
-
- (setf (obj-data-fmtstr view) fmtstr)
- (setf (obj-data-value-func view) value-func)
- (setf (link-slots view) (nreverse links))
-
- (case category
- ((or :compact-text :compact-text-labels)
- (initialize-text-view view))
- ((or :html :xhtml :html-labels :xhtml-labels)
- (initialize-html-view view))
- ((or :xml :xml-labels)
- (initialize-xml-view view))
- ((or :html-link :html-link-labels)
- (initialize-html-view view)
- (setf (link-href-start view) "a href=")
- (setf (link-href-end view) "a")
- (setf (link-ampersand view) "&"))
- ((or :xhtml-link :xhtml-link-labels)
- (initialize-html-view view)
- (setf (link-href-start view) "a href=")
- (setf (link-href-end view) "a")
- (setf (link-ampersand view) "&"))
- ((or :xml-link :xml-link-labels)
- (initialize-xml-view view)
- (setf (link-href-start view)
- "xmllink xlink:type=\"simple\" xlink:href=")
- (setf (link-href-end view) "xmllink")
- (setf (link-ampersand view) "&"))
- ((or :ie-xml-link :ie-xml-link-labels)
- (initialize-xml-view view)
- (setf (link-href-start view) "html:a href=")
- (setf (link-href-end view) "html:a")
- (setf (link-ampersand view) "&"))))
- view)
-
;;;; *************************************************************************
;;;; View Data Format Section
(setf (obj-start-str-or-func view) "<li>")
(setf (obj-end-indent view) t)
(setf (obj-end-str-or-func view) (format nil "</li>~%"))
- (setf (obj-data-indent view) t))
+ (setf (obj-data-indent view) nil))
(defun initialize-xhtml-view (view)
(initialize-text-view view)
(setf (obj-start-str-or-func view) "<li>")
(setf (obj-end-indent view) t)
(setf (obj-end-str-or-func view) (format nil "</li>~%"))
- (setf (obj-data-indent view) t))
+ (setf (obj-data-indent view) nil))
(defun xmlformat-list-end-func (x strm)
(write-string "</" strm)
;;; Object Data
+
(defun make-link-start (view fieldfunc fieldvalue refvars)
(with-output-to-string (s)
(write-string (link-href-start view) s)
(write-char #\" s)
(write-string (make-url (link-page-name view)) s)
(write-string "?func=" s)
- (write-string fieldfunc s)
+ (write-simple fieldfunc s)
(write-string (link-ampersand view) s)
(write-string "key=" s)
- (write-string fieldvalue s)
+ (write-simple fieldvalue s)
(dolist (var refvars)
(write-string (link-ampersand view) s)
- (write-string (car var) s)
+ (write-simple (car var) s)
(write-char #\= s)
- (write-string (cdr var) s))
+ (write-simple (cdr var) s))
(write-char #\" s)))
(defun make-link-end (obj view fieldname)