/*********************************************************************************************************
 * 프로그램명 : MItemInfo.java 프로그램설명 : 집계문서의 표의 각각의 셀에 대한 정보 처리 작성자 : 강원중 작성일 : 2003.12.10 변경일 : 2004.09.16
 **********************************************************************************************************/

package kr.co.kihyun.moumi.doc.table.item;

import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

import kr.co.kihyun.beans.entity.TotDoc;
import kr.co.kihyun.beans.entity.TotItem;
import kr.co.kihyun.beans.entity.TotItemType;
import kr.co.kihyun.beans.tosys.etc1.TotsysEtc;
import kr.co.kihyun.moumi.MoumiConfig;
import kr.co.kihyun.lang.MInteger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class MItemInfo {
        
        private static final Logger LOG = LoggerFactory.getLogger(MItemInfo.class);
                
	private int[] itemNumList = null;
	private String[] itemNameList = null;
	private String[] itemExprList = null;
	private int[] itemSizeList = null;
	private String[] itemDescList = null;
	private String[] tmpTypeList = null;
	private int[] itemTypeList = null;
	private int[] tableNumList = null;
	private int[] rowNumList = null;
	private int[] colNumList = null;

	public void itemInfo(String itemNames, String itemSizes, String itemExprs, String itemDescs, String itemTypes,
/*
		String tableNums, String colNums, String rowNums, int defItemSize) {
		StringTokenizer stkNames = new StringTokenizer(itemNames, (MItem.LIST_DELIM));
		StringTokenizer stkSizes = new StringTokenizer(itemSizes, (MItem.LIST_DELIM));
		StringTokenizer stkExprs = new StringTokenizer(itemExprs, (MItem.LIST_DELIM));
		StringTokenizer stkDesc = new StringTokenizer(itemDescs, (MItem.LIST_DELIM));
		StringTokenizer stkTypes = new StringTokenizer(itemTypes, (MItem.LIST_DELIM));
		StringTokenizer stkTableNums = new StringTokenizer(tableNums, (MItem.LIST_DELIM));
		StringTokenizer stkColNums = new StringTokenizer(colNums, (MItem.LIST_DELIM));
		StringTokenizer stkRowNums = new StringTokenizer(rowNums, (MItem.LIST_DELIM));

		int itemCount = stkNames.countTokens();
		String strTmp1 = null;
		String strTmp2 = null;
		String strTmp3 = null;
		String strTmp4 = null;
		String strTmp5 = null;
		String strTmp6 = null;
		String strTmp7 = null;
		String strTmp8 = null;
		itemNumList = new int[itemCount];
		itemNameList = new String[itemCount];
		itemExprList = new String[itemCount];
		itemSizeList = new int[itemCount];
		itemDescList = new String[itemCount];
		tmpTypeList = new String[itemCount];
		itemTypeList = new int[itemCount];
		tableNumList = new int[itemCount];
		rowNumList = new int[itemCount];
		colNumList = new int[itemCount];

		try {

            

		for (int i = 0; i < itemCount; i++) {
			strTmp1 = stkNames.nextToken();
			itemNumList[i] = MInteger.parseInt(strTmp1.substring(0, strTmp1.indexOf(":")).trim());
			itemNameList[i] = strTmp1.substring(strTmp1.indexOf(":") + 1, strTmp1.length()).trim();

			strTmp2 = stkExprs.nextToken();
			itemExprList[i] = strTmp2.substring(strTmp2.indexOf(":") + 1, strTmp2.length()).trim();

			strTmp3 = stkSizes.nextToken();
			itemSizeList[i] = MInteger.parseInt(strTmp3.substring(strTmp3.indexOf(":") + 1, strTmp3.length()).trim(),
					defItemSize);

			strTmp4 = stkDesc.nextToken();
            
            
			itemDescList[i] = strTmp4.substring(strTmp4.indexOf(":") + 1, strTmp4.length()).trim();

			strTmp5 = stkTypes.nextToken();
			tmpTypeList[i] = strTmp5.substring(strTmp5.indexOf(":") + 1, strTmp5.length()).trim();


			if (!itemDescList[i].equals("empty")) {
				itemTypeList[i] = MItem.TITLE;
			} else if (tmpTypeList[i] == null || tmpTypeList[i].equals(MoumiConfig.getMessageBundle().getString("moumi.message.tot_doc.text"))) {
				// 문자
				itemTypeList[i] = MItem.CHAR;
			} else if (tmpTypeList[i] == null || tmpTypeList[i].equals(MoumiConfig.getMessageBundle().getString("moumi.message.tot_doc.figure"))) {
				// 숫자
				itemTypeList[i] = MItem.INT;
			} else if (tmpTypeList[i] == null || tmpTypeList[i].equals(MoumiConfig.getMessageBundle().getString("moumi.message.tot_doc.date"))) {
				// 날짜

				itemTypeList[i] = MItem.DATE;

			} else if (tmpTypeList[i] == null || tmpTypeList[i].equals(MoumiConfig.getMessageBundle().getString("moumi.message.tot_doc.title2"))) {
				// 날짜
				itemTypeList[i] = MItem.TITLE;
				itemDescList[i] = "";
			}

			strTmp6 = stkTableNums.nextToken();
			tableNumList[i] = MInteger.parseInt(strTmp6.substring(strTmp6.indexOf(":") + 1, strTmp6.length()).trim());

			strTmp7 = stkRowNums.nextToken();
			rowNumList[i] = MInteger.parseInt(strTmp7.substring(strTmp7.indexOf(":") + 1, strTmp7.length()).trim());

			strTmp8 = stkColNums.nextToken();
			colNumList[i] = MInteger.parseInt(strTmp8.substring(strTmp8.indexOf(":") + 1, strTmp8.length()).trim());
		}
		} catch (StringIndexOutOfBoundsException sioobe) {
			throw new StringIndexOutOfBoundsException(strTmp1 + ", " + strTmp2 + ", " + strTmp3 + ", " + strTmp4 + ", " + strTmp5 + ", " + strTmp6 + ", " + strTmp7 + ", " + strTmp8);
		}
 */
        String tableNums, String colNums, String rowNums, int defItemSize) {
		String[] stkNames = TotsysEtc.getDeliToArr(itemNames, "!@!");
		String[] stkSizes = TotsysEtc.getDeliToArr(itemSizes, "!@!");
		String[] stkExprs = TotsysEtc.getDeliToArr(itemExprs, "!@!");
		String[] stkDesc = TotsysEtc.getDeliToArr(itemDescs, "!@!");
		String[] stkTypes = TotsysEtc.getDeliToArr(itemTypes, "!@!");
		String[] stkTableNums = TotsysEtc.getDeliToArr(tableNums, "!@!");
		String[] stkColNums = TotsysEtc.getDeliToArr(colNums, "!@!");
		String[] stkRowNums = TotsysEtc.getDeliToArr(rowNums, "!@!");

		int itemCount = stkNames.length;
		String strTmp1 = null;
		String strTmp2 = null;
		String strTmp3 = null;
		String strTmp4 = null;
		String strTmp5 = null;
		String strTmp6 = null;
		String strTmp7 = null;
		String strTmp8 = null;
		itemNumList = new int[itemCount];
		itemNameList = new String[itemCount];
		itemExprList = new String[itemCount];
		itemSizeList = new int[itemCount];
		itemDescList = new String[itemCount];
		tmpTypeList = new String[itemCount];
		itemTypeList = new int[itemCount];
		tableNumList = new int[itemCount];
		rowNumList = new int[itemCount];
		colNumList = new int[itemCount];

		try {

                    //v2 22.정수형 오버플로우_CWE-190 : Update by YOUNGJUN,CHO
                    for (int i = 0; i < itemCount; i++) {
                            strTmp1 = stkNames[i];
                            
                            if (strTmp1.length() < Integer.MAX_VALUE) {
                                itemNumList[i] = MInteger.parseInt(strTmp1.substring(0, strTmp1.indexOf(":")).trim());
                                itemNameList[i] = strTmp1.substring(strTmp1.indexOf(":") + 1, strTmp1.length()).trim();
                            } else {
                                LOG.debug("MItemInfo itemInfo() strTmp1 : 정수형 오버플로우_CWE-190");
                            }
                            
                            strTmp2 = stkExprs[i];
                            
                            if (strTmp2.length() < Integer.MAX_VALUE) {
                                itemExprList[i] = strTmp2.substring(strTmp2.indexOf(":") + 1, strTmp2.length()).trim();
                            } else {
                                LOG.debug("MItemInfo itemInfo() strTmp2 : 정수형 오버플로우_CWE-190");
                            }

                            strTmp3 = stkSizes[i];
                            
                            if (strTmp3.length() < Integer.MAX_VALUE) {
                                itemSizeList[i] = MInteger.parseInt(strTmp3.substring(strTmp3.indexOf(":") + 1, strTmp3.length()).trim(), defItemSize);
                            } else {
                                LOG.debug("MItemInfo itemInfo() strTmp3 : 정수형 오버플로우_CWE-190");
                            }
                            
                            strTmp4 = stkDesc[i];

                            if (strTmp4.length() < Integer.MAX_VALUE) {
                                itemDescList[i] = strTmp4.substring(strTmp4.indexOf(":") + 1, strTmp4.length()).trim();
                            } else {
                                LOG.debug("MItemInfo itemInfo() strTmp4 : 정수형 오버플로우_CWE-190");
                            }
                            
                            strTmp5 = stkTypes[i];
                            
                            if (strTmp5.length() < Integer.MAX_VALUE) {
                                tmpTypeList[i] = strTmp5.substring(strTmp5.indexOf(":") + 1, strTmp5.length()).trim();
                            } else {
                                LOG.debug("MItemInfo itemInfo() strTmp5 : 정수형 오버플로우_CWE-190");
                            }
                            
                            if (!itemDescList[i].equals("empty")) {
                                    itemTypeList[i] = MItem.TITLE;
                            } else if (tmpTypeList[i] == null || tmpTypeList[i].equals(MoumiConfig.getMessageBundle().getString("moumi.message.tot_doc.text"))) {
                                    // 문자
                                    itemTypeList[i] = MItem.CHAR;
                            } else if (tmpTypeList[i] == null || tmpTypeList[i].equals(MoumiConfig.getMessageBundle().getString("moumi.message.tot_doc.figure"))) {
                                    // 숫자
                                    itemTypeList[i] = MItem.INT;
                            } else if (tmpTypeList[i] == null || tmpTypeList[i].equals(MoumiConfig.getMessageBundle().getString("moumi.message.tot_doc.date"))) {
                                    // 날짜
                                    itemTypeList[i] = MItem.DATE;

                            } else if (tmpTypeList[i] == null || tmpTypeList[i].equals(MoumiConfig.getMessageBundle().getString("moumi.message.tot_doc.title2"))) {
                                    // 날짜
                                    itemTypeList[i] = MItem.TITLE;
                                    itemDescList[i] = "";
                            }

                            strTmp6 = stkTableNums[i];
                            
                            if (strTmp6.length() < Integer.MAX_VALUE) {
                                tableNumList[i] = MInteger.parseInt(strTmp6.substring(strTmp6.indexOf(":") + 1, strTmp6.length()).trim());
                            } else {
                                LOG.debug("MItemInfo itemInfo() strTmp6 : 정수형 오버플로우_CWE-190");
                            }
                            
                            strTmp7 = stkRowNums[i];
                            
                            if (strTmp7.length() < Integer.MAX_VALUE) {
                                rowNumList[i] = MInteger.parseInt(strTmp7.substring(strTmp7.indexOf(":") + 1, strTmp7.length()).trim());
                            } else {
                                LOG.debug("MItemInfo itemInfo() strTmp7 : 정수형 오버플로우_CWE-190");
                            }
                            
                            strTmp8 = stkColNums[i];
                            
                            if (strTmp8.length() < Integer.MAX_VALUE) {
                                colNumList[i] = MInteger.parseInt(strTmp8.substring(strTmp8.indexOf(":") + 1, strTmp8.length()).trim());
                            } else {
                                LOG.debug("MItemInfo itemInfo() strTmp8 : 정수형 오버플로우_CWE-190");
                            }
                            
                    }
                    //================================================
                    
		} catch (StringIndexOutOfBoundsException sioobe) {
			throw new StringIndexOutOfBoundsException(strTmp1 + ", " + strTmp2 + ", " + strTmp3 + ", " + strTmp4 + ", " + strTmp5 + ", " + strTmp6 + ", " + strTmp7 + ", " + strTmp8);
		}
	}

	public List<TotItem> toTotItemList(TotDoc totDoc) {
		List<TotItem> totItemList = new ArrayList<TotItem>();

		for (int i = 0; i < itemNumList.length; i++) {
			TotItem totItem = new TotItem(totDoc, itemNameList[i]);
			totItem.setNum((short) itemNumList[i]);
			totItem.setExpr(itemExprList[i]);
			totItem.setInputSize((short) itemSizeList[i]);
			totItem.setDescription(itemDescList[i]);
			totItem.setType(TotItemType.asTotItemType(itemTypeList[i]));

			totItem.setTableNum((short) tableNumList[i]);
			totItem.setRowNum((short) rowNumList[i]);
			totItem.setColNum((short) colNumList[i]);

			totItemList.add(totItem);
		}
		return totItemList;
	}

	public int[] getItemNumList() {
            //v2 27.Public 메소드로부터 반환된 Private배열_CWE-495 : Update by  YOUNGJUN,CHO
            //return itemNumList;
            
            int ret[] = new int[itemNumList.length];
            
            for (int i = 0 ; i < itemNumList.length ; i++) {
                ret[i] = itemNumList[i];
            }
            
            return ret;
            //====================================================================
	}

	public String[] getItemNameList() {
            //v2 27.Public 메소드로부터 반환된 Private배열_CWE-495 : Update by  YOUNGJUN,CHO
            //return itemNameList;
            
            String ret[] = new String[itemNameList.length];
            
            for (int i = 0 ; i < itemNameList.length ; i++) {
                ret[i] = itemNameList[i];
            }
            
            return ret;
            //====================================================================
	}

	public String[] getItemExprList() {
            //v2 27.Public 메소드로부터 반환된 Private배열_CWE-495 : Update by  YOUNGJUN,CHO
            //return itemExprList;
            
            String ret[] = new String[itemExprList.length];
            
            for (int i = 0 ; i < itemExprList.length ; i++) {
                ret[i] = itemExprList[i];
            }
            
            return ret;
            //====================================================================
	}

	public int[] getItemSizeList() {
            //v2 27.Public 메소드로부터 반환된 Private배열_CWE-495 : Update by  YOUNGJUN,CHO
            //return itemSizeList;
            
            int ret[] = new int[itemSizeList.length];
            
            for (int i = 0 ; i < itemSizeList.length ; i++) {
                ret[i] = itemSizeList[i];
            }
            
            return ret;
            //====================================================================
	}

	public String[] getItemDescList() {
            //v2 27.Public 메소드로부터 반환된 Private배열_CWE-495 : Update by  YOUNGJUN,CHO
            //return itemDescList;
            
            String ret[] = new String[itemDescList.length];
            
            for (int i = 0 ; i < itemDescList.length ; i++) {
                ret[i] = itemDescList[i];
            }
            
            return ret;
            //====================================================================
	}

	public String[] getTmpTypeList() {
            //v2 27.Public 메소드로부터 반환된 Private배열_CWE-495 : Update by  YOUNGJUN,CHO
            //return tmpTypeList;
            
            String ret[] = new String[tmpTypeList.length];
            
            for (int i = 0 ; i < tmpTypeList.length ; i++) {
                ret[i] = tmpTypeList[i];
            }
            
            return ret;
            //====================================================================
	}

	public int[] getItemTypeList() {
            //v2 27.Public 메소드로부터 반환된 Private배열_CWE-495 : Update by  YOUNGJUN,CHO
            //return itemTypeList;
            
            int ret[] = new int[itemTypeList.length];
            
            for (int i = 0 ; i < itemTypeList.length ; i++) {
                ret[i] = itemTypeList[i];
            }
            
            return ret;
            //====================================================================
	}

	public int[] getTableNumList() {
            //v2 27.Public 메소드로부터 반환된 Private배열_CWE-495 : Update by  YOUNGJUN,CHO	
            //return tableNumList;
            
            int ret[] = new int[tableNumList.length];
            
            for (int i = 0 ; i < tableNumList.length ; i++) {
                ret[i] = tableNumList[i];
            }
            
            return ret;
            //====================================================================
	}

	public int[] getRowNumList() {
            //v2 27.Public 메소드로부터 반환된 Private배열_CWE-495 : Update by  YOUNGJUN,CHO	
            //return rowNumList;
            
            int ret[] = new int[rowNumList.length];
            
            for (int i = 0 ; i < rowNumList.length ; i++) {
                ret[i] = rowNumList[i];
            }
            
            return ret;
            //====================================================================
	}

	public int[] getColNumList() {
            //v2 27.Public 메소드로부터 반환된 Private배열_CWE-495 : Update by  YOUNGJUN,CHO
            //return colNumList;
            
            int ret[] = new int[colNumList.length];
            
            for (int i = 0 ; i < colNumList.length ; i++) {
                ret[i] = colNumList[i];
            }
            
            return ret;
            //====================================================================
	}
}
