1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
(define-module (ldp resource sxml)
#:use-module (ldp resource)
#:use-module (ldp path)
#:use-module (sxml match))
(define-public (sxml->resource res)
(sxml-match
res
((*TOP* (*PI* . ,whatever) . ,rest)
(sxml->resource `(*TOP* ,@rest)))
((*TOP* ,rest)
(sxml->resource rest))
((https://linked-data-platform.planete-kraus.eu/ns:resource
(@ (container "no")
(uri-path ,uri-path)
(etag ,etag)
(content-type ,content-type)))
(make-resource (string->path uri-path)
etag
(string->symbol content-type)
#f))
((https://linked-data-platform.planete-kraus.eu/ns:resource
(@ (container "yes")
(uri-path ,uri-path)
(etag ,etag)
(content-type ,content-type))
(https://linked-data-platform.planete-kraus.eu/ns:contains
(@ (path ,contents)))
...)
(make-resource (string->path uri-path)
etag
(string->symbol content-type)
(map string->path contents)))
(,otherwise
(scm-error 'wrong-type-arg
"sxml->resource"
"Expected a SXML fragment with the correct schema, not ~s."
(list res)
(list res)))))
(define-public (resource->sxml x)
`(*TOP* (*PI* xml "version=\"1.0\" encoding=\"utf-8\"")
(resource
(@ (xmlns "https://linked-data-platform.planete-kraus.eu/ns")
(container ,(if (container? x) "yes" "no"))
(uri-path ,(path->string (resource-path x)))
(etag ,(resource-etag x))
(content-type ,(symbol->string (resource-content-type x))))
,@(map (lambda (p)
`(contains (@ (path ,(path->string p)))))
(or (resource-contained x) '())))))
|