// 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;
        }
        // Token: 0x06006382 RID: 25474 RVA: 0x001BFF98 File Offset: 0x001BE198
        private XmlCompatibilityReader SetupReader(IDictionary <Uri, IList <Uri> > knownNamespaces)
        {
            IList <string> list = new List <string>();

            foreach (Uri uri in XmlStreamStore._predefinedNamespaces.Keys)
            {
                list.Add(uri.ToString());
            }
            if (knownNamespaces != null)
            {
                foreach (Uri uri2 in knownNamespaces.Keys)
                {
                    list.Add(uri2.ToString());
                }
            }
            XmlCompatibilityReader xmlCompatibilityReader = new XmlCompatibilityReader(new XmlTextReader(this._stream), new IsXmlNamespaceSupportedCallback(this.IsXmlNamespaceSupported), list);

            if (knownNamespaces != null)
            {
                foreach (KeyValuePair <Uri, IList <Uri> > keyValuePair in knownNamespaces)
                {
                    if (keyValuePair.Value != null)
                    {
                        foreach (Uri uri3 in keyValuePair.Value)
                        {
                            xmlCompatibilityReader.DeclareNamespaceCompatibility(keyValuePair.Key.ToString(), uri3.ToString());
                        }
                    }
                }
            }
            this._ignoredNamespaces.Clear();
            return(xmlCompatibilityReader);
        }
