r4917: Auto commit for Debian build
[hyperobject.git] / views.lisp
index f8b2649a76794daf026b73251610ca22ec8540c8..1f01b7f5c8e3849abe86a4473a5f463c801cae3f 100644 (file)
@@ -7,7 +7,7 @@
 ;;;; Programmer:    Kevin M. Rosenberg
 ;;;; Date Started:  Apr 2000
 ;;;;
-;;;; $Id: views.lisp,v 1.17 2002/12/24 06:30:29 kevin Exp $
+;;;; $Id: views.lisp,v 1.31 2003/05/13 15:56:50 kevin Exp $
 ;;;;
 ;;;; This file is Copyright (c) 2000-2002 by Kevin M. Rosenberg
 ;;;;
 
 
 (defclass object-view ()
-  ((object-class :initform nil :initarg :object-class :accessor object-class
-                :documentation "Name of class for object to be viewed.")
+  ((object-class-name :initform nil :initarg :object-class-name
+                     :accessor object-class-name
+                :documentation "Name of class of object to be viewed.")
+   (object-class :initform nil :initarg :object-class
+                :accessor object-class
+                :documentation "Class of object to be viewed.")
    (slots :initform nil :initarg :slots :accessor slots
          :documentation "List of effective slots for object to be viewed.")
    (name :initform nil :initarg :name :accessor name
    (country-language :initform :en :initarg :country-language
                     :documentation "Country's Language for this view.")
    ;;
-   (file-start-str :type string :initform nil :initarg :file-start-str
+   (file-start-str :type (or string null) :initform nil :initarg :file-start-str
                   :accessor file-start-str)
-   (file-end-str :type string :initform nil :initarg :file-end-str
+   (file-end-str :type (or string null) :initform nil :initarg :file-end-str
                 :accessor file-end-str)
-   (list-start-fmtstr :type string :initform nil :initarg :list-start-fmtstr
+   (list-start-fmtstr :type (or string null) :initform nil :initarg :list-start-fmtstr
                      :accessor list-start-fmtstr)
-   (list-start-value-func :type function :initform nil
+   (list-start-value-func :type (or function symbol null) :initform nil
                          :initarg :list-start-value-func
                          :accessor list-start-value-func)
    (list-start-indent :initform nil :initarg :list-start-indent
                      :accessor list-start-indent)
-   (list-end-fmtstr :type string :initform nil :initarg :list-end-fmtstr
+   (list-end-fmtstr :type (or string null) :initform nil :initarg :list-end-fmtstr
                    :accessor list-end-fmtstr)
-   (list-end-value-func :type function :initform nil
+   (list-end-value-func :type (or function symbol null) :initform nil
                        :initarg :list-end-value-func
                        :accessor list-end-value-func)
    (list-end-indent :initform nil :initarg :list-end-indent
                    :accessor list-end-indent)
-   (obj-start-fmtstr :type string :initform nil :initarg :obj-start-fmtstr
+   (obj-start-fmtstr :type (or string symbol null) :initform nil :initarg :obj-start-fmtstr
                     :accessor obj-start-fmtstr)
    (obj-start-value-func :initform nil :initarg :obj-start-value-func
                         :accessor obj-start-value-func)
    (obj-start-indent :initform nil :initarg :obj-start-indent
                     :accessor obj-start-indent)
-   (obj-end-fmtstr :type string :initform nil :initarg :obj-end-fmtstr
+   (obj-end-fmtstr :type (or string null) :initform nil :initarg :obj-end-fmtstr
                   :accessor obj-end-fmtstr)
-   (obj-end-value-func :type function :initform nil
+   (obj-end-value-func :type (or function symbol null) :initform nil
                       :initarg :obj-end-value-func
                       :accessor obj-end-value-func)
    (obj-end-indent :initform nil :initarg :obj-end-indent
                   :accessor obj-end-indent)
    (obj-data-indent :initform nil :initarg :obj-data-indent
                    :accessor obj-data-indent)
-   (obj-data-fmtstr :type string :initform nil :initarg :obj-data-fmtstr
+   (obj-data-fmtstr :type (or string null) :initform nil :initarg :obj-data-fmtstr
                    :accessor obj-data-fmtstr)
-   (obj-data-end-fmtstr :type string :initform nil
+   (obj-data-end-fmtstr :type (or string null) :initform nil
                        :initarg :obj-data-end-fmtstr
                        :accessor obj-data-end-fmtstr)
-   (obj-data-value-func :type function :initform nil
+   (obj-data-value-func :type (or function symbol null) :initform nil
                        :initarg :obj-data-value-func
                        :accessor obj-data-value-func)
    (link-slots :type list :initform nil
               :documentation "List of slot names that have hyperlinks"
               :accessor link-slots)
-   (link-page-name :type string :initform nil :initarg :link-page-name
+   (link-page-name :type (or string null) :initform nil :initarg :link-page-name
                   :accessor link-page-name)
-   (link-href-start :type string :initform nil :initarg :link-href-start
+   (link-href-start :type (or string null) :initform nil :initarg :link-href-start
                    :accessor link-href-start)
-   (link-href-end :type string :initform nil :initarg :link-href-end
+   (link-href-end :type (or string null) :initform nil :initarg :link-href-end
                  :accessor link-href-end)
-   (link-ampersand :type string :initform nil :initarg :link-ampersand
+   (link-ampersand :type (or string null) :initform nil :initarg :link-ampersand
                   :accessor link-ampersand))
   (:default-initargs :link-page-name "disp-func1")
   (:documentation "View class for a hyperobject"))
        (aif (find category (views obj-class) :key #'category)
             it
             (let ((view
-                   (make-instance 'object-view :object-class (class-name obj-class)
+                   (make-instance 'object-view
+                                  :object-class-name (class-name obj-class)
+                                  :object-class obj-class
                                   :category category
                                   :slots slots)))
               (push view (views obj-class))
     ((eq view-def :default)
      (let* ((name (class-name cl))
            (view (make-instance 'object-view :name "automatic"
-                                :object-class name
+                                :object-class-name name
+                                :object-class cl
                                 :category :compact-text)))
        view))
     ((consp view-def)
 
 (defmethod initialize-instance :after ((view object-view)
                                       &rest initargs &key &allow-other-keys)
-  (initialize-view (find-class (object-class view)) view))
+  (initialize-view (object-class view) view))
   
 (defun initialize-view (obj-cl view)
   "Calculate all view slots for a hyperobject class"
       (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 (slot-definition-name slot))))
-             (type (slot-value slot 'type))
-             (print-formatter (esd-print-formatter slot)))
+       (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
              (: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\"><![CDATA[" namestr-lower "]]></span> <span class=\"" namestr-lower "\">" value-fmt "</span>")))
+              (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><[!CDATA[" namestr-lower "]]></label> <" namestr-lower ">" value-fmt "</" namestr-lower ">")))
+              (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)
               (push name links)
               (if (esd-hyperlink slot)
                   (string-append fmtstr "<~~a>" value-fmt "</~~a>")
-                  (string-append fmtstr (concatenate 'string "<" namestr-lower ">" value-fmt "</" namestr-lower ">"))))
+                  (string-append fmtstr (concatenate 'string "<" xml-tag ">" value-fmt "</" xml-tag ">"))))
              (:html-link-labels
               (push name links)
               (if (esd-hyperlink slot)
              (:xhtml-link-labels
               (push name links)
               (if (esd-hyperlink slot)
-                  (string-append fmtstr "<span class=\"label\"><[!CDATA[" namestr-lower "]]></span> <~~a>" value-fmt "</~~a>")
-                  (string-append fmtstr (concatenate 'string "<span class=\"label\"><![CDATA[" namestr-lower "]]></span> <span class=\"" namestr-lower "\">" value-fmt "</span>"))))
+                  (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><[![CDATA[" namestr-lower "]]></label> <~~a>" value-fmt "</~~a>")
-                  (string-append fmtstr (concatenate 'string "<label><![CDATA[" namestr-lower "]]></label> <" namestr-lower ">" value-fmt "</" namestr-lower ">")))))
+                  (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
-                          (string-equal (write-to-string type) "string")))
+                          (lisp-type-is-a-string type)))
              (setq func `(kmrcl:xml-cdata ,func)))
            (push func value-func))
          )))
   (setf (list-end-indent view) t)
   (setf (list-end-fmtstr view) "</~a>~%")
   (setf (list-end-value-func view) #'xmlformat-list-end-value-func)
-  (setf (obj-start-fmtstr view) (format nil "<~(~a~)>" (object-class view)))
+  (setf (obj-start-fmtstr view) (format nil "<~(~a~)>" (object-class-name view)))
   (setf (obj-start-indent view) t)
-  (setf (obj-end-fmtstr view) (format nil "</~(~a~)>~%" (object-class view)))
+  (setf (obj-end-fmtstr view) (format nil "</~(~a~)>~%" (object-class-name view)))
   (setf (obj-end-indent view) nil)
   (setf (obj-data-indent view) nil))
 
     (indent-spaces indent strm))
   (let-when (fmtstr (list-start-fmtstr view))
            (let-if (value-func (list-start-value-func view))
-                   (apply #'format strm fmtstr
-                          (multiple-value-list (funcall value-func
-                                                        obj num-items)))
+                   (multiple-value-call #'format strm fmtstr
+                                        (funcall value-func obj num-items))
                    (write-string fmtstr strm))))
 
 (defun fmt-list-end (obj view strm indent num-items)
       (indent-spaces indent strm))
   (let-when (fmtstr (list-end-fmtstr view))
            (let-if (value-func (list-end-value-func view))
-                   (apply #'format strm fmtstr (multiple-value-list
-                                                (funcall value-func obj)))
+                   (multiple-value-call #'format strm fmtstr
+                                        (funcall value-func obj))
                    (write-string fmtstr strm))))
 
 ;;; Object Start and Ends
     (indent-spaces indent strm))
   (let-when (fmtstr (obj-start-fmtstr view))
            (let-if (value-func (obj-start-value-func view))
-                   (apply #'format strm fmtstr (multiple-value-list
-                                                (funcall value-func obj)))
+                   (multiple-value-call #'format strm fmtstr
+                                        (funcall value-func obj))
                    (write-string fmtstr strm))))
 
 (defun fmt-obj-end (obj view strm indent)
     (indent-spaces indent strm))
   (let-when (fmtstr (obj-end-fmtstr view))
            (let-if (value-func (obj-end-value-func view))
-                   (apply #'format strm fmtstr (multiple-value-list
-                                                (funcall value-func obj)))
+                   (multiple-value-call #'format strm fmtstr 
+                                        (funcall value-func obj))
                    (write-string fmtstr strm))))
   
 ;;; Object Data 
 
 (defun fmt-obj-data-plain (obj view strm)
   (awhen (obj-data-value-func view)
-        (apply #'format strm (obj-data-fmtstr view)
-               (multiple-value-list (funcall it obj)))))
+        (multiple-value-call #'format strm (obj-data-fmtstr view)
+                             (funcall it obj))))
 
 (defun fmt-obj-data-with-link (obj view strm refvars)
   (let ((refvalues '()))
 (defun obj-data (obj view)
   "Returns the objects data as a string. Used by common-graphics outline function"
   (awhen (obj-data-value-func view)
-        (apply #'format nil (funcall (obj-data-fmtstr view))
-               (multiple-value-list (funcall it obj)))))
+        (multiple-value-call #'format nil (funcall (obj-data-fmtstr view))
+                             (funcall it obj))))
 
 (defun make-link-data-str (obj view)
   "Return fmt string for that contains ~a slots for hyperlink link start and end"
   (awhen (obj-data-value-func view)
-        (apply #'format nil (obj-data-fmtstr view)
-               (multiple-value-list (funcall it obj)))))
+        (multiple-value-call #'format nil (obj-data-fmtstr view)
+                             (funcall it obj))))
 
 ;;; Display method for objects
 
 
 (defun fmt-comma-integer (i)
   (format nil "~:d" i))
-