From: Oleg T. <he...@us...> - 2004-10-26 19:29:32
|
Update of /cvsroot/mvp-xml/XInclude/v1/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11487/v1/src Modified Files: SR.cs SR.resx TextIncludingReader.cs TextUtils.cs XIncludeException.cs XIncludingReader.cs Log Message: Working on bugs. Index: TextUtils.cs =================================================================== RCS file: /cvsroot/mvp-xml/XInclude/v1/src/TextUtils.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- TextUtils.cs 29 Sep 2004 21:26:28 -0000 1.2 +++ TextUtils.cs 26 Oct 2004 19:28:41 -0000 1.3 @@ -46,6 +46,19 @@ } } + /// <summary> + /// Checks value of the 'accept' attribute for validity. + /// Characters must be in #x20 through #x7E range. + /// </summary> + public static void CheckAcceptValue(string accept) + { + foreach (char c in accept) + { + if (c < 0x0020 || c > 0x007E) + throw new InvalidAcceptHTTPHeaderValue(c); + } + } + #endregion } } Index: XIncludeException.cs =================================================================== RCS file: /cvsroot/mvp-xml/XInclude/v1/src/XIncludeException.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- XIncludeException.cs 18 Oct 2004 18:19:21 -0000 1.5 +++ XIncludeException.cs 26 Oct 2004 19:28:41 -0000 1.6 @@ -103,4 +103,23 @@ { public MalformedXInclusionResultError(string message) : base(message) {} } + + /// <summary> + /// Value of the "accept" attribute contains an invalid for + /// HTTP header character (outside #x20 through #x7E range). + /// </summary> + public class InvalidAcceptHTTPHeaderValue : FatalException + { + public InvalidAcceptHTTPHeaderValue(char c) : + base(SR.GetString("InvalidCharForAccept", ((int)c).ToString("X2"))) {} + } + + /// <summary> + /// Fragment identifiers must not be used. + /// </summary> + public class FragmentIdentifierInHrefAttribute : FatalException + { + public FragmentIdentifierInHrefAttribute() : base(SR.FragmentIDInHref) {} + } + } Index: XIncludingReader.cs =================================================================== RCS file: /cvsroot/mvp-xml/XInclude/v1/src/XIncludingReader.cs,v retrieving revision 1.15 retrieving revision 1.16 diff -u -d -r1.15 -r1.16 --- XIncludingReader.cs 25 Oct 2004 19:32:39 -0000 1.15 +++ XIncludingReader.cs 26 Oct 2004 19:28:41 -0000 1.16 @@ -67,6 +67,8 @@ private FallbackState _prevFallbackState; //XmlResolver to resolve URIs XmlResolver _xmlResolver; + //Expose text inclusions as CDATA + private bool _exposeTextAsCDATA; #endregion #region Constructors @@ -689,10 +691,7 @@ //Read internal reader bool baseRead = _reader.Read(); if (baseRead) - { - //No provision to preserve whitespace outside document element - if (_reader.Depth == 0 && _reader.NodeType == XmlNodeType.Whitespace) - return Read(); + { //If we are including and including reader is at 0 depth - //we are in top level included item _topLevel = (_readers.Count>0 && _reader.Depth == 0)? true : false; @@ -831,11 +830,23 @@ /// Flag indicating whether to emit xml:base as relative URI. /// Note, it's true by default /// </summary> - public bool RelativeBaseUri + public bool MakeRelativeBaseUri { get { return _relativeBaseUri; } set { _relativeBaseUri = value; } } + + /// <summary> + /// Flag indicating whether expose text inclusions + /// as CDATA or as Text. By default it's Text. + /// </summary> + public bool ExposeTextInclusionsAsCDATA + { + get { return _exposeTextAsCDATA; } + set { _exposeTextAsCDATA = value; } + } + + #endregion #region Private methods @@ -915,7 +926,8 @@ if (httpReq != null) { if (accept != null) - { + { + TextUtils.CheckAcceptValue(accept); if (httpReq.Accept == null || httpReq.Accept == String.Empty) httpReq.Accept = accept; else @@ -949,7 +961,7 @@ { string href = _reader.GetAttribute(_keywords.Href); string xpointer = _reader.GetAttribute(_keywords.Xpointer); - if (href == null) + if (href == null || href == String.Empty) { if (xpointer == null) { @@ -978,6 +990,8 @@ { //Include document as XML Uri includeLocation = ResolveHref(href); + if (includeLocation.Fragment != String.Empty) + throw new FragmentIdentifierInHrefAttribute(); if (_xmlResolver == null) { //No custom resolver @@ -987,10 +1001,12 @@ _reader.GetAttribute(_keywords.AcceptLanguage), out wRes); //Push current reader to the stack _readers.Push(_reader); - if (xpointer != null) - _reader = new XPointerReader(wRes.ResponseUri, stream, _nameTable, xpointer); - else if (includeLocation.Fragment != String.Empty) - _reader = new XPointerReader(wRes.ResponseUri, stream, _nameTable, includeLocation.Fragment.Substring(1)); + if (xpointer != null) + { + //Well, XPointers should be resolved against the acquired infoset, + //not the source infoset + _reader = new XPointerReader(wRes.ResponseUri, stream, _nameTable, xpointer); + } else { _reader = new XmlBaseAwareXmlTextReader(wRes.ResponseUri.AbsoluteUri, stream, _nameTable); @@ -1044,7 +1060,8 @@ _readers.Push(_reader); _reader = new TextIncludingReader(includeLocation, encoding, _reader.GetAttribute(_keywords.Accept), - _reader.GetAttribute(_keywords.AcceptLanguage)); + _reader.GetAttribute(_keywords.AcceptLanguage), + _exposeTextAsCDATA); return Read(); } else @@ -1073,7 +1090,7 @@ try { if (_xmlResolver == null) - includeLocation = new Uri(new Uri(_reader.BaseURI), href); + includeLocation = new Uri(new Uri(_reader.BaseURI), href, false); else includeLocation = _xmlResolver.ResolveUri(new Uri(_reader.BaseURI), href); } @@ -1211,9 +1228,9 @@ } else throw new XIncludeSyntaxError(SR.GetString("IncludeChildOfInclude", - _reader.BaseURI.ToString())); + _reader.BaseURI.ToString())); } - if (IsFallbackElement(_reader)) + else if (IsFallbackElement(_reader)) { //Found xi:fallback if (fallbackElem) @@ -1235,6 +1252,11 @@ SkipContent(); } } + //Check anything else in XInclude namespace + else if(XIncludeKeywords.Equals(_reader.NamespaceURI, _keywords.XIncludeNamespace)) + { + throw new XIncludeSyntaxError(SR.GetString("UnknownXIncludeElement", _reader.Name)); + } else //Ignore everything else SkipContent(); Index: SR.cs =================================================================== RCS file: /cvsroot/mvp-xml/XInclude/v1/src/SR.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- SR.cs 18 Oct 2004 18:19:21 -0000 1.3 +++ SR.cs 26 Oct 2004 19:28:41 -0000 1.4 @@ -92,6 +92,16 @@ return SR.GetString("MalformedXInclusionResult"); } } + + + /// <summary></summary> + public static string FragmentIDInHref + { + get + { + return SR.GetString("FragmentIDInHref"); + } + } } } Index: SR.resx =================================================================== RCS file: /cvsroot/mvp-xml/XInclude/v1/src/SR.resx,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- SR.resx 18 Oct 2004 18:19:21 -0000 1.3 +++ SR.resx 26 Oct 2004 19:28:41 -0000 1.4 @@ -123,4 +123,13 @@ <data name="MalformedXInclusionResult" type="System.String" mimetype="System.String"> <value>Malformed XInclusion result - xi:include element at the top level can't include more than one element.</value> </data> + <data name="InvalidCharForAccept" type="System.String" mimetype="System.String"> + <value>'accept' attribute contains a character not allowed in HTTP header: 0x{0}.</value> + </data> + <data name="FragmentIDInHref" type="System.String" mimetype="System.String"> + <value>Fragment identifiers must not be used in 'href' attribute.</value> + </data> + <data name="UnknownXIncludeElement" type="System.String" mimetype="System.String"> + <value>Unknown element in the XInclude namespace has been detected: {0}.</value> + </data> </root> \ No newline at end of file Index: TextIncludingReader.cs =================================================================== RCS file: /cvsroot/mvp-xml/XInclude/v1/src/TextIncludingReader.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- TextIncludingReader.cs 14 Oct 2004 14:17:55 -0000 1.4 +++ TextIncludingReader.cs 26 Oct 2004 19:28:41 -0000 1.5 @@ -28,19 +28,21 @@ private Uri _includeLocation; private string _accept, _acceptLanguage; private string _href; + private bool _exposeCDATA; - #endregion + #endregion #region constructors - internal TextIncludingReader(Uri includeLocation, string encoding, - string accept, string acceptLanguage) { + public TextIncludingReader(Uri includeLocation, string encoding, + string accept, string acceptLanguage, bool exposeCDATA) { _includeLocation = includeLocation; _href = includeLocation.AbsoluteUri; _encoding = encoding; _state = ReadState.Initial; _accept = accept; _acceptLanguage = acceptLanguage; + _exposeCDATA = exposeCDATA; } #endregion @@ -105,7 +107,9 @@ } public override XmlNodeType NodeType { - get { return _state==ReadState.Interactive? XmlNodeType.Text : XmlNodeType.None; } + get { return _state==ReadState.Interactive? + _exposeCDATA? XmlNodeType.CDATA : XmlNodeType.Text + : XmlNodeType.None; } } public override string Prefix { |