通过XML入库操作 EsbmMessageProcessor 04

// 通过XPath解析出Value
xPath = doc.createXPath(xpathStr);
if (namespaceMap != null && namespaceMap.size() > 0)
{
xPath.setNamespaceURIs(namespaceMap);
}
node = xPath.selectSingleNode(doc);
if (node != null)
{
if (node instanceof DefaultText
|| node instanceof DefaultAttribute)
{
value = node.getText();
}
else
{
value = node.asXML();
}
}
else
{
value = "";
}
}
if (logger.isDebugEnabled())
{
logger.debug("The field of DataBase mapping to properties key is:"
+ entry.getKey() + " and value is:" + value);
}
propertiesValue.put((String) entry.getKey(), value);
}
return propertiesValue;
}

/**
* @function:
* @param propertiesValue
* @param prefixMap
*
*/
public static void addPrefix(Map<String, String> propertiesValue,
Map<Object, Object> prefixMap)
{
Iterator<Map.Entry<Object, Object>> iterator = prefixMap.entrySet()
.iterator();
String str = null;
String prefix = null;
Map.Entry<Object, Object> entry = null;
while (iterator.hasNext())
{
entry = iterator.next();
prefix = (String) entry.getKey();
if (prefix == null || "".equals(prefix))
{
continue;
}
str = propertiesValue.get(prefix);
str = str == null ? "" : str;
propertiesValue.remove(prefix);
propertiesValue.put(prefix, entry.getValue() + str);
}
}

/**
* 原始数据数据加密
*
* @param doc 不能为空,由调用者保证
* @param namespaceMap 不能为空,由调用者保证
* @param encryptMap 可以为空
*/

public static void encryptDoc(Document doc,
Map<Object, Object> namespaceMap, Map<Object, Object> encryptMap)
{
XPath xPath = null;
Node node = null;
Iterator<Map.Entry<Object, Object>> iterator = encryptMap.entrySet()
.iterator();
Map.Entry<Object, Object> entry = null;
while (iterator.hasNext())
{
entry = iterator.next();
if (entry.getValue() != null
&& !"".equals((String) entry.getValue()))
{
xPath = doc.createXPath((String) entry.getValue());
// 如果有命名空间,需要将命名加入,否将取不到数据
if (namespaceMap != null && namespaceMap.size() > 0)
{
xPath.setNamespaceURIs(namespaceMap);
}
// 取到要处理的节点
node = xPath.selectSingleNode(doc);
node.setText(EncryptUtil.encrypt(node.getText(),
Tools.getENCRYPT_ALGO()));
}
}
}

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值