<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<TITLE>XML Editer</TITLE>
<HTA:APPLICATION ID="oHTA"
APPLICATIONNAME="myApp"
BORDER="thick"
BORDERSTYLE="normal"
CAPTION="yes"
ContextMenu="yes"
ICON=""
MAXIMIZEBUTTON="yes"
MINIMIZEBUTTON="yes"
scroll="no"
selection="no"
SHOWINTASKBAR="yes"
SINGLEINSTANCE="yes"
SYSMENU="yes"
VERSION="1.0"
WINDOWSTATE="normal"
>
<style type="text/css">
</style>
</HEAD>
<script language="javascript">
// load the xml file
var xmlDoc = new ActiveXObject("Msxml2.DOMDocument");
xmlDoc.async = false;
xmlDoc.resolveExternals = false;
xmlDoc.load("rule.xml");
// load the xsl file
var xslDoc = new ActiveXObject("Msxml2.FreeThreadedDOMDocument");
xslDoc.async = false;
xslDoc.resolveExternals = false;
xslDoc.load("rule.xsl");
// create the xslt object
var xslt = new ActiveXObject("Msxml2.XSLTemplate");
xslt.stylesheet = xslDoc;
var xslProc = xslt.createProcessor();
xslProc.input = xmlDoc;
var checked_count = 0;
var cur_page = 1;
var total_page = 1;
function OutputDocument(number){
xslProc.addParameter("ename", number);
xslProc.addParameter("startno", (cur_page - 1)*10);
xslProc.addParameter("endno", cur_page*10);
xslProc.transform();
return xslProc.output;
}
function delete_node(node){
if( node.hasChildNodes() ) {
var kids = node.childNodes;
for(var i=0;i<kids.length;i++) {
delete_node(kids);
}
}
node.parentNode.removeChild(node);
}
function delete_rule(id){
var node = xmlDoc.selectSingleNode("/rules/rule[event/id="+id+"]");
delete_node(node);
}
function modify_node(node){
node.selectSingleNode("event/id").text = modify_id.value;
node.selectSingleNode("event/name").text = modify_name.value;
if( modify_state.checked ) {
node.selectSingleNode("enable").text = "true";
} else {
node.selectSingleNode("enable").text = "false";
}
}
function modify_rule(id){
var node = xmlDoc.selectSingleNode("/rules/rule[event/id="+id+"]");
modify_node(node);
}
function add_rule(){
var id = xmlDoc.createElement("id");
id.appendChild(xmlDoc.createTextNode(add_id.value));
var name = xmlDoc.createElement("name");
name.appendChild(xmlDoc.createTextNode(add_name.value));
var event = xmlDoc.createElement("event");
event.appendChild(id);
event.appendChild(name);
var enable = xmlDoc.createElement("enable");
if( add_state.checked ) {
enable.appendChild(xmlDoc.createTextNode("true"));
} else {
enable.appendChild(xmlDoc.createTextNode("false"));
}
var rule = xmlDoc.createElement("rule");
rule.appendChild(event);
rule.appendChild(enable);
var parent = xmlDoc.selectSingleNode("/rules");
if( parent.hasChildNodes() ) {
parent.insertBefore(rule, parent.firstChild);
} else {
parent.appendChild(rule);
}
}
function gotoPage(pageno){
if( pageno < 1 ) {
cur_page = 1;
} else if( pageno >= total_page ) {
cur_page = total_page;
} else {
cur_page = pageno;
}
Transform();
}
function saveXML(){
xmlDoc.save("rule.xml");
}
function protectsubmit(val){
if( val == 1 ) { //add
if( add_id.value < 10000 || add_name.value == "" ) {
window.alert("事件号必须是5位整数且事件名不能为空");
} else if( xmlDoc.selectSingleNode("/rules/rule/event/id[. = " + add_id.value + "]") ) {
window.alert("事件号" + add_id.value + "已经存在");
} else {
add_rule();
saveXML();
Transform();
}
} else if( val == 2 ) { //modify
var id = viewTable.rows[getFirstCheckedLine()].cells[2].innerText;
if( modify_id.value < 10000 || modify_name.value == "" ) {
window.alert("事件号必须是5位整数且事件名不能为空");
} else if( id != modify_id.value && xmlDoc.selectSingleNode("/rules/rule/event/id[. = " + modify_id.value + "]") ) {
window.alert("事件号" + modify_id.value + "已经存在");
} else {
if( confirm("确认修改?") ) {
modify_rule(id);
saveXML();
Transform();
}
}
} else if( val == 3 ) { //delete
if( !confirm("确认删除?") ) {
return;
}
for( var i = 1; i < viewTable.rows.length; i++ ) {
var id = viewTable.rows.cells[2].innerText;
if( eval("viewchk_" + id + ".checked") == true ) {
delete_rule(id)
}
}
saveXML();
Transform();
} else if( val == 4 ) { //select all
checked_count = viewTable.rows.length - 1;
for( var i = 1; i < viewTable.rows.length; i++ ) {
var id = viewTable.rows.cells[2].innerText;
eval("viewchk_" + id + ".checked = true");
}
changeState();
} else if( val == 5 ) { //cancel all
checked_count = 0;
for( var i = 1; i < viewTable.rows.length; i++ ) {
var id = viewTable.rows.cells[2].innerText;
eval("viewchk_" + id + ".checked = false");
}
changeState();
}
}
function getFirstCheckedLine(){
for( var i = 1; i < viewTable.rows.length; i++ ) {
var id = viewTable.rows.cells[2].innerText;
if( eval("viewchk_" + id + ".checked") == true ) {
return i;
}
}
return 0;
}
function checkOVItem(val){
if( eval("viewchk_" + val+".checked") == true ) {
checked_count++;
} else {
checked_count--;
}
changeState();
}
function changeState(){
if( checked_count ) {
delete_btn.disabled = false;
cancel_all_btn.disabled = false;
} else {
delete_btn.disabled = true;
cancel_all_btn.disabled = true;
}
if( (checked_count + 1) == viewTable.rows.length ) {
select_all_btn.disabled = true;
} else {
select_all_btn.disabled = false;
}
if( checked_count == 1 ) {
modify_btn.disabled = false;
modify_id.disabled = false;
modify_name.disabled = false;
modify_state.disabled = false;
var id = getFirstCheckedLine();
modify_id.value = viewTable.rows(id).cells(2).innerText;
modify_name.value = viewTable.rows(id).cells(3).innerText;
if( viewTable.rows(id).cells(1).innerText == "有效" ) {
modify_state.checked = true;
} else {
modify_state.checked = false;
}
} else {
modify_btn.disabled = true;
modify_id.disabled = true;
modify_name.disabled = true;
modify_state.disabled = true;
modify_id.value="请选择一条规则";
modify_name.value="请选择一条规则";
}
}
function showPageInfo(){
if( total_item.value == 0 ) {
total_page = 1;
} else {
total_page = Math.floor((9 + parseInt(total_item.value)) / 10);
}
var txt = " 共"+total_item.value+"条记录";
var prev_page = cur_page - 1;
var next_page = parseInt(cur_page) + 1;
if( cur_page > 1 ) {
txt += " <input type='button' value='<' onClick='gotoPage(" + prev_page + ")'/>"
} else {
txt += " <input type='button' value='<' onClick='gotoPage(" + prev_page + ")' disabled/>"
}
if( cur_page < total_page ) {
txt += " <input type='button' value='>' onClick='gotoPage(" + next_page + ")'/>"
} else {
txt += " <input type='button' value='>' onClick='gotoPage(" + next_page + ")' disabled/>"
}
txt += " 第<input type='text' id='page_number' size='4' maxlength='4' value='" + cur_page + "' onBlur='gotoPage(this.value)'/>页 共" + total_page + "页";
page_info.innerHTML = txt;
// window.alert(txt);
}
function Transform(){
var txt = document.getElementById("ename").value;
var str = OutputDocument(txt);
rule_list.innerHTML = str;
checked_count = 0;
showPageInfo();
changeState();
// window.alert(str);
}
</script>
<BODY onLoad="Transform()">
<table width="550" border="1" cellpadding="0" cellspacing="0" style="border-collapse:collapse;">
<tr>
<td>
<table width="100%" border="0" cellpadding="0" cellspacing="0" style="border-collapse:collapse;">
<TR height=5><td colspan=10 style="font-size:0px;"></td></TR>
<TR height=25>
<td colspan=3 align=center>事件名包含:</td>
<td colspan=3 align=center><input type="text" value="" id="ename" size="35" maxlength="16"/></td>
<td colspan=4><input type="button" value="搜索" onClick="Transform()"/></td>
</TR>
<TR height=1><td colspan=10 bgcolor=#2b7297></td></TR>
<TR height=30>
<td width=45 align=center><b>添加</b></td>
<td width=5 align=center><font color=gray>|</font></td>
<td width=50 align=center>事件号</td>
<td width=55 align=center><input type="text" name="add_id" value="" size="5" maxlength="5" onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')"></td>
<td width=55 align=center>事件名</td>
<td width=* align=center><input type="text" name="add_name" maxlength="48" value=""></td>
<td width=70 align=center>是否使用</td>
<td width=30 align=center>
<input type='checkbox' name='add_state' checked>
</td>
<td width=5 align=center><font color=gray>|</font></td>
<td width=70 align=center><input type="button" name="add_btn" value="确定" onClick="protectsubmit(1)"></td>
</TR>
<TR height=1><td colspan=10 bgcolor=#2b7297></td></TR>
<TR height=30>
<td width=45 align=center><b>修改</b></td>
<td width=5 align=center><font color=gray>|</font></td>
<td width=50 align=center>事件号</td>
<td width=55 align=center>
<input type="text" name="modify_id" value="<请选择一条规则>" size="5" maxlength="5" onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')" disabled></td>
<td width=55 align=center>事件名</td>
<td width=* align=center>
<input type="text" name="modify_name" maxlength="48" value="<请选择一条规则>" disabled></td>
<td width=70 align=center>是否使用</td>
<td width=30 align=center>
<input type='checkbox' name='modify_state' disabled>
</td>
<td width=5 align=center><font color=gray>|</font></td>
<td width=70 align=center><input type="button" name="modify_btn" value="确定" onClick="protectsubmit(2)"></td>
</TR>
<TR height=1><td colspan=10 bgcolor=#2b7297></td></TR>
<TR height=30>
<td colspan=5 align=left class=tablefont></td>
<td align=right><input type="button" name="select_all_btn" value="全部选择" onClick="protectsubmit(4)"></td>
<td colspan=2 align=right><input type="button" name="cancel_all_btn" value="全部不选" onClick="protectsubmit(5)" disabled></td>
<td align=center></td>
<td align=center><input type="button" name="delete_btn" value="删除" onClick="protectsubmit(3)" disabled></td>
</TR>
<TR height=30><td colspan=4>规则列表</td><TD colspan=6 align=right><div id="page_info" name="page_info"/></TR>
<TR>
<TD colspan=10><div id="rule_list" name="rule_list"/></TD>
</TR>
<TR height=5><td colspan=10></td></TR>
</table>
</td>
</tr>
<tr>
</tr>
</table>
</BODY>
</HTML>
rule.xml
============
<?xml version="1.0" encoding="GB2312"?>
<?xml:stylesheet type="text/xsl" href="rule.xsl"?>
<rules>
<rule>
<event>
<id>10001</id>
<name>TFTP下载文件</name>
</event>
<enable>false</enable>
</rule>
<rule>
<event>
<id>10002</id>
<name>TFTP上传文件</name>
</event>
<enable>false</enable>
</rule>
<rule>
<event>
<id>10003</id>
<name>telnet登录成功</name>
</event>
<enable>false</enable>
</rule>
</rules>
rule.xsl
=============
<?xml version="1.0" encoding="GB2312"?>
<xsl:stylesheet version="1.0" xmlns:xsl="
http://www.w3.org/1999/XSL/Transform">
<xsl:strip-space elements="*"/>
<xsl:output method= "html"/>
<xsl:param name="ename">undefined</xsl:param>
<xsl:param name="startno">undefined</xsl:param>
<xsl:param name="endno">undefined</xsl:param>
<xsl:template match="/">
<html>
<body>
<xsl:apply-templates select="rules"/>
</body>
</html>
</xsl:template>
<xsl:template match="rules">
<input type="hidden" name="total_item">
<xsl:attribute name="value"><xsl:value-of select="count(rule[contains(event/name, $ename)])"/></xsl:attribute>
</input>
<TABLE id="viewTable" name="viewTable" width="100%" border="1" bordercolor="#85979f" cellSpacing="0" cellPadding="0" style="border-collapse:collapse;">
<tr height="25">
<TD width="10%" align="center">选择</TD>
<TD width="10%" align="center">状态</TD>
<TD width="10%" align="center">事件号</TD>
<TD width="*" align="center">事件名</TD>
</tr>
<xsl:for-each select='rule[contains(event/name, $ename)]'>
<xsl:sort select="event/id"/>
<xsl:if test="position()> $startno and position()<= $endno">
<tr>
<td align="center">
<input type='checkbox'>
<xsl:attribute name="name">viewchk_<xsl:value-of select="event/id"/></xsl:attribute>
<xsl:attribute name="value"><xsl:value-of select="event/id"/></xsl:attribute>
<xsl:attribute name="onClick">checkOVItem(<xsl:value-of select="event/id"/>)</xsl:attribute>
</input>
</td>
<xsl:choose>
<xsl:when test="enable[. = 'true']">
<td align="center">有效</td>
</xsl:when>
<xsl:otherwise>
<td align="center">禁用</td>
</xsl:otherwise>
</xsl:choose>
<td align="center"><xsl:value-of select="event/id"/></td>
<td><xsl:value-of select="event/name"/></td>
</tr>
</xsl:if>
</xsl:for-each>
</TABLE>
</xsl:template>
</xsl:stylesheet>
|