ruper2/src/java/core/org/krysalis/ruper/util/text MessageConstants.java,1.8,1.9 Messages.java,1.4,1.5

[email protected]
Newsgroups gmane.comp.krysalis.metamorphosis.cvs
Message-ID <[email protected]>
Update of /cvsroot/metamorphosis/ruper2/src/java/core/org/krysalis/ruper/util/text
In directory sc8-pr-cvs1:/tmp/cvs-serv17764/src/java/core/org/krysalis/ruper/util/text

Modified Files:
	MessageConstants.java Messages.java 
Log Message:
1) Unit test for messages
2) Fallback to "en" if messages in default locale not available
3) First stab at loading ruper.xml from a resource (classloader) not just file

Index: MessageConstants.java
===================================================================
RCS file: /cvsroot/metamorphosis/ruper2/src/java/core/org/krysalis/ruper/util/text/MessageConstants.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** MessageConstants.java	22 Sep 2003 19:18:31 -0000	1.8
--- MessageConstants.java	22 Sep 2003 20:18:28 -0000	1.9
***************
*** 4,27 ****
  package org.krysalis.ruper.util.text;
  
  /**
   * @author anou_mana
   */
! public class MessageConstants
! {
! 	
  	//:TODO: We have to (1) organzied (2) document these ASAP
  	// before they get out of control...
! 	
! 	
  	public static final String GENERAL_EXCEPTION2 = "GENERAL_EXCEPTION2";
  	public static final String GENERAL_EXCEPTION3 = "GENERAL_EXCEPTION3";
! 	
  	//ERRORS
  	public static final String WRONG_TYPE = "WRONG_TYPE";
- 	public static final String CONFIG_ERROR = "CONFIG_ERROR";
- 	public static final String UNABLE_TO_LOAD_CONFIG_FILE = "RUPER_MSG_UNABLE_TO_LOAD_CONFIG_FILE";
  	public static final String NO_SUCH_REFERENCE = "NO_SUCH_REFERENCE";
  	public static final String CREATE_OBJECT_ERROR = "CREATE_OBJECT_ERROR";
  
  	// Repository Operations..
  	public static final String LIST_GROUPS = "LIST_GROUPS";
--- 4,34 ----
  package org.krysalis.ruper.util.text;
  
+ import java.lang.reflect.Field;
+ import java.util.ArrayList;
+ import java.util.List;
+ 
  /**
   * @author anou_mana
   */
! public class MessageConstants {
! 
  	//:TODO: We have to (1) organzied (2) document these ASAP
  	// before they get out of control...
! 
  	public static final String GENERAL_EXCEPTION2 = "GENERAL_EXCEPTION2";
  	public static final String GENERAL_EXCEPTION3 = "GENERAL_EXCEPTION3";
! 
  	//ERRORS
  	public static final String WRONG_TYPE = "WRONG_TYPE";
  	public static final String NO_SUCH_REFERENCE = "NO_SUCH_REFERENCE";
  	public static final String CREATE_OBJECT_ERROR = "CREATE_OBJECT_ERROR";
  
+ 	// Configuration
+ 
+ 	public static final String CONFIG = "CONFIG";
+ 	public static final String CONFIG_ERROR = "CONFIG_ERROR";
+ 	public static final String UNABLE_TO_LOAD_CONFIG =
+ 		"UNABLE_TO_LOAD_CONFIG";
+ 		
  	// Repository Operations..
  	public static final String LIST_GROUPS = "LIST_GROUPS";
***************
*** 33,48 ****
  	public static final String LIST_GROUPS_FAILED = "LIST_GROUPS_FAILED";
  	public static final String LIST_RESOURCES_FAILED = "LIST_RESOURCES_FAILED";
! 	public static final String LIST_SPECIFIERS_FAILED = "LIST_SPECIFIERS_FAILED";
! 	public static final String DELETE_RESOURCE_FAILED = "DELETE_RESOURCES_FAILED";
! 	public static final String PUBLISH_RESOURCE_FAILED = "PUBLISH_RESOURCE_FAILED";
  
  	public static final String SEARCH_REPOSITORY = "SEARCH_REPOSITORY";
  	public static final String RESOURCE_GROUP = "RESOURCE_GROUP";
  	public static final String RESOURCE_REQUEST = "RESOURCE_REQUEST";
! 	
  	public static final String NO_RESOURCES_FOUND = "NO_RESOURCES_FOUND";
  	public static final String NO_UPDATE_FOUND = "NO_UPDATE_FOUND";
  	public static final String LIST_FAILED = "LIST_FAILED";
- 	
  
  	public static final String PROCESS = "PROCESS";
--- 40,57 ----
  	public static final String LIST_GROUPS_FAILED = "LIST_GROUPS_FAILED";
  	public static final String LIST_RESOURCES_FAILED = "LIST_RESOURCES_FAILED";
! 	public static final String LIST_SPECIFIERS_FAILED =
! 		"LIST_SPECIFIERS_FAILED";
! 	public static final String DELETE_RESOURCE_FAILED =
! 		"DELETE_RESOURCES_FAILED";
! 	public static final String PUBLISH_RESOURCE_FAILED =
! 		"PUBLISH_RESOURCE_FAILED";
  
  	public static final String SEARCH_REPOSITORY = "SEARCH_REPOSITORY";
  	public static final String RESOURCE_GROUP = "RESOURCE_GROUP";
  	public static final String RESOURCE_REQUEST = "RESOURCE_REQUEST";
! 
  	public static final String NO_RESOURCES_FOUND = "NO_RESOURCES_FOUND";
  	public static final String NO_UPDATE_FOUND = "NO_UPDATE_FOUND";
  	public static final String LIST_FAILED = "LIST_FAILED";
  
  	public static final String PROCESS = "PROCESS";
***************
*** 54,58 ****
  	public static final String TYPE_COMPARATOR = "TYPE_COMPARATOR";
  	public static final String VERSION_COMPARATOR = "VERSION_COMPARATOR";
- 	
  
  	public static final String FILENAME_SELECTOR = "FILENAME_SELECTOR";
--- 63,66 ----
***************
*** 60,62 ****
--- 68,96 ----
  	public static final String TYPE_SELECTOR = "TYPE_SELECTOR";
  	public static final String VERSION_SELECTOR = "VERSION_SELECTOR";
+ 
+ 	// For introspection, see below...
+ 	private MessageConstants() {
+ 	}
+ 
+ 	public static List getCodes() {
+ 		List codes = new ArrayList();
+ 
+ 		Object me = new MessageConstants();
+ 		Class myself = MessageConstants.class;
+ 
+ 		Field[] fields = myself.getFields();
+ 
+ 		for (int i = 0; i < fields.length; ++i) {
+ 			Field field = fields[i];
+ 
+ 			try {
+ 				codes.add((String) field.get(me));
+ 			}
+ 			catch (Exception e) {
+ 				//Ignore...
+ 			}
+ 		}
+ 
+ 		return codes;
+ 	}
  }

Index: Messages.java
===================================================================
RCS file: /cvsroot/metamorphosis/ruper2/src/java/core/org/krysalis/ruper/util/text/Messages.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** Messages.java	22 Sep 2003 19:18:31 -0000	1.4
--- Messages.java	22 Sep 2003 20:18:28 -0000	1.5
***************
*** 16,25 ****
  public class Messages {
  	//Name of the resource Bundle
! 	private static final String BUNDLE_NAME =
! 		"org.krysalis.ruper.util.text.rupermsg";
  
  	//Intialized the ResourceBundle.
! 	private static final ResourceBundle RESOURCE_BUNDLE =
! 		ResourceBundle.getBundle(BUNDLE_NAME,Locale.getDefault());
  
  	private Messages() {
--- 16,54 ----
  public class Messages {
  	//Name of the resource Bundle
! 	private static final String BUNDLE_NAME = "org.krysalis.ruper";
! 
! 	private static final Locale FALLBACK_LOCALE = Locale.ENGLISH;
  
  	//Intialized the ResourceBundle.
! 	private static ResourceBundle l_resourceBundle = null;
! 
! 	static {
! 		try {
! 			l_resourceBundle =
! 				ResourceBundle.getBundle(BUNDLE_NAME, Locale.getDefault());
! 
! 		}
! 		catch (Exception e) {System.err.println(
! 			"Unable to find Ruper resource bundle ["
! 				+ BUNDLE_NAME
! 				+ "] with locale ["
! 				+ Locale.getDefault()
! 				+ "]");
! 				
! 			try {
! 				l_resourceBundle =
! 					ResourceBundle.getBundle(BUNDLE_NAME, FALLBACK_LOCALE);
! 
! 			}
! 			catch (Exception ee) {
! 				System.err.println(
! 					"Unable to find Ruper resource bundle ["
! 						+ BUNDLE_NAME
! 						+ "] with locale "
! 						+ FALLBACK_LOCALE
! 						+ "]");
! 			}
! 		}
! 	}
  
  	private Messages() {
***************
*** 88,102 ****
  	 * Locates a message by its code.
  	 */
! 	private static MessageFormat findMessage(final String code)
  		throws MissingResourceException {
  
  		MessageFormat msg = null;
  
! 		// Locate the message resources
! 		String msgText = RESOURCE_BUNDLE.getString(code);
  		// get the message format
! 		if (msgText != null) {
  			msg = new MessageFormat(msgText);
! 		}
  		return msg;
  	}
--- 117,134 ----
  	 * Locates a message by its code.
  	 */
! 	static MessageFormat findMessage(final String code)
  		throws MissingResourceException {
  
  		MessageFormat msg = null;
  
! 		String msgText =
! 			(null != l_resourceBundle)
! 				? l_resourceBundle.getString(code)
! 				: null;
! 
  		// get the message format
! 		if (msgText != null)
  			msg = new MessageFormat(msgText);
! 
  		return msg;
  	}




-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.