return canvas;
}
-Canvas::Handle
-synfig::string_to_canvas(const String &data)
-{
- CanvasParser parser;
-
- parser.set_allow_errors(true);
-
- Canvas::Handle canvas=parser.parse_from_string(data);
-
- if(parser.error_count())
- return Canvas::Handle();
-
- return canvas;
-}
-
/* === M E T H O D S ======================================================= */
void
{
string str=strprintf("%s:<%s>:%d: error: ",filename.c_str(),element->get_name().c_str(),element->get_line())+text;
total_errors_++;
- errors_text += " " + str + "\n";
+ errors_text += " * " + str + "\n";
if(!allow_errors_)
throw runtime_error(str);
cerr<<str<<endl;
Canvas::Handle
CanvasParser::parse_from_file_as(const String &file_,const String &as_,String &errors)
{
+ ChangeLocale change_locale(LC_NUMERIC, "C");
+ String file(unix_to_local_path(file_));
+ String as(unix_to_local_path(as_));
+
try
{
- ChangeLocale change_locale(LC_NUMERIC, "C");
- String file(unix_to_local_path(file_));
- String as(unix_to_local_path(as_));
-
if(get_open_canvas_map().count(etl::absolute_path(as)))
return get_open_canvas_map()[etl::absolute_path(as)];
if(parser)
{
Canvas::Handle canvas(parse_canvas(parser.get_document()->get_root_node(),0,false,as));
+ if (!canvas) return canvas;
get_open_canvas_map()[etl::absolute_path(as)]=canvas;
canvas->signal_deleted().connect(sigc::bind(sigc::ptr_fun(_remove_from_open_canvas_map),canvas.get()));
canvas->signal_file_name_changed().connect(sigc::bind(sigc::ptr_fun(_canvas_file_name_changed),canvas.get()));
-
-
const ValueNodeList& value_node_list(canvas->value_node_list());
again:
catch(Exception::FileNotFound) { synfig::error("FileNotFound Thrown"); }
catch(Exception::IDNotFound) { synfig::error("IDNotFound Thrown"); }
catch(Exception::IDAlreadyExists) { synfig::error("IDAlreadyExists Thrown"); }
- catch(const std::exception& ex)
- {
- synfig::error("Standard Exception: "+String(ex.what()));
- errors = ex.what();
- return Canvas::Handle();
- }
- catch(const String& str)
- {
- cerr<<str<<endl;
- // synfig::error(str);
- errors = str;
- return Canvas::Handle();
- }
- return Canvas::Handle();
-}
-
-Canvas::Handle
-CanvasParser::parse_from_string(const String &data)
-{
- try
+ catch(xmlpp::internal_error x)
{
- ChangeLocale change_locale(LC_NUMERIC, "C");
- filename=_("<INTERNAL>");
- total_warnings_=0;
- xmlpp::DomParser parser;
- parser.parse_memory(data);
- xmlpp::Element *root=parser.get_document()->get_root_node();
- if(parser)
- {
- Canvas::Handle canvas(parse_canvas(root));
- canvas->signal_deleted().connect(sigc::bind(sigc::ptr_fun(_remove_from_open_canvas_map),canvas.get()));
- canvas->signal_file_name_changed().connect(sigc::bind(sigc::ptr_fun(_canvas_file_name_changed),canvas.get()));
-
- const ValueNodeList& value_node_list(canvas->value_node_list());
- again:
- ValueNodeList::const_iterator iter;
- for(iter=value_node_list.begin();iter!=value_node_list.end();++iter)
- {
- ValueNode::Handle value_node(*iter);
- if(value_node->is_exported() && value_node->get_id().find("Unnamed")==0)
- {
- canvas->remove_value_node(value_node);
- goto again;
- }
- }
-
- return canvas;
- }
+ printf("caught internal error\n");
+ if (!strcmp(x.what(), "Couldn't create parsing context"))
+ throw runtime_error(String(" * ") + _("Can't open file") + " \"" + file + "\"");
+ throw;
}
- catch(Exception::BadLinkName) { synfig::error("BadLinkName Thrown"); }
- catch(Exception::BadType) { synfig::error("BadType Thrown"); }
- catch(Exception::FileNotFound) { synfig::error("FileNotFound Thrown"); }
- catch(Exception::IDNotFound) { synfig::error("IDNotFound Thrown"); }
- catch(Exception::IDAlreadyExists) { synfig::error("IDAlreadyExists Thrown"); }
catch(const std::exception& ex)
{
synfig::error("Standard Exception: "+String(ex.what()));
+ errors = ex.what();
return Canvas::Handle();
}
catch(const String& str)
{
cerr<<str<<endl;
// synfig::error(str);
+ errors = str;
return Canvas::Handle();
}
return Canvas::Handle();