|
@@ -95,6 +95,41 @@ public class XmlUtil implements InitializingBean {
|
|
}
|
|
}
|
|
return "NG";
|
|
return "NG";
|
|
}
|
|
}
|
|
|
|
+ //将字符串string类型转换成xml文件
|
|
|
|
+ public String strChangeXMLs(String str, String name) throws IOException {
|
|
|
|
+ SAXReader saxReader = new SAXReader();
|
|
|
|
+ Document document;
|
|
|
|
+ try {
|
|
|
|
+ document = DocumentHelper.parseText(str);
|
|
|
|
+ document.setXMLEncoding("GBK");
|
|
|
|
+ document.asXML();
|
|
|
|
+// document = saxReader.read(new ByteArrayInputStream(str.getBytes("UTF-8")));
|
|
|
|
+ OutputFormat format = OutputFormat.createPrettyPrint();
|
|
|
|
+ format.setEncoding("GBK");
|
|
|
|
+// File file = new File(new String(("templates" + File.separator + name + ".xml").getBytes(StandardCharsets.UTF_8), StandardCharsets.UTF_8));
|
|
|
|
+// if (!file.exists()) {
|
|
|
|
+// boolean flag = file.mkdirs();
|
|
|
|
+// }
|
|
|
|
+ Path path = FileSystems.getDefault().getPath(new File("templates" + File.separator + name + ".xml").getAbsoluteFile().getPath());
|
|
|
|
+ File file = new File(String.valueOf(path));
|
|
|
|
+ /** 将document中的内容写入文件中 */
|
|
|
|
+ OutputStream out = new FileOutputStream(file);
|
|
|
|
+ Writer wr = new OutputStreamWriter(out,"GBK");
|
|
|
|
+ XMLWriter writer = new XMLWriter(wr, format);
|
|
|
|
+ FileInputStream fileInputStream = new FileInputStream(String.valueOf(path));
|
|
|
|
+ writer.write(document);
|
|
|
|
+ writer.close();
|
|
|
|
+ out.close();
|
|
|
|
+ wr.close();
|
|
|
|
+ MultipartFile multipartFile = new MockMultipartFile(ContentType.APPLICATION_OCTET_STREAM.toString(), fileInputStream);
|
|
|
|
+ String returnFile = upload(multipartFile, name);
|
|
|
|
+ file.delete();
|
|
|
|
+ return returnFile;
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ return "NG";
|
|
|
|
+ }
|
|
|
|
|
|
public String readXml(PaymentManagement paymentManagement) {
|
|
public String readXml(PaymentManagement paymentManagement) {
|
|
|
|
|
|
@@ -263,7 +298,7 @@ public class XmlUtil implements InitializingBean {
|
|
"<Spxx>\n" +
|
|
"<Spxx>\n" +
|
|
"\n" +
|
|
"\n" +
|
|
"\n" +
|
|
"\n" +
|
|
- "-<Sph>\n" +
|
|
|
|
|
|
+ "<Sph>\n" +
|
|
"\n" +
|
|
"\n" +
|
|
"<Xh>1</Xh>\n" +
|
|
"<Xh>1</Xh>\n" +
|
|
"\n" +
|
|
"\n" +
|
|
@@ -305,7 +340,7 @@ public class XmlUtil implements InitializingBean {
|
|
"\n" +
|
|
"\n" +
|
|
"</Kp>";
|
|
"</Kp>";
|
|
try {
|
|
try {
|
|
- String returnFile = strChangeXML(s, paymentManagement.getId());
|
|
|
|
|
|
+ String returnFile = strChangeXMLs(s, paymentManagement.getId());
|
|
return returnFile;
|
|
return returnFile;
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|