Example #3
0
        // Token: 0x06002E76 RID: 11894 RVA: 0x000D289C File Offset: 0x000D0A9C
        private static string _ConstructPageString(Stream pageStream, bool reverseRTL)
        {
            XmlTextReader baseReader = new XmlTextReader(pageStream);
            XmlReader     xmlReader  = new XmlCompatibilityReader(baseReader, FixedFindEngine._predefinedNamespaces);

            xmlReader = XmlReader.Create(xmlReader, new XmlReaderSettings
            {
                IgnoreWhitespace = true,
                IgnoreComments   = true,
                ProhibitDtd      = true
            });
            xmlReader.MoveToContent();
            StringBuilder stringBuilder = new StringBuilder();
            bool          flag          = false;
            string        text          = null;

            while (xmlReader.Read())
            {
                XmlNodeType nodeType = xmlReader.NodeType;
                if (nodeType == XmlNodeType.Element && xmlReader.Name == "Glyphs")
                {
                    text = xmlReader.GetAttribute("UnicodeString");
                    if (!string.IsNullOrEmpty(text))
                    {
                        string attribute = xmlReader.GetAttribute("IsSideways");
                        flag = false;
                        if (attribute != null && string.Compare(attribute, bool.TrueString, StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            flag = true;
                        }
                        if (reverseRTL)
                        {
                            string attribute2 = xmlReader.GetAttribute("BidiLevel");
                            int    num        = 0;
                            if (!string.IsNullOrEmpty(attribute2))
                            {
                                try
                                {
                                    num = Convert.ToInt32(attribute2, CultureInfo.InvariantCulture);
                                }
                                catch (Exception)
                                {
                                }
                            }
                            string attribute3 = xmlReader.GetAttribute("CaretStops");
                            if (num == 0 && !flag && string.IsNullOrEmpty(attribute3) && FixedTextBuilder.MostlyRTL(text))
                            {
                                char[] array = text.ToCharArray();
                                Array.Reverse(array);
                                text = new string(array);
                            }
                        }
                        stringBuilder.Append(text);
                    }
                }
            }
            return(stringBuilder.ToString());
        }
Example #4
0
        private void Initialize(XmlReader givenXmlReader, XamlSchemaContext schemaContext, XamlTextReaderSettings settings)
        {
            XmlReader myXmlReader;

            if (givenXmlReader == null)
            {
                throw new ArgumentNullException("XmlReader is null");
            }

            _mergedSettings = (settings == null) ? new XamlTextReaderSettings() : new XamlTextReaderSettings(settings);

            //Wrap the xmlreader with a XmlCompatReader instance to apply MarkupCompat rules.
            if (!_mergedSettings.SkipXmlCompatibilityProcessing)
            {
                XmlCompatibilityReader mcReader =
                    new XmlCompatibilityReader(givenXmlReader,
                                               new IsXmlNamespaceSupportedCallback(IsXmlNamespaceSupported)
                                               );
                myXmlReader = mcReader;
            }
            else
            {   // Don't wrap the xmlreader with XmlCompatReader.
                // Useful for uses where users want to keep mc: content in the XamlNode stream.
                // Or have already processed the markup compat and want that extra perf.
                // We need to go make sure the parser thinks it knows mc: uri,
                // in case SkipXmlCompatibilityProcessing is true... likely won't work yet.
                myXmlReader = givenXmlReader;
            }
            // Pick up the XmlReader settings to override the "settings" defaults.
            if (!String.IsNullOrEmpty(myXmlReader.BaseURI))
            {
                _mergedSettings.BaseUri = new Uri(myXmlReader.BaseURI);
            }
            if (myXmlReader.XmlSpace == XmlSpace.Preserve)
            {
                _mergedSettings.XmlSpacePreserve = true;
            }
            if (!String.IsNullOrEmpty(myXmlReader.XmlLang))
            {
                _mergedSettings.XmlLang = myXmlReader.XmlLang;
            }

            if (schemaContext == null)
            {
                schemaContext = new XamlSchemaContext();
            }

            _endOfStreamNode = new InternalNode(InternalNodeType.EndOfStream);

            _context = (XamlParserContext)XamlContext.CreateContext(UsageMode.Parser, schemaContext,
                                                                    _mergedSettings.LocalAssembly, false /*ignoreCanConvert*/);

            XamlScanner    xamlScanner = new XamlScanner(_context, myXmlReader, _mergedSettings);
            XamlPullParser parser      = new XamlPullParser(_context, xamlScanner, _mergedSettings);

            _nodeStream = new NodeStreamSorter(_context, parser, _mergedSettings);
            _current    = _endOfStreamNode; // user must call Read() before using properties.
        }
Example #5
0
        //This method processes the attributes that are present on the Relationship element
        private void ProcessRelationshipAttributes(XmlCompatibilityReader reader)
        {
            // Attribute : TargetMode

            string?targetModeAttributeValue = reader.GetAttribute(TargetModeAttributeName);

            //If the TargetMode attribute is missing in the underlying markup then we assume it to be internal
            TargetMode relationshipTargetMode = TargetMode.Internal;

            if (targetModeAttributeValue != null)
            {
                try
                {
#if NET6_0_OR_GREATER
                    relationshipTargetMode = Enum.Parse <TargetMode>(targetModeAttributeValue, ignoreCase: false);
#else
                    relationshipTargetMode = (TargetMode)(Enum.Parse(typeof(TargetMode), targetModeAttributeValue, ignoreCase: false));
#endif
                }
                catch (ArgumentNullException argNullEx)
                {
                    ThrowForInvalidAttributeValue(reader, TargetModeAttributeName, argNullEx);
                }
                catch (ArgumentException argEx)
                {
                    //if the targetModeAttributeValue is not Internal|External then Argument Exception will be thrown.
                    ThrowForInvalidAttributeValue(reader, TargetModeAttributeName, argEx);
                }
            }

            // Attribute : Target
            // create a new PackageRelationship
            string?targetAttributeValue = reader.GetAttribute(TargetAttributeName);
            if (string.IsNullOrEmpty(targetAttributeValue))
            {
                throw new XmlException(SR.Format(SR.RequiredRelationshipAttributeMissing, TargetAttributeName), null, reader.LineNumber, reader.LinePosition);
            }

            Uri targetUri = new Uri(targetAttributeValue, DotNetRelativeOrAbsolute);

            // Attribute : Type
            string?typeAttributeValue = reader.GetAttribute(TypeAttributeName);
            if (string.IsNullOrEmpty(typeAttributeValue))
            {
                throw new XmlException(SR.Format(SR.RequiredRelationshipAttributeMissing, TypeAttributeName), null, reader.LineNumber, reader.LinePosition);
            }

            // Attribute : Id
            // Get the Id attribute (required attribute).
            string?idAttributeValue = reader.GetAttribute(IdAttributeName);
            if (string.IsNullOrEmpty(idAttributeValue))
            {
                throw new XmlException(SR.Format(SR.RequiredRelationshipAttributeMissing, IdAttributeName), null, reader.LineNumber, reader.LinePosition);
            }

            // Add the relationship to the collection
            Add(targetUri, relationshipTargetMode, typeAttributeValue, idAttributeValue, parsing: true);
        }
Example #6
0
        private IEnumerable <Instruction> ConvertToNodes(Stream stream)
        {
            var reader            = new XmlCompatibilityReader(stream);
            var runtimeTypeSource = RuntimeTypeSource;
            var pullParser        = new InstructionParser(runtimeTypeSource);
            var protoParser       = new ProtoInstructionParser(runtimeTypeSource);

            return(pullParser.Parse(protoParser.Parse(reader)).ToList());
        }
        //Throws an exception if the xml:base attribute is present in the Relationships XML
        private void ThrowIfXmlBaseAttributeIsPresent(XmlCompatibilityReader reader)
        {
            string xmlBaseAttributeValue = reader.GetAttribute(s_xmlBaseAttributeName);

            if (xmlBaseAttributeValue != null)
            {
                throw new XmlException(SR.Format(SR.InvalidXmlBaseAttributePresent, s_xmlBaseAttributeName), null, reader.LineNumber, reader.LinePosition);
            }
        }
        //This method processes the attributes that are present on the Relationship element
        private void ProcessRelationshipAttributes(XmlCompatibilityReader reader)
        {
            // Attribute : TargetMode

            string targetModeAttributeValue = reader.GetAttribute(s_targetModeAttributeName);

            //If the TargetMode attribute is missing in the underlying markup then we assume it to be internal
            TargetMode relationshipTargetMode = TargetMode.Internal;

            if (targetModeAttributeValue != null)
            {
                try
                {
                    relationshipTargetMode = (TargetMode)(Enum.Parse(typeof(TargetMode), targetModeAttributeValue, false /* ignore case */));
                }
                catch (ArgumentNullException argNullEx)
                {
                    ThrowForInvalidAttributeValue(reader, s_targetModeAttributeName, argNullEx);
                }
                catch (ArgumentException argEx)
                {
                    //if the targetModeAttributeValue is not Internal|External then Argument Exception will be thrown.
                    ThrowForInvalidAttributeValue(reader, s_targetModeAttributeName, argEx);
                }
            }

            // Attribute : Target
            // create a new PackageRelationship
            string targetAttributeValue = reader.GetAttribute(s_targetAttributeName);

            if (targetAttributeValue == null || targetAttributeValue == String.Empty)
            {
                throw new XmlException(SR.Format(SR.RequiredRelationshipAttributeMissing, s_targetAttributeName), null, reader.LineNumber, reader.LinePosition);
            }

            Uri targetUri = new Uri(targetAttributeValue, UriKind.RelativeOrAbsolute);

            // Attribute : Type
            string typeAttributeValue = reader.GetAttribute(s_typeAttributeName);

            if (typeAttributeValue == null || typeAttributeValue == String.Empty)
            {
                throw new XmlException(SR.Format(SR.RequiredRelationshipAttributeMissing, s_typeAttributeName), null, reader.LineNumber, reader.LinePosition);
            }

            // Attribute : Id
            // Get the Id attribute (required attribute).
            string idAttributeValue = reader.GetAttribute(s_idAttributeName);

            if (idAttributeValue == null || idAttributeValue == String.Empty)
            {
                throw new XmlException(SR.Format(SR.RequiredRelationshipAttributeMissing, s_idAttributeName), null, reader.LineNumber, reader.LinePosition);
            }

            // Add the relationship to the collection
            Add(targetUri, relationshipTargetMode, typeAttributeValue, idAttributeValue, true /*parsing*/);
        }
Example #9
0
        private IEnumerable <XamlInstruction> ConvertToNodes(Stream stream)
        {
            var reader        = new XmlCompatibilityReader(stream);
            var wiringContext = WiringContext;
            var pullParser    = new XamlInstructionParser(wiringContext);
            var protoParser   = new XamlProtoInstructionParser(wiringContext);

            return(pullParser.Parse(protoParser.Parse(reader)).ToList());
        }
        private ICollection <XamlInstruction> ExtractNodesFromPullParser(string xml)
        {
            var pullParser = new XamlInstructionParser(WiringContext);

            using (var stream = new StringReader(xml))
            {
                var reader = new XmlCompatibilityReader(stream);
                return(pullParser.Parse(new XamlProtoInstructionParser(WiringContext).Parse(reader)).ToList());
            }
        }
        private ICollection <Instruction> ExtractNodesFromPullParser(string xml)
        {
            var pullParser = new InstructionParser(RuntimeTypeSource);

            using (var stream = new StringReader(xml))
            {
                var reader = new XmlCompatibilityReader(stream);
                return(pullParser.Parse(new ProtoInstructionParser(RuntimeTypeSource).Parse(reader)).ToList());
            }
        }
Example #12
0
        private static IEnumerable <XamlInstruction> ReadNodes(Type underlyingType)
        {
            var resourceProvider = new InflatableTranslator();

            using (var stream = resourceProvider.GetInflationSourceStream(underlyingType))
            {
                var reader        = new XmlCompatibilityReader(stream);
                var wiringContext = (IWiringContext) new WpfWiringContext(new TypeFactory());
                var loader        = new XamlInstructionParser(wiringContext);
                var protoParser   = new XamlProtoInstructionParser(wiringContext);

                return(loader.Parse(protoParser.Parse(reader)));
            }
        }
Example #13
0
        private static IEnumerable <Instruction> ReadNodes(Type underlyingType)
        {
            var resourceProvider = new InflatableTranslator();

            using (var stream = resourceProvider.GetInflationSourceStream(underlyingType))
            {
                var reader            = new XmlCompatibilityReader(stream);
                var runtimeTypeSource = new WpfRuntimeTypeSource();
                var loader            = new InstructionParser(runtimeTypeSource);
                var protoParser       = new ProtoInstructionParser(runtimeTypeSource);

                return(loader.Parse(protoParser.Parse(reader)));
            }
        }
Example #14
0
        /// <summary>
        /// Creates and initializes the XmlCompatibilityReader
        /// </summary>
        /// <param name="knownNamespaces">Dictionary of external known namespaces</param>
        /// <returns>The XmlCompatibilityReader</returns>
        private XmlCompatibilityReader SetupReader(IDictionary <Uri, IList <Uri> > knownNamespaces)
        {
            IList <string> supportedNamespaces = new List <string>();

            //add AnnotationFramework namespaces
            foreach (Uri name in _predefinedNamespaces.Keys)
            {
                supportedNamespaces.Add(name.ToString());
            }

            //add external namespaces
            if (knownNamespaces != null)
            {
                foreach (Uri knownNamespace in knownNamespaces.Keys)
                {
                    Debug.Assert(knownNamespace != null, "null knownNamespace");
                    supportedNamespaces.Add(knownNamespace.ToString());
                }
            }

            //create XmlCompatibilityReader first
            XmlCompatibilityReader reader = new XmlCompatibilityReader(new XmlTextReader(_stream),
                                                                       new IsXmlNamespaceSupportedCallback(IsXmlNamespaceSupported), supportedNamespaces);

            // Declare compatibility.
            // Skip the Framework ones because they are all null in this version
            if (knownNamespaces != null)
            {
                foreach (KeyValuePair <Uri, IList <Uri> > item in knownNamespaces)
                {
                    if (item.Value != null)
                    {
                        foreach (Uri name in item.Value)
                        {
                            Debug.Assert(name != null, "null compatible namespace");
                            reader.DeclareNamespaceCompatibility(item.Key.ToString(), name.ToString());
                        } //foreach
                    }     //if
                }         //foreach
            }             //if

            //cleanup the _ignoredNamespaces
            _ignoredNamespaces.Clear();
            return(reader);
        }
        //If End element is present for Relationship then we process it
        private void ProcessEndElementForRelationshipTag(XmlCompatibilityReader reader)
        {
            Debug.Assert(!reader.IsEmptyElement, "This method should only be called if the Relationship Element is not empty");

            reader.Read();

            //Skips over the following - ProcessingInstruction, DocumentType, Comment, Whitespace, or SignificantWhitespace
            reader.MoveToContent();

            if (reader.NodeType == XmlNodeType.EndElement && String.CompareOrdinal(s_relationshipTagName, reader.LocalName) == 0)
            {
                return;
            }
            else
            {
                throw new XmlException(SR.Format(SR.ElementIsNotEmptyElement, s_relationshipTagName), null, reader.LineNumber, reader.LinePosition);
            }
        }
        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;
        }
