2017-03-27 21:35:15 +00:00
|
|
|
/* 9.3 Relationships */
|
2017-02-10 19:23:01 +00:00
|
|
|
var RELS = ({
|
2014-05-16 00:33:34 +00:00
|
|
|
WB: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument",
|
|
|
|
SHEET: "http://sheetjs.openxmlformats.org/officeDocument/2006/relationships/officeDocument"
|
2017-02-10 19:23:01 +00:00
|
|
|
}/*:any*/);
|
2014-05-16 00:33:34 +00:00
|
|
|
|
2017-03-27 21:35:15 +00:00
|
|
|
/* 9.3.3 Representing Relationships */
|
|
|
|
function get_rels_path(file/*:string*/)/*:string*/ {
|
|
|
|
var n = file.lastIndexOf("/");
|
|
|
|
return file.substr(0,n) + '/_rels' + file.substr(n) + ".rels";
|
|
|
|
}
|
|
|
|
|
2017-02-10 19:23:01 +00:00
|
|
|
function parse_rels(data/*:?string*/, currentFilePath/*:string*/) {
|
2014-05-16 00:33:34 +00:00
|
|
|
if (!data) return data;
|
|
|
|
if (currentFilePath.charAt(0) !== '/') {
|
|
|
|
currentFilePath = '/'+currentFilePath;
|
|
|
|
}
|
|
|
|
var rels = {};
|
|
|
|
var hash = {};
|
|
|
|
|
2017-02-10 19:23:01 +00:00
|
|
|
(data.match(tagregex)||[]).forEach(function(x) {
|
2014-05-16 00:33:34 +00:00
|
|
|
var y = parsexmltag(x);
|
|
|
|
/* 9.3.2.2 OPC_Relationships */
|
|
|
|
if (y[0] === '<Relationship') {
|
|
|
|
var rel = {}; rel.Type = y.Type; rel.Target = y.Target; rel.Id = y.Id; rel.TargetMode = y.TargetMode;
|
2017-03-27 21:35:15 +00:00
|
|
|
var canonictarget = y.TargetMode === 'External' ? y.Target : resolve_path(y.Target, currentFilePath);
|
2014-05-16 00:33:34 +00:00
|
|
|
rels[canonictarget] = rel;
|
|
|
|
hash[y.Id] = rel;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
rels["!id"] = hash;
|
|
|
|
return rels;
|
|
|
|
}
|
|
|
|
|
|
|
|
XMLNS.RELS = 'http://schemas.openxmlformats.org/package/2006/relationships';
|
|
|
|
|
|
|
|
var RELS_ROOT = writextag('Relationships', null, {
|
|
|
|
//'xmlns:ns0': XMLNS.RELS,
|
|
|
|
'xmlns': XMLNS.RELS
|
|
|
|
});
|
|
|
|
|
|
|
|
/* TODO */
|
2017-02-10 19:23:01 +00:00
|
|
|
function write_rels(rels)/*:string*/ {
|
2014-05-16 00:33:34 +00:00
|
|
|
var o = [];
|
2014-06-29 18:29:45 +00:00
|
|
|
o[o.length] = (XML_HEADER);
|
|
|
|
o[o.length] = (RELS_ROOT);
|
2014-05-16 00:33:34 +00:00
|
|
|
keys(rels['!id']).forEach(function(rid) { var rel = rels['!id'][rid];
|
2014-06-29 18:29:45 +00:00
|
|
|
o[o.length] = (writextag('Relationship', null, rel));
|
2014-05-16 00:33:34 +00:00
|
|
|
});
|
2014-06-29 18:29:45 +00:00
|
|
|
if(o.length>2){ o[o.length] = ('</Relationships>'); o[1]=o[1].replace("/>",">"); }
|
2014-05-16 00:33:34 +00:00
|
|
|
return o.join("");
|
|
|
|
}
|