Esempio n. 1
0
 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;
     }
 }
Esempio n. 2
0
        /**
         * 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;
            }
        }