Skip to content
This repository has been archived by the owner on May 12, 2020. It is now read-only.

Commit

Permalink
* Add webodfversion.js.in (thanks Friedrich!)
Browse files Browse the repository at this point in the history
to track the webodf version in js.
* OdfContainer gets updateMetadataForSaving,
which is called just before saving
and updates dc:generator.
  • Loading branch information
adityab committed Nov 25, 2013
1 parent b53d615 commit 6826fe2
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
6 changes: 5 additions & 1 deletion webodf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ if(WRONGCMAKEDIR)
message(FATAL_ERROR "You should point CMake to the parent directory.")
endif(WRONGCMAKEDIR)

configure_file(webodfversion.js.in ${CMAKE_CURRENT_BINARY_DIR}/webodfversion.js)

set(TESTJSFILES tests/core/ZipTests.js
tests/core/Base64Tests.js
tests/core/DomUtilsTests.js
Expand Down Expand Up @@ -36,6 +38,7 @@ add_custom_target(jslintcheck ALL
COMMAND ${NODE} lib/runtime.js tools/runjslint.js
${LIBJSFILES} ${TESTJSFILES}
${CMAKE_CURRENT_BINARY_DIR}/webodf.css.js
${CMAKE_CURRENT_BINARY_DIR}/webodfversion.js
DEPENDS NodeJS webodf.css.js
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
SOURCES ${LIBJSFILES} ${TESTJSFILES}
Expand Down Expand Up @@ -71,7 +74,8 @@ if (Java_JAVA_EXECUTABLE)
endforeach(JSFILE ${TESTJSFILES})

set(LIB_CLOSURE_ARGS ${LIB_CLOSURE_ARGS}
--js ${CMAKE_CURRENT_BINARY_DIR}/webodf.css.js)
--js ${CMAKE_CURRENT_BINARY_DIR}/webodf.css.js
--js ${CMAKE_CURRENT_BINARY_DIR}/webodfversion.js)

add_custom_command(
OUTPUT simplecompiled.js
Expand Down
33 changes: 32 additions & 1 deletion webodf/lib/odf/OdfContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
* @source: https://github.com/kogmbh/WebODF/
*/

/*global Node, NodeFilter, runtime, core, xmldom, odf, DOMParser, document*/
/*global Node, NodeFilter, runtime, core, xmldom, odf, DOMParser, document, webodf_version */

runtime.loadClass("core.Base64");
runtime.loadClass("core.Zip");
Expand Down Expand Up @@ -904,6 +904,32 @@ odf.OdfContainer = (function () {
zip.load(url, callback);
};

/**
* Write pre-saving metadata to the DOM
* @return {undefined}
*/
function updateMetadataForSaving() {
// set the opendocument provider used to create/
// last modify the document.
// this string should match the definition for
// user-agents in the http protocol as specified
// in section 14.43 of [RFC2616].
var generatorString,
window = runtime.getWindow();

generatorString = "WebODF/" + (
String(typeof webodf_version) !== "undefined"
? webodf_version
: "FromSource"
);

if (window) {
generatorString = generatorString + " " + window.navigator.userAgent;
}

metadataManager.setMetadata({"meta:generator": generatorString});
}

/**
* @return {!core.Zip}
*/
Expand Down Expand Up @@ -941,6 +967,8 @@ odf.OdfContainer = (function () {
addToplevelElement("body");
root.body.appendChild(text);

initializeMetadataManager(root.meta);

setState(OdfContainer.DONE);
return emptyzip;
}
Expand All @@ -955,6 +983,9 @@ odf.OdfContainer = (function () {
// update the zip entries with the data from the live ODF DOM
var data,
date = new Date();

updateMetadataForSaving();

data = runtime.byteArrayFromString(serializeSettingsXml(), "utf8");
zip.save("settings.xml", data, true, date);
data = runtime.byteArrayFromString(serializeMetaXml(), "utf8");
Expand Down
1 change: 1 addition & 0 deletions webodf/webodfversion.js.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
var /**@const{!string}*/webodf_version = "@WEBODF_VERSION@";

0 comments on commit 6826fe2

Please sign in to comment.