Example #17
0
        public void CheckIgnorable()
        {
            var xml = @"
<Root xmlns:mc='http://schemas.openxmlformats.org/markup-compatibility/2006' 
     xmlns:i1='i1Uri' xmlns:i2='i2Uri' 
	xmlns:compat='mapped' xmlns:ignoredCompat='mapped2' xmlns:ignoredCompat2='preserve' 
	mc:Ignorable='i1 ignoredCompat ignoredCompat2'>
    <Element i2:ShouldNotIgnore='1'/>
	<i1:ShouldIgnore/>
	<i1:ShouldIgnore>
		<i2:ShouldIgnore/>
	</i1:ShouldIgnore>
    <Element i2:ShouldNotIgnore='1'>
		<i1:ShouldIgnore/> 
		<i2:ShouldNotIgnore/>
		<i2:ShouldNotIgnore>
			<i2:ShouldNotIgnore/>
		</i2:ShouldNotIgnore>
		<i1:ShouldIgnore> 
			<i2:ShouldIgnore/>
		</i1:ShouldIgnore> 
	</Element>
    <Element i1:ShouldAlwaysIgnore='1' mc:Ignorable='i2' i2:ShouldIgnore='1'/>
    <Element i1:ShouldAlwaysIgnore='1' mc:Ignorable='i2' i2:ShouldIgnore='1'>
		<i2:ShouldIgnore/>
		<i2:ShouldIgnore>
			<ShouldIgnore/>
		</i2:ShouldIgnore>
		<Element i2:ShouldIgnore='1'/>
	</Element>
	<Element i2:ShouldNotIgnore='1'/>
    <Element compat:ShouldMap='1' ignoredCompat:ShouldMap='1' ignoredCompat2:ShouldMapAndPreserve='1'/>
</Root>";
            // TODO: Use XamlXmlParser directly with compaibility mode turned on.
            var rdr = new XmlCompatibilityReader(XmlReader.Create(new StringReader(xml)),
                                                 (string ns, out string mapped) =>
            {
                if (ns == "mapped")
                {
                    mapped = "mappedTo";
                    return(true);
                }
                if (ns == "mapped2")
                {
                    mapped = "mappedTo2";
                    return(true);
                }
                if (ns == "preserve")
                {
                    mapped = "preserve";
                    return(true);
                }
                mapped = null;
                return(false);
            });
            var actual   = XElement.Load(rdr).ToString();
            var expected =
                @"
<Root xmlns:mc='http://schemas.openxmlformats.org/markup-compatibility/2006' xmlns:i1='i1Uri' xmlns:i2='i2Uri' xmlns:compat='mappedTo' xmlns:ignoredCompat='mappedTo2' xmlns:ignoredCompat2='preserve'>
    <Element i2:ShouldNotIgnore='1' />
	<Element i2:ShouldNotIgnore='1'>
		<i2:ShouldNotIgnore />
		<i2:ShouldNotIgnore>
			<i2:ShouldNotIgnore />
		</i2:ShouldNotIgnore>
		</Element>
    <Element />
    <Element>
		<Element />
	</Element>
	<Element i2:ShouldNotIgnore='1' />
    <Element compat:ShouldMap='1' ignoredCompat:ShouldMap='1' ignoredCompat2:ShouldMapAndPreserve='1' />
</Root>";
            Func <string, string> filter = s => expected.Replace(" ", "").Replace('\'', '"').Replace("\n", "").Replace("\r", "");

            Assert.AreEqual(filter(expected), filter(actual));
        }
        private static String _ConstructPageString(Stream pageStream, bool reverseRTL)
        {
            Debug.Assert(pageStream != null);

            XmlTextReader xmlTextReader = new XmlTextReader(pageStream);

            //Wrap around a compatibility reader
            XmlReader xmlReader = new XmlCompatibilityReader(xmlTextReader, _predefinedNamespaces);

            XmlReaderSettings settings = new XmlReaderSettings();

            settings.IgnoreWhitespace = true;
            settings.IgnoreComments   = true;
            settings.ProhibitDtd      = true;

            xmlReader = XmlReader.Create(xmlReader, settings);

            xmlReader.MoveToContent();

            StringBuilder pageString = new StringBuilder();
            bool          isSideways = false;
            string        unicodeStr = null;

            while (xmlReader.Read())
            {
                switch (xmlReader.NodeType)
                {
                case XmlNodeType.Element:
                {
                    if (xmlReader.Name == "Glyphs")
                    {
                        unicodeStr = xmlReader.GetAttribute("UnicodeString");

                        if (!String.IsNullOrEmpty(unicodeStr))
                        {
                            string sidewaysString = xmlReader.GetAttribute("IsSideways");
                            isSideways = false;
                            if (sidewaysString != null &&
                                String.Compare(sidewaysString, Boolean.TrueString, StringComparison.OrdinalIgnoreCase) == 0)
                            {
                                isSideways = true;
                            }

                            if (reverseRTL)
                            {
                                //This is to cover for MXDW generation
                                //RTL Glyphs are saved LTR and bidi level is not set
                                //In this case we need to reverse the UnicodeString
                                string bidiLevelAsString = xmlReader.GetAttribute("BidiLevel");
                                int    bidiLevel         = 0;
                                if (!String.IsNullOrEmpty(bidiLevelAsString))
                                {
                                    try
                                    {
                                        bidiLevel = Convert.ToInt32(bidiLevelAsString, CultureInfo.InvariantCulture);
                                    }
                                    catch (Exception)
                                    {
                                    }
                                }

                                string caretStops = xmlReader.GetAttribute("CaretStops");

                                if (bidiLevel == 0 &&
                                    !isSideways &&
                                    String.IsNullOrEmpty(caretStops) &&
                                    FixedTextBuilder.MostlyRTL(unicodeStr))
                                {
                                    char[] chars = unicodeStr.ToCharArray();
                                    Array.Reverse(chars);
                                    unicodeStr = new String(chars);
                                }
                            }


                            pageString.Append(unicodeStr);
                        }
                    }
                }
                break;
                }
            }
            return(pageString.ToString());
        }
        /// <summary>
        /// Parse PackageRelationship Stream
        /// </summary>
        /// <param name="part">relationship part</param>
        /// <exception cref="XmlException">Thrown if XML is malformed</exception>
        private void ParseRelationshipPart(PackagePart part)
        {
            //We can safely open the stream as FileAccess.Read, as this code
            //should only be invoked if the Package has been opened in Read or ReadWrite mode.
            Debug.Assert(_package.FileOpenAccess == FileAccess.Read || _package.FileOpenAccess == FileAccess.ReadWrite,
                         "This method should only be called when FileAccess is Read or ReadWrite");

            using (Stream s = part.GetStream(FileMode.Open, FileAccess.Read))
            {
                // load from the relationship part associated with the given part
                using (XmlReader baseReader = XmlReader.Create(s))
                {
                    using (XmlCompatibilityReader reader = new XmlCompatibilityReader(baseReader, s_relationshipKnownNamespaces))
                    {
                        //This method expects the reader to be in ReadState.Initial.
                        //It will make the first read call.
                        PackagingUtilities.PerformInitialReadAndVerifyEncoding(baseReader);

                        //Note: After the previous method call the reader should be at the first tag in the markup.
                        //MoveToContent - Skips over the following - ProcessingInstruction, DocumentType, Comment, Whitespace, or SignificantWhitespace
                        //If the reader is currently at a content node then this function call is a no-op
                        reader.MoveToContent();

                        // look for our tag and namespace pair - throw if other elements are encountered
                        // Make sure that the current node read is an Element
                        if (reader.NodeType == XmlNodeType.Element &&
                            (reader.Depth == 0) &&
                            (String.CompareOrdinal(s_relationshipsTagName, reader.LocalName) == 0) &&
                            (String.CompareOrdinal(PackagingUtilities.RelationshipNamespaceUri, reader.NamespaceURI) == 0))
                        {
                            ThrowIfXmlBaseAttributeIsPresent(reader);

                            //There should be a namespace Attribute present at this level.
                            //Also any other attribute on the <Relationships> tag is an error including xml: and xsi: attributes
                            if (PackagingUtilities.GetNonXmlnsAttributeCount(reader) > 0)
                            {
                                throw new XmlException(SR.RelationshipsTagHasExtraAttributes, null, reader.LineNumber, reader.LinePosition);
                            }

                            // start tag encountered for Relationships
                            // now parse individual Relationship tags
                            while (reader.Read())
                            {
                                //Skips over the following - ProcessingInstruction, DocumentType, Comment, Whitespace, or SignificantWhitespace
                                //If the reader is currently at a content node then this function call is a no-op
                                reader.MoveToContent();

                                //If MoveToContent() takes us to the end of the content
                                if (reader.NodeType == XmlNodeType.None)
                                {
                                    continue;
                                }

                                if (reader.NodeType == XmlNodeType.Element &&
                                    (reader.Depth == 1) &&
                                    (String.CompareOrdinal(s_relationshipTagName, reader.LocalName) == 0) &&
                                    (String.CompareOrdinal(PackagingUtilities.RelationshipNamespaceUri, reader.NamespaceURI) == 0))
                                {
                                    ThrowIfXmlBaseAttributeIsPresent(reader);

                                    int expectedAttributesCount = 3;

                                    string targetModeAttributeValue = reader.GetAttribute(s_targetModeAttributeName);
                                    if (targetModeAttributeValue != null)
                                    {
                                        expectedAttributesCount++;
                                    }

                                    //check if there are expected number of attributes.
                                    //Also any other attribute on the <Relationship> tag is an error including xml: and xsi: attributes
                                    if (PackagingUtilities.GetNonXmlnsAttributeCount(reader) == expectedAttributesCount)
                                    {
                                        ProcessRelationshipAttributes(reader);

                                        //Skip the EndElement for Relationship
                                        if (!reader.IsEmptyElement)
                                        {
                                            ProcessEndElementForRelationshipTag(reader);
                                        }
                                    }
                                    else
                                    {
                                        throw new XmlException(SR.RelationshipTagDoesntMatchSchema, null, reader.LineNumber, reader.LinePosition);
                                    }
                                }
                                else
                                if (!(String.CompareOrdinal(s_relationshipsTagName, reader.LocalName) == 0 && (reader.NodeType == XmlNodeType.EndElement)))
                                {
                                    throw new XmlException(SR.UnknownTagEncountered, null, reader.LineNumber, reader.LinePosition);
                                }
                            }
                        }
                        else
                        {
                            throw new XmlException(SR.ExpectedRelationshipsElementTag, null, reader.LineNumber, reader.LinePosition);
                        }
                    }
                }
            }
        }
