<%@ page import="java.io.*, java.util.*"%>
<%@ page language="java" contentType="text/html;charset=utf-8"%>
<%@ page import="com.eactive.eai.common.EAITable"%>
<%@ page import="com.eactive.eai.common.message.EAIMessage"%>
<%@ page import="com.eactive.eai.common.message.ServiceMessage"%>
<%@ page import="com.eactive.eai.common.message.EAIMessageManager"%>
<%@ page import="java.util.HashMap"%>

<%!
	/**
	* <pre>
	* 문자열을 받아서 널이면 제로스트링을, 아니면 트림된 문자열을 리턴.
	* </pre>
	* @param	String		변환 대상
	* @return	'String'
	*/
	public static String checkNull( String str ) {

		String sResult = new String();
		if ( str == null ) {
			sResult = "";
		}
		else {
			sResult = str.trim();
		}
		return sResult;
	}
%>
<%
    
    String  action      = request.getParameter("actionType");
    String  seq         = request.getParameter("actionSeq");
    String  eAISvcCd 	= checkNull(request.getParameter("id"));
    
    EAIMessageManager manager = EAIMessageManager.getInstance();    
    String[] eaiSvcCds = manager.getAllEAISvcCd();

    String selectedSvcCds = request.getParameter("svcCds");
    if(selectedSvcCds == null && eaiSvcCds.length>=1) {
        selectedSvcCds  = eaiSvcCds[0];
    }
    if(eAISvcCd.length() > 0)
        selectedSvcCds = eAISvcCd;
   
    EAIMessage eAIMsg   = new EAIMessage();
    List<ServiceMessage> svcMsg = new ArrayList();

    
    if(selectedSvcCds!=null) {
        System.out.println("selectedSvcCds : "+ selectedSvcCds);
        eAIMsg = manager.getEAIMessage(selectedSvcCds);   
        svcMsg = eAIMsg.getSvcMsgs();     
    }
    
%>


<html>
    <head>
        <title>
            EAI RefMessageIds Manager
        </title>
         <script>
        function doAction() {
            document.frm.submit();
        }
        
        </script>
    </head>
    <body>
        <p style="font-size:12pt;">
        <b>EAI RefMessageIDs Configuration</b> <br><br>
        </p>
        <form name="frm" action="">
        <input type="hidden" name="actionType" value="">
        <input type="hidden" name="actionSeq" value="">
        <table width="800" border=0 bgcolor='black' cellpadding="1" cellspacing="1">
        <!-- 
        <tr bgcolor='white'>
            <td align='right' width='180' bgcolor="#ccccff"><label value="EAI Service Message ID : "/>&nbsp;</td>
            <td align='left'>&nbsp;<select name="svcCds" onchange="doAction();">
            <%
                for(int i=0;i<eaiSvcCds.length;i++) {
            %>
                <option value="<%=eaiSvcCds[i]%>" <%= (eaiSvcCds[i].equals(selectedSvcCds)) ? "selected" : "" %>><%=eaiSvcCds[i]%>
            <%           
                }
            %></select>
            </td>
        </tr>
         -->
        <tr bgcolor='white'>
            <td align='right' width='350' bgcolor="#ccccff">EAI 서비스코드</td>
            <td align='left'>&nbsp;&nbsp;<input type="text" name="selectedKey" value="<%=selectedSvcCds%>" />
            </td>
        </tr>
        </table><br>
        <table width="800" border=0 bgcolor='black' cellpadding="1" cellspacing="1">
        <tr bgcolor='white'>
            <td align='right' colspan='2' width='350' bgcolor="#003366">&nbsp; <font color="yellow"><b>내용</b> &nbsp;</font></td>
            
        </tr>
<%
    if(svcMsg != null) {
        int size = svcMsg.size();
        for(int i=0; i<size; i++) {
            ServiceMessage sm =  (ServiceMessage)svcMsg.get(i);  
            String[] refmsgid = sm.getRefMsgIDs();
%>
        <tr bgcolor='white'>
        <td  align='right' colspan="2">
        
        </td>

        </tr>
        <tr bgcolor='white'>
            <td align='right' colspan='2' width="350" height="5" bgcolor="#003366" colspan="2">&nbsp;<font color="yellow"><b>SvcPssSeq[<%= i+1 %>]</b> &nbsp;</font></td>
        </tr>
         

<%
    if(refmsgid != null && refmsgid.length >0){
        for(int j=0; j<refmsgid.length; j++){
            int idseq = j+1;
%>
        <tr bgcolor='white'>
            <td align='right' width='350' bgcolor="#ccccff">&nbsp; RefMsgIDSeq : &nbsp;</td>
            <td align='left'>&nbsp;<input type="text" name="refMsgIDSeq" size='60' value="<%=idseq%>"></td>
        </tr>
        <tr bgcolor='white'>
            <td align='right' width='350' bgcolor="#ccccff">&nbsp; RefMsgID : &nbsp;</td>
            <td align='left'>&nbsp;<input type="text" name="refMsgIDSeq" size='60' value="<%=refmsgid[j]%>"></td>
        </tr>
<%
        }
    }
  } 
} 
   
%>    
        </table>
        </form>
    </body>
</html>