Esempio n. 1
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;
        }
Esempio n. 2
0
        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();
 
        }
 public PreserveItemSet(string namespaceName, XmlCompatibilityReader reader)
 {
     _namespaceName = namespaceName;
     _reader = reader;
 }
 public ProcessContentSet(string namespaceName, XmlCompatibilityReader reader)
 {
     _namespaceName = namespaceName;
     _reader = reader;
 }
 public CompatibilityScope(CompatibilityScope previous, int depth, XmlCompatibilityReader reader)
 {
     _previous = previous;
     _depth = depth;
     _reader = reader;
 }
Esempio n. 6
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; 
 
        }