Example #20
0
        private void Initialize(XmlReader givenXmlReader, XamlSchemaContext schemaContext, XamlXmlReaderSettings settings)
        {
            XmlReader myXmlReader;

            _mergedSettings = (settings == null) ? new XamlXmlReaderSettings() : new XamlXmlReaderSettings(settings);
            //Wrap the xmlreader with a XmlCompatReader instance to apply MarkupCompat rules.
            if (!_mergedSettings.SkipXmlCompatibilityProcessing)
            {
                XmlCompatibilityReader mcReader =
                    new XmlCompatibilityReader(givenXmlReader,
                                               new IsXmlNamespaceSupportedCallback(IsXmlNamespaceSupported)
                                               );
                mcReader.Normalization = true;
                myXmlReader            = mcReader;
            }
            else
            {   //Don't wrap the xmlreader with XmlCompatReader.
                // Useful for uses where users want to keep mc: content in the XamlNode stream.
                // Or have already processed the markup compat and want that extra perf.
                myXmlReader = givenXmlReader;
            }
            // Pick up the XmlReader settings to override the "settings" defaults.
            if (!String.IsNullOrEmpty(myXmlReader.BaseURI))
            {
                _mergedSettings.BaseUri = new Uri(myXmlReader.BaseURI);
            }
            if (myXmlReader.XmlSpace == XmlSpace.Preserve)
            {
                _mergedSettings.XmlSpacePreserve = true;
            }
            if (!String.IsNullOrEmpty(myXmlReader.XmlLang))
            {
                _mergedSettings.XmlLang = myXmlReader.XmlLang;
            }
            IXmlNamespaceResolver       myXmlReaderNS   = myXmlReader as IXmlNamespaceResolver;
            Dictionary <string, string> xmlnsDictionary = null;

            if (myXmlReaderNS != null)
            {
                IDictionary <string, string> rootNamespaces = myXmlReaderNS.GetNamespacesInScope(XmlNamespaceScope.Local);
                if (rootNamespaces != null)
                {
                    foreach (KeyValuePair <string, string> ns in rootNamespaces)
                    {
                        if (xmlnsDictionary == null)
                        {
                            xmlnsDictionary = new Dictionary <string, string>();
                        }
                        xmlnsDictionary[ns.Key] = ns.Value;
                    }
                }
            }

            if (schemaContext == null)
            {
                schemaContext = new XamlSchemaContext();
            }

            _endOfStreamNode = new XamlNode(XamlNode.InternalNodeType.EndOfStream);

            _context = new XamlParserContext(schemaContext, _mergedSettings.LocalAssembly);
            _context.AllowProtectedMembersOnRoot = _mergedSettings.AllowProtectedMembersOnRoot;
            _context.AddNamespacePrefix(KnownStrings.XmlPrefix, XamlLanguage.Xml1998Namespace);

            Func <string, string> namespaceResolver = myXmlReader.LookupNamespace;

            _context.XmlNamespaceResolver = namespaceResolver;

            XamlScanner    xamlScanner = new XamlScanner(_context, myXmlReader, _mergedSettings);
            XamlPullParser parser      = new XamlPullParser(_context, xamlScanner, _mergedSettings);

            _nodeStream      = new NodeStreamSorter(_context, parser, _mergedSettings, xmlnsDictionary);
            _current         = new XamlNode(XamlNode.InternalNodeType.StartOfStream); // user must call Read() before using properties.
            _currentLineInfo = new LineInfo(0, 0);
        }
