|
@@ -9,6 +9,7 @@ import lombok.Getter;
|
|
|
import org.apache.http.entity.ContentType;
|
|
|
import org.dom4j.Document;
|
|
|
import org.dom4j.DocumentException;
|
|
|
+import org.dom4j.DocumentHelper;
|
|
|
import org.dom4j.io.OutputFormat;
|
|
|
import org.dom4j.io.SAXReader;
|
|
|
import org.dom4j.io.XMLWriter;
|
|
@@ -64,20 +65,21 @@ public class XmlUtil implements InitializingBean {
|
|
|
SAXReader saxReader = new SAXReader();
|
|
|
Document document;
|
|
|
try {
|
|
|
- document = saxReader.read(new ByteArrayInputStream(str.getBytes("UTF-8")));
|
|
|
+ document = DocumentHelper.parseText(str);
|
|
|
+// document = saxReader.read(new ByteArrayInputStream(str.getBytes("UTF-8")));
|
|
|
OutputFormat format = OutputFormat.createPrettyPrint();
|
|
|
- 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(file.getAbsoluteFile().getPath());
|
|
|
+// 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(new String(("templates" + File.separator + name + ".xml").getBytes(StandardCharsets.UTF_8), StandardCharsets.UTF_8)).getAbsoluteFile().getPath());
|
|
|
+ File file = new File(String.valueOf(path));
|
|
|
/** 将document中的内容写入文件中 */
|
|
|
- XMLWriter writer = new XMLWriter(new FileWriter(new File(String.valueOf(path))), format);
|
|
|
+ XMLWriter writer = new XMLWriter(new FileWriter(file), format);
|
|
|
FileInputStream fileInputStream = new FileInputStream(String.valueOf(path));
|
|
|
-
|
|
|
- MultipartFile multipartFile = new MockMultipartFile(ContentType.APPLICATION_OCTET_STREAM.toString(), fileInputStream);
|
|
|
writer.write(document);
|
|
|
writer.close();
|
|
|
+ MultipartFile multipartFile = new MockMultipartFile(ContentType.APPLICATION_OCTET_STREAM.toString(), fileInputStream);
|
|
|
String returnFile = upload(multipartFile, name);
|
|
|
file.delete();
|
|
|
return returnFile;
|