2017-04-10 05:10:54 +00:00
|
|
|
/* Common Name -> XLML Name */
|
|
|
|
var XLMLDocPropsMap = {
|
2017-04-26 02:27:12 +00:00
|
|
|
Title: 'Title',
|
|
|
|
Subject: 'Subject',
|
|
|
|
Author: 'Author',
|
2017-04-10 05:10:54 +00:00
|
|
|
Keywords: 'Keywords',
|
2017-04-26 02:27:12 +00:00
|
|
|
Comments: 'Description',
|
2017-04-10 05:10:54 +00:00
|
|
|
LastAuthor: 'LastAuthor',
|
|
|
|
RevNumber: 'Revision',
|
2017-04-26 02:27:12 +00:00
|
|
|
Application: 'AppName',
|
|
|
|
/* TotalTime: 'TotalTime', */
|
|
|
|
LastPrinted: 'LastPrinted',
|
2017-04-10 05:10:54 +00:00
|
|
|
CreatedDate: 'Created',
|
|
|
|
ModifiedDate: 'LastSaved',
|
2017-04-26 02:27:12 +00:00
|
|
|
/* Pages */
|
|
|
|
/* Words */
|
|
|
|
/* Characters */
|
|
|
|
Category: 'Category',
|
|
|
|
/* PresentationFormat */
|
2017-04-10 05:10:54 +00:00
|
|
|
Manager: 'Manager',
|
2017-04-26 02:27:12 +00:00
|
|
|
Company: 'Company',
|
|
|
|
/* Guid */
|
|
|
|
/* HyperlinkBase */
|
|
|
|
/* Bytes */
|
|
|
|
/* Lines */
|
|
|
|
/* Paragraphs */
|
|
|
|
/* CharactersWithSpaces */
|
|
|
|
AppVersion: 'Version',
|
|
|
|
|
|
|
|
ContentStatus: 'ContentStatus', /* NOTE: missing from schema */
|
|
|
|
Identifier: 'Identifier', /* NOTE: missing from schema */
|
|
|
|
Language: 'Language' /* NOTE: missing from schema */
|
2017-04-10 05:10:54 +00:00
|
|
|
};
|
|
|
|
var evert_XLMLDPM = evert(XLMLDocPropsMap);
|
|
|
|
|
2017-02-10 19:23:01 +00:00
|
|
|
function xlml_set_prop(Props, tag/*:string*/, val) {
|
2017-04-10 05:10:54 +00:00
|
|
|
tag = evert_XLMLDPM[tag] || tag;
|
2015-04-02 20:32:22 +00:00
|
|
|
Props[tag] = val;
|
|
|
|
}
|
|
|
|
|
2017-04-10 05:10:54 +00:00
|
|
|
function xlml_write_docprops(Props, opts) {
|
2017-12-30 05:40:35 +00:00
|
|
|
var o/*:Array<string>*/ = [];
|
2017-04-26 02:27:12 +00:00
|
|
|
keys(XLMLDocPropsMap).map(function(m) {
|
|
|
|
for(var i = 0; i < CORE_PROPS.length; ++i) if(CORE_PROPS[i][1] == m) return CORE_PROPS[i];
|
|
|
|
for(i = 0; i < EXT_PROPS.length; ++i) if(EXT_PROPS[i][1] == m) return EXT_PROPS[i];
|
|
|
|
throw m;
|
|
|
|
}).forEach(function(p) {
|
2017-04-10 05:10:54 +00:00
|
|
|
if(Props[p[1]] == null) return;
|
|
|
|
var m = opts && opts.Props && opts.Props[p[1]] != null ? opts.Props[p[1]] : Props[p[1]];
|
2017-03-14 08:19:51 +00:00
|
|
|
switch(p[2]) {
|
2017-04-26 02:27:12 +00:00
|
|
|
case 'date': m = new Date(m).toISOString().replace(/\.\d*Z/,"Z"); break;
|
2017-03-14 08:19:51 +00:00
|
|
|
}
|
2017-04-10 05:10:54 +00:00
|
|
|
if(typeof m == 'number') m = String(m);
|
2017-04-11 22:15:36 +00:00
|
|
|
else if(m === true || m === false) { m = m ? "1" : "0"; }
|
2017-04-26 02:27:12 +00:00
|
|
|
else if(m instanceof Date) m = new Date(m).toISOString().replace(/\.\d*Z/,"");
|
2017-04-10 05:10:54 +00:00
|
|
|
o.push(writetag(XLMLDocPropsMap[p[1]] || p[1], m));
|
2017-03-14 08:19:51 +00:00
|
|
|
});
|
2017-04-10 05:10:54 +00:00
|
|
|
return writextag('DocumentProperties', o.join(""), {xmlns:XLMLNS.o });
|
2017-03-14 08:19:51 +00:00
|
|
|
}
|
2017-04-10 05:10:54 +00:00
|
|
|
function xlml_write_custprops(Props, Custprops, opts) {
|
|
|
|
var BLACKLIST = ["Worksheets","SheetNames"];
|
2017-03-14 08:19:51 +00:00
|
|
|
var T = 'CustomDocumentProperties';
|
2017-12-30 05:40:35 +00:00
|
|
|
var o/*:Array<string>*/ = [];
|
2017-03-14 08:19:51 +00:00
|
|
|
if(Props) keys(Props).forEach(function(k) {
|
|
|
|
/*:: if(!Props) return; */
|
|
|
|
if(!Props.hasOwnProperty(k)) return;
|
2017-04-10 05:10:54 +00:00
|
|
|
for(var i = 0; i < CORE_PROPS.length; ++i) if(k == CORE_PROPS[i][1]) return;
|
|
|
|
for(i = 0; i < EXT_PROPS.length; ++i) if(k == EXT_PROPS[i][1]) return;
|
|
|
|
for(i = 0; i < BLACKLIST.length; ++i) if(k == BLACKLIST[i]) return;
|
|
|
|
|
2017-03-14 08:19:51 +00:00
|
|
|
var m = Props[k];
|
|
|
|
var t = "string";
|
|
|
|
if(typeof m == 'number') { t = "float"; m = String(m); }
|
|
|
|
else if(m === true || m === false) { t = "boolean"; m = m ? "1" : "0"; }
|
|
|
|
else m = String(m);
|
|
|
|
o.push(writextag(escapexmltag(k), m, {"dt:dt":t}));
|
|
|
|
});
|
|
|
|
if(Custprops) keys(Custprops).forEach(function(k) {
|
|
|
|
/*:: if(!Custprops) return; */
|
|
|
|
if(!Custprops.hasOwnProperty(k)) return;
|
|
|
|
var m = Custprops[k];
|
|
|
|
var t = "string";
|
|
|
|
if(typeof m == 'number') { t = "float"; m = String(m); }
|
|
|
|
else if(m === true || m === false) { t = "boolean"; m = m ? "1" : "0"; }
|
|
|
|
else if(m instanceof Date) { t = "dateTime.tz"; m = m.toISOString(); }
|
|
|
|
else m = String(m);
|
|
|
|
o.push(writextag(escapexmltag(k), m, {"dt:dt":t}));
|
|
|
|
});
|
|
|
|
return '<' + T + ' xmlns="' + XLMLNS.o + '">' + o.join("") + '</' + T + '>';
|
|
|
|
}
|