Browse Source

2005-05-11 Peter Bartok <[email protected]>

	* ResXResourceSet.cs: Implemented
	* ResXFileRef.cs: Implemented
	* ResXNullRef.cs: Added missing attribute
	* ResXResourceReader.cs: Implemented missing .ctor()s and other
	  assorted fun stuff, should now be complete
	* ResResourceWriter.cs: Implemented missing methods and added
	  missing static fields


svn path=/trunk/mcs/; revision=44376
Peter Dennis Bartok 20 years ago
parent
commit
5ee050db80

+ 10 - 0
mcs/class/Managed.Windows.Forms/System.Resources/ChangeLog

@@ -1,3 +1,13 @@
+2005-05-11  Peter Bartok  <[email protected]>
+
+	* ResXResourceSet.cs: Implemented
+	* ResXFileRef.cs: Implemented
+	* ResXNullRef.cs: Added missing attribute
+	* ResXResourceReader.cs: Implemented missing .ctor()s and other
+	  assorted fun stuff, should now be complete
+	* ResResourceWriter.cs: Implemented missing methods and added
+	  missing static fields
+
 2005-04-14  Jackson Harper  <[email protected]>
 
 	* ResXResourceReader.cs: Use serialization on values that have a

+ 105 - 0
mcs/class/Managed.Windows.Forms/System.Resources/ResXFileRef.cs

@@ -0,0 +1,105 @@
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+// Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
+//
+// Authors:
+//	Peter Bartok	([email protected])
+//
+//
+
+// COMPLETE
+
+using System;
+using System.ComponentModel;
+using System.IO;
+using System.Reflection;
+
+namespace System.Resources {
+	[Serializable]
+	[TypeConverter(typeof(ResXFileRef.Converter))]
+	public class ResXFileRef {
+		#region Converter Class
+		public class Converter : TypeConverter {
+			#region Constructors
+			public Converter() {
+			}
+			#endregion	// Constructors
+
+			#region Methods
+			public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) {
+				return sourceType == typeof(string);
+			}
+
+			public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) {
+				return destinationType == typeof(string);
+			}
+
+			public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) {
+				string[]	parts;
+				byte[]		buffer;
+
+				if ( !(value is String)) {
+					return base.ConvertFrom(context, culture, value);
+				}
+
+				parts = ((string)value).Split(';');
+
+				using (FileStream file = new FileStream(parts[0], FileMode.Open, FileAccess.Read, FileShare.Read)) {
+					buffer = new byte[file.Length];
+
+					file.Read(buffer, 0, (int)file.Length);
+				}
+
+				return Activator.CreateInstance(Type.GetType(parts[1]), BindingFlags.CreateInstance | BindingFlags.Public | BindingFlags.Instance, null, new object[] { new MemoryStream(buffer) }, culture);
+			}
+
+			public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType) {
+				if (destinationType != typeof(String)) {
+					return base.ConvertTo (context, culture, value, destinationType);
+				}
+
+				return ((ResXFileRef)value).ToString();
+			}
+			#endregion	// Methods
+		}
+		#endregion	// Converter Class
+
+		#region Local Variables
+		private string filename;
+		private string typename;
+		#endregion	// Local Variables
+
+		#region Public Constructors
+		public ResXFileRef(string fileName, string typeName) {
+			this.filename = fileName;
+			this.typename = typeName;
+		}
+		#endregion	// Public Constructors
+
+		#region Public Instance Properties
+		#endregion	// Public Instance Properties
+
+		#region Public Instance Methods
+		public override string ToString() {
+			return filename + ";" + typename;
+		}
+		#endregion	// Public Instance Methods
+	}
+}

+ 4 - 1
mcs/class/Managed.Windows.Forms/System.Resources/ResXNullRef.cs

@@ -23,9 +23,12 @@
 // 	Geoff Norton	[email protected]
 //
 
+using System;
+
 namespace System.Resources
 {
+	[Serializable]
 	internal class ResXNullRef
 	{
 	}
-}
+}

+ 77 - 14
mcs/class/Managed.Windows.Forms/System.Resources/ResXResourceReader.cs

