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;
}
}
{
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;
}
}