From: Oleg T. <he...@us...> - 2004-11-03 12:56:22
|
Update of /cvsroot/mvp-xml/XInclude/v1/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32016/v1/src Modified Files: XIncludeException.cs XIncludingReader.cs Log Message: Optimizations/Simplifications. Index: XIncludeException.cs =================================================================== RCS file: /cvsroot/mvp-xml/XInclude/v1/src/XIncludeException.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- XIncludeException.cs 26 Oct 2004 19:28:41 -0000 1.6 +++ XIncludeException.cs 3 Nov 2004 12:55:39 -0000 1.7 @@ -36,24 +36,7 @@ public FatalException(string message) : base(message) {} public FatalException(string message, Exception innerException) : base(message, innerException) {} - } - - /// <summary> - /// Missing both "href" and "xpointer" attributes exception. - /// </summary> - public class MissingHrefAndXpointerException : FatalException { - public MissingHrefAndXpointerException(string message) : base(message) {} - } - - /// <summary> - /// Unknown "parse" attribute value exception. - /// </summary> - public class UnknownParseAttributeValueException : FatalException { - public UnknownParseAttributeValueException(string attrValue) : - base(SR.GetString("UnknownParseAttrValue", attrValue)) {} - public UnknownParseAttributeValueException(string attrValue, string uri, int line, int position) : - base(SR.GetString("UnknownParseAttrValueLong", attrValue, uri, line, position)) {} - } + } /// <summary> /// Non XML character in a document to include exception. @@ -112,14 +95,5 @@ { 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.25 retrieving revision 1.26 diff -u -d -r1.25 -r1.26 --- XIncludingReader.cs 2 Nov 2004 16:49:39 -0000 1.25 +++ XIncludingReader.cs 3 Nov 2004 12:55:41 -0000 1.26 @@ -235,9 +235,7 @@ { if (_state == XIncludingReaderState.Default) return _reader.IsDefault; - else - //TODO: It might be wrong if xml:base or xml:lang - //are default + else return false; } } @@ -423,7 +421,7 @@ else if (XIncludeKeywords.Equals(name, _keywords.Lang) && XIncludeKeywords.Equals(namespaceURI, _keywords.XmlNamespace)) return _reader.XmlLang; - } + } return _reader.GetAttribute(name, namespaceURI); } @@ -460,7 +458,7 @@ _state = XIncludingReaderState.ExposingXmlLangAttr; return true; } - } + } return _reader.MoveToAttribute(name); } @@ -515,7 +513,8 @@ } } - return _reader.MoveToFirstAttribute(); + else + return _reader.MoveToFirstAttribute(); } /// <summary>See <see cref="XmlReader.MoveToNextAttribute"/></summary> @@ -566,7 +565,8 @@ } } - return _reader.MoveToNextAttribute(); + else + return _reader.MoveToNextAttribute(); } /// <summary>See <see cref="XmlReader.ReadAttributeValue"/></summary> @@ -642,7 +642,8 @@ case XIncludingReaderState.ExposingXmlBaseAttrValue: if (_reader.BaseURI == String.Empty) { - //No Base URI? Use previous one's. + //No Base URI? Use previous one's. + //TODO:How come? return ((XmlReader)_readers.Peek()).BaseURI; } if (_relativeBaseUri) @@ -755,8 +756,9 @@ if (baseRead) { //If we are including and including reader is at 0 depth - - //we are in top level included item + //we are at a top level included item _topLevel = (_readers.Count>0 && _reader.Depth == 0)? true : false; + //Check if included item has different language if (_topLevel) _differentLang = AreDifferentLangs(_reader.XmlLang, ((XmlReader)_readers.Peek()).XmlLang); if (_topLevel && _reader.NodeType == XmlNodeType.Attribute) @@ -1040,13 +1042,13 @@ IXmlLineInfo li = _reader as IXmlLineInfo; if (li != null && li.HasLineInfo()) { - throw new MissingHrefAndXpointerException( + throw new XIncludeSyntaxError( SR.GetString("MissingHrefAndXpointerExceptionLong", _reader.BaseURI.ToString(), li.LineNumber, li.LinePosition)); } else - throw new MissingHrefAndXpointerException( + throw new XIncludeSyntaxError( SR.GetString("MissingHrefAndXpointerException", _reader.BaseURI.ToString())); } @@ -1072,12 +1074,15 @@ IXmlLineInfo li2 = _reader as IXmlLineInfo; if (li2 != null && li2.HasLineInfo()) { - throw new UnknownParseAttributeValueException(parse, + throw new XIncludeSyntaxError( + SR.GetString("UnknownParseAttrValueLong", + parse, _reader.BaseURI.ToString(), - li2.LineNumber, li2.LinePosition); + li2.LineNumber, li2.LinePosition)); } else - throw new UnknownParseAttributeValueException(parse); + throw new XIncludeSyntaxError( + SR.GetString("UnknownParseAttrValue", parse)); } /// <summary> @@ -1282,33 +1287,7 @@ private bool AreDifferentLangs(string lang1, string lang2) { return lang1.ToLower() != lang2.ToLower(); - } - - /// <summary> - /// Creates a XmlReader over acquired infoset. - /// </summary> - /// <param name="uri">Resource URI</param> - /// <param name="stream">Stream to load from</param> - private XmlReader CreateAcquiredInfoset(string uri, Stream stream) - { - //TODO: Try to stream out this stuff - XIncludingReader xir = new XIncludingReader(uri, stream, _nameTable); - StringWriter sw = new StringWriter(); - XmlTextWriter w = new XmlTextWriter(sw); - try - { - while (xir.Read()) - w.WriteNode(xir, false); - } - finally - { - if (xir != null) - xir.Close(); - if (w != null) - w.Close(); - } - return new XmlTextReader(uri, new StringReader(sw.ToString())); - } + } /// <summary> /// Creates a XmlReader over acquired infoset. @@ -1347,7 +1326,7 @@ Uri includeLocation = ResolveHref(href); CheckLoops(includeLocation, xpointer); if (includeLocation.Fragment != String.Empty) - throw new FragmentIdentifierInHrefAttribute(); + throw new XIncludeSyntaxError(SR.FragmentIDInHref); if (_xmlResolver == null) { //No custom resolver @@ -1362,7 +1341,9 @@ //XPointers should be resolved against the acquired infoset, //not the source infoset _reader = new XPointerReader( - CreateAcquiredInfoset(wRes.ResponseUri.AbsoluteUri, stream), xpointer); + CreateAcquiredInfoset( + new XIncludingReader(wRes.ResponseUri.AbsoluteUri, stream)), + xpointer); } else { @@ -1391,16 +1372,19 @@ //Push current reader to the stack _readers.Push(_reader); - //Ok, we accept Stream and XmlReader only + //Ok, we accept Stream, TextReader and XmlReader only + if (resource is Stream) + resource = new StreamReader((Stream)resource); if (xpointer != null) { - if (resource is Stream) + if (resource is TextReader) { //XPointers should be resolved against the acquired infoset, //not the source infoset _reader = new XPointerReader( - CreateAcquiredInfoset(includeLocation.AbsoluteUri, (Stream)resource), - xpointer); + CreateAcquiredInfoset( + new XIncludingReader(includeLocation.AbsoluteUri, (TextReader)resource)), + xpointer); } else if (resource is XmlReader) { @@ -1418,8 +1402,8 @@ else { //No XPointer - if (resource is Stream) - _reader = new XmlBaseAwareXmlTextReader(includeLocation.AbsoluteUri, (Stream)resource, _nameTable); + if (resource is TextReader) + _reader = new XmlBaseAwareXmlTextReader(includeLocation.AbsoluteUri, (TextReader)resource, _nameTable); else if (resource is XmlReader) _reader = (XmlReader)resource; else |