Browse Source

org-odt: Include mimetype in the exported odt file

* contrib/lisp/org-odt.el (org-export-odt-save-list): Add the
file "mimetype".
(org-odt-init-outfile): Write contents of "mimetype".
(org-odt-save-as-outfile): Include "mimetype" file in the
exported file.
(org-export-odt-mimetype-lines): Removed.

This change knocks of an error while validating against
http://tools.services.openoffice.org/odfvalidator/.
Jambunathan K 13 years ago
parent
commit
5aae06d9f4
1 changed files with 16 additions and 16 deletions
  1. 16 16
      contrib/lisp/org-odt.el

+ 16 - 16
contrib/lisp/org-odt.el

@@ -1091,7 +1091,7 @@ MAY-INLINE-P allows inlining it as an image."
 
 
 ;; xml files generated on-the-fly
 ;; xml files generated on-the-fly
 (defconst org-export-odt-save-list
 (defconst org-export-odt-save-list
-  '("META-INF/manifest.xml" "content.xml" "meta.xml" "styles.xml"))
+  '("mimetype" "META-INF/manifest.xml" "content.xml" "meta.xml" "styles.xml"))
 
 
 ;; xml files that are copied
 ;; xml files that are copied
 (defconst org-export-odt-nosave-list '())
 (defconst org-export-odt-nosave-list '())
@@ -1262,6 +1262,10 @@ MAY-INLINE-P allows inlining it as an image."
       (save-excursion
       (save-excursion
 	(insert (mapconcat 'identity (cdr org-export-odt-meta-lines) "\n"))))
 	(insert (mapconcat 'identity (cdr org-export-odt-meta-lines) "\n"))))
 
 
+    ;; mimetype
+    (with-current-buffer (find-file-noselect mimetype-file t)
+      (insert "application/vnd.oasis.opendocument.text"))
+
     ;; styles file
     ;; styles file
     ;; (copy-file org-export-odt-styles-file styles-file t)
     ;; (copy-file org-export-odt-styles-file styles-file t)
 
 
@@ -1273,9 +1277,6 @@ MAY-INLINE-P allows inlining it as an image."
 	  (append org-export-odt-save-list org-export-odt-nosave-list)))
 	  (append org-export-odt-save-list org-export-odt-nosave-list)))
     content-file))
     content-file))
 
 
-(defconst org-export-odt-mimetype-lines
-  '("application/vnd.oasis.opendocument.text"))
-
 (defconst org-odt-manifest-file-entry-tag
 (defconst org-odt-manifest-file-entry-tag
   "<manifest:file-entry manifest:media-type=\"%s\" manifest:full-path=\"%s\"/>")
   "<manifest:file-entry manifest:media-type=\"%s\" manifest:full-path=\"%s\"/>")
 
 
@@ -1319,23 +1320,22 @@ MAY-INLINE-P allows inlining it as an image."
 
 
     (let* ((target-name (file-name-nondirectory target))
     (let* ((target-name (file-name-nondirectory target))
 	   (target-dir (file-name-directory target))
 	   (target-dir (file-name-directory target))
-	   (cmd (format "zip -rmTq %s %s" target-name ".")))
+	   (cmds `(("zip" "-mX0" ,target-name "mimetype")
+		   ("zip" "-rmTq" ,target-name "."))))
       (when (file-exists-p target)
       (when (file-exists-p target)
 	;; FIXME: If the file is locked this throws a cryptic error
 	;; FIXME: If the file is locked this throws a cryptic error
 	(delete-file target))
 	(delete-file target))
 
 
       (let ((coding-system-for-write 'no-conversion) exitcode)
       (let ((coding-system-for-write 'no-conversion) exitcode)
-	(message "Creating odt file using \"%s\"" cmd)
-	(setq exitcode
-	      (apply 'call-process
-		     "zip"
-		     nil
-		     nil
-		     nil
-		     (append (list "-rmTq") (list target-name "."))))
-
-	(or (zerop exitcode)
-	    (error "Unable to create odt file (%S)" exitcode)))
+	(message "Creating odt file...")
+	(mapc
+	 (lambda (cmd)
+	   (message "Running %s" (mapconcat 'identity cmd " "))
+	   (setq exitcode
+		 (apply 'call-process (car cmd) nil nil nil (cdr cmd)))
+	   (or (zerop exitcode)
+	       (error "Unable to create odt file (%S)" exitcode)))
+	 cmds))
 
 
       ;; move the file from outdir to target-dir
       ;; move the file from outdir to target-dir
       (rename-file target-name target-dir)
       (rename-file target-name target-dir)