/*********************************************************************
* All Rights reserved,Copyright (c) K-Opticom
**********************************************************************
*＜プログラム内容＞
*   システム名      ：eo顧客基幹システム
*   モジュール名    ：JZMChangeKana
*   ソースファイル名：JZMChangeKana.java
*   作成者          ：富士通
*   日付            ：2012年03月09日
*＜機能概要＞
*   Viewロジック部品です。
*＜修正履歴＞
*   バージョン  修正日       修正者      修正内容
*   v1.00.00    2012/03/09   FJ          新規作成
*  v16.00.00    2016/02/02   FJ) 真崎    【IT1-2015-0000090】対応
*
**********************************************************************/
package com.fujitsu.futurity.bp.custom.common;

import java.util.HashMap;

/**
 * フリガナ編集部品
 * @author FJ
 */
public class JKKChangeKana
{
	/** 変換テーブル */
	private static final HashMap<String, String[]> KANA_TABLE = new HashMap<String, String[]>();
	
	/** ドット（パスワード関連フリガナ用）半角 */
	private static final String HAN_DOT = "･";
	
	/** ドット　全角 */
	private static final String ZEN_DOT = "・";
	static
	{
		KANA_TABLE.put("0", new String[] {"ｾﾞﾛ", "ゼロ"});
		KANA_TABLE.put("1", new String[] {"ｲﾁ", "イチ"});
		KANA_TABLE.put("2", new String[] {"ﾆ", "ニ"});
		KANA_TABLE.put("3", new String[] {"ｻﾝ", "サン"});
		KANA_TABLE.put("4", new String[] {"ﾖﾝ", "ヨン"});
		KANA_TABLE.put("5", new String[] {"ｺﾞ", "ゴ"});
		KANA_TABLE.put("6", new String[] {"ﾛｸ", "ロク"});
		KANA_TABLE.put("7", new String[] {"ﾅﾅ", "ナナ"});
		KANA_TABLE.put("8", new String[] {"ﾊﾁ", "ハチ"});
		KANA_TABLE.put("9", new String[] {"ｷｭｳ", "キュウ"});
		KANA_TABLE.put("A", new String[] {"ｴｰ", "エー"});
		KANA_TABLE.put("B", new String[] {"ﾋﾞｰ", "ビー"});
		KANA_TABLE.put("C", new String[] {"ｼｰ", "シー"});
		KANA_TABLE.put("D", new String[] {"ﾃﾞｨｰ", "ディー"});
		KANA_TABLE.put("E", new String[] {"ｲｰ", "イー"});
		KANA_TABLE.put("F", new String[] {"ｴﾌ", "エフ"});
		KANA_TABLE.put("G", new String[] {"ｼﾞｰ", "ジー"});
		KANA_TABLE.put("H", new String[] {"ｴｲﾁ", "エイチ"});
		KANA_TABLE.put("I", new String[] {"ｱｲ", "アイ"});
		KANA_TABLE.put("J", new String[] {"ｼﾞｪｲ", "ジェイ"});
		KANA_TABLE.put("K", new String[] {"ｹｲ", "ケイ"});
		KANA_TABLE.put("L", new String[] {"ｴﾙ", "エル"});
		KANA_TABLE.put("M", new String[] {"ｴﾑ", "エム"});
		KANA_TABLE.put("N", new String[] {"ｴﾇ", "エヌ"});
		KANA_TABLE.put("O", new String[] {"ｵｰ", "オー"});
		KANA_TABLE.put("P", new String[] {"ﾋﾟｰ", "ピー"});
		KANA_TABLE.put("Q", new String[] {"ｷｭｰ", "キュー"});
		KANA_TABLE.put("R", new String[] {"ｱｰﾙ", "アール"});
		KANA_TABLE.put("S", new String[] {"ｴｽ", "エス"});
		KANA_TABLE.put("T", new String[] {"ﾃｨｰ", "ティー"});
		KANA_TABLE.put("U", new String[] {"ﾕｰ", "ユー"});
		KANA_TABLE.put("V", new String[] {"ﾌﾞｲ", "ブイ"});
		KANA_TABLE.put("W", new String[] {"ﾀﾞﾌﾞﾙ", "ダブル"});
		KANA_TABLE.put("X", new String[] {"ｴｯｸｽ", "エックス"});
		KANA_TABLE.put("Y", new String[] {"ﾜｲ", "ワイ"});
		KANA_TABLE.put("Z", new String[] {"ｾﾞｯﾄ", "ゼット"});
		KANA_TABLE.put("a", new String[] {"ｴｰ", "エー"});
		KANA_TABLE.put("b", new String[] {"ﾋﾞｰ", "ビー"});
		KANA_TABLE.put("c", new String[] {"ｼｰ", "シー"});
		KANA_TABLE.put("d", new String[] {"ﾃﾞｨｰ", "ディー"});
		KANA_TABLE.put("e", new String[] {"ｲｰ", "イー"});
		KANA_TABLE.put("f", new String[] {"ｴﾌ", "エフ"});
		KANA_TABLE.put("g", new String[] {"ｼﾞｰ", "ジー"});
		KANA_TABLE.put("h", new String[] {"ｴｲﾁ", "エイチ"});
		KANA_TABLE.put("i", new String[] {"ｱｲ", "アイ"});
		KANA_TABLE.put("j", new String[] {"ｼﾞｪｲ", "ジェイ"});
		KANA_TABLE.put("k", new String[] {"ｹｲ", "ケイ"});
		KANA_TABLE.put("l", new String[] {"ｴﾙ", "エル"});
		KANA_TABLE.put("m", new String[] {"ｴﾑ", "エム"});
		KANA_TABLE.put("n", new String[] {"ｴﾇ", "エヌ"});
		KANA_TABLE.put("o", new String[] {"ｵｰ", "オー"});
		KANA_TABLE.put("p", new String[] {"ﾋﾟｰ", "ピー"});
		KANA_TABLE.put("q", new String[] {"ｷｭｰ", "キュー"});
		KANA_TABLE.put("r", new String[] {"ｱｰﾙ", "アール"});
		KANA_TABLE.put("s", new String[] {"ｴｽ", "エス"});
		KANA_TABLE.put("t", new String[] {"ﾃｨｰ", "ティー"});
		KANA_TABLE.put("u", new String[] {"ﾕｰ", "ユー"});
		KANA_TABLE.put("v", new String[] {"ﾌﾞｲ", "ブイ"});
		KANA_TABLE.put("w", new String[] {"ﾀﾞﾌﾞﾙ", "ダブル"});
		KANA_TABLE.put("x", new String[] {"ｴｯｸｽ", "エックス"});
		KANA_TABLE.put("y", new String[] {"ﾜｲ", "ワイ"});
		KANA_TABLE.put("z", new String[] {"ｾﾞｯﾄ", "ゼット"});
// ▼▼ IT1-2015-0000090 2016/02/02 MOD START ▼▼
//		KANA_TABLE.put("!", new String[] {" ", "　"});
//		KANA_TABLE.put("#", new String[] {" ", "　"});
//		KANA_TABLE.put("$", new String[] {" ", "　"});
		KANA_TABLE.put("!", new String[] {"ｴｸｽｸﾗﾒｰｼｮﾝﾏｰｸ", "エクスクラメーションマーク"});
		KANA_TABLE.put("#", new String[] {"ｼｬｰﾌﾟ", "シャープ"});
		KANA_TABLE.put("$", new String[] {"ﾄﾞﾙ", "ドル"});
// ▲▲ IT1-2015-0000090 2016/02/02 MOD END   ▲▲
		KANA_TABLE.put("%", new String[] {"ﾊﾟｰｾﾝﾄ", "パーセント"});
// ▼▼ IT1-2015-0000090 2016/02/02 MOD START ▼▼
//		KANA_TABLE.put("&", new String[] {" ", "　"});
//		KANA_TABLE.put("\\", new String[] {" ", "　"});
		KANA_TABLE.put("&", new String[] {"ｱﾝﾄﾞ", "アンド"});
		KANA_TABLE.put("\\", new String[] {"ｴﾝ", "エン"});
// ▲▲ IT1-2015-0000090 2016/02/02 MOD END   ▲▲
		KANA_TABLE.put("@", new String[] {"ｱｯﾄﾏｰｸ", "アットマーク"});
		KANA_TABLE.put("+", new String[] {"ﾌﾟﾗｽ", "プラス"});
// ▼▼ IT1-2015-0000090 2016/02/02 MOD START ▼▼
//		KANA_TABLE.put("-", new String[] {"ﾊｲﾌﾝ", "ハイフン"});
//		KANA_TABLE.put("*", new String[] {" ", "　"});
		KANA_TABLE.put("-", new String[] {"ﾏｲﾅｽ", "マイナス"});
		KANA_TABLE.put("*", new String[] {"ｱｽﾀﾘｽｸ", "アスタリスク"});
// ▲▲ IT1-2015-0000090 2016/02/02 MOD END   ▲▲
		KANA_TABLE.put("/", new String[] {"ｽﾗｯｼｭ", "スラッシュ"});
		KANA_TABLE.put("_", new String[] {"ｱﾝﾀﾞｰﾊﾞｰ", "アンダーバー"});
		KANA_TABLE.put(".", new String[] {"ﾋﾟﾘｵﾄﾞ", "ピリオド"});
// ▼▼ IT1-2015-0000090 2016/02/02 MOD START ▼▼
//		KANA_TABLE.put(":", new String[] {"ｺﾛﾝ", "コロン"});
//		KANA_TABLE.put("=", new String[] {"ｲｺｰﾙ", "イコール"});
//		KANA_TABLE.put("^", new String[] {"ｷｬﾚｯﾄ", "キャレット"});
		KANA_TABLE.put(":", new String[] {" ", "　"});
		KANA_TABLE.put("=", new String[] {" ", "　"});
		KANA_TABLE.put("^", new String[] {" ", "　"});
// ▲▲ IT1-2015-0000090 2016/02/02 MOD END   ▲▲
	}
	
