You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by ar...@apache.org on 2009/12/07 06:25:35 UTC

svn commit: r887837 - in /incubator/lucene.net/trunk/C#/src: Lucene.Net/ Lucene.Net/Messages/ Test/ Test/Messages/

Author: aroush
Date: Mon Dec  7 05:25:34 2009
New Revision: 887837

URL: http://svn.apache.org/viewvc?rev=887837&view=rev
Log:
port of org.apache.lucene.messages

Added:
    incubator/lucene.net/trunk/C#/src/Lucene.Net/Messages/
    incubator/lucene.net/trunk/C#/src/Lucene.Net/Messages/Message.cs
    incubator/lucene.net/trunk/C#/src/Lucene.Net/Messages/MessageImpl.cs
    incubator/lucene.net/trunk/C#/src/Lucene.Net/Messages/NLS.cs
    incubator/lucene.net/trunk/C#/src/Lucene.Net/Messages/NLSException.cs
    incubator/lucene.net/trunk/C#/src/Lucene.Net/Messages/Package.html
    incubator/lucene.net/trunk/C#/src/Test/Messages/
    incubator/lucene.net/trunk/C#/src/Test/Messages/MessagesTestBundle.cs
    incubator/lucene.net/trunk/C#/src/Test/Messages/MessagesTestBundle.ja.resources   (with props)
    incubator/lucene.net/trunk/C#/src/Test/Messages/MessagesTestBundle.resources   (with props)
    incubator/lucene.net/trunk/C#/src/Test/Messages/TestNLS.cs
