//------------------------------------------------------ // // Internal Methods // //------------------------------------------------------ /// <summary> /// Constructor /// </summary> /// <param name="uri">part uri of part in question</param> /// <param name="contentType">type of part</param> /// <param name="hashAlgorithm">digest method</param> /// <param name="hashValue">value of the hash calculation extracted from the signature Xml</param> /// <param name="transforms">ordered transform list - may be null</param> /// <param name="relationshipSelectors">may be null but can never be empty</param> internal PartManifestEntry(Uri uri, ContentType contentType, String hashAlgorithm, String hashValue, List<String> transforms, List<PackageRelationshipSelector> relationshipSelectors) { Invariant.Assert(uri != null); Invariant.Assert(contentType != null); Invariant.Assert(hashAlgorithm != null); _uri = uri; _contentType = contentType; _hashAlgorithm = hashAlgorithm; _hashValue = hashValue; _transforms = transforms; _relationshipSelectors = relationshipSelectors; _owningPartUri = null; if (_relationshipSelectors != null) { Invariant.Assert(relationshipSelectors.Count > 0); #if DEBUG Invariant.Assert(DoAllSelectorsHaveSameOwningPart(relationshipSelectors), "All relationship selectors should have same owningPart for a given part manifest"); #endif //Get owning Part uri from one of the relationship selectors _owningPartUri = relationshipSelectors[0].SourceUri; } }
XpsSchemaValidator( XpsValidatingLoader loader, XpsSchema schema, ContentType mimeType, Stream objectStream, Uri packageUri, Uri baseUri ) { XmlTextReader xmlTextReader = new XmlEncodingEnforcingTextReader(objectStream); xmlTextReader.ProhibitDtd = true; xmlTextReader.Normalization = true; XmlReader xmlReader = xmlTextReader; string [] predefinedNamespaces = _predefinedNamespaces; if ( !string.IsNullOrEmpty(schema.RootNamespaceUri) ) { predefinedNamespaces = new string[_predefinedNamespaces.Length + 1]; predefinedNamespaces[0] = schema.RootNamespaceUri; _predefinedNamespaces.CopyTo(predefinedNamespaces, 1); } xmlReader = new XmlCompatibilityReader(xmlReader, predefinedNamespaces); xmlReader = XmlReader.Create(xmlReader, schema.GetXmlReaderSettings()); if (schema.HasUriAttributes(mimeType) && packageUri != null && baseUri != null) { xmlReader = new RootXMLNSAndUriValidatingXmlReader(loader, schema, xmlReader, packageUri, baseUri); } else { xmlReader = new RootXMLNSAndUriValidatingXmlReader(loader, schema, xmlReader); } _compatReader = xmlReader; }
public override bool AllowsMultipleReferencesToSameUri(ContentType mimeType) { if (_fixedDocumentSequenceContentType.AreTypeAndSubTypeEqual(mimeType) || _fixedDocumentContentType.AreTypeAndSubTypeEqual(mimeType)) { // FixedDocumentSequence - FixedDocument - FixedPage must form a tree. Cannot share elements return false; } else { return true; } }
public override bool HasRequiredResources(ContentType mimeType) { if (_fixedPageContentType.AreTypeAndSubTypeEqual(mimeType)) { return true; } return false; }
public bool IsValidRequiredResourceMimeType(ContentType mimeType) { foreach (ContentType ct in _requiredResourceMimeTypes.Keys) { if (ct.AreTypeAndSubTypeEqual(mimeType)) { return true; } } return false; }
public virtual bool HasUriAttributes(ContentType mimeType) { return false; }
public virtual void ValidateRelationships(SecurityCriticalData<Package> package, Uri packageUri, Uri partUri, ContentType mimeType) { }
static protected void RegisterSchema(XpsSchema schema, ContentType[] handledMimeTypes) { foreach (ContentType mime in handledMimeTypes) { _schemas.Add(mime, schema); } }
public static void LoadComponent(Object component, Uri resourceLocator) { if (component == null) throw new ArgumentNullException("component"); if (resourceLocator == null) throw new ArgumentNullException("resourceLocator"); if (resourceLocator.OriginalString == null) throw new ArgumentException(SR.Get(SRID.ArgumentPropertyMustNotBeNull,"resourceLocator", "OriginalString")); if (resourceLocator.IsAbsoluteUri == true) throw new ArgumentException(SR.Get(SRID.AbsoluteUriNotAllowed)); // Passed a relative Uri here. // needs to resolve it to Pack://Application. //..\..\ in the relative Uri will get stripped when creating the new Uri and resolving to the //PackAppBaseUri, i.e. only relative Uri within the appbase are created here Uri currentUri = new Uri(BaseUriHelper.PackAppBaseUri, resourceLocator); // // Generate the ParserContext from packUri // ParserContext pc = new ParserContext(); pc.BaseUri = currentUri; bool bCloseStream = true; // Whether or not to close the stream after LoadBaml is done. Stream stream = null; // stream could be extracted from the manifest resource or cached in the // LoadBamlSyncInfo depends on how this method is called. // // We could be here because of an InitializeCompoenent() call from the ctor of this component. // Check if this component was originally being created from the same Uri by the BamlConverter // or LoadComponent(uri). // if (IsComponentBeingLoadedFromOuterLoadBaml(currentUri) == true) { NestedBamlLoadInfo nestedBamlLoadInfo = s_NestedBamlLoadInfo.Peek(); // If so, use the stream already created for this component on this thread by the // BamlConverter and seek to origin. This gives better perf by avoiding a duplicate // WebRequest. stream = nestedBamlLoadInfo.BamlStream; stream.Seek(0, SeekOrigin.Begin); pc.SkipJournaledProperties = nestedBamlLoadInfo.SkipJournaledProperties; // Reset the OuterUri in the top LoadBamlSyncInfo in the stack for the performance optimization. nestedBamlLoadInfo.BamlUri = null; // Start a new load context for this component to allow it to initialize normally via // its InitializeComponent() so that code in the ctor following it can access the content. // This call will not close the stream since it is owned by the load context created by // the BamlConverter and will be closed from that context after this function returns. bCloseStream = false; } else { // if not, this is a first time regular load of the component. PackagePart part = GetResourceOrContentPart(resourceLocator); ContentType contentType = new ContentType(part.ContentType); stream = part.GetStream(); bCloseStream = true; // // The stream must be a BAML stream. // check the content type. // if (!MimeTypeMapper.BamlMime.AreTypeAndSubTypeEqual(contentType)) { throw new Exception(SR.Get(SRID.ContentTypeNotSupported, contentType)); } } IStreamInfo bamlStream = stream as IStreamInfo; if (bamlStream == null || bamlStream.Assembly != component.GetType().Assembly) { throw new Exception(SR.Get(SRID.UriNotMatchWithRootType, component.GetType( ), resourceLocator)); } XamlReader.LoadBaml(stream, pc, component, bCloseStream); }
internal static ContentType GetContentType(WebResponse response) { ContentType contentType = ContentType.Empty; // FileWebResponse returns a generic mime type for all files regardless of extension. // We have requested fix but it's postponed to orcas. This is a work around for that. // if (!(response is FileWebResponse)) { // For all other cases use the WebResponse's ContentType if it is available try { contentType = new ContentType(response.ContentType); // If our content type is octet-stream or text/plain, we might be dealing with an unconfigured server. // If the extension is .xaml or .xbap we ignore the server's content type and determine // the content type based on the URI's extension. if (MimeTypeMapper.OctetMime.AreTypeAndSubTypeEqual(contentType, true) || MimeTypeMapper.TextPlainMime.AreTypeAndSubTypeEqual(contentType, true)) { string extension = MimeTypeMapper.GetFileExtension(response.ResponseUri); if ((String.Compare(extension, MimeTypeMapper.XamlExtension, StringComparison.OrdinalIgnoreCase) == 0) || (String.Compare(extension, MimeTypeMapper.XbapExtension, StringComparison.OrdinalIgnoreCase) == 0)) { contentType = ContentType.Empty; // Will cause GetMimeTypeFromUri to be called below } } } #pragma warning disable 6502 catch (NotImplementedException) { // this is a valid result and indicates that the subclass chose not to implement this property } catch (NotSupportedException) { // this is a valid result and indicates that the subclass chose not to implement this property } #pragma warning restore 6502 } // DevDiv2 29007 - IE9 - pack://siteoforigin:,,,/ Uris fail for standalone applications // Something about the contentType object we get when IE9 is installed breaks file-system pack://siteoforigin:,,, Uris // when we get here with a blank ContentType object. // Workaround: Since we're only checking that content type hasn't been determined yet, checking the public properties versus // ContentType.Empty's copy of the same gets the same result, and also works for all versions of IE. if (contentType.TypeComponent == ContentType.Empty.TypeComponent && contentType.OriginalString == ContentType.Empty.OriginalString && contentType.SubTypeComponent == ContentType.Empty.SubTypeComponent) { contentType = MimeTypeMapper.GetMimeTypeFromUri(response.ResponseUri); } return contentType; }
internal static Stream GetResponseStream(WebRequest request, out ContentType contentType) { WebResponse response = GetResponse(request); contentType = GetContentType(response); return response.GetResponseStream(); }
internal static Stream CreateRequestAndGetResponseStream(Uri uri, out ContentType contentType) { WebRequest request = CreateRequest(uri); return GetResponseStream(request, out contentType); }
protected override Stream GetStreamCore(FileMode mode, FileAccess access) { Stream stream = null; stream = EnsureResourceLocationSet(); // in order to find the resource we might have to open a stream. // rather than waste the stream it is returned here and we can use it. if (stream == null) { // Start looking for resources using the current ui culture. // The resource manager will fall back to invariant culture automatically. stream = _rmWrapper.Value.GetStream(_name); if (stream == null) { throw new IOException(SR.Get(SRID.UnableToLocateResource, _name)); } } // // If this is a Baml stream, it will return BamlStream object, which contains // both raw stream and the host assembly. // ContentType curContent = new ContentType(ContentType); if (MimeTypeMapper.BamlMime.AreTypeAndSubTypeEqual(curContent)) { BamlStream bamlStream = new BamlStream(stream, _rmWrapper.Value.Assembly); stream = bamlStream; } return stream; }
private void WriteOverrideElement(XmlWriter xmlWriter, PackUriHelper.ValidatedPartUri partUri, ContentType contentType) { xmlWriter.WriteStartElement(s_overrideTagName); xmlWriter.WriteAttributeString(s_partNameAttributeName, partUri.PartUriString); xmlWriter.WriteAttributeString(s_contentTypeAttributeName, contentType.ToString()); xmlWriter.WriteEndElement(); }
/// <summary> /// Access the registry to get the filter's CLSID associated with contentType, /// unless contentType is empty, in which case the content type is inferred from /// the file's extension. /// </summary> private string GetFilterClsid(ContentType contentType, Uri partUri) { // Find the file type guid associated with the mime content or (as a second choice) with the extension. string fileTypeGuid = null; if (contentType != null && !ContentType.Empty.AreTypeAndSubTypeEqual(contentType)) { fileTypeGuid = FileTypeGuidFromMimeType(contentType); } else { string extension = GetPartExtension(partUri); if (extension != null) { fileTypeGuid = FileTypeGuidFromFileExtension(extension); } } // Get the default value of // /HKEY_CLASSES_ROOT/CLSID/<fileTypeGuid>/PersistentAddinsRegistered/<IID_IFilter>. if (fileTypeGuid == null) { return null; } RegistryKey iFilterIidKey = FindSubkey( Registry.ClassesRoot, MakeRegistryPath(_IFilterAddinPath, fileTypeGuid)); if (iFilterIidKey == null) { return null; } return (string)iFilterIidKey.GetValue(null); }
/// <summary> /// This method does a strong comparison of the content types, as parameters are not allowed. /// We only compare the type and subType values in an ASCII case-insensitive manner. /// Parameters are not allowed to be present on any of the content type operands. /// </summary> /// <param name="contentType">Content type to be compared with</param> /// <returns></returns> internal bool AreTypeAndSubTypeEqual(ContentType contentType) { return(AreTypeAndSubTypeEqual(contentType, false)); }
/// <summary> /// Gets the content type's GUID and find the associated PersistentHandler GUID. /// </summary> private string FileTypeGuidFromMimeType(ContentType contentType) { // This method is invoked only if contentType has been found to be non-empty. Debug.Assert(contentType != null && contentType.ToString().Length > 0); // Get the string in value Extension of key \HKEY_CLASSES_ROOT\MIME\Database\Content Type\<MIME type>. RegistryKey mimeContentType = FindSubkey(Registry.ClassesRoot, _mimeContentTypeKey); RegistryKey mimeTypeKey = (mimeContentType == null ? null : mimeContentType.OpenSubKey(contentType.ToString())); if (mimeTypeKey == null) { return null; } string extension = (string)mimeTypeKey.GetValue(_extension); if (extension == null) { return null; } // Use the extension to find the type GUID. return FileTypeGuidFromFileExtension(extension); }
internal static object LoadComponent(Uri resourceLocator, bool bSkipJournaledProperties) { // // Only the Public LoadComponent(uri) and Journal navigation for PageFunction resume // call this method, the caller should have ensure the passed paramaters are valid. // So don't need to explicitly do the validation check for the parameters. // // Passed a relative Uri here. // needs to resolve it to Pack://Application. //..\..\ in the relative Uri will get stripped when creating the new Uri and resolving to the //PackAppBaseUri, i.e. only relative Uri within the appbase are created here Uri packUri = BindUriHelper.GetResolvedUri(BaseUriHelper.PackAppBaseUri, resourceLocator); PackagePart part = GetResourceOrContentPart(packUri); ContentType contentType = new ContentType(part.ContentType); Stream stream = part.GetStream(); ParserContext pc = new ParserContext(); pc.BaseUri = packUri; pc.SkipJournaledProperties = bSkipJournaledProperties; // // The stream must be a BAML or XAML stream. // if (MimeTypeMapper.BamlMime.AreTypeAndSubTypeEqual(contentType)) { return LoadBamlStreamWithSyncInfo(stream, pc); } else if (MimeTypeMapper.XamlMime.AreTypeAndSubTypeEqual(contentType)) { return XamlReader.Load(stream, pc); } else { throw new Exception(SR.Get(SRID.ContentTypeNotSupported, contentType.ToString())); } }
private static object ValidateAndLoadPartFromAbsoluteUri(Uri AbsoluteUriDoc, bool validateOnly, string rootElement, out ContentType mimeType) { mimeType = null; Stream pageStream = null; object o = null; try { pageStream = WpfWebRequestHelper.CreateRequestAndGetResponseStream(AbsoluteUriDoc, out mimeType); ParserContext pc = new ParserContext(); pc.BaseUri = AbsoluteUriDoc; XpsValidatingLoader loader = new XpsValidatingLoader(); if (validateOnly) { loader.Validate(pageStream, null, pc, mimeType, rootElement); } else { o = loader.Load(pageStream, null, pc, mimeType); } } catch (Exception e) { //System.Net.WebException will be thrown when the document structure does not exist in a non-container //and System.InvalidOperation will be thrown when calling Package.GetPart() in a container. //We ignore these but all others need to be rethrown if (!(e is System.Net.WebException || e is System.InvalidOperationException)) { throw; } } return o; }
protected void RegisterRequiredResourceMimeTypes(ContentType[] requiredResourceMimeTypes) { if (requiredResourceMimeTypes != null) { foreach (ContentType type in requiredResourceMimeTypes) { _requiredResourceMimeTypes.Add(type, true); } } }
/// <summary> /// Get the part uri and it's content type from the current Reference tag /// </summary> /// <param name="reader"></param> /// <param name="contentType">contentType extracted from the query portion of the Uri</param> /// <returns>PackagePart uri and contentType</returns> private static Uri ParsePartUri(XmlReader reader, out ContentType contentType) { // should be a relative Package uri with a query portion that contains the ContentType contentType = ContentType.Empty; Uri partUri = null; // must be one and only one attribute if (PackagingUtilities.GetNonXmlnsAttributeCount(reader) == 1) { string uriAttrValue = reader.GetAttribute(XTable.Get(XTable.ID.UriAttrName)); if (uriAttrValue != null) { partUri = ParsePartUriAttribute(uriAttrValue, out contentType); } } // will be null if we had no success if (partUri == null) throw new XmlException(SR.Get(SRID.RequiredXmlAttributeMissing, XTable.Get(XTable.ID.UriAttrName))); return partUri; }
public virtual bool HasRequiredResources(ContentType mimeType) { return false; }
private static Uri ParsePartUriAttribute(String attrValue, out ContentType contentType) { // extract the query portion - do not ask the Uri class for it because it will escape // characters and we want to do a simple text comparison later contentType = ContentType.Empty; // out argument must always be set int index = attrValue.IndexOf('?'); Uri uri = null; if (index > 0) { try { // ensure it starts with the correct query prefix String query = attrValue.Substring(index); if ((query.Length > _contentTypeQueryStringPrefix.Length) && (query.StartsWith(_contentTypeQueryStringPrefix, StringComparison.Ordinal))) { // truncate the prefix and validate contentType = new ContentType(query.Substring(_contentTypeQueryStringPrefix.Length)); } // now construct the uri without the query uri = PackUriHelper.ValidatePartUri(new Uri(attrValue.Substring(0, index), UriKind.Relative)); } catch (ArgumentException ae) { // Content type or part uri is malformed so we have a bad signature. // Rethrow as XmlException so outer validation loop can catch it and return validation result. throw new XmlException(SR.Get(SRID.PartReferenceUriMalformed), ae); } } // throw if we failed if (contentType.ToString().Length <= 0) throw new XmlException(SR.Get(SRID.PartReferenceUriMalformed)); return uri; }
public virtual bool AllowsMultipleReferencesToSameUri(ContentType mimeType) { return true; }
static internal bool IsXamlMimeType(ContentType mimeType) { if (MimeTypeMapper.XamlMime.AreTypeAndSubTypeEqual(mimeType) || MimeTypeMapper.FixedDocumentSequenceMime.AreTypeAndSubTypeEqual(mimeType) || MimeTypeMapper.FixedDocumentMime.AreTypeAndSubTypeEqual(mimeType) || MimeTypeMapper.FixedPageMime.AreTypeAndSubTypeEqual(mimeType)) { return true; } return false; }
static public XpsSchema GetSchema(ContentType mimeType) { XpsSchema schema = null; if (!_schemas.TryGetValue(mimeType, out schema)) { throw new FileFormatException(SR.Get(SRID.XpsValidatingLoaderUnsupportedMimeType)); } return schema; }
internal object Load(Stream stream, Uri parentUri, ParserContext pc, ContentType mimeType) { return Load(stream, parentUri, pc, mimeType, null); }
public override bool HasUriAttributes(ContentType mimeType) { // All of the root elements for content types supported by this schema have Uri attributes that need to be checked return true; }
internal void Validate(Stream stream, Uri parentUri, ParserContext pc, ContentType mimeType, string rootElement) { Load(stream, parentUri, pc, mimeType, rootElement); }
public override void ValidateRelationships(SecurityCriticalData<Package> package, Uri packageUri, Uri partUri, ContentType mimeType) { PackagePart part = package.Value.GetPart(partUri); PackageRelationshipCollection checkRels; int count; // Can only have 0 or 1 PrintTicket per FDS, FD or FP part checkRels = part.GetRelationshipsByType(_printTicketRel); count = 0; foreach (PackageRelationship rel in checkRels) { count++; if (count > 1) { throw new FileFormatException(SR.Get(SRID.XpsValidatingLoaderMoreThanOnePrintTicketPart)); } // Also check for existence and type Uri targetUri = PackUriHelper.ResolvePartUri(partUri, rel.TargetUri); Uri absTargetUri = PackUriHelper.Create(packageUri, targetUri); PackagePart targetPart = package.Value.GetPart(targetUri); if (!_printTicketContentType.AreTypeAndSubTypeEqual(new ContentType(targetPart.ContentType))) { throw new FileFormatException(SR.Get(SRID.XpsValidatingLoaderPrintTicketHasIncorrectType)); } } checkRels = part.GetRelationshipsByType(_thumbnailRel); count = 0; foreach (PackageRelationship rel in checkRels) { count++; if (count > 1) { throw new FileFormatException(SR.Get(SRID.XpsValidatingLoaderMoreThanOneThumbnailPart)); } // Also check for existence and type Uri targetUri = PackUriHelper.ResolvePartUri(partUri, rel.TargetUri); Uri absTargetUri = PackUriHelper.Create(packageUri, targetUri); PackagePart targetPart = package.Value.GetPart(targetUri); if (!_jpgContentType.AreTypeAndSubTypeEqual(new ContentType(targetPart.ContentType)) && !_pngContentType.AreTypeAndSubTypeEqual(new ContentType(targetPart.ContentType))) { throw new FileFormatException(SR.Get(SRID.XpsValidatingLoaderThumbnailHasIncorrectType)); } } // FixedDocument only has restricted font relationships if (_fixedDocumentContentType.AreTypeAndSubTypeEqual(mimeType)) { // Check if target of restricted font relationship is present and is actually a font checkRels = part.GetRelationshipsByType(_restrictedFontRel); foreach (PackageRelationship rel in checkRels) { // Check for existence and type Uri targetUri = PackUriHelper.ResolvePartUri(partUri, rel.TargetUri); Uri absTargetUri = PackUriHelper.Create(packageUri, targetUri); PackagePart targetPart = package.Value.GetPart(targetUri); if (!_fontContentType.AreTypeAndSubTypeEqual(new ContentType(targetPart.ContentType)) && !_obfuscatedContentType.AreTypeAndSubTypeEqual(new ContentType(targetPart.ContentType))) { throw new FileFormatException(SR.Get(SRID.XpsValidatingLoaderRestrictedFontHasIncorrectType)); } } } // check constraints for XPS fixed payload start part if (_fixedDocumentSequenceContentType.AreTypeAndSubTypeEqual(mimeType)) { // This is the XPS payload root part. We also should check if the Package only has at most one discardcontrol... checkRels = package.Value.GetRelationshipsByType(_discardControlRel); count = 0; foreach (PackageRelationship rel in checkRels) { count++; if (count > 1) { throw new FileFormatException(SR.Get(SRID.XpsValidatingLoaderMoreThanOneDiscardControlInPackage)); } // Also check for existence and type Uri targetUri = PackUriHelper.ResolvePartUri(partUri, rel.TargetUri); Uri absTargetUri = PackUriHelper.Create(packageUri, targetUri); PackagePart targetPart = package.Value.GetPart(targetUri); if (!_discardControlContentType.AreTypeAndSubTypeEqual(new ContentType(targetPart.ContentType))) { throw new FileFormatException(SR.Get(SRID.XpsValidatingLoaderDiscardControlHasIncorrectType)); } } // This is the XPS payload root part. We also should check if the Package only has at most one thumbnail... checkRels = package.Value.GetRelationshipsByType(_thumbnailRel); count = 0; foreach (PackageRelationship rel in checkRels) { count++; if (count > 1) { throw new FileFormatException(SR.Get(SRID.XpsValidatingLoaderMoreThanOneThumbnailInPackage)); } // Also check for existence and type Uri targetUri = PackUriHelper.ResolvePartUri(partUri, rel.TargetUri); Uri absTargetUri = PackUriHelper.Create(packageUri, targetUri); PackagePart targetPart = package.Value.GetPart(targetUri); if (!_jpgContentType.AreTypeAndSubTypeEqual(new ContentType(targetPart.ContentType)) && !_pngContentType.AreTypeAndSubTypeEqual(new ContentType(targetPart.ContentType))) { throw new FileFormatException(SR.Get(SRID.XpsValidatingLoaderThumbnailHasIncorrectType)); } } } }
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; // Using PackUriHelper.ValidateAndGetPackUriComponents internal method // to get Package and Part Uri in one step Uri packageUri; Uri partUri; PackUriHelper.ValidateAndGetPackUriComponents(uri, out packageUri, out partUri); 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; }
/// <summary> /// Protected constructor for the abstract Base class. /// This is the current contract between the subclass and the base class /// If we decide some registration mechanism then this might change /// /// NOTE : If you are using this constructor from your subclass or passing a null /// for the content type parameter, be sure to implement the GetContentTypeCore /// method, as that will be called to get the content type value. This is provided /// to enable lazy initialization of the ContentType property. /// /// </summary> /// <param name="package">Package in which this part is being created</param> /// <param name="partUri">uri of the part</param> /// <param name="contentType">Content Type of the part, can be null if the value /// is unknown at the time of construction. However the value has to be made /// available anytime the ContentType property is called. A null value only indicates /// that the value will be provided later. Every PackagePart must have a valid /// Content Type</param> /// <param name="compressionOption">compression option for this part</param> /// <exception cref="ArgumentNullException">If parameter "package" is null</exception> /// <exception cref="ArgumentNullException">If parameter "partUri" is null</exception> /// <exception cref="ArgumentOutOfRangeException">If CompressionOption enumeration [compressionOption] does not have one of the valid values</exception> /// <exception cref="ArgumentException">If parameter "partUri" does not conform to the valid partUri syntax</exception> protected PackagePart(Package package, Uri partUri, string contentType, CompressionOption compressionOption) { if (package == null) throw new ArgumentNullException("package"); if (partUri == null) throw new ArgumentNullException("partUri"); Package.ThrowIfCompressionOptionInvalid(compressionOption); _uri = PackUriHelper.ValidatePartUri(partUri); _container = package; if (contentType == null) _contentType = null; else _contentType = new ContentType(contentType); _requestedStreams = null; _compressionOption = compressionOption; _isRelationshipPart = PackUriHelper.IsRelationshipPartUri(partUri); }
private static void WriteDefaultElement(XmlWriter xmlWriter, string extension, ContentType contentType) { xmlWriter.WriteStartElement(DefaultTagName); xmlWriter.WriteAttributeString(ExtensionAttributeName, extension); xmlWriter.WriteAttributeString(ContentTypeAttributeName, contentType.ToString()); xmlWriter.WriteEndElement(); }