	/**
	 * 指定された文字列（半角英数字）のフリガナを返します。<BR>
	 * chg_flgでtrueが指定された場合、半角カナをfalseが指定された場合、全角カナを返します。<BR>
	 * @param editing_str 変換対象となる文字列
	 * @param chg_flg true:半角カナを返します。 false:全角カナを返します。
	 * @param addDot true:文字間にドット（･）を設定する
	 * @return フリガナを返します。
	 */
	public static String changeKana(String editing_str, boolean chg_flg, boolean addDot)
	{
		//(1) パラメータチェック処理
		//  ・変換対象となる文字列がnullの場合
		if(editing_str == null)
		{
			return null;
		}
		//  ・変換対象となる文字列が空文字("")の場合
		if("".equals(editing_str))
		{
			return null;
		}
		//(2) フリガナ変換処理
		StringBuilder retValue = new StringBuilder();
		//   (a) 変換対象となる文字列の桁数を取得する。
		int lenEditingStr = editing_str.length();
		int index = chg_flg ? 0:1;
		//   (b) 以下の処理を(a)で取得した桁数分繰り返す。
		for(int iCnt = 0; iCnt < lenEditingStr; iCnt++)
		{
			//@ 変換対象となる文字列から1文字取り出し、上記の表に一致するフリガナを取得する。
			//  （変換フラグを参照し、半角のフリガナを取得するか全角のフリガナを取得するか判定する）
			String key = editing_str.substring(iCnt, iCnt + 1);
			if(KANA_TABLE.containsKey(key))
			{
				//A 取得したフリガナを返却用文字列に追加する。
				String[] value = KANA_TABLE.get(key);
				retValue.append(value[index]);
				
				// ドット追加がTRUE かつ 最終文字でなければドットを追加する
				if (addDot && lenEditingStr -1 != iCnt)
				{
					retValue.append(HAN_DOT);
				}
				
			}
			else
			{
				return null;
			}
		}
		
		return retValue.toString();
	}
}
