コード例 #1
0
 static protected void RegisterSchema(XpsSchema schema, ContentType[] handledMimeTypes)
 {
     foreach (ContentType mime in handledMimeTypes)
     {
         _schemas.Add(mime, schema);
     }
 }
コード例 #2
0
 // Token: 0x06002D0B RID: 11531 RVA: 0x000CB4B8 File Offset: 0x000C96B8
 public XpsS0ResourceDictionarySchema()
 {
     XpsSchema.RegisterSchema(this, new ContentType[]
     {
         XpsS0Schema._resourceDictionaryContentType
     });
 }
コード例 #3
0
 // Token: 0x06002CF1 RID: 11505 RVA: 0x000CABE8 File Offset: 0x000C8DE8
 protected static void RegisterSchema(XpsSchema schema, ContentType[] handledMimeTypes)
 {
     foreach (ContentType key in handledMimeTypes)
     {
         XpsSchema._schemas.Add(key, schema);
     }
 }
コード例 #4
0
        // Token: 0x06002CED RID: 11501 RVA: 0x000CAB00 File Offset: 0x000C8D00
        public XpsSchemaValidator(XpsValidatingLoader loader, XpsSchema schema, ContentType mimeType, Stream objectStream, Uri packageUri, Uri baseUri)
        {
            XmlReader xmlReader = new XpsSchemaValidator.XmlEncodingEnforcingTextReader(objectStream)
            {
                ProhibitDtd   = true,
                Normalization = true
            };

            string[] array = XpsSchemaValidator._predefinedNamespaces;
            if (!string.IsNullOrEmpty(schema.RootNamespaceUri))
            {
                array    = new string[XpsSchemaValidator._predefinedNamespaces.Length + 1];
                array[0] = schema.RootNamespaceUri;
                XpsSchemaValidator._predefinedNamespaces.CopyTo(array, 1);
            }
            xmlReader = new XmlCompatibilityReader(xmlReader, array);
            xmlReader = XmlReader.Create(xmlReader, schema.GetXmlReaderSettings());
            if (schema.HasUriAttributes(mimeType) && packageUri != null && baseUri != null)
            {
                xmlReader = new XpsSchemaValidator.RootXMLNSAndUriValidatingXmlReader(loader, schema, xmlReader, packageUri, baseUri);
            }
            else
            {
                xmlReader = new XpsSchemaValidator.RootXMLNSAndUriValidatingXmlReader(loader, schema, xmlReader);
            }
            this._compatReader = xmlReader;
        }
コード例 #5
0
 // Token: 0x06008480 RID: 33920 RVA: 0x00248506 File Offset: 0x00246706
 public RootXMLNSAndUriValidatingXmlReader(XpsValidatingLoader loader, XpsSchema schema, XmlReader xmlReader, Uri packageUri, Uri baseUri) : base(xmlReader)
 {
     this._loader     = loader;
     this._schema     = schema;
     this._packageUri = packageUri;
     this._baseUri    = baseUri;
 }
コード例 #6
0
 // Token: 0x06002D0D RID: 11533 RVA: 0x000CB4FC File Offset: 0x000C96FC
 public XpsDocStructSchema()
 {
     XpsSchema.RegisterSchema(this, new ContentType[]
     {
         XpsDocStructSchema._documentStructureContentType,
         XpsDocStructSchema._storyFragmentsContentType
     });
 }
コード例 #7
0
 public RootXMLNSAndUriValidatingXmlReader(
     XpsValidatingLoader loader,
     XpsSchema schema,
     XmlReader xmlReader)
     : base(xmlReader)
 {
     _loader = loader;
     _schema = schema;
 }
コード例 #8
0
        // Token: 0x06002CFC RID: 11516 RVA: 0x000CACDC File Offset: 0x000C8EDC
        public static XpsSchema GetSchema(ContentType mimeType)
        {
            XpsSchema result = null;

            if (!XpsSchema._schemas.TryGetValue(mimeType, out result))
            {
                throw new FileFormatException(SR.Get("XpsValidatingLoaderUnsupportedMimeType"));
            }
            return(result);
        }
コード例 #9
0
        static public XpsSchema GetSchema(ContentType mimeType)
        {
            XpsSchema schema = null;

            if (!_schemas.TryGetValue(mimeType, out schema))
            {
                throw new FileFormatException(SR.Get(SRID.XpsValidatingLoaderUnsupportedMimeType));
            }

            return(schema);
        }
コード例 #10
0
 // Token: 0x06002D09 RID: 11529 RVA: 0x000CB050 File Offset: 0x000C9250
 public XpsS0FixedPageSchema()
 {
     XpsSchema.RegisterSchema(this, new ContentType[]
     {
         XpsS0Schema._fixedDocumentSequenceContentType,
         XpsS0Schema._fixedDocumentContentType,
         XpsS0Schema._fixedPageContentType
     });
     base.RegisterRequiredResourceMimeTypes(new ContentType[]
     {
         XpsS0Schema._resourceDictionaryContentType,
         XpsS0Schema._fontContentType,
         XpsS0Schema._colorContextContentType,
         XpsS0Schema._obfuscatedContentType,
         XpsS0Schema._jpgContentType,
         XpsS0Schema._pngContentType,
         XpsS0Schema._tifContentType,
         XpsS0Schema._wmpContentType
     });
 }
