summaryrefslogtreecommitdiff
path: root/ldp/resource/load.scm
diff options
context:
space:
mode:
Diffstat (limited to 'ldp/resource/load.scm')
-rw-r--r--ldp/resource/load.scm57
1 files changed, 57 insertions, 0 deletions
diff --git a/ldp/resource/load.scm b/ldp/resource/load.scm
new file mode 100644
index 0000000..9ae9134
--- /dev/null
+++ b/ldp/resource/load.scm
@@ -0,0 +1,57 @@
+(define-module (ldp resource load)
+ #:use-module (ldp resource)
+ #:use-module (ldp path)
+ #:use-module (ldp resource xml)
+ #:use-module (rnrs bytevectors)
+ #:use-module (web uri))
+
+(define-public (load uri)
+ (cond
+ ((string? uri)
+ (load (string->path uri)))
+ ((uri? uri)
+ (load (uri->path uri)))
+ ((or (resource? uri) (container? uri))
+ (load (resource-path uri)))
+ (else
+ (let* ((dirname (path->filename uri))
+ (filename (string-append dirname
+ "/representation/manifest.xml"))
+ (port
+ (catch #t
+ (lambda ()
+ (open-input-file filename))
+ (lambda error
+ (throw 'not-found))))
+ (resource (xml->resource port))
+ (container-def
+ (if (container? resource)
+ (format #f "
+</~a> a <http://www.w3.org/ns/ldp#Container>,
+ <http://www.w3.org/ns/ldp#BasicContainer> .
+"
+ (path->string (resource-path resource)))
+ ""))
+ (containment-triples
+ (if (and (container? resource)
+ (not (null? (resource-contained resource))))
+ (format #f "
+</~a> a <http://www.w3.org/ns/ldp#contains> ~a .
+"
+ (path->string (resource-path resource))
+ (string-join
+ (map (lambda (p)
+ (format #f "</~a>"
+ (path->string p)))
+ (resource-contained resource))
+ ", "))
+ ""))
+ (content-filename
+ (string-append dirname
+ "/representation/content")))
+ (values
+ resource
+ (open-input-file content-filename #:binary #t)
+ (and (container? resource)
+ (string->utf8
+ (string-append container-def containment-triples))))))))