<%@ page import="java.io.*, java.util.*"%>
<%@ page language="java" contentType="text/html;charset=utf-8"%>
<%@ page import="com.eactive.eai.agent.AgentUtil"%>
<%@ page import="com.eactive.eai.agent.command.Command"%>
<%@ page import="com.eactive.eai.common.EAITable"%>
<%@ page import="com.eactive.eai.common.stdmessage.*"%>
<%@ page import="com.eactive.eai.common.server.EAIServerManager"%>
<%@ page import="java.util.HashMap"%>
<%@ page import="com.eactive.eai.message.StandardMessage"%>
<%!
	/**
	* <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;
	}
%>
<%
	STDMessageManager manager = STDMessageManager.getInstance(); 
    String[]         alls    = manager.getAllSTDMessageKeys();
    String           action  = request.getParameter("actionType");

    String selectedKey = request.getParameter("selectedKey");
    if(selectedKey == null && alls.length>=1) {
    	selectedKey  = alls[0];
    }
    if ("reload".equals(action)){
    	manager.reload(selectedKey);
    }else if ("reloadAll".equals(action)){
    	manager.reload();
    }else {
    	;
    }
    StandardMessage vo    = null;
    
    if(selectedKey != null) {
        vo = manager.getSTDMessage(selectedKey);
    }
%>

<html>
    <head>
        <title>
            EAI STDMessage Manager
        </title>
        <script>
        function doAction() {
            document.frm.submit();
        }
        function managerReload(){ 
        	document.frm.actionType.value="reload";
        	document.frm.submit();
        	
        }
        function managerReloadAll(){
        	document.frm.actionType.value="reloadAll";
        	document.frm.submit();
        }
        function doSearch(){
        	var searchValue = document.frm.searchTxt.value;
        	document.frm.selectedKey.value = searchValue;
        	document.frm.submit();
        }
        function enterEvent(){
        	if(window.event.keyCode==13){
        		doSearch();
        	}
        }
        </script>
    </head>
    <body>
        <p style="font-size:12pt;">
        <b>EAI 내부표준 메시지 관리</b> <br><br>
        </p>
        <form name="frm" action="">
        <input type="hidden" name="actionType" value="">
        <table width="800" border=0 bgcolor='black' cellpadding="1" cellspacing="1">
	        <tr bgcolor='white'>
	            <td rowspan="2" align='right' width='350' bgcolor="#ccccff">업무 서비스 키 :&nbsp;&nbsp;</td>
	            <td align='left' >&nbsp;<select name="selectedKey" onchange="doAction();"style="width:98%" >
	            <%
	                for(int i=0;i<alls.length;i++) {
	            %>
	                <option value="<%=alls[i]%>" <%= (alls[i].equals(selectedKey)) ? "selected" : "" %>><%=alls[i]%>
	            <%           
	                }
	            %></select>
	            </td> 
	            <td width='50'><input type="button" name="reload" value="reload" onClick="managerReload()" /></td>
	            <td width='70'><input type="button" name="reloadAll" value="reloadAll" onClick="managerReloadAll()" /></td>
	        </tr>
	        <tr bgcolor='white'>
	            <td align='left' >&nbsp;<input type="edit"   name="searchTxt" onkeydown="enterEvent()" value="<%=selectedKey%>" style="width:98%"  /></td> 
	            <td colspan="2" align="center"><input type="button" name="search" value="search" onClick="doSearch()" /></td>
	        </tr> 
        </table>
        </form>
        <br>
        <table width="800" border=0 bgcolor='black' cellpadding="1" cellspacing="1">
        <tr bgcolor='white'>
            <td align='right' bgcolor="#003366">&nbsp; <font color="yellow"><b>Property Key</b> &nbsp;</font></td>
            <td align='left' bgcolor="#003366">&nbsp;<font color="yellow">&nbsp; <b>Property Value</b></font></td>
        </tr>
<%
    if(vo != null) {
%>
 
         <tr bgcolor='white'>                                                                                                                                                              
            <td align='right' width='350' bgcolor="#ccccff">&nbsp; XML : &nbsp;&nbsp;</td>                                                                                                 
            <td align='left' style="height:40px;"><%=vo.toPrettyJson(false)%></td>                                                                         
        </tr>
<% 
    } 
%>
        </table>
    </body>
</html>