/** * Create a new child POIXMLDocumentPart * * @param descriptor the part descriptor * @param factory the factory that will create an instance of the requested relation * @param idx part number * @param noRelation if true, then no relationship is Added. * @return the Created child POIXMLDocumentPart */ protected POIXMLDocumentPart CreateRelationship(POIXMLRelation descriptor, POIXMLFactory factory, int idx, bool noRelation) { try { PackagePartName ppName = PackagingUriHelper.CreatePartName(descriptor.GetFileName(idx)); PackageRelationship rel = null; PackagePart part = packagePart.Package.CreatePart(ppName, descriptor.ContentType); if (!noRelation) { /* only add to relations, if according relationship is being Created. */ rel = packagePart.AddRelationship(ppName, TargetMode.Internal, descriptor.Relation); } POIXMLDocumentPart doc = factory.CreateDocumentPart(descriptor); doc.packageRel = rel; doc.packagePart = part; doc.parent = this; if (!noRelation) { /* only add to relations, if according relationship is being Created. */ AddRelation(rel.Id, doc); } return(doc); } catch (Exception e) { throw new POIXMLException(e); } }
/** * Create a new child POIXMLDocumentPart * * @param descriptor the part descriptor * @param factory the factory that will create an instance of the requested relation * @param idx part number * @param noRelation if true, then no relationship is Added. * @return the Created child POIXMLDocumentPart */ protected POIXMLDocumentPart CreateRelationship(POIXMLRelation descriptor, POIXMLFactory factory, int idx, bool noRelation) { try { PackagePartName ppName = PackagingUriHelper.CreatePartName(descriptor.GetFileName(idx)); PackageRelationship rel = null; PackagePart part = packagePart.Package.CreatePart(ppName, descriptor.ContentType); if (!noRelation) { /* only add to relations, if according relationship is being Created. */ rel = packagePart.AddRelationship(ppName, TargetMode.Internal, descriptor.Relation); } POIXMLDocumentPart doc = factory.CreateDocumentPart(descriptor); doc.packageRel = rel; doc.packagePart = part; doc.parent = this; if (!noRelation) { /* only add to relations, if according relationship is being Created. */ AddRelation(rel.Id, doc); } return(doc); } catch (PartAlreadyExistsException pae) { // Return the specific exception so the user knows // that the name is already taken throw pae; } catch (Exception e) { // Give a general wrapped exception for the problem throw new POIXMLException(e); } }
protected POIXMLDocumentPart CreateRelationship(POIXMLRelation descriptor, POIXMLFactory factory, int idx, bool noRelation) { try { PackagePartName partName = PackagingUriHelper.CreatePartName(descriptor.GetFileName(idx)); PackageRelationship packageRelationship = (PackageRelationship)null; PackagePart part = this.packagePart.Package.CreatePart(partName, descriptor.ContentType); if (!noRelation) { packageRelationship = this.packagePart.AddRelationship(partName, TargetMode.Internal, descriptor.Relation); } POIXMLDocumentPart documentPart = factory.CreateDocumentPart(descriptor); documentPart.packageRel = packageRelationship; documentPart.packagePart = part; documentPart.parent = this; if (!noRelation) { this.AddRelation(packageRelationship.Id, documentPart); } return(documentPart); } catch (PartAlreadyExistsException ex) { throw ex; } catch (Exception ex) { throw new POIXMLException(ex); } }
protected void Read(POIXMLFactory factory, Dictionary <PackagePart, POIXMLDocumentPart> context) { try { foreach (PackageRelationship relationship in this.packagePart.Relationships) { TargetMode?targetMode = relationship.TargetMode; if ((targetMode.GetValueOrDefault() != TargetMode.Internal ? 0 : (targetMode.HasValue ? 1 : 0)) != 0) { Uri targetUri = relationship.TargetUri; PackagePart index; if (targetUri.OriginalString.IndexOf('#') >= 0) { index = (PackagePart)null; } else { index = this.packagePart.Package.GetPart(PackagingUriHelper.CreatePartName(targetUri)); if (index == null) { POIXMLDocumentPart.logger.Log(7, (object)("Skipped invalid entry " + (object)relationship.TargetUri)); continue; } } if (index == null || !context.ContainsKey(index)) { POIXMLDocumentPart documentPart = factory.CreateDocumentPart(this, relationship, index); documentPart.parent = this; this.AddRelation(relationship.Id, documentPart); if (index != null) { context[index] = documentPart; if (index.HasRelationships) { documentPart.Read(factory, context); } } } else { this.AddRelation(relationship.Id, context[index]); } } } } catch (Exception ex) { if (ex.InnerException != null && ex.InnerException.InnerException != null) { POIXMLDocumentPart.logger.Log(1, ex.InnerException.InnerException); } throw; } }
protected void Load(POIXMLFactory factory) { Dictionary <PackagePart, POIXMLDocumentPart> context = new Dictionary <PackagePart, POIXMLDocumentPart>(); try { Read(factory, context); } catch (OpenXml4NetException e) { throw new POIXMLException(e); } OnDocumentRead(); context.Clear(); }
protected void Load(POIXMLFactory factory) { Dictionary<PackagePart, POIXMLDocumentPart> context = new Dictionary<PackagePart, POIXMLDocumentPart>(); try { Read(factory, context); } catch (OpenXml4NetException e) { throw new POIXMLException(e); } OnDocumentRead(); context.Clear(); }
/** * Iterate through the underlying PackagePart and create child POIXMLFactory instances * using the specified factory * * @param factory the factory object that Creates POIXMLFactory instances * @param context context map Containing already visited noted keyed by tarGetURI */ protected void Read(POIXMLFactory factory, Dictionary <PackagePart, POIXMLDocumentPart> context) { try { PackageRelationshipCollection rels = packagePart.Relationships; foreach (PackageRelationship rel in rels) { if (rel.TargetMode == TargetMode.Internal) { Uri uri = rel.TargetUri; PackagePart p; if (uri.OriginalString.IndexOf('#') >= 0) { /* * For internal references (e.g. '#Sheet1!A1') the namespace part is null */ p = null; } else { PackagePartName relName = PackagingUriHelper.CreatePartName(uri); p = packagePart.Package.GetPart(relName); if (p == null) { logger.Log(POILogger.ERROR, "Skipped invalid entry " + rel.TargetUri); continue; } } if (p == null || !context.ContainsKey(p)) { POIXMLDocumentPart childPart = factory.CreateDocumentPart(this, rel, p); childPart.parent = this; AddRelation(rel.Id, childPart); if (p != null) { context[p] = childPart; if (p.HasRelationships) { childPart.Read(factory, context); } } } else { AddRelation(rel.Id, context[p]); } } } } catch (Exception ex) { if ((null != ex.InnerException) && (null != ex.InnerException.InnerException)) { // this type of exception is thrown when the XML Serialization does not match the input. logger.Log(1, ex.InnerException.InnerException); } throw; } }
public POIXMLDocumentPart CreateRelationship(POIXMLRelation descriptor, POIXMLFactory factory, int idx) { return(CreateRelationship(descriptor, factory, idx, false)); }
/** * Iterate through the underlying PackagePart and create child POIXMLFactory instances * using the specified factory * * @param factory the factory object that Creates POIXMLFactory instances * @param context context map Containing already visited noted keyed by tarGetURI */ protected void Read(POIXMLFactory factory, Dictionary<PackagePart, POIXMLDocumentPart> context) { try { PackageRelationshipCollection rels = packagePart.Relationships; foreach (PackageRelationship rel in rels) { if (rel.TargetMode == TargetMode.Internal) { Uri uri = rel.TargetUri; PackagePart p; if (uri.OriginalString.IndexOf('#')>=0) { /* * For internal references (e.g. '#Sheet1!A1') the namespace part is null */ p = null; } else { PackagePartName relName = PackagingUriHelper.CreatePartName(uri); p = packagePart.Package.GetPart(relName); if (p == null) { logger.Log(POILogger.ERROR, "Skipped invalid entry " + rel.TargetUri); continue; } } if (p == null || !context.ContainsKey(p)) { POIXMLDocumentPart childPart = factory.CreateDocumentPart(this, rel, p); childPart.parent = this; AddRelation(rel.Id, childPart); if (p != null) { context[p] = childPart; if (p.HasRelationships) childPart.Read(factory, context); } } else { AddRelation(rel.Id, context[p]); } } } } catch (Exception ex) { if ((null != ex.InnerException) && (null != ex.InnerException.InnerException)) { // this type of exception is thrown when the XML Serialization does not match the input. logger.Log(1, ex.InnerException.InnerException); } throw; } }
/** * Create a new child POIXMLDocumentPart * * @param descriptor the part descriptor * @param factory the factory that will create an instance of the requested relation * @param idx part number * @param noRelation if true, then no relationship is Added. * @return the Created child POIXMLDocumentPart */ protected POIXMLDocumentPart CreateRelationship(POIXMLRelation descriptor, POIXMLFactory factory, int idx, bool noRelation) { try { PackagePartName ppName = PackagingUriHelper.CreatePartName(descriptor.GetFileName(idx)); PackageRelationship rel = null; PackagePart part = packagePart.Package.CreatePart(ppName, descriptor.ContentType); if (!noRelation) { /* only add to relations, if according relationship is being Created. */ rel = packagePart.AddRelationship(ppName, TargetMode.Internal, descriptor.Relation); } POIXMLDocumentPart doc = factory.CreateDocumentPart(descriptor); doc.packageRel = rel; doc.packagePart = part; doc.parent = this; if (!noRelation) { /* only add to relations, if according relationship is being Created. */ AddRelation(rel.Id, doc); } return doc; } catch (PartAlreadyExistsException pae) { // Return the specific exception so the user knows // that the name is already taken throw pae; } catch (Exception e) { // Give a general wrapped exception for the problem throw new POIXMLException(e); } }
public POIXMLDocumentPart CreateRelationship(POIXMLRelation descriptor, POIXMLFactory factory, int idx) { return CreateRelationship(descriptor, factory, idx, false); }
/** * Iterate through the underlying PackagePart and create child POIXMLFactory instances * using the specified factory * * @param factory the factory object that Creates POIXMLFactory instances * @param context context map Containing already visited noted keyed by tarGetURI */ protected void Read(POIXMLFactory factory, Dictionary <PackagePart, POIXMLDocumentPart> context) { PackagePart pp = GetPackagePart(); // add mapping a second time, in case of initial caller hasn't done so POIXMLDocumentPart otherChild = PutDictionary(context, pp, this); if (otherChild != null && otherChild != this) { throw new POIXMLException("Unique PackagePart-POIXMLDocumentPart relation broken!"); } if (!pp.HasRelationships) { return; } PackageRelationshipCollection rels = packagePart.Relationships; List <POIXMLDocumentPart> readLater = new List <POIXMLDocumentPart>(); // scan breadth-first, so parent-relations are hopefully the shallowest element foreach (PackageRelationship rel in rels) { if (rel.TargetMode == TargetMode.Internal) { Uri uri = rel.TargetUri; // check for internal references (e.g. '#Sheet1!A1') PackagePartName relName; //if (uri.getRawFragment() != null) if (uri.OriginalString.IndexOf('#') >= 0) { string path = string.Empty; try { path = uri.AbsolutePath; } catch (InvalidOperationException) { path = uri.OriginalString.Substring(0, uri.OriginalString.IndexOf('#')); } relName = PackagingUriHelper.CreatePartName(path); } else { relName = PackagingUriHelper.CreatePartName(uri); } PackagePart p = packagePart.Package.GetPart(relName); if (p == null) { //logger.log(POILogger.ERROR, "Skipped invalid entry " + rel.TargetUri); continue; } POIXMLDocumentPart childPart = GetDictionary(context, p); if (childPart == null) { childPart = factory.CreateDocumentPart(this, p); childPart.parent = this; // already add child to context, so other children can reference it PutDictionary(context, p, childPart); readLater.Add(childPart); } AddRelation(rel, childPart); } } foreach (POIXMLDocumentPart childPart in readLater) { childPart.Read(factory, context); } }
/** * Create a new child POIXMLDocumentPart * * @param descriptor the part descriptor * @param factory the factory that will create an instance of the requested relation * @return the Created child POIXMLDocumentPart */ public POIXMLDocumentPart CreateRelationship(POIXMLRelation descriptor, POIXMLFactory factory) { return(CreateRelationship(descriptor, factory, -1, false).DocumentPart); }
/** * Create a new child POIXMLDocumentPart * * @param descriptor the part descriptor * @param factory the factory that will create an instance of the requested relation * @param idx part number * @param noRelation if true, then no relationship is Added. * @return the Created child POIXMLDocumentPart */ protected POIXMLDocumentPart CreateRelationship(POIXMLRelation descriptor, POIXMLFactory factory, int idx, bool noRelation){ try { PackagePartName ppName = PackagingUriHelper.CreatePartName(descriptor.GetFileName(idx)); PackageRelationship rel = null; PackagePart part = packagePart.Package.CreatePart(ppName, descriptor.ContentType); if(!noRelation) { /* only add to relations, if according relationship is being Created. */ rel = packagePart.AddRelationship(ppName, TargetMode.Internal, descriptor.Relation); } POIXMLDocumentPart doc = factory.CreateDocumentPart(descriptor); doc.packageRel = rel; doc.packagePart = part; doc.parent = this; if(!noRelation) { /* only add to relations, if according relationship is being Created. */ AddRelation(rel.Id,doc); } return doc; } catch (Exception e){ throw new POIXMLException(e); } }
public void Parse(POIXMLFactory factory) { Load(factory); }