From: Oleg T. <he...@us...> - 2005-10-28 22:29:12
|
Update of /cvsroot/mvp-xml/XInclude/v2/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20225/v2/src Added Files: .cvsignore AssemblyInfo.cs SR.cs SR.resx TextIncludingReader.cs TextUtils.cs XInclude.csproj XIncludeException.cs XIncludeKeywords.cs XIncludingReader.cs XIncludingReaderState.cs Log Message: --- NEW FILE: .cvsignore --- bin obj *.user *.suo --- NEW FILE: XIncludeException.cs --- #region using using System; #endregion namespace Mvp.Xml.XInclude { /// <summary> /// Generic XInclude exception. /// </summary> public abstract class XIncludeException : Exception { /// <summary> /// Initializes a new instance of the <see cref="XIncludeException"/> /// class with a specified error message. /// </summary> /// <param name="message">Error message</param> public XIncludeException(string message) : base(message) {} /// <summary> /// Initializes a new instance of the <see cref="XIncludeException"/> /// class with a specified error message and a reference to the /// inner exception that is the cause of this exception. /// </summary> /// <param name="message">Error message</param> /// <param name="innerException">Inner exceptiion</param> public XIncludeException(string message, Exception innerException) : base(message, innerException) {} } /// <summary> /// <c>ResourceException</c> represents resource error as per XInclude specification. /// </summary> /// <remarks> /// Resource error is internal error and should lead to the fallback processing. /// <c>ResourceException</c> therefore should never be thrown outside /// the XInclude Processor. /// </remarks> internal class ResourceException : XIncludeException { /// <summary> /// Initializes a new instance of the <see cref="ResourceException"/> /// class with a specified error message. /// </summary> /// <param name="message">Error message</param> public ResourceException(string message) : base(message) {} /// <summary> /// Initializes a new instance of the <see cref="ResourceException"/> /// class with a specified error message and a reference to the /// inner exception that is the cause of this exception. /// </summary> /// <param name="message">Error message</param> /// <param name="innerException">Inner exceptiion</param> public ResourceException(string message, Exception innerException) : base(message, innerException) {} } /// <summary> /// <c>FatalException</c> represents fatal error as per XInclude spcification. /// </summary> public abstract class FatalException : XIncludeException { /// <summary> /// Initializes a new instance of the <see cref="FatalException"/> /// class with a specified error message. /// </summary> /// <param name="message">Error message</param> public FatalException(string message) : base(message) {} /// <summary> /// Initializes a new instance of the <see cref="FatalException"/> /// class with a specified error message and a reference to the /// inner exception that is the cause of this exception. /// </summary> /// <param name="message">Error message</param> /// <param name="innerException">Inner exceptiion</param> public FatalException(string message, Exception innerException) : base(message, innerException) {} } /// <summary> /// Non XML character in a document to include exception. /// </summary> public class NonXmlCharacterException : FatalException { /// <summary> /// Initializes a new instance of the <see cref="NonXmlCharacterException"/> /// class with a specified invalid character. /// </summary> /// <param name="c">Invalid character</param> public NonXmlCharacterException(char c) : base(SR.GetString("NonXmlCharacter", ((int)c).ToString("X2"))) {} } /// <summary> /// Circular inclusion exception. /// </summary> public class CircularInclusionException : FatalException { /// <summary> /// Initializes a new instance of the <see cref="CircularInclusionException"/> /// class with a specified Uri that causes inclusion loop. /// </summary> /// <param name="uri">Uri that causes inclusion loop</param> public CircularInclusionException(Uri uri) : base(SR.GetString("CircularInclusion", uri.AbsoluteUri)) {} /// <summary> /// Initializes a new instance of the <see cref="CircularInclusionException"/> /// class with a specified Uri that causes inclusion loop and error location within /// XML document. /// </summary> /// <param name="uri">Uri that causes inclusion loop</param> /// <param name="line">Line number</param> /// <param name="locationUri">Location Uri</param> /// <param name="position">Column number</param> public CircularInclusionException(Uri uri, string locationUri, int line, int position) : base(SR.GetString("CircularInclusionLong", uri.AbsoluteUri, locationUri, line, position)) {} } /// <summary> /// Resource error not backed up by xi:fallback exception. /// </summary> public class FatalResourceException : FatalException { /// <summary> /// Initializes a new instance of the <see cref="FatalResourceException"/> /// class with the specified inner exception that is the cause of this exception. /// </summary> /// <param name="re">Inner exceptiion</param> public FatalResourceException(Exception re) : base(SR.GetString("FatalResourceException", re.Message), re) {} } /// <summary> /// XInclude syntax error exception. /// </summary> public class XIncludeSyntaxError : FatalException { /// <summary> /// Initializes a new instance of the <see cref="XIncludeSyntaxError"/> /// class with a specified error message. /// </summary> /// <param name="message">Error message</param> public XIncludeSyntaxError(string message) : base(message) {} } /// <summary> /// Include location identifies an attribute or namespace node. /// </summary> public class AttributeOrNamespaceInIncludeLocationError : FatalException { /// <summary> /// Initializes a new instance of the <see cref="AttributeOrNamespaceInIncludeLocationError"/> /// class with a specified error message. /// </summary> /// <param name="message">Error message</param> public AttributeOrNamespaceInIncludeLocationError(string message) : base(message) {} } /// <summary> /// Not wellformed inclusion result (e.g. top-level xi:include /// includes multiple elements). /// </summary> public class MalformedXInclusionResultError : FatalException { /// <summary> /// Initializes a new instance of the <see cref="MalformedXInclusionResultError"/> /// class with a specified error message. /// </summary> /// <param name="message">Error message</param> 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 InvalidAcceptHTTPHeaderValueError : FatalException { /// <summary> /// Initializes a new instance of the <see cref="InvalidAcceptHTTPHeaderValueError"/> /// class with a specified invalid character. /// </summary> /// <param name="c">Invalid character</param> public InvalidAcceptHTTPHeaderValueError(char c) : base(SR.GetString("InvalidCharForAccept", ((int)c).ToString("X2"))) {} } } --- NEW FILE: XInclude.csproj --- (This appears to be a binary file; contents omitted.) --- NEW FILE: XIncludingReader.cs --- #region using using System; using System.Xml; using System.Xml.Schema; using System.Xml.XPath; using System.IO; using System.Net; using System.Text; using System.Security; using System.Collections.Generic; using System.Reflection; using Mvp.Xml.Common; using Mvp.Xml.Common.XPath; using Mvp.Xml.XPointer; #endregion [...1487 lines suppressed...] /// <summary> /// Checks for inclusion loops. /// </summary> private void CheckLoops(Uri url, string xpointer) { //Check circular inclusion Uri baseUri = _reader.BaseURI==""? _topBaseUri : new Uri(_reader.BaseURI); if (baseUri.Equals(url)) ThrowCircularInclusionError(_reader, url); foreach (XmlReader r in _readers) { baseUri = r.BaseURI==""? _topBaseUri : new Uri(r.BaseURI); if (baseUri.Equals(url)) ThrowCircularInclusionError(_reader, url); } } #endregion } } --- NEW FILE: SR.resx --- <?xml version="1.0" encoding="utf-8"?> <root> <!-- Microsoft ResX Schema Version 2.0 The primary goals of this format is to allow a simple XML format that is mostly human readable. The generation and parsing of the various data types are done through the TypeConverter classes associated with the data types. Example: ... ado.net/XML headers & schema ... <resheader name="resmimetype">text/microsoft-resx</resheader> <resheader name="version">2.0</resheader> <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader> <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader> <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data> <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data> <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64"> <value>[base64 mime encoded serialized .NET Framework object]</value> </data> <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value> <comment>This is a comment</comment> </data> There are any number of "resheader" rows that contain simple name/value pairs. Each data row contains a name, and value. The row also contains a type or mimetype. Type corresponds to a .NET class that support text/value conversion through the TypeConverter architecture. Classes that don't support this are serialized and stored with the mimetype set. The mimetype is used for serialized objects, and tells the ResXResourceReader how to depersist the object. This is currently not extensible. For a given mimetype the value must be set accordingly: Note - application/x-microsoft.net.object.binary.base64 is the format that the ResXResourceWriter will generate, however the reader can read any of the formats listed below. mimetype: application/x-microsoft.net.object.binary.base64 value : The object must be serialized with : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter : and then encoded with base64 encoding. mimetype: application/x-microsoft.net.object.soap.base64 value : The object must be serialized with : System.Runtime.Serialization.Formatters.Soap.SoapFormatter : and then encoded with base64 encoding. mimetype: application/x-microsoft.net.object.bytearray.base64 value : The object must be serialized into a byte array : using a System.ComponentModel.TypeConverter : and then encoded with base64 encoding. --> <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> <xsd:import namespace="http://www.w3.org/XML/1998/namespace" /> <xsd:element name="root" msdata:IsDataSet="true"> <xsd:complexType> <xsd:choice maxOccurs="unbounded"> <xsd:element name="metadata"> <xsd:complexType> <xsd:sequence> <xsd:element name="value" type="xsd:string" minOccurs="0" /> </xsd:sequence> <xsd:attribute name="name" use="required" type="xsd:string" /> <xsd:attribute name="type" type="xsd:string" /> <xsd:attribute name="mimetype" type="xsd:string" /> <xsd:attribute ref="xml:space" /> </xsd:complexType> </xsd:element> <xsd:element name="assembly"> <xsd:complexType> <xsd:attribute name="alias" type="xsd:string" /> <xsd:attribute name="name" type="xsd:string" /> </xsd:complexType> </xsd:element> <xsd:element name="data"> <xsd:complexType> <xsd:sequence> <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" /> </xsd:sequence> <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" /> <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" /> <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" /> <xsd:attribute ref="xml:space" /> </xsd:complexType> </xsd:element> <xsd:element name="resheader"> <xsd:complexType> <xsd:sequence> <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> </xsd:sequence> <xsd:attribute name="name" type="xsd:string" use="required" /> </xsd:complexType> </xsd:element> </xsd:choice> </xsd:complexType> </xsd:element> </xsd:schema> <resheader name="resmimetype"> <value>text/microsoft-resx</value> </resheader> <resheader name="version"> <value>2.0</value> </resheader> <resheader name="reader"> <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> </resheader> <resheader name="writer"> <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> </resheader> <data name="NotSupportedEncoding" type="System.String" mimetype="System.String"> <value>Not supported encoding '{0}'.</value> </data> <data name="OutOfMemoryWhileFetchingResource" type="System.String" mimetype="System.String"> <value>Out of memory error while reading resource '{0}'.</value> </data> <data name="IOErrorWhileFetchingResource" type="System.String" mimetype="System.String"> <value>I/O error while reading resource '{0}'.</value> </data> <data name="UnknownParseAttrValue" type="System.String" mimetype="System.String"> <value>Unknown 'parse' attribute value: '{0}'.</value> </data> <data name="UnknownParseAttrValueLong" type="System.String" mimetype="System.String"> <value>Unknown 'parse' attribute value: '{0}'. In {1}, Line {2}, Position {3}.</value> </data> <data name="NonXmlCharacter" type="System.String" mimetype="System.String"> <value>Included document contains a character not allowed in XML: 0x{0}.</value> </data> <data name="CircularInclusion" type="System.String" mimetype="System.String"> <value>Circular inclusion has been detected, inclusion location: {0}.</value> </data> <data name="CircularInclusionLong" type="System.String" mimetype="System.String"> <value>Circular inclusion has been detected, inclusion location: {0}. In {1}, Line {2}, Position {3}.</value> </data> <data name="FatalResourceException" type="System.String" mimetype="System.String"> <value>Resource error has occured and no fallback has been provided: {0}.</value> </data> <data name="AttributeOrNamespaceInIncludeLocationError" type="System.String" mimetype="System.String"> <value>Include location identifies an attribute or namespace node!</value> </data> <data name="FallbackNotChildOfInclude" type="System.String" mimetype="System.String"> <value>xi:fallback element must be direct child of xi:include element. Location: {0}.</value> </data> <data name="FallbackNotChildOfIncludeLong" type="System.String" mimetype="System.String"> <value>xi:fallback element must be direct child of xi:include element. Location: {0}, Line {1}, Position {2}.</value> </data> <data name="URISchemaNotSupported" type="System.String" mimetype="System.String"> <value>URI schema is not supported: '{0}'.</value> </data> <data name="SecurityException" type="System.String" mimetype="System.String"> <value>Security exception while fetching '{0}'.</value> </data> <data name="ResourceError" type="System.String" mimetype="System.String"> <value>Resource '{0}' cannot be fetched.</value> </data> <data name="MissingHrefAndXpointerException" type="System.String" mimetype="System.String"> <value>'href' or 'xpointer' attributes can't both be omitted on xi:include element. Location: {0}."</value> </data> <data name="MissingHrefAndXpointerExceptionLong" type="System.String" mimetype="System.String"> <value>'href' or 'xpointer' attributes can't both be omitted on xi:include element. Location: {0}, Line {1}, Position {2}.</value> </data> <data name="IntradocumentReferencesNotSupported" type="System.String" mimetype="System.String"> <value>XIncludingReader doesn't support intra-document references.</value> </data> <data name="CustomXmlResolverError" type="System.String" mimetype="System.String"> <value>An exception has occured during GetEntity call to custom XmlResolver.</value> </data> <data name="CustomXmlResolverReturnedNull" type="System.String" mimetype="System.String"> <value>Custom XmlResolver returned null.</value> </data> <data name="CustomXmlResolverReturnedUnsupportedType" type="System.String" mimetype="System.String"> <value>Custom XmlResolver returned object of an unsupported type '{0}'.</value> </data> <data name="InvalidURI" type="System.String" mimetype="System.String"> <value>Invalid URI '{0}'.</value> </data> <data name="UnresolvableURI" type="System.String" mimetype="System.String"> <value>Unable to resolve URI reference '{0}'.</value> </data> <data name="IncludeChildOfInclude" type="System.String" mimetype="System.String"> <value>xi:include element cannot be child of xi:include element. Location: {0}.</value> </data> <data name="IncludeChildOfIncludeLong" type="System.String" mimetype="System.String"> <value>xi:include element cannot be child of xi:include element. Location: {0}, Line {1}, Position {2}.</value> </data> <data name="TwoFallbacks" type="System.String" mimetype="System.String"> <value>xi:include element cannot contain more than one xi:fallback element. Location: {0}.</value> </data> <data name="TwoFallbacksLong" type="System.String" mimetype="System.String"> <value>xi:include element cannot contain more than one xi:fallback element. Location: {0}, Line {1}, Position {2}.</value> </data> <data name="MalformedXInclusionResult" type="System.String" mimetype="System.String"> <value>Malformed XInclusion result - xi:include element at the top level must include a single element and optional comments and PIs.</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> --- NEW FILE: TextIncludingReader.cs --- #region using using System; using System.Xml; using System.IO; using System.Net; using System.Text; using System.Security; #endregion namespace Mvp.Xml.XInclude { /// <summary> /// Custom <c>XmlReader</c>, handler for parse="text" case. /// </summary> /// <author>Oleg Tkachenko, ol...@tk...</author> /// <remarks> /// Allows to read specified resource as a text node. /// </remarks> internal class TextIncludingReader : XmlReader { #region private fields private string _encoding; private ReadState _state; private string _value; private Uri _includeLocation; private string _accept, _acceptLanguage; private string _href; private bool _exposeCDATA; #endregion #region constructors 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; } public TextIncludingReader(string value, bool exposeCDATA) { _state = ReadState.Initial; _exposeCDATA = exposeCDATA; _value = value; } #endregion #region XmlReader overrides public override int AttributeCount { get { return 0; } } public override string BaseURI { get { return _href; } } public override int Depth { get { return _state==ReadState.Interactive? 1:0; } } public override bool EOF { get { return _state==ReadState.EndOfFile? true : false;} } public override bool HasValue{ get { return _state==ReadState.Interactive? true : false; } } public override bool IsDefault { get { return false; } } public override bool IsEmptyElement { get { return false; } } public override string this[int index] { get { return String.Empty; } } public override string this[string qname] { get { return String.Empty; } } public override string this[string localname , string nsuri] { get { return String.Empty; } } public override string LocalName { get { return String.Empty; } } public override string Name { get { return String.Empty; } } public override string NamespaceURI { get { return String.Empty; } } public override XmlNameTable NameTable { get { return null; } } public override XmlNodeType NodeType { get { return _state==ReadState.Interactive? _exposeCDATA? XmlNodeType.CDATA : XmlNodeType.Text : XmlNodeType.None; } } public override string Prefix { get { return String.Empty; } } public override char QuoteChar { get { return '"'; } } public override ReadState ReadState { get { return _state; } } public override string Value { get { return _state==ReadState.Interactive? _value : String.Empty; } } public override string XmlLang { get { return String.Empty; } } public override XmlSpace XmlSpace { get { return XmlSpace.None; } } public override void Close() { _state = ReadState.Closed; } public override string GetAttribute (int index) { throw new ArgumentOutOfRangeException("index", index, "No attributes exposed"); } public override string GetAttribute (string qname) { return null; } public override string GetAttribute (string localname, string nsuri){ return null; } public override string LookupNamespace (string prefix) { return null; } public override void MoveToAttribute (int index) {} public override bool MoveToAttribute (string qname) { return false; } public override bool MoveToAttribute (string localname, string nsuri) { return false; } public override bool MoveToElement() { return false; } public override bool MoveToFirstAttribute() { return false; } public override bool MoveToNextAttribute() { return false; } public override bool ReadAttributeValue() { return false; } public override string ReadInnerXml() { return _state==ReadState.Interactive? _value : String.Empty; } public override string ReadOuterXml() { return _state==ReadState.Interactive? _value : String.Empty; } public override string ReadString() { return _state==ReadState.Interactive? _value : String.Empty; } public override void ResolveEntity() {} public override bool Read() { switch (_state) { case ReadState.Initial: if (_value == null) { WebResponse wRes; Stream stream = XIncludingReader.GetResource(_includeLocation.AbsoluteUri, _accept, _acceptLanguage, out wRes); StreamReader reader; /* According to the spec, encoding should be determined as follows: * external encoding information, if available, otherwise * if the media type of the resource is text/xml, application/xml, or matches the conventions text/*+xml or application/*+xml as described in XML Media Types [IETF RFC 3023], the encoding is recognized as specified in XML 1.0, otherwise * the value of the encoding attribute if one exists, otherwise * UTF-8. */ try { //TODO: try to get "content-encoding" from wRes.Headers collection? //If mime type is xml-aware, get resource encoding as per XML 1.0 string contentType = wRes.ContentType.ToLower(); if (contentType == "text/xml" || contentType == "application/xml" || contentType.StartsWith("text/") && contentType.EndsWith("+xml") || contentType.StartsWith("application/") && contentType.EndsWith("+xml")) { //Yes, that's xml, let's read encoding from the xml declaration reader = new StreamReader(stream, GetEncodingFromXMLDecl(_href)); } else if (_encoding != null) { //Try to use user-specified encoding Encoding enc; try { enc = Encoding.GetEncoding(_encoding); } catch (Exception e) { throw new ResourceException(SR.GetString("NotSupportedEncoding", _encoding), e); } reader = new StreamReader(stream, enc); } else //Fallback to UTF-8 reader = new StreamReader(stream, Encoding.UTF8); _value = reader.ReadToEnd(); TextUtils.CheckForNonXmlChars(_value); } catch (ResourceException re) { throw re; } catch (OutOfMemoryException oome) { //Crazy include - memory is out //TODO: what about reading by chunks? throw new ResourceException(SR.GetString("OutOfMemoryWhileFetchingResource", _href), oome); } catch (IOException ioe) { throw new ResourceException(SR.GetString("IOErrorWhileFetchingResource", _href), ioe); } } _state = ReadState.Interactive; return true; case ReadState.Interactive: //No more input _state = ReadState.EndOfFile; return false; default: return false; } } // Read() #endregion #region private methods /// <summary> /// Reads encoding from the XML declarartion. /// </summary> /// <param name="href">URI reference indicating the location /// of the resource to inlclude.</param> /// <returns>The document encoding as per XML declaration.</returns> /// <exception cref="ResourceException">Resource error.</exception> private Encoding GetEncodingFromXMLDecl(string href) { XmlTextReader tmpReader = new XmlTextReader(href); tmpReader.WhitespaceHandling = WhitespaceHandling.None; try { while (tmpReader.Read() && tmpReader.Encoding == null) {} Encoding enc = tmpReader.Encoding; return enc==null? Encoding.UTF8 : enc; } finally { tmpReader.Close(); } } #endregion } } --- NEW FILE: TextUtils.cs --- #region using using System; #endregion namespace Mvp.Xml.XInclude { /// <summary> /// Text inclusion related utility methods. /// </summary> /// <author>Oleg Tkachenko, ol...@tk...</author> internal class TextUtils { #region public static util methods /// <summary> /// Checks string for a presense of characters, /// not permitted in XML 1.0 documents. /// </summary> /// <param name="str">Input string to check.</param> /// <exception cref="NonXmlCharacterException">Given string contains a character, /// forbidden in XML 1.0.</exception> public static void CheckForNonXmlChars(string str) { int i = 0; while (i < str.Length) { char c = str[i]; //Allowed unicode XML characters if (c >= 0x0020 && c <= 0xD7FF || c >= 0xE000 && c <= 0xFFFD || c == 0xA || c == 0xD || c == 0x9) { //Ok, approved. i++; continue; //Check then surrogate pair } else if (c >= 0xd800 && c <=0xdbff) { //Looks like first char in a surrogate pair, check second one if (++i < str.Length) { if (str[i] >=0xdc00 && str[i] <= 0xdfff) //Ok, valid surrogate pair i++; continue; } } throw new NonXmlCharacterException(str[i]); } } /// <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 InvalidAcceptHTTPHeaderValueError(c); } } #endregion } } --- NEW FILE: AssemblyInfo.cs --- using System; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Security.Permissions; [assembly: ComVisible(false)] [assembly: CLSCompliant(true)] [assembly: AssemblyTitle("Mvp.Xml.XInclude")] [assembly: AssemblyDescription("MVP XML Library - XInclude.NET Module")] [assembly: AssemblyVersion("2.0.*")] #region Security Permissions //[assembly: SecurityPermission(SecurityAction.RequestRefuse, UnmanagedCode=true)] #endregion Security Permissions --- NEW FILE: SR.cs --- #region using using System; using System.Resources; using System.Threading; #endregion namespace Mvp.Xml.XInclude { /// <summary>Contains resources for the application.</summary> internal sealed class SR { private static ResourceManager resourceManager = new ResourceManager(typeof(SR).FullName, typeof(SR).Module.Assembly ); private SR() {} /// <summary> /// Gets the specified resource for the <see cref='Thread.CurrentUICulture'/>. /// </summary> /// <param name='key'>The key of the resource to retrieve.</param> /// <returns>The object resource.</returns> public static object GetObject(string key) { return resourceManager.GetObject(key); } /// <summary> /// Gets the specified resource for the <see cref='Thread.CurrentUICulture'/>. /// </summary> /// <param name='key'>The key of the resource to retrieve.</param> /// <returns>The string resource.</returns> public static string GetString(string key) { return resourceManager.GetString(key); } /// <summary> /// Gets the specified resource for the <see cref='Thread.CurrentUICulture'/> and /// formats it with the arguments received. /// </summary> /// <param name='key'>The key of the resource to retrieve.</param> /// <param name='args'>The arguments to format the resource with.</param> /// <returns>The string resource.</returns> internal static string GetString (string key, params object[] args) { return String.Format(GetString(key), args); } /// <summary></summary> public static string AttributeOrNamespaceInIncludeLocationError { get { return SR.GetString("AttributeOrNamespaceInIncludeLocationError"); } } /// <summary></summary> public static string IntradocumentReferencesNotSupported { get { return SR.GetString("IntradocumentReferencesNotSupported"); } } /// <summary></summary> public static string CustomXmlResolverError { get { return SR.GetString("CustomXmlResolverError"); } } /// <summary></summary> public static string CustomXmlResolverReturnedNull { get { return SR.GetString("CustomXmlResolverError"); } } /// <summary></summary> public static string MalformedXInclusionResult { get { return SR.GetString("MalformedXInclusionResult"); } } /// <summary></summary> public static string FragmentIDInHref { get { return SR.GetString("FragmentIDInHref"); } } } } --- NEW FILE: XIncludingReaderState.cs --- namespace Mvp.Xml.XInclude { internal struct FallbackState { //Fallback is being processed public bool Fallbacking; //xi:fallback element depth public int FallbackDepth; //Fallback processed flag public bool FallbackProcessed; } /// <summary> /// XIncludingReader state machine. /// </summary> /// <author>Oleg Tkachenko, ol...@tk...</author> internal enum XIncludingReaderState { //Default state Default, //xml:base attribute is being exposed ExposingXmlBaseAttr, //xml:base attribute value is being exposed ExposingXmlBaseAttrValue, //xml:lang attribute is being exposed ExposingXmlLangAttr, //xml:lang attribute value is being exposed ExposingXmlLangAttrValue } } --- NEW FILE: XIncludeKeywords.cs --- #region using using System; using System.Xml; #endregion namespace Mvp.Xml.XInclude { /// <summary> /// XInclude syntax keyword collection. /// </summary> /// <author>Oleg Tkachenko, ol...@tk...</author> internal class XIncludeKeywords { #region constructors public XIncludeKeywords(XmlNameTable nt) { nameTable = nt; //Preload some keywords _XIncludeNamespace = nameTable.Add(s_XIncludeNamespace); _OldXIncludeNamespace = nameTable.Add(s_OldXIncludeNamespace); _Include = nameTable.Add(s_Include); _Href = nameTable.Add(s_Href); _Parse = nameTable.Add(s_Parse); } #endregion #region private constants // // Keyword strings private const string s_XIncludeNamespace = "http://www.w3.org/2001/XInclude"; private const string s_OldXIncludeNamespace = "http://www.w3.org/2003/XInclude"; private const string s_Include = "include"; private const string s_Href = "href"; private const string s_Parse = "parse"; private const string s_Xml = "xml"; private const string s_Text = "text"; private const string s_Xpointer = "xpointer"; private const string s_Accept = "accept"; private const string s_AcceptLanguage = "accept-language"; private const string s_Encoding = "encoding"; private const string s_Fallback = "fallback"; private const string s_XmlNamespace = "http://www.w3.org/XML/1998/namespace"; private const string s_Base = "base"; private const string s_XmlBase = "xml:base"; private const string s_Lang = "lang"; private const string s_XmlLang = "xml:lang"; #endregion #region private fields private XmlNameTable nameTable; // // Properties private string _XIncludeNamespace; private string _OldXIncludeNamespace; private string _Include; private string _Href; private string _Parse; private string _Xml; private string _Text; private string _Xpointer; private string _Accept; private string _AcceptLanguage; private string _Encoding; private string _Fallback; private string _XmlNamespace; private string _Base; private string _XmlBase; private string _Lang; private string _XmlLang; #endregion #region public props // http://www.w3.org/2003/XInclude public string XIncludeNamespace { get { return _XIncludeNamespace; } } // http://www.w3.org/2001/XInclude public string OldXIncludeNamespace { get { return _OldXIncludeNamespace; } } // include public string Include { get { return _Include; } } // href public string Href { get { return _Href; } } // parse public string Parse { get { return _Parse; } } // xml public string Xml { get { if (_Xml == null) _Xml = nameTable.Add(s_Xml); return _Xml; } } // text public string Text { get { if (_Text == null) _Text = nameTable.Add(s_Text); return _Text; } } // xpointer public string Xpointer { get { if (_Xpointer == null) _Xpointer = nameTable.Add(s_Xpointer); return _Xpointer; } } // accept public string Accept { get { if (_Accept == null) _Accept = nameTable.Add(s_Accept); return _Accept; } } // accept-language public string AcceptLanguage { get { if (_AcceptLanguage == null) _AcceptLanguage = nameTable.Add(s_AcceptLanguage); return _AcceptLanguage; } } // encoding public string Encoding { get { if (_Encoding == null) _Encoding = nameTable.Add(s_Encoding); return _Encoding; } } // fallback public string Fallback { get { if (_Fallback == null) _Fallback = nameTable.Add(s_Fallback); return _Fallback; } } // Xml namespace public string XmlNamespace { get { if (_XmlNamespace == null) _XmlNamespace = nameTable.Add(s_XmlNamespace); return _XmlNamespace; } } // Base public string Base { get { if (_Base == null) _Base = nameTable.Add(s_Base); return _Base; } } // xml:base public string XmlBase { get { if (_XmlBase == null) _XmlBase = nameTable.Add(s_XmlBase); return _XmlBase; } } // Lang public string Lang { get { if (_Lang == null) _Lang = nameTable.Add(s_Lang); return _Lang; } } // xml:lang public string XmlLang { get { if (_XmlLang == null) _XmlLang = nameTable.Add(s_XmlLang); return _XmlLang; } } #endregion #region public methods // Comparison public static bool Equals(string keyword1, string keyword2) { return (object)keyword1 == (object)keyword2; } #endregion } } |