String和告警规则比较 RuleTools 02

public static String freshXML(String ruleStr)
{
Document rule_from = Tools.string2Dom4J(ruleStr);
String resultfreshXML = "0,SyncRule successful.";
String user = rule_from.selectSingleNode(
"//SyncRulesRequest/RequestHeader/User").getText();
String password = rule_from.selectSingleNode(
"//SyncRulesRequest/RequestHeader/Password").getText();

String authorization = FileManager.getProperty("init.properties",
"AUTHORIZATION");
if (authorization.equals("1"))
{
if ((!user.equals(FileManager.getProperty("init.properties",
"USERNAME")))
|| (!password.equals(FileManager.getProperty(
"init.properties", "PASSWORD"))))
{
resultfreshXML = "1,The Username or password is error.";
return resultfreshXML;
}
}

FileListener rulefile = FileManager.getFileListener(RULE_FILE_NAME_XML);
Document rule_destination = getXmlDocument(rulefile.getPath());
Node action = rule_from
.selectSingleNode("//SyncRulesRequest/RuleContents/@Action");
List<?> ruleContent_from = rule_from
.selectNodes("//SyncRulesRequest/RuleContents/Rule");
Element ruleContents_dest = rule_destination.getRootElement().element(
"RuleContents");

String action_value = action.getText();
Node node = null;
Iterator<?> iterator = ruleContent_from.iterator();
String ruleid = null;
String ruleContent = null;
if (action_value.equals("Add"))
{
while (iterator.hasNext())
{
node = (Node) iterator.next();
ruleid = node.selectSingleNode("@RuleId").getText();
if (checkRuleMap(ruleid))
{
resultfreshXML = "2,This rule_id:" + ruleid
+ " was exist so can not add the Rule .";
break;
}
ruleContent = node.selectSingleNode("@RuleContent").getText();
Element element = ruleContents_dest.addElement("Rule");
element.addAttribute("RuleId", ruleid);
element.addAttribute("RuleContent", ruleContent);
ruleMap.put(ruleid, parseRule(ruleContent));
}
}
else if (action_value.equals("Del"))
{
while (iterator.hasNext())
{
node = (Node) iterator.next();
ruleid = node.selectSingleNode("@RuleId").getText();
if (checkRuleMap(ruleid))
{
resultfreshXML = "3,This rule_id:"
+ ruleid
+ " was not exist so can not stick up for the Rule.";
break;
}
// 删除节点
node = ruleContents_dest.selectSingleNode("Rule[@RuleId='"
+ ruleid + "']");
ruleContents_dest.remove(node);
ruleMap.remove(ruleid);
}
}
else if (action_value.equals("Mod"))
{
while (iterator.hasNext())
{
node = (Node) iterator.next();
ruleid = node.selectSingleNode("@RuleId").getText();
if (checkRuleMap(ruleid))
{
resultfreshXML = "3,This rule_id:"
+ ruleid
+ " was not exist so can not stick up for the Rule.";
break;
}
ruleContent = node.selectSingleNode("@RuleContent").getText();
node = ruleContents_dest.selectSingleNode("Rule[@RuleId='"
+ ruleid + "']");
node = node.selectSingleNode("@RuleContent");
node.setText(ruleContent);
ruleMap.remove(ruleid);
ruleMap.put(ruleid, parseRule(ruleContent));
}
}
delete(rulefile.getPath());
saveXmlDocument(rulefile.getPath(), rule_destination);
logger.info("resultfreshXML result:"+resultfreshXML);
return resultfreshXML;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值