forked from sheetjs/sheetjs
SheetJS
6bc24374b9
- parsexmltag and other hot functions now better optimized for v8 - monomorphic functions (different types -> different funcs) - more efficient decode_range implementation when source is trusted - regular expressions cached and simplified without breaking correctness - more efficient utf8 techniques when available - XLSX: large functions broken down into sub-functions (e.g. `parse_ws_xml`) - XLSB: avoid unnecessary binds - XLSB: assume no exotic codepage exists (no one else tries to write XLSB) - demo exposes rABS / worker / transferable options - more tests - jszip updated to 2.3.0 - SSF updated to 0.8.1 - codepage updated to 1.3.1
62 lines
1.8 KiB
JavaScript
62 lines
1.8 KiB
JavaScript
/* 9.3.2 OPC Relationships Markup */
|
|
var RELS = {
|
|
WB: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument",
|
|
SHEET: "http://sheetjs.openxmlformats.org/officeDocument/2006/relationships/officeDocument"
|
|
};
|
|
|
|
function parse_rels(data, currentFilePath) {
|
|
if (!data) return data;
|
|
if (currentFilePath.charAt(0) !== '/') {
|
|
currentFilePath = '/'+currentFilePath;
|
|
}
|
|
var rels = {};
|
|
var hash = {};
|
|
var resolveRelativePathIntoAbsolute = function (to) {
|
|
var toksFrom = currentFilePath.split('/');
|
|
toksFrom.pop(); // folder path
|
|
var toksTo = to.split('/');
|
|
var reversed = [];
|
|
while (toksTo.length !== 0) {
|
|
var tokTo = toksTo.shift();
|
|
if (tokTo === '..') {
|
|
toksFrom.pop();
|
|
} else if (tokTo !== '.') {
|
|
toksFrom.push(tokTo);
|
|
}
|
|
}
|
|
return toksFrom.join('/');
|
|
};
|
|
|
|
data.match(tagregex).forEach(function(x) {
|
|
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;
|
|
var canonictarget = y.TargetMode === 'External' ? y.Target : resolveRelativePathIntoAbsolute(y.Target);
|
|
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 */
|
|
function write_rels(rels) {
|
|
var o = [];
|
|
o[o.length] = (XML_HEADER);
|
|
o[o.length] = (RELS_ROOT);
|
|
keys(rels['!id']).forEach(function(rid) { var rel = rels['!id'][rid];
|
|
o[o.length] = (writextag('Relationship', null, rel));
|
|
});
|
|
if(o.length>2){ o[o.length] = ('</Relationships>'); o[1]=o[1].replace("/>",">"); }
|
|
return o.join("");
|
|
}
|