[oform] Handle relative links writing to xml

This commit is contained in:
KirillovIlya
2022-12-23 19:48:41 +03:00
parent b782a77389
commit dbd10ccedc
5 changed files with 64 additions and 51 deletions

View File

@ -234,9 +234,9 @@
if (!xmlContext.haveUserPart(user))
{
xmlWriter.Seek(0);
let part = main.addPartWithoutRels(AscCommon.openXml.Types.oformUser);
let part = xmlPkg.addPart(AscCommon.openXml.Types.oformUser);
if (part)
part.setDataXml(user, xmlWriter);
part.part.setDataXml(user, xmlWriter);
}
});
@ -245,9 +245,9 @@
if (!xmlContext.haveUserMasterPart(userMaster))
{
xmlWriter.Seek(0);
let part = main.addPartWithoutRels(AscCommon.openXml.Types.oformUserMaster);
let part = xmlPkg.addPart(AscCommon.openXml.Types.oformUserMaster);
if (part)
part.setDataXml(userMaster, xmlWriter);
part.part.setDataXml(userMaster, xmlWriter);
}
});
@ -256,9 +256,9 @@
if (!xmlContext.haveFieldMasterPart(fieldMaster))
{
xmlWriter.Seek(0);
let part = main.addPartWithoutRels(AscCommon.openXml.Types.oformFieldMaster);
let part = xmlPkg.addPart(AscCommon.openXml.Types.oformFieldMaster);
if (part)
part.setDataXml(fieldMaster, xmlWriter);
part.part.setDataXml(fieldMaster, xmlWriter);
}
});
};

View File

@ -204,19 +204,19 @@
continue;
writer.WriteXmlNodeStart("user");
writer.WriteXmlNullableAttributeString("r:id", part.rId);
writer.WriteXmlNullableAttributeString("r:id", context.getRId(part));
writer.WriteXmlAttributesEnd(true);
}
for (let fieldIndex = 0, fieldCount = this.Fields.length; fieldIndex < fieldCount; ++fieldIndex)
{
// let part = context.getFieldMasterPart(this.Fields[fieldIndex]);
// if (!part)
// continue;
//
// writer.WriteXmlNodeStart("field");
// writer.WriteXmlNullableAttributeString("r:id", part.rId);
// writer.WriteXmlAttributesEnd(true);
let part = context.getFieldMasterPart(this.Fields[fieldIndex]);
if (!part)
continue;
writer.WriteXmlNodeStart("field");
writer.WriteXmlNullableAttributeString("r:id", context.getRId(part));
writer.WriteXmlAttributesEnd(true);
}
writer.WriteXmlNodeEnd("fieldGroup");

View File

@ -81,31 +81,9 @@
{
return this.UserMaster;
};
CUser.prototype.readChildXml = function(name, reader)
{
let bRead = false;
switch (name)
{
case "Email":
{
let node = CT_XmlNode.fromReader(reader);
this.setEmail(node.text);
bRead = true;
break;
}
case "Telephone":
{
let node = CT_XmlNode.fromReader(reader);
this.setTelephone(node.text);
bRead = true;
break;
}
}
return bRead;
};
CUser.prototype.toXml = function(writer)
{
writer.WriteXmlString(AscCommonWord.g_sXmlHeader);
writer.WriteXmlHeader();
writer.WriteXmlNodeStart("user");
writer.WriteXmlAttributesEnd();
@ -114,8 +92,6 @@
if (this.Telephone)
writer.WriteXmlNodeWithText("telephone", this.Telephone);
// TODO: color
writer.WriteXmlNodeEnd("user");
};
CUser.fromXml = function(reader)

View File

@ -190,9 +190,41 @@
XmlWriterContext.prototype.clearCurrentPartDataMaps = function()
{
};
XmlWriterContext.prototype.getUserPart = function(user, part)
XmlWriterContext.prototype.getRId = function(part)
{
return this.getPart(this.userToPart, user, AscCommon.openXml.Types.oformUser);
if (!this.part)
return "";
let target = part.uri;
let base = this.part.uri;
if (target.startsWith('/'))
target = target.substring(1);
if (base.startsWith('/'))
base = base.substring(1);
let baseSplit = base.split('/');
let targetSplit = target.split('/');
while (baseSplit.length && targetSplit.length && baseSplit[0] === targetSplit[0])
{
baseSplit.shift();
targetSplit.shift()
}
let relative = "";
for (let index = 0, count = baseSplit.length - 1; index < count; ++index)
{
relative += "../";
}
relative += targetSplit.join('/');
return this.part.addRelationship(null, relative);
};
XmlWriterContext.prototype.getUserPart = function(user)
{
return this.getPartFromPkg(this.userToPart, user, AscCommon.openXml.Types.oformUser);
};
XmlWriterContext.prototype.haveUserPart = function(user)
{
@ -200,7 +232,7 @@
};
XmlWriterContext.prototype.getUserMasterPart = function(userMaster)
{
return this.getPart(this.userMasterToPart, userMaster, AscCommon.openXml.Types.oformUserMaster);
return this.getPartFromPkg(this.userMasterToPart, userMaster, AscCommon.openXml.Types.oformUserMaster);
};
XmlWriterContext.prototype.haveUserMasterPart = function(userMaster)
{
@ -208,7 +240,7 @@
};
XmlWriterContext.prototype.getFieldPart = function(field)
{
return this.getPart(this.fieldToPart, field, AscCommon.openXml.Types.oformField);
return this.getPartFromPkg(this.fieldToPart, field, AscCommon.openXml.Types.oformField);
};
XmlWriterContext.prototype.haveFieldPart = function(field)
{
@ -216,7 +248,7 @@
};
XmlWriterContext.prototype.getFieldMasterPart = function(fieldMaster)
{
return this.getPart(this.fieldMasterToPart, fieldMaster, AscCommon.openXml.Types.oformFieldMaster);
return this.getPartFromPkg(this.fieldMasterToPart, fieldMaster, AscCommon.openXml.Types.oformFieldMaster);
};
XmlWriterContext.prototype.haveFieldMasterPart = function(fieldMaster)
{
@ -225,18 +257,18 @@
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Private area
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
XmlWriterContext.prototype.getPart = function(map, object, contentType, curPart)
XmlWriterContext.prototype.getPartFromPkg = function(map, object, contentType)
{
let objectId = object.GetId();
if (map[objectId])
return map[objectId];
let part = curPart.addPart(contentType);
let part = this.pkg.addPart(contentType).part;
let xmlWriter = new AscCommon.CMemory();
xmlWriter.context = this;
part.part.setDataXml(object, xmlWriter);
part.setDataXml(object, xmlWriter);
map[objectId] = part;
return part;

File diff suppressed because one or more lines are too long