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) */
|
|
|
|
var CORE_PROPS = [
|
|
|
|
["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']
|
|
|
|
];
|
|
|
|
|
|
|
|
XMLNS.CORE_PROPS = "http://schemas.openxmlformats.org/package/2006/metadata/core-properties";
|
|
|
|
RELS.CORE_PROPS = 'http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties';
|
|
|
|
|
|
|
|
|
|
|
|
function parse_core_props(data) {
|
|
|
|
var p = {};
|
|
|
|
|
2014-06-29 18:29:45 +00:00
|
|
|
for(var i = 0; i != CORE_PROPS.length; ++i) {
|
|
|
|
var f = CORE_PROPS[i];
|
2014-05-16 00:33:34 +00:00
|
|
|
var g = "(?:"+ f[0].substr(0,f[0].indexOf(":")) +":)"+ f[0].substr(f[0].indexOf(":")+1);
|
|
|
|
var cur = data.match(new RegExp("<" + g + "[^>]*>(.*)<\/" + g + ">"));
|
2014-06-29 18:29:45 +00:00
|
|
|
if(cur != null && cur.length > 0) p[f[1]] = cur[1];
|
2014-05-16 00:33:34 +00:00
|
|
|
if(f[2] === 'date' && p[f[1]]) p[f[1]] = new Date(p[f[1]]);
|
2014-06-29 18:29:45 +00:00
|
|
|
}
|
2014-05-16 00:33:34 +00:00
|
|
|
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
var CORE_PROPS_XML_ROOT = 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
|
|
|
|
});
|
|
|
|
|
2014-06-29 18:29:45 +00:00
|
|
|
function cp_doit(f, g, h, o, p) {
|
|
|
|
if(p[f] != null || g == null || g === "") return;
|
|
|
|
if(typeof g !== 'string') g = String(g); /* TODO: remove */
|
|
|
|
p[f] = g;
|
|
|
|
o[o.length] = (h ? writextag(f,g,h) : writetag(f,g));
|
|
|
|
}
|
|
|
|
|
2014-05-16 00:33:34 +00:00
|
|
|
function write_core_props(cp, opts) {
|
2014-06-29 18:29:45 +00:00
|
|
|
var o = [XML_HEADER, CORE_PROPS_XML_ROOT], p = {};
|
2014-05-16 00:33:34 +00:00
|
|
|
if(!cp) return o.join("");
|
|
|
|
|
|
|
|
|
2014-06-29 18:29:45 +00:00
|
|
|
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
|
|
|
|
2014-06-29 18:29:45 +00:00
|
|
|
for(var i = 0; i != CORE_PROPS.length; ++i) { var f = CORE_PROPS[i]; cp_doit(f[0], cp[f[1]], null, o, p); }
|
|
|
|
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("");
|
|
|
|
}
|