root/trunk/projects/bos/m2/import.lisp

Revision 3663, 3.5 kB (checked in by hans, 4 months ago)

Remove stripe related code and definitions.

  • Property svn:eol-style set to native
  • Property svn:keywords set to author date id revision
Line 
1 (in-package :bos.m2)
2
3 (defclass importer ()
4   ((sponsor :accessor importer-sponsor)
5    (price :accessor importer-price)
6    (date :accessor importer-date)
7    (m2s :accessor importer-m2s)
8    (area-active-p :accessor importer-area-active-p)
9    (area-y :accessor importer-area-y)
10    (area-vertices :accessor importer-area-vertices)
11    (area :accessor importer-area)))
12
13 (defun import-database (pathname)
14   (cxml:parse-file pathname (cxml:make-recoder (make-instance 'importer))))
15
16 (defun string-or-nil (x)
17   (if (zerop (length x)) nil x))
18
19 (defun getattribute (name attributes)
20   (let ((a (find name attributes
21                  :key #'sax:attribute-qname
22                  :test #'string=)))
23     (if a (string-or-nil (sax:attribute-value a)) nil)))
24
25 (defun parse-iso-time (str)
26   (let ((y (parse-integer str :start 0 :end 4))
27         (m (parse-integer str :start 5 :end 7))
28         (d (parse-integer str :start 8 :end 10))
29         (h (parse-integer str :start 11 :end 13))
30         (min (parse-integer str :start 14 :end 16))
31         (s (parse-integer str :start 17 :end 19)))
32     (encode-universal-time s min h d m y 0)))
33
34 (defmethod sax:start-element
35     ((handler importer) namespace-uri local-name qname attrs)
36   (declare (ignore namespace-uri local-name))
37   (cond
38     ((string= qname "sponsor")
39      (setf (importer-sponsor handler)
40            (make-sponsor
41             :login (getattribute "profile-id" attrs)
42             :full-name (getattribute "full-name" attrs)
43             :email-address (getattribute "email-address" attrs)
44             :info-text (getattribute "info-text" attrs)
45             :country (getattribute "country" attrs)))
46      ;; XXX Achtung, das Passwort nicht als schon Initarg uebergeben, weil
47      ;; die USER-Klasse es sonst fuer Cleartext haelt und fuer uns MD5t.
48      (change-slot-values
49       (importer-sponsor handler)
50       'bknr.web::password
51       (getattribute "password" attrs)))
52     ((string= qname "contract")
53      (setf (importer-price handler)
54            (parse-integer (getattribute "price" attrs)))
55      (setf (importer-date handler)
56            (parse-iso-time (getattribute "date" attrs)))
57      (setf (importer-m2s handler) '()))
58     ((string= qname "m2")
59      (let ((m2 (ensure-m2-with-num
60                 (parse-integer (getattribute "sqm-num" attrs))))
61            (x (getattribute "x" attrs))
62            (y (getattribute "y" attrs))
63            (utm-x (getattribute "utm-x" attrs))
64            (utm-y (getattribute "utm-y" attrs))
65            (*read-eval* nil))
66        (when x (assert (eql (parse-integer x) (m2-x m2))))
67        (when y (assert (eql (parse-integer y) (m2-y m2))))
68        (when utm-x (assert (= (read-from-string utm-x) (m2-utm-x m2))))
69        (when utm-y (assert (= (read-from-string utm-y) (m2-utm-y m2))))
70        (push m2 (importer-m2s handler))))
71     ((string= qname "allocation-area")
72      (setf (importer-area-active-p handler)
73            (equal (getattribute "active" attrs) "yes"))
74      (setf (importer-area-y handler)
75            (parse-integer (getattribute "y" attrs)))
76      (setf (importer-area handler) nil)
77      (setf (importer-area-vertices handler) nil))
78     ((string= qname "point")
79      (push (cons (parse-integer (getattribute "x" attrs))
80                  (parse-integer (getattribute "y" attrs)))
81            (importer-area-vertices handler)))))
82
83 (defmethod sax:end-element ((handler importer) namespace-uri local-name qname)
84   (declare (ignore namespace-uri local-name))
85   (cond
86     ((string= qname "contract")
87      (make-contract (importer-sponsor handler)
88                     (importer-m2s handler)
89                     :date (importer-date handler)))))
Note: See TracBrowser for help on using the browser.