Package org.boco.seamUtility.messages

Source Code of org.boco.seamUtility.messages.MessagesLoader

/***************************************************************************
* Copyright (c) 2004 - 2008  Fabrizio Boco fabboco@users.sourceforge.net  *
*                                                                         *
*                                                                         *
*   This is free software; you can redistribute it and/or                 *
*   modify it under the terms of the GNU Library General Public           *
*   License (version 2.1) as published by the Free Software Foundation    *
*                                                                         *
*   This library  is distributed in the hope that it will be useful,      *
*   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
*   GNU Library General Public License for more details.                  *
*                                                                         *
*   You should have received a copy of the GNU Library General Public     *
*   License along with this library; see the file COPYING.LIB. If not,    *
*   write to the Free Software Foundation, Inc., 59 Temple Place,         *
*   Suite 330, Boston, MA  02111-1307, USA                                *
*                                                                         *
***************************************************************************/
/**
- $Header: /usr/local/cvslocalrepository/SeamUtility/src/org/boco/seamUtility/messages/MessagesLoader.java,v 1.1.10.2 2008/04/22 06:14:36 fab Exp $
- $Author: fab $
- $Revision: 1.1.10.2 $
- $Date: 2008/04/22 06:14:36 $
-
- $Log: MessagesLoader.java,v $
- Revision 1.1.10.2  2008/04/22 06:14:36  fab
- Aggiornamento indirizzo di posta
-
- Revision 1.1.10.1  2008/04/19 11:14:41  fab
- Aggiornamento riferimenti licenza e documentazione
-
- Revision 1.1  2007/09/30 07:45:41  fab
- Nuova versione iniziale del 30/09/2007
-
- Revision 1.1  2006/11/28 10:52:14  dev
- Versione Iniziale
-
**/
package org.boco.seamUtility.messages;

import java.text.MessageFormat;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;


/**
* Classe per la lettura del file dei messaggi
*
*/
public class MessagesLoader
{

  protected static ClassLoader getCurrentClassLoader(Object defaultObject)
  {

    ClassLoader loader = Thread.currentThread().getContextClassLoader();

    if (loader == null)
    {
      loader = defaultObject.getClass().getClassLoader();
    }

    return loader;
  }

  public static String getMessageResourceString(String bundleName, String key, Object params[], Locale locale)
  {

    String text = null;

    ResourceBundle bundle = ResourceBundle.getBundle(bundleName, locale, getCurrentClassLoader(params));

    try
    {
      text = bundle.getString(key);
    }
    catch (MissingResourceException e)
    {
      text = "?? key " + key + " not found ??";
    }

    if (params != null)
    {
      MessageFormat mf = new MessageFormat(text, locale);
      text = mf.format(params, new StringBuffer(), null).toString();
    }

    return text;
  }
}
TOP

Related Classes of org.boco.seamUtility.messages.MessagesLoader

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.