2014-05-16 00:33:34 +00:00
|
|
|
/* ECMA-376 Part II 11.1 Core Properties Part */
|
|
|
|
/* [MS-OSHARED] 2.3.3.2.[1-2].1 (PIDSI/PIDDSI) */
|
2017-02-10 19:23:01 +00:00
|
|
|
var CORE_PROPS/*:Array<Array<string> >*/ = [
|
2014-05-16 00:33:34 +00:00
|
|
|
["cp:category", "Category"],
|
|
|
|
["cp:contentStatus", "ContentStatus"],
|
|
|
|
["cp:keywords", "Keywords"],
|
|
|
|
["cp:lastModifiedBy", "LastAuthor"],
|
|
|
|
["cp:lastPrinted", "LastPrinted"],
|
|
|
|
["cp:revision", "RevNumber"],
|
|
|
|
["cp:version", "Version"],
|
|
|
|
["dc:creator", "Author"],
|
|
|
|
["dc:description", "Comments"],
|
|
|
|
["dc:identifier", "Identifier"],
|
|
|
|
["dc:language", "Language"],
|
|
|
|
["dc:subject", "Subject"],
|
|
|
|
["dc:title", "Title"],
|
|
|
|
["dcterms:created", "CreatedDate", 'date'],
|
|
|
|
["dcterms:modified", "ModifiedDate", 'date']
|
|
|
|
];
|
|
|
|
|
2022-03-12 14:05:57 +00:00
|
|
|
var CORE_PROPS_REGEX/*:Array<RegExp>*/ = /*#__PURE__*/(function() {
|
2014-07-28 13:22:32 +00:00
|
|
|
var r = new Array(CORE_PROPS.length);
|
|
|
|
for(var i = 0; i < CORE_PROPS.length; ++i) {
|
|
|
|
var f = CORE_PROPS[i];
|
2018-01-11 08:01:25 +00:00
|
|
|
var g = "(?:"+ f[0].slice(0,f[0].indexOf(":")) +":)"+ f[0].slice(f[0].indexOf(":")+1);
|
2017-07-05 22:27:54 +00:00
|
|
|
r[i] = new RegExp("<" + g + "[^>]*>([\\s\\S]*?)<\/" + g + ">");
|
2014-07-28 13:22:32 +00:00
|
|
|
}
|
|
|
|
return r;
|
|
|
|
})();
|
2014-05-16 00:33:34 +00:00
|
|
|
|
|
|
|
function parse_core_props(data) {
|
|
|
|
var p = {};
|
2017-09-30 06:18:11 +00:00
|
|
|
data = utf8read(data);
|
2014-05-16 00:33:34 +00:00
|
|
|
|
2014-07-28 13:22:32 +00:00
|
|
|
for(var i = 0; i < CORE_PROPS.length; ++i) {
|
|
|
|
var f = CORE_PROPS[i], cur = data.match(CORE_PROPS_REGEX[i]);
|
2019-11-27 09:47:16 +00:00
|
|
|
if(cur != null && cur.length > 0) p[f[1]] = unescapexml(cur[1]);
|
2017-03-23 01:18:40 +00:00
|
|
|
if(f[2] === 'date' && p[f[1]]) p[f[1]] = parseDate(p[f[1]]);
|
2014-06-29 18:29:45 +00:00
|
|
|
}
|
2014-05-16 00:33:34 +00:00
|
|
|
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2014-06-29 18:29:45 +00:00
|
|
|
function cp_doit(f, g, h, o, p) {
|
|
|
|
if(p[f] != null || g == null || g === "") return;
|
|
|
|
p[f] = g;
|
2019-11-27 09:47:16 +00:00
|
|
|
g = escapexml(g);
|
2014-06-29 18:29:45 +00:00
|
|
|
o[o.length] = (h ? writextag(f,g,h) : writetag(f,g));
|
|
|
|
}
|
|
|
|
|
2017-04-10 05:10:54 +00:00
|
|
|
function write_core_props(cp, _opts) {
|
|
|
|
var opts = _opts || {};
|
2022-03-14 06:51:33 +00:00
|
|
|
var o = [XML_HEADER, writextag('cp:coreProperties', null, {
|
|
|
|
//'xmlns': XMLNS.CORE_PROPS,
|
|
|
|
'xmlns:cp': XMLNS.CORE_PROPS,
|
|
|
|
'xmlns:dc': XMLNS.dc,
|
|
|
|
'xmlns:dcterms': XMLNS.dcterms,
|
|
|
|
'xmlns:dcmitype': XMLNS.dcmitype,
|
|
|
|
'xmlns:xsi': XMLNS.xsi
|
|
|
|
})], p = {};
|
2017-04-10 05:10:54 +00:00
|
|
|
if(!cp && !opts.Props) return o.join("");
|
2014-05-16 00:33:34 +00:00
|
|
|
|
2017-04-10 05:10:54 +00:00
|
|
|
if(cp) {
|
|
|
|
if(cp.CreatedDate != null) cp_doit("dcterms:created", typeof cp.CreatedDate === "string" ? cp.CreatedDate : write_w3cdtf(cp.CreatedDate, opts.WTF), {"xsi:type":"dcterms:W3CDTF"}, o, p);
|
|
|
|
if(cp.ModifiedDate != null) cp_doit("dcterms:modified", typeof cp.ModifiedDate === "string" ? cp.ModifiedDate : write_w3cdtf(cp.ModifiedDate, opts.WTF), {"xsi:type":"dcterms:W3CDTF"}, o, p);
|
|
|
|
}
|
2014-05-16 00:33:34 +00:00
|
|
|
|
2017-04-10 05:10:54 +00:00
|
|
|
for(var i = 0; i != CORE_PROPS.length; ++i) {
|
|
|
|
var f = CORE_PROPS[i];
|
|
|
|
var v = opts.Props && opts.Props[f[1]] != null ? opts.Props[f[1]] : cp ? cp[f[1]] : null;
|
|
|
|
if(v === true) v = "1";
|
|
|
|
else if(v === false) v = "0";
|
|
|
|
else if(typeof v == "number") v = String(v);
|
|
|
|
if(v != null) cp_doit(f[0], v, null, o, p);
|
|
|
|
}
|
2014-06-29 18:29:45 +00:00
|
|
|
if(o.length>2){ o[o.length] = ('</cp:coreProperties>'); o[1]=o[1].replace("/>",">"); }
|
2014-05-16 00:33:34 +00:00
|
|
|
return o.join("");
|
|
|
|
}
|