From af759288a2517f9acf4c28f79d9c43be0086a221 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Mon, 18 Aug 2008 03:49:35 +0000 Subject: More copy/paste and serialisation work. Don't die on invalid path for set_property and set_variable (return error to client). Working paste to subpatches, paste of connected patch ports and modules. git-svn-id: http://svn.drobilla.net/lad/ingen@1428 a436a847-0d15-0410-975c-d299462d15a1 --- src/libs/serialisation/Parser.cpp | 85 ++++++++++++++++++++------------------- src/libs/serialisation/Parser.hpp | 8 ---- 2 files changed, 43 insertions(+), 50 deletions(-) (limited to 'src/libs/serialisation') diff --git a/src/libs/serialisation/Parser.cpp b/src/libs/serialisation/Parser.cpp index 9ddfb601..6d90499a 100644 --- a/src/libs/serialisation/Parser.cpp +++ b/src/libs/serialisation/Parser.cpp @@ -70,9 +70,9 @@ Parser::parse_document( Redland::Model model(*world->rdf_world, document_uri, document_uri); if (object_uri == document_uri || object_uri == "") - cout << "[Parser] Parsing document " << object_uri << endl; + cout << "Parsing document " << object_uri << " (base " << document_uri << ")" << endl; else - cout << "[Parser] Parsing " << object_uri << " from " << document_uri << endl; + cout << "Parsing " << object_uri << " from " << document_uri << endl; return parse(world, target, model, document_uri, object_uri, parent, symbol, data);; } @@ -92,11 +92,11 @@ Parser::parse_string( Redland::Model model(*world->rdf_world, str.c_str(), str.length(), base_uri); if (object_uri) - cout << "[Parser] Parsing " << object_uri.get() << " (base " << base_uri << ")" << endl; + cout << "Parsing " << object_uri.get() << " (base " << base_uri << ")" << endl; else - cout << "[Parser] Parsing all objects found in string (base " << base_uri << ")" << endl; - - bool ret = parse(world, target, model, base_uri, object_uri, parent, symbol, data);; + cout << "Parsing all objects found in string (base " << base_uri << ")" << endl; + + bool ret = parse(world, target, model, base_uri, object_uri, parent, symbol, data); if (ret) { const Glib::ustring subject = Glib::ustring("<") + base_uri + Glib::ustring(">"); parse_connections(world, target, model, base_uri, subject, parent ? parent.get() : "/"); @@ -117,9 +117,6 @@ Parser::parse( boost::optional symbol, boost::optional data) { - //if (object_uri) - // object_uri = uri_relative_to_base(base_uri, object_uri.get()); - const Redland::Node::Type res = Redland::Node::RESOURCE; Glib::ustring query_str; if (object_uri) @@ -143,9 +140,29 @@ Parser::parse( for (Redland::Query::Results::iterator i = results.begin(); i != results.end(); ++i) { const Redland::Node subject = (object_uri ? subject_uri : (*i)["subject"]); const Redland::Node rdf_class = (*i)["class"]; + if (!object_uri) { + std::string path_str = "/" + uri_relative_to_base(base_uri, subject.to_c_string()); + if (Path(path_str).parent() != "/") + continue; + } + if (rdf_class == patch_class || rdf_class == node_class || rdf_class == in_port_class || rdf_class == out_port_class) { - Path path = parse_path(world, model, base_uri, subject.to_c_string(), parent, symbol); + Raul::Path path("/"); + if (base_uri != subject.to_c_string()) { + string path_str = string("/") + (string)uri_relative_to_base( + base_uri, subject.to_c_string()); + if (Path::is_valid(path_str)) { + path = path_str; + } else { + cerr << "[Parser] ERROR: Invalid path " << path << endl; + continue; + } + } + + if (path.parent() != "/") + continue; + if (rdf_class == patch_class) { ret = parse_patch(world, target, model, base_uri, subject.to_c_string(), path, data); if (ret) @@ -169,37 +186,6 @@ Parser::parse( } -Path -Parser::parse_path(Ingen::Shared::World* world, - Redland::Model& model, - const Glib::ustring& base_uri, - const Glib::ustring& object_uri, - boost::optional& parent, - boost::optional& symbol) -{ - string subject = string(""; - - Redland::Query query(*world->rdf_world, Glib::ustring( - "SELECT DISTINCT ?sym WHERE { ") + subject + " ingen:symbol ?sym }"); - - Redland::Query::Results results = query.run(*world->rdf_world, model, base_uri); - if (results.size() > 0) { - symbol = (*results.begin())["sym"].to_string(); - } else { - const string sym = object_uri.substr(base_uri.find_last_of("/")+1); - symbol = Symbol::symbolify(sym.substr(0, sym.find("."))); - } - - Path ret; - if (base_uri == object_uri) - ret = (parent ? parent.get().base() : Path("/")); - else - ret = (parent ? parent.get().base() : Path("/")) + symbol.get(); - cout << "Parsing " << object_uri << " (base " << base_uri << ") to " << ret << endl; - return ret; -} - - bool Parser::parse_patch( Ingen::Shared::World* world, @@ -518,7 +504,7 @@ Parser::parse_variables( Raul::Path path, boost::optional data=boost::optional()) { - Redland::Query query = Redland::Query(*world->rdf_world, Glib::ustring( + Redland::Query query(*world->rdf_world, Glib::ustring( "SELECT DISTINCT ?varkey ?varval WHERE {\n") + subject + " ingen:variable ?variable .\n" "?variable ingen:key ?varkey ;\n" @@ -532,6 +518,21 @@ Parser::parse_variables( if (key != "") target->set_variable(path, key, AtomRDF::node_to_atom(val_node)); } + + query = Redland::Query(*world->rdf_world, Glib::ustring( + "SELECT DISTINCT ?key ?val WHERE {\n") + + subject + " ingen:property ?property .\n" + "?property ingen:key ?key ;\n" + " ingen:value ?val .\n" + "}"); + + results = query.run(*world->rdf_world, model, base_uri); + for (Redland::Query::Results::iterator i = results.begin(); i != results.end(); ++i) { + const string key = world->rdf_world->prefixes().qualify(string((*i)["key"])); + const Redland::Node& val_node = (*i)["val"]; + if (key != "") + target->set_property(path, key, AtomRDF::node_to_atom(val_node)); + } // Set passed variables last to override any loaded values if (data) diff --git a/src/libs/serialisation/Parser.hpp b/src/libs/serialisation/Parser.hpp index 3a99b7da..fd5fdece 100644 --- a/src/libs/serialisation/Parser.hpp +++ b/src/libs/serialisation/Parser.hpp @@ -73,14 +73,6 @@ private: boost::optional symbol=boost::optional(), boost::optional data=boost::optional()); - Raul::Path parse_path( - Ingen::Shared::World* world, - Redland::Model& model, - const Glib::ustring& base_uri, - const Glib::ustring& object_uri, - boost::optional& parent, - boost::optional& symbol); - bool parse_patch( Ingen::Shared::World* world, Ingen::Shared::CommonInterface* target, -- cgit v1.2.1