String和告警规则比较 RuleTools 03

private static boolean delete(String path)
{
boolean result=false;
if(path!=null && "".equals(path))
{
File file=new File(path);
result=file.delete();
}
return result;
}

private static void saveXmlDocument(String path, Document doc)
{
XMLWriter writer=null;
try
{
writer = new XMLWriter(new FileWriter(new File(path)));
writer.write(doc);
}
catch (IOException e)
{
logger.error("Can't save file, path:" + path + ", context is:"
+ doc.asXML());
}
finally
{
if (writer != null)
{
try
{
writer.close();
}
catch (IOException e)
{
logger.error("Can't close file, path:" + path
+ ", context is:" + doc.asXML());
}
}
}
}

private static Document getXmlDocument(String path)
{
Document doc = null;
SAXReader reader = new SAXReader();
File file = null;
try
{
file = new File(path);
doc = reader.read(file);
}
catch (Exception e)
{
logger.error("Can't open file, path:" + path);
}
return doc;
}

/**
* 将content转换成List<Rule>的对象,For example:RetCode in
* (1489999,168888);FromSystem = ECARE 2012-1-9,Xgw123485
*/
public static List<Rule> parseRule(String content)
{
logger.debug("parseRule content :" + content);
List<Rule> ruleList = new ArrayList<Rule>();
// 分割";"
String[] condition = content.split("\\;");
String[] ruleValue = null;
Rule rule = null;
Locale locale = Locale.getDefault();
for (String str : condition)
{
// 分割"空格 " ,for example:RetCode in (1489999,168888), 在数据第一个值的key,
// 第二个是符号,第三个是比较的值

if (!"".equals(str.trim()))
{
rule = new Rule();
// not in
if (str.indexOf(NOTINCLUDE) != -1)
{
ruleValue = str.split(NOTINCLUDE);
rule.setKey(ruleValue[0].trim().toLowerCase(locale));
rule.setSign(NOTINCLUDE);
rule.setStandValue(ruleValue[1].trim());
rule.formatList();
}
else
{
ruleValue = str.trim().split("\\ ");
if (ruleValue.length == 3)
{
rule.setKey(ruleValue[0].trim().toLowerCase(locale));
rule.setSign(ruleValue[1]);
rule.setStandValue(ruleValue[2].trim());
if (ruleValue[1].equals(INCLUDE))
{
rule.formatList();
}
}
}
ruleList.add(rule);
}
}
logger.debug("The size of Rule list :" + ruleList.size());
return ruleList;
}

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值