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

📄 resourcebundleservicepropertyhandlerutil.java

📁 intra_mart是日本NDD公司开发的著名企业应用解决方案中间件。集成了J2ee服务器
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
/*
 * ResourceBundleServicePropertyHandlerUtil.java
 *
 * Created on 2002/08/12, 19:51
 */

package jp.co.intra_mart.framework.base.service;

import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import java.util.StringTokenizer;

/**
 * 巜掕偝傟偨儕僜乕僗僶儞僪儖偐傜僒乕價僗僾儘僷僥傿傪庢摼偡傞儐乕僥傿儕僥傿偱偡丅
 *
 * @author INTRAMART
 * @since 3.2
 */
class ResourceBundleServicePropertyHandlerUtil {

    /**
     * 僋儔僀傾儞僩偺僄儞僐乕僪傪庢摼偟傑偡丅
     *
     * @param commonBundle 嫟捠偺儕僜乕僗僶儞僪儖
     * @return 僋儔僀傾儞僩偺僄儞僐乕僨傿儞僌
     * @throws ServicePropertyException 僋儔僀傾儞僩偺僄儞僐乕僪偺庢摼帪偵椺奜偑敪惗
     */
    public static String getClientEncoding(ResourceBundle commonBundle)
        throws ServicePropertyException {
        String encoding;

        try {
            encoding = commonBundle.getString("client.encoding");
        } catch (MissingResourceException e) {
            String message = null;
            try {
                message =
                    ResourceBundle
                        .getBundle("jp.co.intra_mart.framework.base.service.i18n")
                        .getString("ResourceBundleServicePropertyHandlerUtil.FailedToGetClientEncoding");
            } catch (MissingResourceException ex) {
            }
            throw new ServicePropertyException(message, e);
        }

        return encoding;
    }

    /**
     * 僋儔僀傾儞僩偺儘働乕儖傪庢摼偟傑偡丅
     *
     * @param commonBundle 嫟捠偺儕僜乕僗僶儞僪儖
     * @return 僋儔僀傾儞僩偺儘働乕儖
     * @throws ServicePropertyException 僋儔僀傾儞僩偺儘働乕儖偺庢摼帪偵椺奜偑敪惗
     * @since 4.2
     */
    public static Locale getClientLocale(ResourceBundle commonBundle)
        throws ServicePropertyException {
        String localeString = null;
        Locale locale = null;

        try {
            localeString = commonBundle.getString("client.locale");
        } catch (MissingResourceException e) {
            String message = null;
            try {
                message =
                    ResourceBundle
                        .getBundle("jp.co.intra_mart.framework.base.service.i18n")
                        .getString("ResourceBundleServicePropertyHandlerUtil.FailedToGetClientLocale");
            } catch (MissingResourceException ex) {
            }
            throw new ServicePropertyException(message, e);
        }
        if (localeString != null) {
            locale = getRealLocale(localeString);
        }

        return locale;
    }

    /**
     * 儘働乕儖暥帤楍偐傜幚嵺偺儘働乕儖傪庢摼偟傑偡丅
     * 儘働乕儖暥帤楍偼埲壓偺彂幃偵廬偄傑偡丅<BR>
     * <I>尵岅</I>_<I>崙</I>[_<I>僶儕傾儞僩</I>]<BR>
     * 儘働乕儖暥帤楍偺傾儞僟乕僶乕(_)偼僴僀僼儞(-)偱偁偭偰傕偐傑偄傑偣傫丅
     *
     * @param localeString 儘働乕儖暥帤楍
     * @return 儘働乕儖
     */
    private static Locale getRealLocale(String localeString) {
        StringTokenizer tokenizer = new StringTokenizer(localeString, "-_");
        if (tokenizer.countTokens() == 2) {
            String language = tokenizer.nextToken();
            String country = tokenizer.nextToken();
            return new Locale(language, country);
        } else if (tokenizer.countTokens() == 3) {
            String language = tokenizer.nextToken();
            String country = tokenizer.nextToken();
            String variant = tokenizer.nextToken();
            return new Locale(language, country, variant);
        } else {
            String message = null;
            try {
                message =
                    ResourceBundle
                        .getBundle("jp.co.intra_mart.framework.base.web.tag.i18n")
                        .getString("MessageTag.LocaleStringIncorrect");
            } catch (MissingResourceException e) {
            }
            throw new IllegalArgumentException(
                message + " : \"" + localeString + "\"");
        }
    }

