mirror of
https://github.com/ONLYOFFICE/sdkjs-forms.git
synced 2026-03-31 10:23:35 +08:00
[oform] Handle relative links writing to xml
This commit is contained in:
@ -234,9 +234,9 @@
|
|||||||
if (!xmlContext.haveUserPart(user))
|
if (!xmlContext.haveUserPart(user))
|
||||||
{
|
{
|
||||||
xmlWriter.Seek(0);
|
xmlWriter.Seek(0);
|
||||||
let part = main.addPartWithoutRels(AscCommon.openXml.Types.oformUser);
|
let part = xmlPkg.addPart(AscCommon.openXml.Types.oformUser);
|
||||||
if (part)
|
if (part)
|
||||||
part.setDataXml(user, xmlWriter);
|
part.part.setDataXml(user, xmlWriter);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -245,9 +245,9 @@
|
|||||||
if (!xmlContext.haveUserMasterPart(userMaster))
|
if (!xmlContext.haveUserMasterPart(userMaster))
|
||||||
{
|
{
|
||||||
xmlWriter.Seek(0);
|
xmlWriter.Seek(0);
|
||||||
let part = main.addPartWithoutRels(AscCommon.openXml.Types.oformUserMaster);
|
let part = xmlPkg.addPart(AscCommon.openXml.Types.oformUserMaster);
|
||||||
if (part)
|
if (part)
|
||||||
part.setDataXml(userMaster, xmlWriter);
|
part.part.setDataXml(userMaster, xmlWriter);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -256,9 +256,9 @@
|
|||||||
if (!xmlContext.haveFieldMasterPart(fieldMaster))
|
if (!xmlContext.haveFieldMasterPart(fieldMaster))
|
||||||
{
|
{
|
||||||
xmlWriter.Seek(0);
|
xmlWriter.Seek(0);
|
||||||
let part = main.addPartWithoutRels(AscCommon.openXml.Types.oformFieldMaster);
|
let part = xmlPkg.addPart(AscCommon.openXml.Types.oformFieldMaster);
|
||||||
if (part)
|
if (part)
|
||||||
part.setDataXml(fieldMaster, xmlWriter);
|
part.part.setDataXml(fieldMaster, xmlWriter);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@ -204,19 +204,19 @@
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
writer.WriteXmlNodeStart("user");
|
writer.WriteXmlNodeStart("user");
|
||||||
writer.WriteXmlNullableAttributeString("r:id", part.rId);
|
writer.WriteXmlNullableAttributeString("r:id", context.getRId(part));
|
||||||
writer.WriteXmlAttributesEnd(true);
|
writer.WriteXmlAttributesEnd(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let fieldIndex = 0, fieldCount = this.Fields.length; fieldIndex < fieldCount; ++fieldIndex)
|
for (let fieldIndex = 0, fieldCount = this.Fields.length; fieldIndex < fieldCount; ++fieldIndex)
|
||||||
{
|
{
|
||||||
// let part = context.getFieldMasterPart(this.Fields[fieldIndex]);
|
let part = context.getFieldMasterPart(this.Fields[fieldIndex]);
|
||||||
// if (!part)
|
if (!part)
|
||||||
// continue;
|
continue;
|
||||||
//
|
|
||||||
// writer.WriteXmlNodeStart("field");
|
writer.WriteXmlNodeStart("field");
|
||||||
// writer.WriteXmlNullableAttributeString("r:id", part.rId);
|
writer.WriteXmlNullableAttributeString("r:id", context.getRId(part));
|
||||||
// writer.WriteXmlAttributesEnd(true);
|
writer.WriteXmlAttributesEnd(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
writer.WriteXmlNodeEnd("fieldGroup");
|
writer.WriteXmlNodeEnd("fieldGroup");
|
||||||
|
|||||||
@ -81,31 +81,9 @@
|
|||||||
{
|
{
|
||||||
return this.UserMaster;
|
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)
|
CUser.prototype.toXml = function(writer)
|
||||||
{
|
{
|
||||||
writer.WriteXmlString(AscCommonWord.g_sXmlHeader);
|
writer.WriteXmlHeader();
|
||||||
writer.WriteXmlNodeStart("user");
|
writer.WriteXmlNodeStart("user");
|
||||||
writer.WriteXmlAttributesEnd();
|
writer.WriteXmlAttributesEnd();
|
||||||
|
|
||||||
@ -114,8 +92,6 @@
|
|||||||
if (this.Telephone)
|
if (this.Telephone)
|
||||||
writer.WriteXmlNodeWithText("telephone", this.Telephone);
|
writer.WriteXmlNodeWithText("telephone", this.Telephone);
|
||||||
|
|
||||||
// TODO: color
|
|
||||||
|
|
||||||
writer.WriteXmlNodeEnd("user");
|
writer.WriteXmlNodeEnd("user");
|
||||||
};
|
};
|
||||||
CUser.fromXml = function(reader)
|
CUser.fromXml = function(reader)
|
||||||
|
|||||||
@ -190,9 +190,41 @@
|
|||||||
XmlWriterContext.prototype.clearCurrentPartDataMaps = function()
|
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)
|
XmlWriterContext.prototype.haveUserPart = function(user)
|
||||||
{
|
{
|
||||||
@ -200,7 +232,7 @@
|
|||||||
};
|
};
|
||||||
XmlWriterContext.prototype.getUserMasterPart = function(userMaster)
|
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)
|
XmlWriterContext.prototype.haveUserMasterPart = function(userMaster)
|
||||||
{
|
{
|
||||||
@ -208,7 +240,7 @@
|
|||||||
};
|
};
|
||||||
XmlWriterContext.prototype.getFieldPart = function(field)
|
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)
|
XmlWriterContext.prototype.haveFieldPart = function(field)
|
||||||
{
|
{
|
||||||
@ -216,7 +248,7 @@
|
|||||||
};
|
};
|
||||||
XmlWriterContext.prototype.getFieldMasterPart = function(fieldMaster)
|
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)
|
XmlWriterContext.prototype.haveFieldMasterPart = function(fieldMaster)
|
||||||
{
|
{
|
||||||
@ -225,18 +257,18 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// Private area
|
// Private area
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
XmlWriterContext.prototype.getPart = function(map, object, contentType, curPart)
|
XmlWriterContext.prototype.getPartFromPkg = function(map, object, contentType)
|
||||||
{
|
{
|
||||||
let objectId = object.GetId();
|
let objectId = object.GetId();
|
||||||
if (map[objectId])
|
if (map[objectId])
|
||||||
return map[objectId];
|
return map[objectId];
|
||||||
|
|
||||||
let part = curPart.addPart(contentType);
|
let part = this.pkg.addPart(contentType).part;
|
||||||
|
|
||||||
let xmlWriter = new AscCommon.CMemory();
|
let xmlWriter = new AscCommon.CMemory();
|
||||||
xmlWriter.context = this;
|
xmlWriter.context = this;
|
||||||
|
|
||||||
part.part.setDataXml(object, xmlWriter);
|
part.setDataXml(object, xmlWriter);
|
||||||
|
|
||||||
map[objectId] = part;
|
map[objectId] = part;
|
||||||
return part;
|
return part;
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user