Example #21
0
        protected XamlParser(
            ParserContext parserContext,
            BamlRecordWriter bamlWriter,
            XmlTextReader textReader) : this(parserContext, bamlWriter)
        {

            // When the XML 1.0 specification was authored, security was not a top concern, and as a result DTDs have the
            // unfortunate capability of severe Denial of Service (DoS) attacks, typically through the use of an internal
            // entity expansion technique. In System.Xml V2.0, in order to provide protection against DTD DoS attacks there
            // is the capability of turning off DTD parsing through the use of the ProhibitDtd property.

            textReader.ProhibitDtd = true;

            XmlCompatibilityReader xcr = new XmlCompatibilityReader(textReader,
                                                                    new IsXmlNamespaceSupportedCallback(IsXmlNamespaceSupported),
                                                                    _predefinedNamespaces );

            TokenReader = new XamlReaderHelper(this,parserContext,xcr);
        }
Example #22
0
        private static IEnumerable<Instruction> ReadNodes(Type underlyingType)
        {
            var resourceProvider = new InflatableTranslator();

            using (var stream = resourceProvider.GetInflationSourceStream(underlyingType))
            {
                var reader = new XmlCompatibilityReader(stream);
                var runtimeTypeSource = new WpfRuntimeTypeSource();
                var loader = new InstructionParser(runtimeTypeSource);
                var protoParser = new ProtoInstructionParser(runtimeTypeSource);

                return loader.Parse(protoParser.Parse(reader));
            }
        }
Example #23
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; 
        } 
 //Throws an XML exception if the attribute value is invalid
 private void ThrowForInvalidAttributeValue(XmlCompatibilityReader reader, String attributeName, Exception ex)
 {
     throw new XmlException(SR.Format(SR.InvalidValueForTheAttribute, attributeName), ex, reader.LineNumber, reader.LinePosition);
 }
Example #25
0
        private static IEnumerable<XamlInstruction> ReadNodes(Type underlyingType)
        {
            var resourceProvider = new InflatableTranslator();

            using (var stream = resourceProvider.GetInflationSourceStream(underlyingType))
            {
                var reader = new XmlCompatibilityReader(stream);
                var wiringContext = (IWiringContext) new WpfWiringContext(new TypeFactory());
                var loader = new XamlInstructionParser(wiringContext);
                var protoParser = new XamlProtoInstructionParser(wiringContext);

                return loader.Parse(protoParser.Parse(reader));
            }
        }