- (let ((fmtstr nil)
- (first-field t)
- (value-func '())
- (links '())
- (category (category view)))
- (unless (slot-value view 'slots)
- (setf (slot-value view 'slots) (slot-value obj-cl 'default-print-slots)))
- (dolist (slot-name (slot-value view 'slots))
- (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 (slot-value slot 'print-formatter)))
-
- (cond
- (first-field
- (setq fmtstr "")
- (setq first-field nil))
- (t
- (string-append fmtstr " ")))
-
- (when (slot-value slot 'hyperlink)
- (push name links))
-
- (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-label
- (string-append fmtstr (concatenate 'string "<span class=\"label\">" namestr-lower "</span> <span class=\"" namestr-lower "\">" value-fmt "</span>")))
- (:xhtml-label
- (string-append fmtstr (concatenate 'string "<span class=\"label\"><![CDATA[" namestr-lower "]]></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 ">")))
- ((or :html-link :xhtml-link)
- (if (slot-value slot 'hyperlink)
- (string-append fmtstr "<~~a>" value-fmt "</~~a>")
- (string-append fmtstr (concatenate 'string "<span class=\"" namestr-lower "\">" value-fmt "</span>"))))
- (:xml-link
- (if (slot-value slot 'hyperlink)
- (string-append fmtstr "<~~a>" value-fmt "</~~a>")
- (string-append fmtstr (concatenate 'string "<" namestr-lower ">" value-fmt "</" namestr-lower ">"))))
- (:html-link-labels
- (if (slot-value slot 'hyperlink)
- (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
- (if (slot-value slot 'hyperlink)
- (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>"))))
- (:xml-link-labels
- (if (slot-value slot 'hyperlink)
- (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 ">")))))
- ) ;; 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
- :xhtml-link-labels :xml-link-labels :ie-xml-link
- :ie-xml-link-labels)
- (or print-formatter
- (string-equal (write-to-string type) "string")))
- (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 (slot-value view 'obj-data-fmtstr) fmtstr)
- (setf (slot-value view 'obj-data-value-func) value-func)
- (setf (slot-value view 'link-slots) (nreverse links))
+ (cond
+ ((category view)
+ (initialize-view-by-category obj-cl view))
+ ((source-code view)
+ (initialize-view-by-source-code obj-cl view))
+ (t
+ (setf (category view) :compact-text)
+ (initialize-view-by-category obj-cl view))))
+
+(defun initialize-view-by-source-code (obj-cl view)
+ "Initialize a view based upon a source code"
+ (let ((source-code (source-code view)))
+ (error "not implemented")
+ )
+ )
+
+(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))
+ (let* ((slot-data (slot-value obj name))
+ (fmt-data (if formatter
+ (funcall formatter slot-data)
+ slot-data))
+ (data (if cdata
+ (kmrcl:xml-cdata fmt-data)
+ fmt-data)))
+ (write-simple data strm)))
+
+
+(defun ppfc-html (title name type formatter cdata print-func)
+ (vector-push-extend '(write-string "<span class=\"" s) print-func)
+ (vector-push-extend `(write-string ,title s) print-func)
+ (vector-push-extend '(write-string "\">" s) print-func)
+ (vector-push-extend `(write-ho-value x ',name ',type ',formatter ,cdata s) print-func)
+ (vector-push-extend '(write-string "</span>" s) print-func))
+
+(defun ppfc-xml (tag name type formatter cdata print-func)
+ (vector-push-extend '(write-char #\< s) print-func)
+ (vector-push-extend `(write-string ,tag s) print-func)
+ (vector-push-extend '(write-char #\> s) print-func)
+ (vector-push-extend `(write-ho-value x ',name ',type ',formatter ,cdata s) print-func)
+ (vector-push-extend '(write-string "</" s) print-func)
+ (vector-push-extend `(write-string ,tag s) print-func)
+ (vector-push-extend '(write-char #\> s) print-func))
+
+(defun ppfc-html-labels (label name type formatter cdata print-func)
+ (vector-push-extend '(write-string "<span class=\"label\">" s) print-func)
+ (vector-push-extend `(write-string ,label s) print-func)
+ (vector-push-extend '(write-string "</span> " s) print-func)
+ (ppfc-html label name type formatter cdata print-func))
+
+(defun ppfc-xhtml-labels (label tag name type formatter cdata print-func)
+ (vector-push-extend '(write-string "<span class=\"label\">" s) print-func)
+ (vector-push-extend `(write-string ,label s) print-func)
+ (vector-push-extend '(write-string "</span> " s) print-func)
+ (ppfc-html tag name type formatter cdata print-func))
+
+(defun ppfc-xml-labels (label tag name type formatter cdata print-func)
+ (vector-push-extend '(write-string "<label>" s) print-func)
+ (vector-push-extend `(write-string ,label s) print-func)
+ (vector-push-extend '(write-string "</label> " s) print-func)
+ (ppfc-xml tag name type formatter cdata print-func))
+
+(defun ppfc-html-link (name type formatter cdata nlink print-func)
+ (declare (fixnum nlink))
+ (vector-push-extend '(write-char #\< s) print-func)
+ (vector-push-extend `(write-string (nth ,(+ nlink nlink) links) s) print-func)
+ (vector-push-extend '(write-char #\> s) print-func)
+ (vector-push-extend `(write-ho-value x ',name ',type ',formatter ,cdata s) print-func)
+ (vector-push-extend '(write-string "</" s) print-func)
+ (vector-push-extend `(write-string (nth ,(+ nlink nlink 1) links) s) print-func)
+ (vector-push-extend '(write-char #\> s) print-func))
+
+(defun ppfc-html-link-labels (label name type formatter cdata nlink print-func)
+ (vector-push-extend '(write-string "<label>" s) print-func)
+ (vector-push-extend `(write-string ,label s) print-func)
+ (vector-push-extend '(write-string "</label> " s) print-func)
+ (ppfc-html-link name type formatter cdata nlink print-func))
+
+(defun push-print-fun-code (category slot nlink print-func)
+ (let* ((formatter (esd-print-formatter slot))
+ (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))
+ (cdata (not (null
+ (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 formatter
+ (lisp-type-is-a-string type))))))
+ (hyperlink (esd-hyperlink slot)))