    /**
     * 擖椡椺奜帪偺儁乕僕偺僷僗傪庢摼偟傑偡丅
     * 奩摉偡傞儁乕僕偺僷僗偑庢摼偱偒側偄応崌丄{@link #getInputErrorPagePath(String, String)}偱庢摼偝傟傞儁乕僕傪曉偟傑偡丅
     *
     * @param commonBundle 嫟捠偺儕僜乕僗僶儞僪儖
     * @param applicationBundle 傾僾儕働乕僔儑儞偺儕僜乕僗僶儞僪儖
     * @param application 傾僾儕働乕僔儑儞ID
     * @param service 僒乕價僗ID
     * @param key 慗堏愭偺僉乕
     * @return 慗堏愭偺儁乕僕偺僷僗
     * @throws ServicePropertyException 慗堏愭偺儁乕僕偺僷僗偺庢摼帪偵椺奜偑敪惗
     */
    public static String getInputErrorPagePath(
        ResourceBundle commonBundle,
        ResourceBundle applicationBundle,
        String application,
        String service,
        String key)
        throws ServicePropertyException {
        String page = null;

        try {
            page =
                applicationBundle.getString(
                    "input.error.page.path." + service + "." + key);
        } catch (MissingResourceException e) {
            try {
                page =
                    getInputErrorPagePath(
                        commonBundle,
                        applicationBundle,
                        application,
                        service);
            } catch (ServicePropertyException ex) {
                String message = null;
                try {
                    message =
                        ResourceBundle
                            .getBundle("jp.co.intra_mart.framework.base.service.i18n")
                            .getString("ResourceBundleServicePropertyHandlerUtil.FailedToGetInputErrorPagePath");
                } catch (MissingResourceException exc) {
                }
                throw new ServicePropertyException(
                    message
                        + " : application = "
                        + application
                        + ", service = "
                        + service
                        + ", key = "
                        + key,
                    e);
            }
        }

        return page;
    }

    /**
     * 擖椡椺奜帪偺儁乕僕偺僷僗傪庢摼偟傑偡丅
     * 奩摉偡傞儁乕僕偺僷僗偑庢摼偱偒側偄応崌丄{@link #getInputErrorPagePath(String)}偱庢摼偝傟傞儁乕僕傪曉偟傑偡丅
     *
     * @param commonBundle 嫟捠偺儕僜乕僗僶儞僪儖
     * @param applicationBundle 傾僾儕働乕僔儑儞偺儕僜乕僗僶儞僪儖
     * @param application 傾僾儕働乕僔儑儞ID
     * @param service 僒乕價僗ID
     * @return 慗堏愭偺儁乕僕偺僷僗
     * @throws ServicePropertyException 慗堏愭偺儁乕僕偺僷僗偺庢摼帪偵椺奜偑敪惗
     */
    public static String getInputErrorPagePath(
        ResourceBundle commonBundle,
        ResourceBundle applicationBundle,
        String application,
        String service)
        throws ServicePropertyException {
        String page = null;

        try {
            page =
                applicationBundle.getString("input.error.page.path." + service);
        } catch (MissingResourceException e) {
            try {
                page =
                    getInputErrorPagePath(
                        commonBundle,
                        applicationBundle,
                        application);
            } catch (ServicePropertyException ex) {
                String message = null;
                try {
                    message =
                        ResourceBundle
                            .getBundle("jp.co.intra_mart.framework.base.service.i18n")
                            .getString("ResourceBundleServicePropertyHandlerUtil.FailedToGetInputErrorPagePath");
                } catch (MissingResourceException exc) {
                }
                throw new ServicePropertyException(
                    message
                        + " : application = "
                        + application
                        + ", service = "
                        + service,
                    e);
            }
        }

        return page;
    }

    /**
     * 擖椡椺奜帪偺儁乕僕偺僷僗傪庢摼偟傑偡丅
     * 奩摉偡傞儁乕僕偺僷僗偑庢摼偱偒側偄応崌丄{@link #getInputErrorPagePath()}偱庢摼偝傟傞儁乕僕傪曉偟傑偡丅
     *
     * @param commonBundle 嫟捠偺儕僜乕僗僶儞僪儖
     * @param applicationBundle 傾僾儕働乕僔儑儞偺儕僜乕僗僶儞僪儖
     * @param application 傾僾儕働乕僔儑儞ID
     * @return 慗堏愭偺儁乕僕偺僷僗
     * @throws ServicePropertyException 慗堏愭偺儁乕僕偺僷僗偺庢摼帪偵椺奜偑敪惗
     */
    public static String getInputErrorPagePath(
        ResourceBundle commonBundle,
        ResourceBundle applicationBundle,
        String application)
        throws ServicePropertyException {
        String page = null;

        try {
            page = applicationBundle.getString("input.error.page.path");
        } catch (MissingResourceException e) {
            try {
                page = getInputErrorPagePath(commonBundle);
            } catch (ServicePropertyException ex) {
                String message = null;
                try {
                    message =
                        ResourceBundle
                            .getBundle("jp.co.intra_mart.framework.base.service.i18n")
                            .getString("ResourceBundleServicePropertyHandlerUtil.FailedToGetInputErrorPagePath");
                } catch (MissingResourceException exc) {
                }
                throw new ServicePropertyException(
                    message + " : application = " + application,
                    e);
            }
        }

        return page;
    }

    /**
     * 擖椡椺奜帪偺儁乕僕偺僷僗傪庢摼偟傑偡丅
     *
     * @param commonBundle 嫟捠偺儕僜乕僗僶儞僪儖
     * @return 慗堏愭偺儁乕僕偺僷僗
     * @throws ServicePropertyException 慗堏愭偺儁乕僕偺僷僗偺庢摼帪偵椺奜偑敪惗
     */
    public static String getInputErrorPagePath(ResourceBundle commonBundle)
        throws ServicePropertyException {
        String page = null;

        try {

⌨️ 快捷键说明

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