@@ -17,33 +17,39 @@
 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
-// Copyright (c) 2004 Novell, Inc.
+// Copyright (c) 2004-2005 Novell, Inc.
 //
 // Authors:
 // 	Duncan Mak	[email protected]
 //	Nick Drochak	[email protected]
 //	Paolo Molaro	[email protected]
+//	Peter Bartok	[email protected]
 //
 
-// NOT COMPLETE
+// COMPLETE
 
+using System;
 using System.Collections;
-using System.Resources;
-using System.IO;
-using System.Xml;
 using System.ComponentModel;
+using System.ComponentModel.Design;
 using System.Globalization;
+using System.IO;
+using System.Resources;
 using System.Runtime.Serialization.Formatters.Binary;
+using System.Xml;
 
 namespace System.Resources
 {
 	public class ResXResourceReader : IResourceReader, IDisposable
 	{
-		Stream stream;
-		XmlTextReader reader;
-		Hashtable hasht;
+		#region Local Variables
+		private Stream			stream;
+		private XmlTextReader		reader;
+		private Hashtable		hasht;
+		private ITypeResolutionService	typeresolver;
+		#endregion	// Local Variables
 
-		// Constructors
+		#region Constructors & Destructor
 		public ResXResourceReader (Stream stream)
 		{
 			if (stream == null)
@@ -55,6 +61,10 @@ namespace System.Resources
 			this.stream = stream;
 			basic_setup ();
 		}
+
+		public ResXResourceReader (Stream stream, ITypeResolutionService typeresolver) : this(stream) {
+			this.typeresolver = typeresolver;
+		}
 		
 		public ResXResourceReader (string fileName)
 		{
@@ -62,6 +72,28 @@ namespace System.Resources
 			basic_setup ();
 		}
 
+		public ResXResourceReader (string fileName, ITypeResolutionService typeresolver) : this(fileName) {
+			this.typeresolver = typeresolver;
+		}
+
+		public ResXResourceReader(TextReader reader) {
+			this.reader = new XmlTextReader(reader);
+			this.hasht = new Hashtable();
+
+			load_data();
+		}
+
+		public ResXResourceReader (TextReader reader, ITypeResolutionService typeresolver) : this(reader) {
+			this.typeresolver = typeresolver;
+		}
+
+		~ResXResourceReader() {
+			Dispose(false);
+		}
+		#endregion	// Constructors & Destructor
+
+
+		#region Private Methods
 		void basic_setup () {
 			reader = new XmlTextReader (stream);
 			hasht = new Hashtable ();
@@ -188,10 +220,27 @@ namespace System.Resources
 			}
 		}
 
+		private Type GetType(string type) {
+			if (typeresolver == null) {
+				return Type.GetType(type);
+			} else {
+				return typeresolver.GetType(type);
+			}
+		}
+		#endregion	// Private Methods
+
+		#region Public Methods
 		public void Close ()
 		{
-			stream.Close ();
-			stream = null;
+			if (stream != null) {
+				stream.Close ();
+				stream = null;
+			}
+
+			if (reader != null) {
+				reader.Close();
+				reader = null;
+			}
 		}
 		
 		public IDictionaryEnumerator GetEnumerator () {
@@ -208,12 +257,26 @@ namespace System.Resources
 			return ((IResourceReader) this).GetEnumerator();
 		}
 		
-		[MonoTODO]
 		void IDisposable.Dispose ()
 		{
-			// FIXME: is this all we need to do?
-			Close();
+			Dispose(true);
 		}
+
+		protected virtual void Dispose(bool disposing) {
+			if (disposing) {
+				Close();
+			}
+		}
+
+		public static ResXResourceReader FromFileContents(string fileContents) {
+			return new ResXResourceReader(new StringReader(fileContents));
+		}
+
+		public static ResXResourceReader FromFileContents(string fileContents, ITypeResolutionService typeResolver) {
+			return new ResXResourceReader(new StringReader(fileContents), typeResolver);
+		}
+
+		#endregion	// Public Methods
 		
 	}  // public sealed class ResXResourceReader
 } // namespace System.Resources

