diff options
author | Atsushi Eno <atsushieno@gmail.com> | 2005-08-16 22:23:16 +0400 |
---|---|---|
committer | Atsushi Eno <atsushieno@gmail.com> | 2005-08-16 22:23:16 +0400 |
commit | 718c8cb031911e2a19c9eb0044a55a49d3ad8624 (patch) | |
tree | 5eb22084bdea9f25f3f131bb97f52020f32ff940 /mcs/class/System.XML/System.Xml/DTDObjectModel.cs | |
parent | 81ca813b86b53cde4064e55b90e287bdcdc5cc56 (diff) |
2005-08-16 Atsushi Enomoto <atsushi@ximian.com>
* XmlTextReader.cs, XmlTextReader2.cs : added internal .ctor() to
receive both TextReader, XmlNodeType and BaseURI for entity
resolution (though it would be removed later).
* XmlParserInput.cs : Now to handle nested PE insertion and correct
BaseURI, it internally holds a stack of "input source".
* DTDObjectModel.cs,
DTDReader.cs :
Required fixes for XmlParserInput.
Handle BaseURI as expected. Added ActualUri for resolved actual
source URI (to resolve nested entities). Pass ActualUri to internal
XmlTextReader.ctor() in ResolveExternalEntityReplacementText()
(well, yes I remember, it is problematic.)
Incorrect Base URI handling bug (part of #51495) is fixed.
svn path=/trunk/mcs/; revision=48443
Diffstat (limited to 'mcs/class/System.XML/System.Xml/DTDObjectModel.cs')
-rw-r--r-- | mcs/class/System.XML/System.Xml/DTDObjectModel.cs | 51 |
1 files changed, 35 insertions, 16 deletions
diff --git a/mcs/class/System.XML/System.Xml/DTDObjectModel.cs b/mcs/class/System.XML/System.Xml/DTDObjectModel.cs index 858430ccc99..5cbebbd8913 100644 --- a/mcs/class/System.XML/System.Xml/DTDObjectModel.cs +++ b/mcs/class/System.XML/System.Xml/DTDObjectModel.cs @@ -953,9 +953,12 @@ namespace Mono.Xml string systemId; string literalValue; string replacementText; + string uriString; + Uri absUri; bool isInvalid; // Exception loadException; bool loadFailed; + XmlResolver resolver; protected DTDEntityBase (DTDObjectModel root) { @@ -997,33 +1000,49 @@ namespace Mono.Xml set { replacementText = value; } } - public void Resolve (XmlResolver resolver) + public XmlResolver XmlResolver { + set { resolver = value; } + } + + public string ActualUri { + get { + if (uriString == null) { + if (resolver == null || SystemId == null || SystemId.Length == 0) + uriString = BaseURI; + else { + Uri baseUri = null; + try { + if (BaseURI != null && BaseURI.Length > 0) + baseUri = new Uri (BaseURI); + } catch (UriFormatException) { + } + + absUri = resolver.ResolveUri (baseUri, SystemId); + uriString = absUri != null ? absUri.ToString () : String.Empty; + } + } + return uriString; + } + } + + public void Resolve () { - if (resolver == null || SystemId == null || SystemId.Length == 0) { + if (ActualUri == String.Empty) { LoadFailed = true; LiteralEntityValue = String.Empty; return; } - Uri baseUri = null; - try { - if (BaseURI != null && BaseURI.Length > 0) - baseUri = new Uri (BaseURI); - } catch (UriFormatException) { - } - - Uri absUri = resolver.ResolveUri (baseUri, SystemId); - string absPath = absUri != null ? absUri.ToString () : String.Empty; - if (Root.ExternalResources.ContainsKey (absPath)) - LiteralEntityValue = (string) Root.ExternalResources [absPath]; + if (Root.ExternalResources.ContainsKey (ActualUri)) + LiteralEntityValue = (string) Root.ExternalResources [ActualUri]; Stream s = null; try { s = resolver.GetEntity (absUri, null, typeof (Stream)) as Stream; - XmlTextReaderImpl xtr = new XmlTextReaderImpl (absPath, s, Root.NameTable); + XmlTextReaderImpl xtr = new XmlTextReaderImpl (ActualUri, s, Root.NameTable); // Don't skip Text declaration here. LiteralEntityValue contains it. See spec 4.5 LiteralEntityValue = xtr.GetRemainder ().ReadToEnd (); - Root.ExternalResources.Add (absPath, LiteralEntityValue); + Root.ExternalResources.Add (ActualUri, LiteralEntityValue); if (Root.ExternalResources.Count > DTDObjectModel.AllowedExternalEntitiesMax) throw new InvalidOperationException ("The total amount of external entities exceeded the allowed number."); @@ -1031,7 +1050,7 @@ namespace Mono.Xml // loadException = ex; LiteralEntityValue = String.Empty; LoadFailed = true; -// throw NotWFError ("Cannot resolve external entity. URI is " + absPath + " ."); +// throw NotWFError ("Cannot resolve external entity. URI is " + ActualUri + " ."); } finally { if (s != null) s.Close (); |