(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 , . " (path->string (resource-path resource))) "")) (containment-triples (if (and (container? resource) (not (null? (resource-contained resource)))) (format #f " a ~a . " (path->string (resource-path resource)) (string-join (map (lambda (p) (format #f "" (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))))))))