Modified:
    incubator/lucene.net/trunk/C#/src/Lucene.Net/Lucene.Net.csproj
    incubator/lucene.net/trunk/C#/src/Test/Test.csproj

Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Lucene.Net.csproj
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Lucene.Net.csproj?rev=887837&r1=887836&r2=887837&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Lucene.Net.csproj (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Lucene.Net.csproj Mon Dec  7 05:25:34 2009
@@ -448,6 +448,10 @@
     <Compile Include="LucenePackage.cs">
       <SubType>Code</SubType>
     </Compile>
+    <Compile Include="Messages\Message.cs" />
+    <Compile Include="Messages\MessageImpl.cs" />
+    <Compile Include="Messages\NLS.cs" />
+    <Compile Include="Messages\NLSException.cs" />
     <Compile Include="QueryParser\CharStream.cs">
       <SubType>Code</SubType>
     </Compile>
@@ -900,6 +904,7 @@
     <Content Include="Document\Package.html" />
     <Content Include="Index\Package.html" />
     <Content Include="Lucene.Net.xml" />
+    <Content Include="Messages\Package.html" />
     <Content Include="Overview.html" />
     <Content Include="Package.html" />
     <Content Include="QueryParser\Package.html" />

Added: incubator/lucene.net/trunk/C#/src/Lucene.Net/Messages/Message.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Messages/Message.cs?rev=887837&view=auto
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Messages/Message.cs (added)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Messages/Message.cs Mon Dec  7 05:25:34 2009
@@ -0,0 +1,37 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+
+namespace Lucene.Net.Messages
+{
+	
+	/// <summary> Message Interface for a lazy loading.
+	/// For Native Language Support (NLS), system of software internationalization.
+	/// </summary>
+	public interface Message
+	{
+		
+		System.String GetKey();
+		
+		System.Object[] GetArguments();
+		
+		System.String GetLocalizedMessage();
+		
+		System.String GetLocalizedMessage(System.Globalization.CultureInfo locale);
+	}
+}
\ No newline at end of file

Added: incubator/lucene.net/trunk/C#/src/Lucene.Net/Messages/MessageImpl.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Messages/MessageImpl.cs?rev=887837&view=auto
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Messages/MessageImpl.cs (added)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Messages/MessageImpl.cs Mon Dec  7 05:25:34 2009
@@ -0,0 +1,80 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+
+namespace Lucene.Net.Messages
+{
+	
+	/// <summary> Default implementation of Message interface.
+	/// For Native Language Support (NLS), system of software internationalization.
+	/// </summary>
+	[Serializable]
+	public class MessageImpl : Message
+	{
+		
+		private const long serialVersionUID = - 3077643314630884523L;
+		
+		private System.String key;
+		
+		private System.Object[] arguments = new System.Object[0];
+		
+		public MessageImpl(System.String key)
+		{
+			this.key = key;
+		}
+		
+		public MessageImpl(System.String key, System.Object[] args):this(key)
+		{
+			this.arguments = args;
+		}
+		
+		public virtual System.Object[] GetArguments()
+		{
+			return this.arguments;
+		}
+		
+		public virtual System.String GetKey()
+		{
+			return this.key;
+		}
+		
+		public virtual System.String GetLocalizedMessage()
+		{
+			return GetLocalizedMessage(System.Threading.Thread.CurrentThread.CurrentCulture);
+		}
+		
+		public virtual System.String GetLocalizedMessage(System.Globalization.CultureInfo locale)
+		{
+			return NLS.GetLocalizedMessage(GetKey(), locale, GetArguments());
+		}
+		
+		public override System.String ToString()
+		{
+			System.Object[] args = GetArguments();
+			System.String argsString = "";
+			if (args != null)
+			{
+				for (int i = 0; i < args.Length; i++)
+				{
+					argsString += (args[i] + (i < args.Length?"":", "));
+				}
+			}
+			return GetKey() + " " + argsString;
+		}
+	}
+}
\ No newline at end of file

Added: incubator/lucene.net/trunk/C#/src/Lucene.Net/Messages/NLS.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Messages/NLS.cs?rev=887837&view=auto
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Messages/NLS.cs (added)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Messages/NLS.cs Mon Dec  7 05:25:34 2009
@@ -0,0 +1,253 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+
+namespace Lucene.Net.Messages
+{
+	
+	/// <summary> MessageBundles classes extend this class, to implement a bundle.
+	/// 
+	/// For Native Language Support (NLS), system of software internationalization.
+	/// 
+	/// This interface is similar to the NLS class in eclipse.osgi.util.NLS class -
+	/// initializeMessages() method resets the values of all static strings, should
+	/// only be called by classes that extend from NLS (see TestMessages.java for
+	/// reference) - performs validation of all message in a bundle, at class load
+	/// time - performs per message validation at runtime - see NLSTest.java for
+	/// usage reference
+	/// 
+	/// MessageBundle classes may subclass this type.
+	/// </summary>
+	public class NLS
+	{
+		public interface IPriviligedAction
+		{
+			/// <summary>
+			/// Performs the priviliged action.
+			/// </summary>
+			/// <returns>A value that may represent the result of the action.</returns>
+			System.Object Run();
+		}
+
+		private class AnonymousClassPrivilegedAction : IPriviligedAction
+		{
+			public AnonymousClassPrivilegedAction(System.Reflection.FieldInfo field)
+			{
+				InitBlock(field);
+			}
+			private void  InitBlock(System.Reflection.FieldInfo field)
+			{
+				this.field = field;
+			}
+			private System.Reflection.FieldInfo field;
+			public virtual System.Object Run()
+			{
+                // field.setAccessible(true); // {{Aroush-2.9}} java.lang.reflect.AccessibleObject.setAccessible
+				return null;
+			}
+		}
+		
+		private static System.Collections.IDictionary bundles = new System.Collections.Hashtable(0);
+		
+		protected internal NLS()
+		{
+			// Do not instantiate
+		}
+		
+		public static System.String GetLocalizedMessage(System.String key)
+		{
+			return GetLocalizedMessage(key, System.Threading.Thread.CurrentThread.CurrentCulture);
+		}
+		
+		public static System.String GetLocalizedMessage(System.String key, System.Globalization.CultureInfo locale)
+		{
+			System.Object message = GetResourceBundleObject(key, locale);
+			if (message == null)
+			{
+				return "Message with key:" + key + " and locale: " + locale + " not found.";
+			}
+			return message.ToString();
+		}
+		
+		public static System.String GetLocalizedMessage(System.String key, System.Globalization.CultureInfo locale, System.Object[] args)
+		{
+			System.String str = GetLocalizedMessage(key, locale);
+			
+			if (args.Length > 0)
+			{
+				str = System.String.Format(str, args);
+			}
+			
+			return str;
+		}
+		
+		public static System.String GetLocalizedMessage(System.String key, System.Object[] args)
+		{
+			return GetLocalizedMessage(key, System.Threading.Thread.CurrentThread.CurrentCulture, args);
+		}
+		
+		/// <summary> Initialize a given class with the message bundle Keys Should be called from
+		/// a class that extends NLS in a static block at class load time.
+		/// 
+		/// </summary>
+		/// <param name="bundleName">Property file with that contains the message bundle
+		/// </param>
+		/// <param name="clazz">where constants will reside
+		/// </param>
+		//@SuppressWarnings("unchecked")
+		protected internal static void  InitializeMessages(System.String bundleName, System.Type clazz)
+		{
+			try
+			{
+				Load(clazz);
+				if (!bundles.Contains(bundleName))
+					bundles[bundleName] = clazz;
+			}
+			catch (System.Exception e)
+			{
+				// ignore all errors and exceptions
+				// because this function is supposed to be called at class load time.
+			}
+		}
+		
+		private static System.Object GetResourceBundleObject(System.String messageKey, System.Globalization.CultureInfo locale)
+		{
+			
+			// slow resource checking
+			// need to loop thru all registered resource bundles
+			for (System.Collections.IEnumerator it = bundles.Keys.GetEnumerator(); it.MoveNext(); )
+			{
+				System.Type clazz = (System.Type) bundles[(System.String) it.Current];
+				System.Threading.Thread.CurrentThread.CurrentUICulture = locale;
+				System.Resources.ResourceManager resourceBundle = System.Resources.ResourceManager.CreateFileBasedResourceManager(clazz.FullName, "", null);
+				if (resourceBundle != null)
+				{
+					try
+					{
+						System.Object obj = resourceBundle.GetObject(messageKey);
+						if (obj != null)
+							return obj;
+					}
+					catch (System.Resources.MissingManifestResourceException e)
+					{
+						// just continue it might be on the next resource bundle
+					}
+				}
+			}
+			// if resource is not found
+			return null;
+		}
+		
+		/// <param name="clazz">
+		/// </param>
+		private static void  Load(System.Type clazz)
+		{
+			System.Reflection.FieldInfo[] fieldArray = clazz.GetFields(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.DeclaredOnly | System.Reflection.BindingFlags.Static);
+			
+			bool isFieldAccessible = clazz.IsPublic;
+			
+			// build a map of field names to Field objects
+			int len = fieldArray.Length;
+			System.Collections.IDictionary fields = new System.Collections.Hashtable(len * 2);
+			for (int i = 0; i < len; i++)
+			{
+				fields[fieldArray[i].Name] = fieldArray[i];
+				LoadfieldValue(fieldArray[i], isFieldAccessible, clazz);
+			}
+		}
+		
+		/// <param name="field">
+		/// </param>
+		/// <param name="isFieldAccessible">
+		/// </param>
+		private static void  LoadfieldValue(System.Reflection.FieldInfo field, bool isFieldAccessible, System.Type clazz)
+		{
+            /*
+			int MOD_EXPECTED = Modifier.PUBLIC | Modifier.STATIC;
+			int MOD_MASK = MOD_EXPECTED | Modifier.FINAL;
+			if ((field.getModifiers() & MOD_MASK) != MOD_EXPECTED)
+				return ;
+            */
+            if (!(field.IsPublic || field.IsStatic))
+                return ;
+			
+			// Set a value for this empty field.
+			if (!isFieldAccessible)
+				MakeAccessible(field);
+			try
+			{
+				field.SetValue(null, field.Name);
+				ValidateMessage(field.Name, clazz);
+			}
+			catch (System.ArgumentException e)
+			{
+				// should not happen
+			}
+			catch (System.UnauthorizedAccessException e)
+			{
+				// should not happen
+			}
+		}
+		
+		/// <param name="key">- Message Key
+		/// </param>
+		private static void  ValidateMessage(System.String key, System.Type clazz)
+		{
+			// Test if the message is present in the resource bundle
+			try
+			{
+				System.Threading.Thread.CurrentThread.CurrentUICulture = System.Threading.Thread.CurrentThread.CurrentCulture;
+				System.Resources.ResourceManager resourceBundle = System.Resources.ResourceManager.CreateFileBasedResourceManager(clazz.FullName, "", null);
+				if (resourceBundle != null)
+				{
+					System.Object obj = resourceBundle.GetObject(key);
+					if (obj == null)
+					{
+						System.Console.Error.WriteLine("WARN: Message with key:" + key + " and locale: " + System.Threading.Thread.CurrentThread.CurrentCulture + " not found.");
+					}
+				}
+			}
+			catch (System.Resources.MissingManifestResourceException e)
+			{
+				System.Console.Error.WriteLine("WARN: Message with key:" + key + " and locale: " + System.Threading.Thread.CurrentThread.CurrentCulture + " not found.");
+			}
+			catch (System.Exception e)
+			{
+				// ignore all other errors and exceptions
+				// since this code is just a test to see if the message is present on the
+				// system
+			}
+		}
+		
+		/*
+		* Make a class field accessible
+		*/
+		//@SuppressWarnings("unchecked")
+		private static void  MakeAccessible(System.Reflection.FieldInfo field)
+		{
+			if (System.Security.SecurityManager.SecurityEnabled)
+			{
+				//field.setAccessible(true);   // {{Aroush-2.9}} java.lang.reflect.AccessibleObject.setAccessible
+			}
+			else
+			{
+                //AccessController.doPrivileged(new AnonymousClassPrivilegedAction(field));     // {{Aroush-2.9}} java.security.AccessController.doPrivileged
+			}
+		}
+	}
+}
\ No newline at end of file

Added: incubator/lucene.net/trunk/C#/src/Lucene.Net/Messages/NLSException.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Messages/NLSException.cs?rev=887837&view=auto
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Messages/NLSException.cs (added)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Messages/NLSException.cs Mon Dec  7 05:25:34 2009
@@ -0,0 +1,37 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+
+namespace Lucene.Net.Messages
+{
+	
+	/// <summary> Interface that exceptions should implement to support lazy loading of messages.
+	/// 
+	/// For Native Language Support (NLS), system of software internationalization.
+	/// 
+	/// This Interface should be implemented by all exceptions that require
+	/// translation
+	/// 
+	/// </summary>
+	public interface NLSException
+	{
+		/// <returns> a instance of a class that implements the Message interface
+		/// </returns>
+		Message GetMessageObject();
+	}
+}
\ No newline at end of file

Added: incubator/lucene.net/trunk/C#/src/Lucene.Net/Messages/Package.html
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Messages/Package.html?rev=887837&view=auto
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Messages/Package.html (added)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Messages/Package.html Mon Dec  7 05:25:34 2009
@@ -0,0 +1,99 @@
+<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements.  See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License.  You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<html>
+<head>
+   <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+</head>
+<body>
+
+For Native Language Support (NLS), system of software internationalization.
+
+<h2>NLS message API</h2>
+<p>
+This utility API, adds support for NLS messages in the apache code.
+It is currently used by the lucene "New Flexible Query PArser".
+</p>
+<p>
+Features:
+    <ol>
+        <li>Message reference in the code, using static Strings</li>
+        <li>Message resource validation at class load time, for easier debugging</li>
+        <li>Allows for message IDs to be re-factored using eclipse or other code re-factor tools</li>
+        <li>Allows for reference count on messages, just like code</li>
+		<li>Lazy loading of Message Strings</li>        
+        <li>Normal loading Message Strings</li>                  
+    </ol>
+</p>
+
+<br/>
+<br/>
+<p>
+Lazy loading of Message Strings
+
+<pre>
+	public class MessagesTestBundle extends NLS {
+	
+	  private static final String BUNDLE_NAME = MessagesTestBundle.class.getName();
+	
+	  private MessagesTestBundle() {
+	    // should never be instantiated
+	  }
+	
+	  static {
+	    // register all string ids with NLS class and initialize static string
+	    // values
+	    NLS.initializeMessages(BUNDLE_NAME, MessagesTestBundle.class);
+	  }
+	
+	  // static string must match the strings in the property files.
+	  public static String Q0001E_INVALID_SYNTAX;
+	  public static String Q0004E_INVALID_SYNTAX_ESCAPE_UNICODE_TRUNCATION;
+	
+	  // this message is missing from the properties file
+	  public static String Q0005E_MESSAGE_NOT_IN_BUNDLE;
+	}
+
+    // Create a message reference
+    Message invalidSyntax = new MessageImpl(MessagesTestBundle.Q0001E_INVALID_SYNTAX, "XXX");
+    
+    // Do other stuff in the code...
+    // when is time to display the message to the user or log the message on a file
+    // the message is loaded from the correct bundle
+    
+    String message1 = invalidSyntax.getLocalizedMessage();
+    String message2 = invalidSyntax.getLocalizedMessage(Locale.JAPANESE);
+</pre>
+</p>
+
+<br/>
+<br/>
+<p>
+Normal loading of Message Strings
+
+<pre>
+	String message1 = NLS.getLocalizedMessage(MessagesTestBundle.Q0004E_INVALID_SYNTAX_ESCAPE_UNICODE_TRUNCATION);
+	String message2 = NLS.getLocalizedMessage(MessagesTestBundle.Q0004E_INVALID_SYNTAX_ESCAPE_UNICODE_TRUNCATION, Locale.JAPANESE);
+</pre>
+</p>
+
+<p>
+The org.apache.lucene.messages.TestNLS junit contains several other examples.
+The TestNLS java code is available from the Apache Lucene code repository.
+</p>
+</body>
+</html>

Added: incubator/lucene.net/trunk/C#/src/Test/Messages/MessagesTestBundle.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Messages/MessagesTestBundle.cs?rev=887837&view=auto
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Messages/MessagesTestBundle.cs (added)
+++ incubator/lucene.net/trunk/C#/src/Test/Messages/MessagesTestBundle.cs Mon Dec  7 05:25:34 2009
@@ -0,0 +1,49 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+
+namespace Lucene.Net.Messages
+{
+	
+	public class MessagesTestBundle:NLS
+	{
+		
+		private static readonly System.String BUNDLE_NAME;
+		
+		private MessagesTestBundle()
+		{
+			// should never be instantiated
+		}
+		
+		// static string must match the strings in the property files.
+		public static System.String Q0001E_INVALID_SYNTAX;
+		public static System.String Q0004E_INVALID_SYNTAX_ESCAPE_UNICODE_TRUNCATION;
+		
+		// this message is missing from the properties file
+		public static System.String Q0005E_MESSAGE_NOT_IN_BUNDLE;
+		static MessagesTestBundle()
+		{
+			BUNDLE_NAME = typeof(MessagesTestBundle).FullName;
+			{
+				// register all string ids with NLS class and initialize static string
+				// values
+				NLS.InitializeMessages(BUNDLE_NAME, typeof(MessagesTestBundle));
+			}
+		}
+	}
+}
\ No newline at end of file

Added: incubator/lucene.net/trunk/C#/src/Test/Messages/MessagesTestBundle.ja.resources
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Messages/MessagesTestBundle.ja.resources?rev=887837&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/lucene.net/trunk/C#/src/Test/Messages/MessagesTestBundle.ja.resources
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: incubator/lucene.net/trunk/C#/src/Test/Messages/MessagesTestBundle.resources
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Messages/MessagesTestBundle.resources?rev=887837&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/lucene.net/trunk/C#/src/Test/Messages/MessagesTestBundle.resources
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: incubator/lucene.net/trunk/C#/src/Test/Messages/TestNLS.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Messages/TestNLS.cs?rev=887837&view=auto
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Messages/TestNLS.cs (added)
+++ incubator/lucene.net/trunk/C#/src/Test/Messages/TestNLS.cs Mon Dec  7 05:25:34 2009
@@ -0,0 +1,83 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+
+using NUnit.Framework;
+
+namespace Lucene.Net.Messages
+{
+	
+	
+	[TestFixture]
+	public class TestNLS
+	{
+		[Test]
+		public virtual void  TestMessageLoading()
+		{
+			Message invalidSyntax = new MessageImpl(MessagesTestBundle.Q0001E_INVALID_SYNTAX, new System.Object[]{"XXX"});
+			Assert.AreEqual("Syntax Error: XXX", invalidSyntax.GetLocalizedMessage());
+		}
+		
+		[Test]
+		public virtual void  TestMessageLoading_ja()
+		{
+			Message invalidSyntax = new MessageImpl(MessagesTestBundle.Q0001E_INVALID_SYNTAX, new System.Object[]{"XXX"});
+			Assert.AreEqual("構文エラー: XXX", invalidSyntax.GetLocalizedMessage(new System.Globalization.CultureInfo("ja")));
+		}
+		
+		[Test]
+		public virtual void  TestNLSLoading()
+		{
+			System.String message = NLS.GetLocalizedMessage(MessagesTestBundle.Q0004E_INVALID_SYNTAX_ESCAPE_UNICODE_TRUNCATION);
+			Assert.AreEqual("Truncated unicode escape sequence.", message);
+			
+			message = NLS.GetLocalizedMessage(MessagesTestBundle.Q0001E_INVALID_SYNTAX, new System.Object[]{"XXX"});
+			Assert.AreEqual("Syntax Error: XXX", message);
+		}
+		
+		[Test]
+		public virtual void  TestNLSLoading_ja()
+		{
+			System.String message = NLS.GetLocalizedMessage(MessagesTestBundle.Q0004E_INVALID_SYNTAX_ESCAPE_UNICODE_TRUNCATION, new System.Globalization.CultureInfo("ja"));
+			Assert.AreEqual("切り捨てられたユニコード・エスケープ・シーケンス。", message);
+			
+			message = NLS.GetLocalizedMessage(MessagesTestBundle.Q0001E_INVALID_SYNTAX, new System.Globalization.CultureInfo("ja"), new System.Object[]{"XXX"});
+			Assert.AreEqual("構文エラー: XXX", message);
+		}
+		
+		[Test]
+		public virtual void  TestNLSLoading_xx_XX()
+		{
+			System.Globalization.CultureInfo locale = new System.Globalization.CultureInfo("xx" + "-" + "XX");
+			System.String message = NLS.GetLocalizedMessage(MessagesTestBundle.Q0004E_INVALID_SYNTAX_ESCAPE_UNICODE_TRUNCATION, locale);
+			Assert.AreEqual("Truncated unicode escape sequence.", message);
+			
+			message = NLS.GetLocalizedMessage(MessagesTestBundle.Q0001E_INVALID_SYNTAX, locale, new System.Object[]{"XXX"});
+			Assert.AreEqual("Syntax Error: XXX", message);
+		}
+		
+		[Test]
+		public virtual void  TestMissingMessage()
+		{
+			System.Globalization.CultureInfo locale = new System.Globalization.CultureInfo("en");
+			System.String message = NLS.GetLocalizedMessage(MessagesTestBundle.Q0005E_MESSAGE_NOT_IN_BUNDLE, locale);
+			
+			Assert.AreEqual("Message with key:Q0005E_MESSAGE_NOT_IN_BUNDLE and locale: " + locale.ToString() + " not found.", message);
+		}
+	}
+}
\ No newline at end of file

Modified: incubator/lucene.net/trunk/C#/src/Test/Test.csproj
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Test.csproj?rev=887837&r1=887836&r2=887837&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Test.csproj (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Test.csproj Mon Dec  7 05:25:34 2009
@@ -272,6 +272,8 @@
     <Compile Include="Index\TestWordlistLoader.cs">
       <SubType>Code</SubType>
     </Compile>
+    <Compile Include="Messages\MessagesTestBundle.cs" />
+    <Compile Include="Messages\TestNLS.cs" />
     <Compile Include="QueryParser\TestMultiAnalyzer.cs">
       <SubType>Code</SubType>
     </Compile>
@@ -474,6 +476,10 @@
     <None Include="Index\index.24.cfs.zip" />
     <None Include="Index\index.24.nocfs.zip" />
   </ItemGroup>
+  <ItemGroup>
+    <EmbeddedResource Include="Messages\MessagesTestBundle.ja.resources" />
+    <EmbeddedResource Include="Messages\MessagesTestBundle.resources" />
+  </ItemGroup>
   <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
   <PropertyGroup>
     <PreBuildEvent>