// 通过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()));
}
}
}
}
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()));
}
}
}
}