|
|
@ -253,116 +253,4 @@ public class XMLUtils {
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static MessageDto tryGetxpathToBean(String xmlStr, Class tClass, String source) {
|
|
|
|
|
|
|
|
MessageDto messageDto = null;
|
|
|
|
|
|
|
|
Document doc = null;
|
|
|
|
|
|
|
|
Object obj = null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
xmlStr = xmlStr.replaceAll("&", "&");
|
|
|
|
|
|
|
|
SAXReader saxReader = new SAXReader();
|
|
|
|
|
|
|
|
saxReader.setXMLFilter(new XMLFilterImpl() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void characters(char[] ch, int start, int length) throws SAXException {
|
|
|
|
|
|
|
|
String text = new String(ch, start, length);
|
|
|
|
|
|
|
|
if (length == 1) {
|
|
|
|
|
|
|
|
if ((int) ch[0] == 160) {
|
|
|
|
|
|
|
|
char[] escape = " ".toCharArray();
|
|
|
|
|
|
|
|
super.characters(escape, 0, escape.length);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
super.characters(ch, start, length);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
doc = saxReader.read(new ByteArrayInputStream(xmlStr.getBytes("UTF-8")), "UTF-8");
|
|
|
|
|
|
|
|
if (tClass != null) {
|
|
|
|
|
|
|
|
messageDto = getInstance(source);
|
|
|
|
|
|
|
|
obj = tClass.newInstance();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// 是检查报告的接口
|
|
|
|
|
|
|
|
String str = "/ns:ClinicalDocument/ns:component/ns:structuredBody/ns:component/ns:section/ns:entry/ns:observation/ns:code[@displayName='检查报告科室']/../ns:value/text()";
|
|
|
|
|
|
|
|
//-----------------------存在一个错误 如果str找不到 就会向外抛出异常org.apache.cxf.interceptor.Fault: org/jaxen/JaxenException
|
|
|
|
|
|
|
|
XPath x = doc.createXPath(str);
|
|
|
|
|
|
|
|
x.setNamespaceURIs(map);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Node node = x.selectSingleNode(doc);
|
|
|
|
|
|
|
|
if (node != null) {
|
|
|
|
|
|
|
|
messageDto = getInstance(node.getText());
|
|
|
|
|
|
|
|
if (messageDto != null) {
|
|
|
|
|
|
|
|
obj = messageDto.getObject();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (obj != null && messageDto != null) {
|
|
|
|
|
|
|
|
if (messageDto.getPropertiesPath() != null) {
|
|
|
|
|
|
|
|
// 加载配置文件
|
|
|
|
|
|
|
|
InputStream inputStream = new BufferedInputStream(new FileInputStream(new File(messageDto.getPropertiesPath())));
|
|
|
|
|
|
|
|
Properties properties = new Properties();
|
|
|
|
|
|
|
|
//加载格式化后的流
|
|
|
|
|
|
|
|
properties.load(new InputStreamReader(inputStream, DEFAULT_ENCODING));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Enumeration<?> enumeration = properties.propertyNames();
|
|
|
|
|
|
|
|
while (enumeration.hasMoreElements()) {
|
|
|
|
|
|
|
|
String key = (String) enumeration.nextElement();
|
|
|
|
|
|
|
|
String xpath = properties.getProperty(key);
|
|
|
|
|
|
|
|
XPath x = doc.createXPath(xpath);
|
|
|
|
|
|
|
|
x.setNamespaceURIs(map);
|
|
|
|
|
|
|
|
// 根据properties的value获取xml的value
|
|
|
|
|
|
|
|
String value = "";
|
|
|
|
|
|
|
|
Node node = x.selectSingleNode(doc);
|
|
|
|
|
|
|
|
if (node != null) {
|
|
|
|
|
|
|
|
value = node.getText();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddhhmmss");
|
|
|
|
|
|
|
|
// 判断属性是否存在
|
|
|
|
|
|
|
|
String objField = existsField(obj.getClass(), key);
|
|
|
|
|
|
|
|
if (objField != null) {
|
|
|
|
|
|
|
|
PropertyDescriptor descriptor = new PropertyDescriptor(key, obj.getClass());
|
|
|
|
|
|
|
|
if (("class java.util.Date").equals(objField)) {
|
|
|
|
|
|
|
|
if (value != null && value.length() > 0) {
|
|
|
|
|
|
|
|
Date parse = simpleDateFormat.parse(value, new ParsePosition(0));
|
|
|
|
|
|
|
|
descriptor.getWriteMethod().invoke(obj, parse);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
descriptor.getWriteMethod().invoke(obj, value);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
String messageField = existsField(messageDto.getClass(), key);
|
|
|
|
|
|
|
|
if (messageField != null) {
|
|
|
|
|
|
|
|
PropertyDescriptor propertyDescriptor = new PropertyDescriptor(key, messageDto.getClass());
|
|
|
|
|
|
|
|
// 给messageDto赋值
|
|
|
|
|
|
|
|
if (("class java.util.Date").equals(messageField)) {
|
|
|
|
|
|
|
|
if (value != null && value.length() > 0) {
|
|
|
|
|
|
|
|
propertyDescriptor.getWriteMethod().invoke(messageDto, simpleDateFormat.parse(value, new ParsePosition(0)));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
propertyDescriptor.getWriteMethod().invoke(messageDto, value);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// 将对象转成json
|
|
|
|
|
|
|
|
messageDto.setObject(JSON.toJSONString(obj));
|
|
|
|
|
|
|
|
return messageDto;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (DocumentException e) {
|
|
|
|
|
|
|
|
logger.error("出错咯!错误信息:" + e);
|
|
|
|
|
|
|
|
} catch (UnsupportedEncodingException e) {
|
|
|
|
|
|
|
|
logger.error("出错咯!错误信息:" + e);
|
|
|
|
|
|
|
|
} catch (FileNotFoundException e) {
|
|
|
|
|
|
|
|
logger.error("出错咯!错误信息:" + e);
|
|
|
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
|
|
|
logger.error("出错咯!错误信息:" + e);
|
|
|
|
|
|
|
|
} catch (IllegalAccessException e) {
|
|
|
|
|
|
|
|
logger.error("出错咯!错误信息:" + e);
|
|
|
|
|
|
|
|
} catch (IntrospectionException e) {
|
|
|
|
|
|
|
|
logger.error("出错咯!错误信息:" + e);
|
|
|
|
|
|
|
|
} catch (InvocationTargetException e) {
|
|
|
|
|
|
|
|
logger.error("出错咯!错误信息:" + e);
|
|
|
|
|
|
|
|
} catch (InstantiationException e) {
|
|
|
|
|
|
|
|
logger.error("出错咯!错误信息:" + e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|