コード例 #11
0
        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;
        }
コード例 #12
0
ファイル: FixedSchema.cs プロジェクト: sjyanxin/WPFSource
        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; 
        } 
コード例 #13
0
        /// <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);
        }
コード例 #14
0
        private object Load(Stream stream, Uri parentUri, ParserContext pc, ContentType mimeType, string rootElement)
        {
            object      result    = null;
            List <Type> safeTypes = new List <Type>
            {
                typeof(ResourceDictionary)
            };

            if (!XpsValidatingLoader.DocumentMode)
            {
                if (rootElement == null)
                {
                    XmlReader reader = XmlReader.Create(stream, null, pc);
                    result = XamlReader.Load(reader, pc, XamlParseMode.Synchronous, FrameworkCompatibilityPreferences.DisableLegacyDangerousXamlDeserializationMode, safeTypes);
                    stream.Close();
                }
            }
            else
            {
                XpsSchema schema  = XpsSchema.GetSchema(mimeType);
                Uri       baseUri = pc.BaseUri;
                Uri       uri;
                Uri       uri2;
                PackUriHelper.ValidateAndGetPackUriComponents(baseUri, out uri, out uri2);
                Package package = PreloadedPackages.GetPackage(uri);
                if (parentUri != null)
                {
                    Uri packageUri = PackUriHelper.GetPackageUri(parentUri);
                    if (!packageUri.Equals(uri))
                    {
                        throw new FileFormatException(SR.Get("XpsValidatingLoaderUriNotInSamePackage"));
                    }
                }
                schema.ValidateRelationships(new SecurityCriticalData <Package>(package), uri, uri2, mimeType);
                if (schema.AllowsMultipleReferencesToSameUri(mimeType))
                {
                    this._uniqueUriRef = null;
                }
                else
                {
                    this._uniqueUriRef = new Hashtable(11);
                }
                Hashtable hashtable = (XpsValidatingLoader._validResources.Count > 0) ? XpsValidatingLoader._validResources.Peek() : null;
                if (schema.HasRequiredResources(mimeType))
                {
                    hashtable = new Hashtable(11);
                    PackagePart part = package.GetPart(uri2);
                    PackageRelationshipCollection relationshipsByType = part.GetRelationshipsByType(XpsValidatingLoader._requiredResourceRel);
                    foreach (PackageRelationship packageRelationship in relationshipsByType)
                    {
                        Uri         partUri = PackUriHelper.ResolvePartUri(uri2, packageRelationship.TargetUri);
                        Uri         key     = PackUriHelper.Create(uri, partUri);
                        PackagePart part2   = package.GetPart(partUri);
                        if (schema.IsValidRequiredResourceMimeType(part2.ValidatedContentType))
                        {
                            if (!hashtable.ContainsKey(key))
                            {
                                hashtable.Add(key, true);
                            }
                        }
                        else if (!hashtable.ContainsKey(key))
                        {
                            hashtable.Add(key, false);
                        }
                    }
                }
                XpsSchemaValidator xpsSchemaValidator = new XpsSchemaValidator(this, schema, mimeType, stream, uri, uri2);
                XpsValidatingLoader._validResources.Push(hashtable);
                if (rootElement != null)
                {
                    xpsSchemaValidator.XmlReader.MoveToContent();
                    if (!rootElement.Equals(xpsSchemaValidator.XmlReader.Name))
                    {
                        throw new FileFormatException(SR.Get("XpsValidatingLoaderUnsupportedMimeType"));
                    }
                    while (xpsSchemaValidator.XmlReader.Read())
                    {
                    }
                }
                else
                {
                    result = XamlReader.Load(xpsSchemaValidator.XmlReader, pc, XamlParseMode.Synchronous, FrameworkCompatibilityPreferences.DisableLegacyDangerousXamlDeserializationMode, safeTypes);
                }
                XpsValidatingLoader._validResources.Pop();
            }
            return(result);
        }
コード例 #15
0
ファイル: FixedSchema.cs プロジェクト: sjyanxin/WPFSource
 public RootXMLNSAndUriValidatingXmlReader( 
             XpsValidatingLoader loader,
             XpsSchema schema,
             XmlReader xmlReader,
             Uri packageUri, 
             Uri baseUri)
             : base(xmlReader) 
 { 
     _loader = loader;
     _schema = schema; 
     _packageUri = packageUri;
     _baseUri = baseUri;
 }
コード例 #16
0
ファイル: FixedSchema.cs プロジェクト: sjyanxin/WPFSource
 public RootXMLNSAndUriValidatingXmlReader(
             XpsValidatingLoader loader, 
             XpsSchema schema, 
             XmlReader xmlReader )
     : base(xmlReader) 
 {
     _loader = loader;
     _schema = schema;
 } 
コード例 #17
0
ファイル: FixedSchema.cs プロジェクト: sjyanxin/WPFSource
 static protected void RegisterSchema(XpsSchema schema, ContentType[] handledMimeTypes) 
 {
     foreach (ContentType mime in handledMimeTypes) 
     {
         _schemas.Add(mime, schema);
     }
 }