MessageUtil

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

import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

public class MessageUtil extends BaseValidator {
    
    private MessageUtil() {
        
    }
    
    /**
     * Get message from language propriety file
     * @param bundle             Language propriety file key
     * @param key                Message key
     * @param defaultMessage     Default message
     * @param arguments          Message arguments
     */
    public static String getText(String bundle, String key, String defaultMessage, String[] arguments) {
        
        String message = null;
        
        try {
            ServletRequestAttributes servletRequestAttributes = 
                (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes();
            
            User user = 
                (User) servletRequestAttributes.getAttribute(
                        LogonConstants.SESSION_USER, 
                        RequestAttributes.SCOPE_SESSION);
            
            String local = null;
            if (user != null) {
                local = user.getLocale().getValue();
            } else {
                local = FieldValidationConstants.DEFAULT_LOCAL.getLanguage() + "_" 
                            + FieldValidationConstants.DEFAULT_LOCAL.getCountry().toLowerCase();
            }
            
            String fullPath = "language." + bundle + "." + bundle + "_" + local;
            ResourceBundle oBundle = ResourceBundle.getBundle(fullPath);
            message = oBundle.getString(key);
        } catch (Exception e) {
            message = defaultMessage;
            e.printStackTrace();
        }
        
        if (arguments != null) {
            message = MessageFormat.format(message, arguments);
        }
        
        return message;  
    }
    
    public static void addPageMessage(boolean success, String successMessage, String errorMessage) {
        if (success) {
            if (!Util.isEmpty(successMessage)) {
                MessageUtil.addPageSuccessMessage(successMessage);
            }
        } else {
            if (!Util.isEmpty(errorMessage)) {
                MessageUtil.addPageErrorMessage(errorMessage);
            }
        }
    }
    
    /**
     * Add page error message to request attribute 
     * @param errorMessage       Page error message
     */
    public static void addPageErrorMessage(String errorMessage) {
        
        if (!Util.isEmpty(errorMessage)) {
            ServletRequestAttributes servletRequestAttributes = 
                (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes();
            
            Messages messages = BaseValidator.getMessages(servletRequestAttributes);
            
            messages.addErrorMessage(errorMessage);
            
            servletRequestAttributes.setAttribute(FieldValidationConstants.MESSAGES, 
                    messages, RequestAttributes.SCOPE_REQUEST);
        }
    }
    
    /**
     * Add page error message to request attribute 
     * @param bundle             Language property file id
     * @param key                Message key
     * @param defaultMessage     Default message
     * @param arguments          The arguments of message
     */
    public static void addPageErrorMessage(String bundle, String key, String defaultMessage, String[] arguments) {
        
        String errorMessage = MessageUtil.getText(bundle, key, defaultMessage, arguments);
        
        MessageUtil.addPageErrorMessage(errorMessage);
    }
    
    
    /**
     * Add page success message to request attribute 
     * @param successMessage     Page success message
     */
    public static void addPageSuccessMessage(String successMessage) {
        
        if (!Util.isEmpty(successMessage)) {
            ServletRequestAttributes servletRequestAttributes = 
                (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes();
            
            Messages messages = BaseValidator.getMessages(servletRequestAttributes);
            
            messages.addSuccessMessage(successMessage);
            
            servletRequestAttributes.setAttribute(FieldValidationConstants.MESSAGES, 
                    messages, RequestAttributes.SCOPE_REQUEST);
        }
    }
    
    /**
     * Add page success message to request attribute 
     * @param bundle             Language property file id
     * @param key                Message key
     * @param defaultMessage     Default message
     * @param arguments          The arguments of message
     */
    public static void addPageSuccessMessage(String bundle, String key, String defaultMessage, String[] arguments) {
        
        String successMessage = MessageUtil.getText(bundle, key, defaultMessage, arguments);
        
        MessageUtil.addPageSuccessMessage(successMessage);
    }
    
}

 

>nih ドキュメント名機能名(L2)版日付作成者 機能設計書受発注マスタ作成1.012025/8/18NEC 丁雨珊開発方式No.1開発方式No.2開発方式No.3開発方式No.4開発方式No.8開発方式No.9開発方式No.10開発方式No.13開発方式No.14(PostgreSQL非互換変換ルール 改版履歴:1.02) 処理仕様クラスIDクラス名 BJ_M_VIVID_LINKReadDaoImplリンクマスタ(全件)ReadDAOクラス ジョブステップIDBJ_M_VIVID_LINKReadDaoImpl.java システム名受発注システム クラス名ViViD_リンクマスタ DAO のクラス 機能概要ViViD_リンクマスタに対するデータベースアクセス機能を提供する. 備考著作権 Copyright © NEC Corporation 2025. All rights reserved. /* V1.01削除 * システム名 :受発注システムV1.01削除 * クラス名:ViViD_リンクマスタ DAO のクラスV1.01削除 * 機能概要:ViViD_リンクマスタに対するデータベースアクセス機能を提供する.V1.01削除 * V1.01削除 * Copyright(c) 2009 FamilyMart Co., Ltd. All Rights Reserved. V1.01削除 * V1.01削除 * 履歴:V1.01削除 * 日付 更新者 内容V1.01削除 * 2009/03/31 徐 利民 初版V1.01削除 * V1.01削除 */V1.01削除 package jp.co.family.bj.dao.impl; import java.sql.ResultSet; import java.sql.SQLException; import jp.co.family.bj.common.core.AbstractDao; import jp.co.family.bj.common.core.AbstractDto; import jp.co.family.bj.common.exception.DatabaseException; import jp.co.family.bj.common.util.Const; import jp.co.family.bj.common.util.MessageUtil; import jp.co.family.bj.dao.BJ_M_VIVID_LINKReadDao; import jp.co.family.bj.dao.VIVID_MST_ReadDao; import jp.co.family.bj.dto.BJ_M_LINKDto; /** * ViViD_リンクマスタに対するデータベースアクセス機能を提供する. * */ public class BJ_M_VIVID_LINKReadDaoImpl extends AbstractDao implements BJ_M_VIVID_LINKReadDao, VIVID_MST_ReadDao { // 発注地区 private static final String HCHIKU = "HCHIKU"; // 店番 private static final String TENBAN = "TENBAN"; // 取引先コード private static final String TRI_CD = "TRI_CD"; // 使用開始日 private static final String START_DATE = "START_DATE"; // 使用終了日 private static final String END_DATE = "END_DATE"; // 登録区分 private static final String UP_KBN = "UP_KBN"; // 店舗配信済みフラグ private static final String H_FLG = "H_FLG"; /** データ検索SQL文 */ private String checkLinkSql; // リンクマスタ作成用データ検索SQL文 private String selectSql; // 検索結果セット private ResultSet resultSet; //リンクDTO private BJ_M_LINKDto bj_M_LINKDto = new BJ_M_LINKDto(); /** データ検索SQL文 */ private String checkLinkDateSql; /** * 検索SQL文を設定する. * * @param checkLinkSql * SQL文 */ public void setCheckLinkSql(String checkLinkSql) { this.checkLinkSql = checkLinkSql; } /** * 検索SQL文を設定する. * * @param checkLinkDateSql * SQL文 */ public void setCheckLinkDateSql(String checkLinkDateSql) { this.checkLinkDateSql = checkLinkDateSql; } /** * @see BJ_M_VIVID_LINKReadDao#checkLink(String, String, String) */ public boolean checkLink(String hchiku, String tenban, String triCd) { int count = 0; Object[] args = { hchiku, tenban, triCd }; ResultSet rs = null; try { // 結果セットのオープン rs = executeQuery(checkLinkSql, args); rs.next(); count = rs.getInt(1); } catch (SQLException se) { Object[] args2 = {}; throw new DatabaseException(MessageUtil.getMessage(Const.E_BJ_0120, args2), se); } finally { // 結果セットをオープンしたら必ずクローズする if (rs != null) { try { rs.close(); } catch (SQLException se) { // 外のtry-catchのExceptionを生かすためにここでは敢えて握りつぶす } } } if (count == 0) { return false; } else { return true; } } /** * @see BJ_M_VIVID_LINKReadDao#checkLinkDate(String, String, String, String) */ public boolean checkLinkDate(String hchiku, String tenban, String triCd, String orderDate) { int count = 0; Object[] args = { hchiku, tenban, triCd, orderDate, orderDate }; ResultSet rs = null; try { // 結果セットのオープン rs = executeQuery(checkLinkDateSql, args); rs.next(); count = rs.getInt(1); } catch (SQLException se) { Object[] args2 = {}; throw new DatabaseException(MessageUtil.getMessage(Const.E_BJ_0120, args2), se); } finally { // 結果セットをオープンしたら必ずクローズする if (rs != null) { try { rs.close(); } catch (SQLException se) { // 外のtry-catchのExceptionを生かすためにここでは敢えて握りつぶす } } } if (count == 0) { return false; } else { return true; } } /** * データ検索SQL文を設定 * * @param selectSql * SQL文 */ public void setSelectSql(String selectSql) { this.selectSql = selectSql; } /** * * リンクマスタ作成用結果セットの生成を行う * * @param gyomuDate 業務日付 */ public void openMstData(String gyomuDate) { Object[] args = {gyomuDate,gyomuDate,gyomuDate,gyomuDate}; resultSet = executeQuery(selectSql, args); } /** * * リンクマスタ作成用結果セットの解放を行う * */ public void closeMstData() { try { if(resultSet!=null){ resultSet.close(); } } catch (SQLException sqle) { Object[] args = {}; //メッセージ:データベースアクセスで例外が発生しました。 throw new DatabaseException(MessageUtil.getMessage(Const.E_BJ_0120, args),sqle); } } /** * 結果セットからデータの取得し、リンクマスタDTOにセットする。 * * @return dto * AbstractDto */ public AbstractDto fetchMstData() { try{ if(resultSet.next()){ return mapRow(resultSet,bj_M_LINKDto); }else{ return null; } }catch (SQLException sqle){ Object[] args = {selectSql}; //メッセージ:レコードのフェッチに失敗しました。(SQL:selectShoSql) throw new DatabaseException(MessageUtil.getMessage(Const.E_BJ_0119, args),sqle); } } /** * データマッピング処理 * 結果セットのデータをリンクマスタDTOにセットする * * @param resultset ResultSet * @param dto BJ_M_LINKDto * @return dto リンクマスタDTO */ private BJ_M_LINKDto mapRow(ResultSet resultset, BJ_M_LINKDto dto){ //DTOをクリアー dto.clear(); try { // 発注地区を設定 dto.setHchiku(resultset.getString(HCHIKU)); // 店番を設定 dto.setTenban(resultset.getString(TENBAN)); // 取引先コードを設定 dto.setTriCd(resultset.getString(TRI_CD)); // 使用開始日を設定 dto.setStartDate(resultset.getString(START_DATE)); // 使用終了日を設定 dto.setEndDate(resultset.getString(END_DATE)); // 登録区分を設定 dto.setUpKbn(resultset.getString(UP_KBN)); // 店舗配信済みフラグを設定 dto.setHFlg(resultset.getString(H_FLG)); } catch (SQLException sqle) { Object[] args = {}; //メッセージ:データベースアクセスで例外が発生しました。 throw new DatabaseException(MessageUtil.getMessage(Const.E_BJ_0120, args),sqle); } return dto; } } 代码解释
最新发布
09-29
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值