⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 _messageutils.java

📁 一个使用struts+hibernate+spring开发的完的网站源代码。
💻 JAVA
字号:
/* * Copyright 2004 The Apache Software Foundation. *  * Licensed 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. */package javax.faces.convert;import javax.faces.application.FacesMessage;import javax.faces.context.FacesContext;import java.text.MessageFormat;import java.util.Locale;import java.util.MissingResourceException;import java.util.ResourceBundle;/** * $Log: _MessageUtils.java,v $ * Revision 1.3  2004/07/01 22:00:51  mwessendorf * ASF switch * * Revision 1.2  2004/03/26 12:08:42  manolito * Exceptions in getAsString now catched and * more relaxed Number casting in all number converters * * @author Manfred Geiler (latest modification by $Author: mwessendorf $) * @version $Revision: 1.3 $ $Date: 2004/07/01 22:00:51 $ */class _MessageUtils{    private static final String DETAIL_SUFFIX = "_detail";    static FacesMessage getErrorMessage(FacesContext facesContext,                                        String messageId,                                        Object args[])    {        return getMessage(facesContext,                          facesContext.getViewRoot().getLocale(),                          FacesMessage.SEVERITY_ERROR,                          messageId,                          args);    }    static FacesMessage getMessage(FacesContext facesContext,                                   Locale locale,                                   FacesMessage.Severity severity,                                   String messageId,                                   Object args[])    {        ResourceBundle appBundle;        ResourceBundle defBundle;        String summary;        String detail;        appBundle = getApplicationBundle(facesContext, locale);        summary = getBundleString(appBundle, messageId);        if (summary != null)        {            detail = getBundleString(appBundle, messageId + DETAIL_SUFFIX);        }        else        {            defBundle = getDefaultBundle(facesContext, locale);            summary = getBundleString(defBundle, messageId);            if (summary != null)            {                detail = getBundleString(defBundle, messageId + DETAIL_SUFFIX);            }            else            {                //Try to find detail alone                detail = getBundleString(appBundle, messageId + DETAIL_SUFFIX);                if (detail != null)                {                    summary = null;                }                else                {                    detail = getBundleString(defBundle, messageId + DETAIL_SUFFIX);                    if (detail != null)                    {                        summary = null;                    }                    else                    {                        //Neither detail nor summary found                        return null;                    }                }            }        }        if (args != null && args.length > 0)        {            MessageFormat format;            if (summary != null)            {                format = new MessageFormat(summary, locale);                summary = format.format(args);            }            if (detail != null)            {                format = new MessageFormat(detail, locale);                detail = format.format(args);            }        }        return new FacesMessage(severity, summary, detail);    }    private static String getBundleString(ResourceBundle bundle, String key)    {        try        {            return bundle == null ? null : bundle.getString(key);        }        catch (MissingResourceException e)        {            return null;        }    }    private static ResourceBundle getApplicationBundle(FacesContext facesContext, Locale locale)    {        String bundleName = facesContext.getApplication().getMessageBundle();        if (bundleName != null)        {            return getBundle(facesContext, locale, bundleName);        }        else        {            return null;        }    }    private static ResourceBundle getDefaultBundle(FacesContext facesContext,                                                   Locale locale)    {        return getBundle(facesContext, locale, FacesMessage.FACES_MESSAGES);    }    private static ResourceBundle getBundle(FacesContext facesContext,                                            Locale locale,                                            String bundleName)    {        try        {            //First we try the JSF implementation class loader            return ResourceBundle.getBundle(bundleName,                                            locale,                                            facesContext.getClass().getClassLoader());        }        catch (MissingResourceException ignore1)        {            try            {                //Next we try the JSF API class loader                return ResourceBundle.getBundle(bundleName,                                                locale,                                                _MessageUtils.class.getClassLoader());            }            catch (MissingResourceException ignore2)            {                try                {                    //Last resort is the context class loader                    return ResourceBundle.getBundle(bundleName,                                                    locale,                                                    Thread.currentThread().getContextClassLoader());                }                catch (MissingResourceException damned)                {                    facesContext.getExternalContext().log("resource bundle " + bundleName + " could not be found");                    return null;                }            }        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -