1 /**
  2  * Copyright (C) 2012 KO GmbH <copyright@kogmbh.com>
  3  *
  4  * @licstart
  5  * This file is part of WebODF.
  6  *
  7  * WebODF is free software: you can redistribute it and/or modify it
  8  * under the terms of the GNU Affero General Public License (GNU AGPL)
  9  * as published by the Free Software Foundation, either version 3 of
 10  * the License, or (at your option) any later version.
 11  *
 12  * WebODF is distributed in the hope that it will be useful, but
 13  * WITHOUT ANY WARRANTY; without even the implied warranty of
 14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 15  * GNU Affero General Public License for more details.
 16  *
 17  * You should have received a copy of the GNU Affero General Public License
 18  * along with WebODF.  If not, see <http://www.gnu.org/licenses/>.
 19  * @licend
 20  *
 21  * @source: http://www.webodf.org/
 22  * @source: https://github.com/kogmbh/WebODF/
 23  */
 24 
 25 /*global runtime, core, odf*/
 26 
 27 /**
 28  * @constructor
 29  */
 30 odf.CommandLineTools = function CommandLineTools() {
 31     "use strict";
 32     /**
 33      * @param {!string} inputfilepath
 34      * @param {!string} outputfilepath
 35      * @param {!function(string=):undefined} callback
 36      * @return {!odf.OdfContainer}
 37      */
 38     this.roundTrip = function (inputfilepath, outputfilepath, callback) {
 39         function onready(odfcontainer) {
 40             if (odfcontainer.state === odf.OdfContainer.INVALID) {
 41                 return callback("Document " + inputfilepath + " is invalid.");
 42             }
 43             if (odfcontainer.state === odf.OdfContainer.DONE) {
 44                 odfcontainer.saveAs(outputfilepath, function (err) {
 45                     callback(err);
 46                 });
 47             } else {
 48                 callback("Document was not completely loaded.");
 49             }
 50         }
 51         var odfcontainer = new odf.OdfContainer(inputfilepath, onready);
 52         return odfcontainer;
 53     };
 54     /**
 55      * @param {!string} inputfilepath
 56      * @param {!Document} document
 57      * @param {!function(*):undefined} callback
 58      * @return {undefined}
 59      */
 60     this.render = function (inputfilepath, document, callback) {
 61         var body = document.getElementsByTagName("body")[0],
 62             odfcanvas;
 63         core.DomUtils.removeAllChildNodes(body);
 64         odfcanvas = new odf.OdfCanvas(body);
 65         odfcanvas.addListener("statereadychange", function (err) {
 66             callback(err);
 67         });
 68         odfcanvas.load(inputfilepath);
 69     };
 70 };
 71