summaryrefslogtreecommitdiffstats
path: root/src/serialisation
diff options
context:
space:
mode:
Diffstat (limited to 'src/serialisation')
-rw-r--r--src/serialisation/Parser.cpp67
-rw-r--r--src/serialisation/Parser.hpp10
2 files changed, 46 insertions, 31 deletions
diff --git a/src/serialisation/Parser.cpp b/src/serialisation/Parser.cpp
index 5b04a426..1fd67498 100644
--- a/src/serialisation/Parser.cpp
+++ b/src/serialisation/Parser.cpp
@@ -19,6 +19,8 @@
#include <set>
+#include <boost/format.hpp>
+
#include <glibmm/convert.h>
#include <glibmm/fileutils.h>
#include <glibmm/miscutils.h>
@@ -126,37 +128,48 @@ Parser::find_patches(Ingen::Shared::World* world,
* @return whether or not load was successful.
*/
bool
-Parser::parse_document(Ingen::Shared::World* world,
- Ingen::Shared::CommonInterface* target,
- Glib::ustring document_uri,
- boost::optional<Raul::Path> data_path,
- boost::optional<Raul::Path> parent,
- boost::optional<Raul::Symbol> symbol,
- boost::optional<GraphObject::Properties> data)
+Parser::parse_file(Ingen::Shared::World* world,
+ Ingen::Shared::CommonInterface* target,
+ Glib::ustring file_uri,
+ boost::optional<Raul::Path> data_path,
+ boost::optional<Raul::Path> parent,
+ boost::optional<Raul::Symbol> symbol,
+ boost::optional<GraphObject::Properties> data)
{
- normalise_uri(document_uri);
-
- if (document_uri.substr(document_uri.length() - 4) != ".ttl") {
- if (document_uri[document_uri.length() - 1] != '/') {
- document_uri.append("/");
+ normalise_uri(file_uri);
+
+ const size_t colon = file_uri.find(":");
+ Glib::ustring file_path = file_uri;
+ if (colon != Glib::ustring::npos) {
+ const Glib::ustring scheme = file_uri.substr(0, colon);
+ if (scheme != "file") {
+ LOG(error) << (boost::format("Unsupported URI scheme `%1%'") % scheme) << endl;
+ return false;
+ }
+ if (file_uri.substr(0, 7) == "file://") {
+ file_path = file_uri.substr(7);
+ } else {
+ file_path = file_uri.substr(5);
}
}
-
- const std::string filename(Glib::filename_from_uri(document_uri));
- const size_t ext = filename.find(INGEN_BUNDLE_EXT);
- const size_t ext_len = strlen(INGEN_BUNDLE_EXT);
- if (ext == filename.length() - ext_len
- || ((ext == filename.length() - ext_len - 1)
- && filename[filename.length() - 1] == '/')) {
- std::string basename(Glib::path_get_basename(filename));
- basename = basename.substr(0, basename.find('.'));
- document_uri += basename + INGEN_PATCH_FILE_EXT;
+
+ std::string filename = Glib::filename_from_uri(file_uri);
+
+ if (file_uri.substr(file_uri.length() - 4) != ".ttl") {
+ // Not a Turtle file, maybe a bundle, check for manifest
+ if (file_uri[file_uri.length() - 1] != '/') {
+ file_uri.append("/");
+ }
+ Parser::PatchRecords records = find_patches(world, file_uri + "manifest.ttl");
+ if (!records.empty()) {
+ filename = Glib::filename_from_uri(records.front().file_uri);
+ }
}
- Sord::Model model(*world->rdf_world(), document_uri);
- model.load_file(document_uri);
+ Sord::Model model(*world->rdf_world(), filename);
+ model.load_file(filename);
- LOG(info) << "Parsing " << document_uri << endl;
+ LOG(info) << "Parsing " << file_uri << endl;
if (data_path)
LOG(info) << "Path: " << *data_path << endl;
if (parent)
@@ -165,11 +178,11 @@ Parser::parse_document(Ingen::Shared::World* world,
LOG(info) << "Symbol: " << *symbol << endl;
boost::optional<Path> parsed_path
- = parse(world, target, model, document_uri, data_path, parent, symbol, data);
+ = parse(world, target, model, filename, data_path, parent, symbol, data);
if (parsed_path) {
target->set_property(*parsed_path, "http://drobilla.net/ns/ingen#document",
- Atom(Atom::URI, document_uri.c_str()));
+ Atom(Atom::URI, file_uri.c_str()));
} else {
LOG(warn) << "Document URI lost" << endl;
}
diff --git a/src/serialisation/Parser.hpp b/src/serialisation/Parser.hpp
index 103cd9a0..d9b33956 100644
--- a/src/serialisation/Parser.hpp
+++ b/src/serialisation/Parser.hpp
@@ -43,7 +43,7 @@ public:
typedef Shared::GraphObject::Properties Properties;
- virtual bool parse_document(
+ virtual bool parse_file(
Ingen::Shared::World* world,
Shared::CommonInterface* target,
Glib::ustring document_uri,
@@ -73,9 +73,11 @@ public:
boost::optional<Properties> data=boost::optional<Properties>());
struct PatchRecord {
- PatchRecord(const Raul::URI& u, const Glib::ustring& f) : uri(u), filename(f) {}
- const Raul::URI uri;
- const Glib::ustring filename;
+ PatchRecord(const Raul::URI& u, const Glib::ustring& f)
+ : patch_uri(u), file_uri(f)
+ {}
+ const Raul::URI patch_uri;
+ const Glib::ustring file_uri;
};
typedef std::list<PatchRecord> PatchRecords;