8using NanoXLSX.Interfaces.Writer;
9using NanoXLSX.Registry;
10using NanoXLSX.Registry.Attributes;
12using System.Collections.Generic;
17 [NanoXlsxQueuePlugIn(PlugInUUID =
"EXTERNAL_LINK_PACKAGE_REGISTRY", QueueUUID = PlugInUUID.WriterPackageRegistryQueue, PlugInOrder = 20000)]
18 internal class ExternalLinkPackageRegistry : IPluginPackageRegistry
21 private const string packagePartPath =
"xl/externalLinks/";
22 private const string contentType =
@"application/vnd.openxmlformats-officedocument.spreadsheetml.externalLink+xml";
23 private const string relationshipType =
@"http://schemas.openxmlformats.org/officeDocument/2006/relationships/externalLink";
24 private const string relationshipPathType =
@"http://schemas.openxmlformats.org/officeDocument/2006/relationships/externalLinkPath";
27 private List<ExternalLink> externalLinks;
29 private List<int> orderNumbers =
new List<int>();
31 private List<string> packagePartPaths =
new List<string>();
33 private List<string> packagePartFileNames =
new List<string>();
35 private List<string> contentTypes =
new List<string>();
37 private List<string> relationshipTypes =
new List<string>();
39 private List<bool> arePackagePartsRoot =
new List<bool>();
41 private List<string> uniquePackagePartIndices =
new List<string>();
43 private List<List<PluginPackageRelationship>> packagePartRelationships =
new List<List<PluginPackageRelationship>>();
49 public Workbook Workbook {
get;
set; }
54 public IReadOnlyList<int> OrderNumbers => orderNumbers;
58 public IReadOnlyList<string> PackagePartPaths => packagePartPaths;
62 public IReadOnlyList<string> PackagePartFileNames => packagePartFileNames;
66 public IReadOnlyList<string> ContentTypes => contentTypes;
71 public IReadOnlyList<string> RelationshipTypes => relationshipTypes;
75 public IReadOnlyList<bool> ArePackagePartsRoot => arePackagePartsRoot;
79 public IReadOnlyList<string> UniquePackagePartIndices => uniquePackagePartIndices;
83 public IReadOnlyList<IReadOnlyList<IPluginPackageRelationship>> PackagePartRelationships => packagePartRelationships;
90 public void Init(IBaseWriter baseWriter)
92 this.Workbook = baseWriter.Workbook;
100 int orderNumber = Workbook.AuxiliaryData.GetData<
int>(PlugInUUID.WriterPackageRegistryQueue, PlugInUUID.LastPackageOrderNumber);
101 List<ExternalLink> storedExternalLinks = Workbook.AuxiliaryData.GetDataList<ExternalLink>(PlugInUUID.CompatibilityInlineProcessor, CompatibilityConstants.EXTERNAL_LINK_OBJECT_ENTITY);
102 externalLinks = storedExternalLinks ==
null ?
new List<ExternalLink>() : storedExternalLinks.OfType<ExternalLink>().ToList();
104 for (
int i = 0; i < externalLinks.Count; i++)
107 string name =
"externalLink" + ParserUtils.ToString(i + 1) +
".xml";
108 string uniqueIndex = CompatibilityConstants.UNIQUE_PACKAGE_PART_INDEX_PREFIX + ParserUtils.ToString(i);
109 orderNumbers.Add(orderNumber);
110 packagePartPaths.Add(packagePartPath);
111 packagePartFileNames.Add(name);
112 contentTypes.Add(contentType);
113 relationshipTypes.Add(relationshipType);
114 arePackagePartsRoot.Add(
false);
115 uniquePackagePartIndices.Add(uniqueIndex);
117 ExternalLink externalLink = externalLinks[i];
118 List<PluginPackageRelationship> relationshipList =
new List<PluginPackageRelationship>();
119 foreach (ExternalLinkUriRelationship rawRelationship
in externalLink.GetUriRelationships())
121 PluginPackageRelationship relationship =
new PluginPackageRelationship();
122 relationship.RelationshipId = rawRelationship.Id;
123 relationship.Target = rawRelationship.SerializedTarget;
124 relationship.TargetMode = System.IO.Packaging.TargetMode.External;
125 relationship.RelationshipType = relationshipPathType;
126 relationshipList.Add(relationship);
128 if (relationshipList.Count > 0)
130 packagePartRelationships.Add(relationshipList);