public static GetPartUri ( Uri packUri ) : Uri | ||
packUri | Uri | |
return | Uri |
/// <summary> /// Resolves the target uri in the relationship against the source part or the /// package root. This resolved Uri is then used by the Add method to figure /// out if a relationship is being created to another relationship part. /// </summary> /// <param name="target">PackageRelationship target uri</param> /// <param name="targetMode"> Enum value specifying the interpretation of the base uri /// for the relationship target uri</param> /// <returns>Resolved Uri</returns> private Uri GetResolvedTargetUri(Uri target, TargetMode targetMode) { if (targetMode == TargetMode.Internal) { Debug.Assert(!target.IsAbsoluteUri, "Uri should be relative at this stage"); if (_sourcePart == null) //indicates that the source is the package root { return(PackUriHelper.ResolvePartUri(PackUriHelper.PackageRootUri, target)); } else { return(PackUriHelper.ResolvePartUri(_sourcePart.Uri, target)); } } else { if (target.IsAbsoluteUri) { if (String.CompareOrdinal(target.Scheme, PackUriHelper.UriSchemePack) == 0) { return(PackUriHelper.GetPartUri(target)); } } else { Debug.Assert(false, "Uri should not be relative at this stage"); } } // relative to the location of the package. return(target); }
/// <summary> /// rootElement == null: Load elements, validation of root element will occur in caller by checking object type or casting /// rootElement != null: Only perform validation, and expect rootElement at root of markup /// </summary> /// <param name="stream"></param> /// <param name="parentUri"></param> /// <param name="pc"></param> /// <param name="mimeType"></param> /// <param name="rootElement"></param> /// <returns></returns> private object Load(Stream stream, Uri parentUri, ParserContext pc, ContentType mimeType, string rootElement) { object obj = null; if (!DocumentMode) { // Loose XAML, just check against schema, don't check content type if (rootElement == null) { obj = XamlReader.Load(stream, pc); } } else { // inside an XPS Document. Perform maximum validation XpsSchema schema = XpsSchema.GetSchema(mimeType); Uri uri = pc.BaseUri; Uri packageUri = PackUriHelper.GetPackageUri(uri); Uri partUri = PackUriHelper.GetPartUri(uri); Package package = PreloadedPackages.GetPackage(packageUri); Uri parentPackageUri = null; if (parentUri != null) { parentPackageUri = PackUriHelper.GetPackageUri(parentUri); if (!parentPackageUri.Equals(packageUri)) { throw new FileFormatException(SR.Get(SRID.XpsValidatingLoaderUriNotInSamePackage)); } } schema.ValidateRelationships(new SecurityCriticalData <Package>(package), packageUri, partUri, mimeType); if (schema.AllowsMultipleReferencesToSameUri(mimeType)) { _uniqueUriRef = null; } else { _uniqueUriRef = new Hashtable(11); } Hashtable validResources = (_validResources.Count > 0 ? _validResources.Peek() : null); if (schema.HasRequiredResources(mimeType)) { validResources = new Hashtable(11); PackagePart part = package.GetPart(partUri); PackageRelationshipCollection requiredResources = part.GetRelationshipsByType(_requiredResourceRel); foreach (PackageRelationship relationShip in requiredResources) { Uri targetUri = PackUriHelper.ResolvePartUri(partUri, relationShip.TargetUri); Uri absTargetUri = PackUriHelper.Create(packageUri, targetUri); PackagePart targetPart = package.GetPart(targetUri); if (schema.IsValidRequiredResourceMimeType(targetPart.ValidatedContentType())) { if (!validResources.ContainsKey(absTargetUri)) { validResources.Add(absTargetUri, true); } } else { if (!validResources.ContainsKey(absTargetUri)) { validResources.Add(absTargetUri, false); } } } } XpsSchemaValidator xpsSchemaValidator = new XpsSchemaValidator(this, schema, mimeType, stream, packageUri, partUri); _validResources.Push(validResources); if (rootElement != null) { xpsSchemaValidator.XmlReader.MoveToContent(); if (!rootElement.Equals(xpsSchemaValidator.XmlReader.Name)) { throw new FileFormatException(SR.Get(SRID.XpsValidatingLoaderUnsupportedMimeType)); } while (xpsSchemaValidator.XmlReader.Read()) { ; } } else { obj = XamlReader.Load(xpsSchemaValidator.XmlReader, pc, XamlParseMode.Synchronous); } _validResources.Pop(); } return(obj); }