Code

Added missing (and very important) file.
[inkscape.git] / src / extension / implementation / xslt.cpp
index cb3260d3731cce87976ecd3244b4f6a2bd722993..f34fea64a36a30daaa4f489ec70f20814be59a5c 100644 (file)
@@ -21,6 +21,9 @@
 #include "xml/repr.h"
 #include "io/sys.h"
 #include "file.h"
+#include <unistd.h>
+#include <cstring>
+#include "document.h"
 
 #include <libxml/parser.h>
 #include <libxslt/transform.h>
@@ -102,10 +105,10 @@ XSLT::load(Inkscape::Extension::Extension *module)
 
     Inkscape::XML::Node *child_repr = sp_repr_children(module->get_repr());
     while (child_repr != NULL) {
-        if (!strcmp(child_repr->name(), "xslt")) {
+        if (!strcmp(child_repr->name(), INKSCAPE_EXTENSION_NS "xslt")) {
             child_repr = sp_repr_children(child_repr);
             while (child_repr != NULL) {
-                if (!strcmp(child_repr->name(), "file")) {
+                if (!strcmp(child_repr->name(), INKSCAPE_EXTENSION_NS "file")) {
                     _filename = solve_reldir(child_repr);
                 }
                 child_repr = sp_repr_next(child_repr);
@@ -134,7 +137,7 @@ XSLT::unload(Inkscape::Extension::Extension *module)
 }
 
 SPDocument *
-XSLT::open(Inkscape::Extension::Input *module, gchar const *filename)
+XSLT::open(Inkscape::Extension::Input */*module*/, gchar const *filename)
 {
     xmlDocPtr filein = xmlParseFile(filename);
     if (filein == NULL) { return NULL; }
@@ -144,7 +147,7 @@ XSLT::open(Inkscape::Extension::Input *module, gchar const *filename)
 
     xmlDocPtr result = xsltApplyStylesheet(_stylesheet, filein, params);
     xmlFreeDoc(filein);
-    
+
     Inkscape::XML::Document * rdoc = sp_repr_do_read( result, SP_SVG_NS_URI);
     xmlFreeDoc(result);
 
@@ -168,7 +171,7 @@ XSLT::open(Inkscape::Extension::Input *module, gchar const *filename)
     } else {
         base = NULL;
         name = g_strdup(filename);
-    }    
+    }
     g_free(s);
 
     SPDocument * doc = sp_document_create(rdoc, filename, base, name, true);
@@ -179,29 +182,27 @@ XSLT::open(Inkscape::Extension::Input *module, gchar const *filename)
 }
 
 void
-XSLT::save(Inkscape::Extension::Output *module, SPDocument *doc, gchar const *filename)
+XSLT::save(Inkscape::Extension::Output */*module*/, SPDocument *doc, gchar const *filename)
 {
+    /* TODO: Should we assume filename to be in utf8 or to be a raw filename?
+     * See JavaFXOutput::save for discussion. */
     g_return_if_fail(doc != NULL);
     g_return_if_fail(filename != NULL);
 
     Inkscape::XML::Node *repr = NULL;
     repr = sp_document_repr_root (doc);
 
-    gchar *save_path = g_path_get_dirname (filename);
-    Inkscape::IO::fixupHrefs( doc, save_path, true );
-    g_free(save_path);
-
     std::string tempfilename_out;
     int tempfd_out = 0;
     try {
-        tempfd_out = Glib::file_open_tmp(tempfilename_out, "ink_ext_XXXXXX");
+        tempfd_out = Inkscape::IO::file_open_tmp(tempfilename_out, "ink_ext_XXXXXX");
     } catch (...) {
         /// \todo Popup dialog here
         return;
     }
 
-    gboolean const s = sp_repr_save_file (repr->document(), tempfilename_out.c_str(), SP_SVG_NS_URI);
-    if (s == FALSE) {
+    if (!sp_repr_save_rebased_file(repr->document(), tempfilename_out.c_str(), SP_SVG_NS_URI,
+                                   doc->base, filename)) {
         throw Inkscape::Extension::Output::save_failed();
     }