X-Git-Url: https://dreyeck.freedombox.rocks/gitweb/topic-maps.git/blobdiff_plain/437ad53ea7539d36db3fa871d0931650b7a6a03e..6a2f8446afca0915882f0d4a06cb891ccfcdc96d:/src/cxtm/canonicalizer.lisp diff --git a/src/cxtm/canonicalizer.lisp b/src/cxtm/canonicalizer.lisp index a788853..6d544ef 100644 --- a/src/cxtm/canonicalizer.lisp +++ b/src/cxtm/canonicalizer.lisp @@ -118,8 +118,26 @@ (unless (and (eq item (canonical-occurrence item)) (eq (occurrence-parent item) topic)) (fail :invalid-parent "Occurrence must be current and owned by its containing Topic.")) (reference (occurrence-type item)) - (unless (member (occurrence-datatype item) (list (string-datatype) (iri-datatype)) :test #'string=) - (fail :unsupported-occurrence-datatype "Only string and anyURI values are supported." t)) + (unless (topic-maps.tmdm::absolute-locator-p (occurrence-datatype item)) + (fail :invalid-occurrence-datatype "Datatype must be an absolute locator.")) + (when (and (string= (occurrence-datatype item) (integer-datatype)) + (not (integer-lexical-p (occurrence-value item)))) + (fail :invalid-integer-value "Occurrence value is not an xsd:integer lexical form.")) + (when (and (string= (occurrence-datatype item) (decimal-datatype)) + (not (decimal-lexical-p (occurrence-value item)))) + (fail :invalid-decimal-value "Occurrence value is not an xsd:decimal lexical form.")) + (when (string= (occurrence-datatype item) (date-datatype)) + (unless (date-lexical-p (occurrence-value item)) + (fail :invalid-date-value "Occurrence value is not a valid XSD 1.0 date.")) + (unless (canonical-date-lexical-form (occurrence-value item)) + (fail :date-timezone-canonicalization "XSD date recoverable-timezone canonicalization is outside this slice." t))) + (when (string= (occurrence-datatype item) (datetime-datatype)) + (unless (datetime-lexical-p (occurrence-value item)) + (fail :invalid-datetime-value "Occurrence value is not a valid XSD 1.0 dateTime.")) + (multiple-value-bind (value reason) (canonical-datetime-lexical-form (occurrence-value item)) + (unless value (fail (if (eq reason :unsupported-bce-timezone-rollover) + :datetime-bce-timezone-rollover :datetime-leap-second-context) + "DateTime BCE rollover/leap-second context is outside this canonical subset." t)))) (when (and (string= (occurrence-datatype item) (iri-datatype)) (not (topic-maps.tmdm::absolute-locator-p (occurrence-value item)))) (fail :invalid-occurrence-value "IRI-valued Occurrences must store an absolute locator.")) @@ -202,8 +220,17 @@ Variants or non-Topic identifiers other than Occurrence identifiers. Does not mu (type-ref (topic-name-type name)) (format out "~%")) (loop for item in (sorted (topic-occurrences topic) #'occurrence-order) for index from 1 do (format out "~%" index) - (xml-text (if (string= (occurrence-datatype item) (iri-datatype)) - (normalized-locator (occurrence-value item)) (occurrence-value item)) out) + (xml-text (cond ((string= (occurrence-datatype item) (iri-datatype)) + (normalized-locator (occurrence-value item))) + ((string= (occurrence-datatype item) (integer-datatype)) + (canonical-integer-lexical-form (occurrence-value item))) + ((string= (occurrence-datatype item) (decimal-datatype)) + (canonical-decimal-lexical-form (occurrence-value item))) + ((string= (occurrence-datatype item) (date-datatype)) + (canonical-date-lexical-form (occurrence-value item))) + ((string= (occurrence-datatype item) (datetime-datatype)) + (canonical-datetime-lexical-form (occurrence-value item))) + (t (occurrence-value item))) out) (format out "~%") ;; CXTM 3.14: datatype locator is NOT base-normalized. (xml-text (occurrence-datatype item) out) (format out "~%")