+ 63 - 0
mcs/class/Managed.Windows.Forms/System.Resources/ResXResourceSet.cs

@@ -0,0 +1,63 @@
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+// Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
+//
+// Authors:
+//	Peter Bartok	([email protected])
+//
+//
+
+// COMPLETE
+
+using System;
+using System.IO;
+using System.Collections;
+
+namespace System.Resources {
+	public class ResXResourceSet : ResourceSet {
+		#region Local Variables
+
+		#endregion	// Local Variables
+
+		#region Public Constructors
+		public ResXResourceSet(Stream stream) {
+			this.Reader = new ResXResourceReader(stream);
+			this.Table = new Hashtable();
+			this.ReadResources();
+		}
+
+		public ResXResourceSet(string fileName) {
+			this.Reader = new ResXResourceReader(fileName);
+			this.Table = new Hashtable();
+			this.ReadResources();
+		}
+		#endregion	// Public Constructors
+
+		#region Public Instance Methods
+		public override Type GetDefaultReader() {
+			return typeof(ResXResourceReader);
+		}
+
+		public override Type GetDefaultWriter() {
+			return typeof(ResXResourceWriter);
+		}
+		#endregion	// Public Instance Methods
+	}
+}

+ 37 - 9
mcs/class/Managed.Windows.Forms/System.Resources/ResXResourceWriter.cs

@@ -17,11 +17,15 @@
 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
-// Copyright (c) 2004 Novell, Inc.
+// Copyright (c) 2004-2005 Novell, Inc.
 //
 // Authors:
 //	Duncan Mak		[email protected]
 //	Gonzalo Paniagua Javier	[email protected]
+//	Peter Bartok		[email protected]
+//
+
+// COMPLETE
 
 using System.ComponentModel;
 using System.IO;
@@ -33,12 +37,25 @@ namespace System.Resources
 {
 	public class ResXResourceWriter : IResourceWriter, IDisposable
 	{
-		string filename;
-		Stream stream;
-		TextWriter textwriter;
-		XmlTextWriter writer;
-		bool written;
-
+		#region Local Variables
+		private string		filename;
+		private Stream		stream;
+		private TextWriter	textwriter;
+		private XmlTextWriter	writer;
+		private bool		written;
+		#endregion	// Local Variables
+
+		#region Static Fields
+		public static readonly string BinSerializedObjectMimeType	= "application/x-microsoft.net.object.binary.base64";
+		public static readonly string ByteArraySerializedObjectMimeType	= "application/x-microsoft.net.object.bytearray.base64";
+		public static readonly string DefaultSerializedObjectMimeType	= BinSerializedObjectMimeType;
+		public static readonly string ResMimeType			= "text/microsoft-resx";
+		public static readonly string ResourceSchema			= schema;
+		public static readonly string SoapSerializedObjectMimeType	= "application/x-microsoft.net.object.soap.base64";
+		public static readonly string Version				= "1.3";
+		#endregion	// Static Fields
+
+		#region Constructors & Destructor
 		public ResXResourceWriter (Stream stream)
 		{
 			if (stream == null)
@@ -65,7 +82,12 @@ namespace System.Resources
 
 			this.filename = fileName;
 		}
-		
+
+		~ResXResourceWriter() {
+			Dispose(false);
+		}
+		#endregion	// Constructors & Destructor
+
 		void InitWriter ()
 		{
 			if (filename != null) {
@@ -212,7 +234,7 @@ namespace System.Resources
 		
 		public void Dispose ()
 		{
-			Close ();
+			Dispose(true);
 		}
 
 		public void Generate ()
@@ -225,6 +247,12 @@ namespace System.Resources
 			writer.Flush ();
 		}
 
+		protected virtual void Dispose(bool disposing) {
+			if (disposing) {
+				Close();
+			}
+		}
+
 		static string schema = @"
   <xsd:schema id='root' xmlns='' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:msdata='urn:schemas-microsoft-com:xml-msdata'>
     <xsd:element name='root' msdata:IsDataSet='true'>