XML工具 Tools 02

/**
* @功能说明:将传入的字符串转换成 dom4j Document
* @param message 需要转化的字符串,不能为空
* @return org.dom4j.Document
*/
public static org.dom4j.Document string2Dom4J(String message)
{
SAXReader reader = new SAXReader();
org.dom4j.Document documentDOM4J = null;
try
{
documentDOM4J = reader.read(new ByteArrayInputStream(message
.getBytes()));
}
catch (Exception e)
{
logger.error("Parse message error:" + message, e);
}
return documentDOM4J;
}

/**
* @功能说明:将传入的DOM 的 Document转换成字符串
* @param Document 不能为空
* @return message
*/
public static String document2String(Document doc)
{
TransformerFactory tff = TransformerFactory.newInstance();
String xmlStr = null;
try
{
Transformer tf = tff.newTransformer();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
tf.transform(new DOMSource(doc), new StreamResult(bos));
xmlStr = bos.toString();
}
catch (Exception e)
{
logger.debug("Fail document2String:", e);
}
return xmlStr;
}

/**
* 将DOM的Node 转换成 String 2012-1-4,Xgw123485
*/
public static String nodeToString(Node node)
{
StringWriter sw = new StringWriter();
try
{
Transformer t = TransformerFactory.newInstance().newTransformer();
t.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
t.setOutputProperty(OutputKeys.INDENT, "yes");
t.transform(new DOMSource(node), new StreamResult(sw));
}
catch (Exception e)
{
logger.error("nodeToString Transformer Exception");
}
return sw.toString();
}

/**
*
* @Function: 将esb消息中的数据,根据CLE的表和字段生成表和字段的对象数组
* @param propertiesValue, 配置的field和value esbmTablefield, CLE 所有的表
* @param esbmTablefield CLE的日志表对象
* @date 下午06:56:25
*
*/
public static TableName_Field[] sqList(Map<String, String> propertiesValue,
Map<String, List<EsbTableField>> esbmTablefield)
{
Iterator<Entry<String, List<EsbTableField>>> iterator = esbmTablefield
.entrySet().iterator();
TableName_Field[] temp_tableName_Fields = new TableName_Field[esbmTablefield
.size()];
TableName_Field tableName_Field = null;
Map.Entry<String, List<EsbTableField>> entry = null;
// 实际的对像长度
int index = 0;
while (iterator.hasNext())
{
entry = iterator.next();
// 将表的字段对应的字段值,写入到tableName_Field中
tableName_Field = setFieldValueMapping(entry, propertiesValue);
if (tableName_Field != null)
{
temp_tableName_Fields[index++] = tableName_Field;
}
}
TableName_Field[] tableName_Fields = null;
// temp_tableName_Fields的大小等于初始化,不要重新拷贝
if (index == esbmTablefield.size())
{
tableName_Fields = temp_tableName_Fields;
}
else
{
tableName_Fields = new TableName_Field[index];
System.arraycopy(temp_tableName_Fields, 0, tableName_Fields, 0,
index);
}
return tableName_Fields;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值