X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;ds=inline;f=views.lisp;h=8f0f9b8c2ff377ff205c2011a4bb2e0095140c81;hb=3e5379739ac86e30f191961b15dd69f3516bf0f0;hp=4d57aa423371dfeb8e649fc975af9060a0687040;hpb=a7f7ec44e3acd442817630a912b5a0c581e23538;p=hyperobject.git
diff --git a/views.lisp b/views.lisp
index 4d57aa4..8f0f9b8 100644
--- a/views.lisp
+++ b/views.lisp
@@ -7,7 +7,7 @@
;;;; Programmer: Kevin M. Rosenberg
;;;; Date Started: Apr 2000
;;;;
-;;;; $Id: views.lisp,v 1.14 2002/12/13 08:25:45 kevin Exp $
+;;;; $Id: views.lisp,v 1.25 2003/03/26 21:03:22 kevin Exp $
;;;;
;;;; This file is Copyright (c) 2000-2002 by Kevin M. Rosenberg
;;;;
@@ -20,15 +20,19 @@
(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
:documentation "Name for this view.")
- (category :initform nil :initarg :category :reader category
+ (category :initform nil :initarg :category :accessor category
:documentation "Category for view. Helpful when want to find a view corresponding to a particular category.")
- (source-code :initform nil :initarg :source-code
+ (source-code :initform nil :initarg :source-code :accessor source-code
:documentation "Source code for generating view.")
(country-language :initform :en :initarg :country-language
:documentation "Country's Language for this view.")
@@ -97,7 +101,9 @@
(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))
@@ -132,7 +138,8 @@
((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)
@@ -142,25 +149,54 @@
(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"
+ (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")
+ )
+ )
+
+
+(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 (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
@@ -186,22 +222,22 @@
(string-append fmtstr (concatenate 'string "" value-fmt "")))
(:xml
(string-append fmtstr (concatenate 'string "<" namestr-lower ">" value-fmt "" namestr-lower ">")))
- (:html-label
+ (:html-labels
(string-append fmtstr (concatenate 'string "" namestr-lower " " value-fmt "")))
- (:xhtml-label
- (string-append fmtstr (concatenate 'string " " value-fmt "")))
+ (:xhtml-labels
+ (string-append fmtstr (concatenate 'string "" xml-namestr " " value-fmt "")))
(:xml-labels
- (string-append fmtstr (concatenate 'string " <" namestr-lower ">" value-fmt "" namestr-lower ">")))
+ (string-append fmtstr (concatenate 'string " <" 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 "" value-fmt ""))))
- (:xml-link
+ ((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 "<" 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)
@@ -210,19 +246,20 @@
(:xhtml-link-labels
(push name links)
(if (esd-hyperlink slot)
- (string-append fmtstr "<[!CDATA[" namestr-lower "]]> <~~a>" value-fmt "~~a>")
- (string-append fmtstr (concatenate 'string " " value-fmt ""))))
- (:xml-link-labels
+ (string-append fmtstr "" xml-namestr " <~~a>" value-fmt "~~a>")
+ (string-append fmtstr (concatenate 'string "" xml-namestr " " value-fmt ""))))
+ ((or :xml-link-labels :ie-xml-link-labels)
(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 " <~~a>" value-fmt "~~a>")
+ (string-append fmtstr (concatenate 'string " <" 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)))))
+ `(,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
@@ -347,9 +384,9 @@
(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))
@@ -425,9 +462,7 @@
(defun make-link-end (obj view fieldname)
(declare (ignore obj fieldname))
- ;;(format nil "~a" (href-end ref))
- (link-href-end view)
- )
+ (link-href-end view))
(defun fmt-obj-data (obj view strm indent refvars)
(when (obj-data-indent view)
@@ -436,7 +471,7 @@
(fmt-obj-data-with-link obj view strm refvars)
(fmt-obj-data-plain obj view strm))
(awhen (obj-data-end-fmtstr view)
- (format strm it)))
+ (write-string it strm)))
(defun fmt-obj-data-plain (obj view strm)
(awhen (obj-data-value-func view)
@@ -526,4 +561,3 @@
(defun fmt-comma-integer (i)
(format nil "~:d" i))
-