/** * Get the PackagePart that is the target of a relationship. * * @param rel A relationship from this part to another one * @return The target part of the relationship */ public PackagePart GetRelatedPart(PackageRelationship rel) { // Ensure this is one of ours if (!IsRelationshipExists(rel)) { throw new ArgumentException("Relationship " + rel + " doesn't start with this part " + _partName); } // Get the target URI, excluding any relative fragments Uri target = rel.TargetUri; if (target.OriginalString.IndexOf('#') >= 0) { String t = target.ToString(); try { target = PackagingUriHelper.ParseUri(t.Substring(0, t.IndexOf('#')), UriKind.Absolute); } catch (UriFormatException e) { throw new InvalidFormatException("Invalid target URI: " + t); } } // Turn that into a name, and fetch PackagePartName relName = PackagingUriHelper.CreatePartName(target); PackagePart part = _container.GetPart(relName); if (part == null) { throw new ArgumentException("No part found for relationship " + rel); } return(part); }
/** * Builds a PackagePartName for the given ZipEntry, * or null if it's the content types / invalid part */ private PackagePartName BuildPartName(ZipEntry entry) { try { // We get an error when we parse [Content_Types].xml // because it's not a valid URI. if (entry.Name.ToLower().Equals( ContentTypeManager.CONTENT_TYPES_PART_NAME.ToLower())) { return(null); } return(PackagingUriHelper.CreatePartName(ZipHelper .GetOPCNameFromZipItemName(entry.Name))); } catch (Exception) { // We assume we can continue, even in degraded mode ... //logger.log(POILogger.WARN,"Entry " // + entry.getName() // + " is not valid, so this part won't be add to the package."); return(null); } }