|
@@ -16,6 +16,7 @@ import org.springframework.beans.factory.InitializingBean;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.mock.web.MockMultipartFile;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import java.io.*;
|
|
@@ -26,18 +27,19 @@ import java.util.Date;
|
|
|
import java.util.regex.Matcher;
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
+@Component
|
|
|
public class XmlUtil implements InitializingBean {
|
|
|
@Getter
|
|
|
@Value("${oss.endpoint.internal:}")
|
|
|
- private static String baseUrl;
|
|
|
+ private String baseUrl;
|
|
|
@Getter
|
|
|
@Value("${oss.bucket.name:}")
|
|
|
- private static String bucket;
|
|
|
+ private String bucket;
|
|
|
@Autowired
|
|
|
- private static OSSClient ossClient;
|
|
|
+ private OSSClient ossClient;
|
|
|
@Getter
|
|
|
@Value("${oss.endpoint.default:}")
|
|
|
- private static String endpoint;
|
|
|
+ private String endpoint;
|
|
|
|
|
|
private String host;
|
|
|
|
|
@@ -46,7 +48,7 @@ public class XmlUtil implements InitializingBean {
|
|
|
host = "http://" + bucket + "." + endpoint;
|
|
|
}
|
|
|
|
|
|
- public static String xmlChangeString(String fileName) {
|
|
|
+ public String xmlChangeString(String fileName) {
|
|
|
try {
|
|
|
SAXReader saxReader = new SAXReader();//新建一个解析类
|
|
|
Document tempDocument = saxReader.read(cn.hutool.core.util.XmlUtil.class.getClassLoader().getResourceAsStream(fileName));//读入一个文件
|
|
@@ -58,7 +60,7 @@ public class XmlUtil implements InitializingBean {
|
|
|
}
|
|
|
|
|
|
//将字符串string类型转换成xml文件
|
|
|
- public static String strChangeXML(String str, String name) throws IOException {
|
|
|
+ public String strChangeXML(String str, String name) throws IOException {
|
|
|
SAXReader saxReader = new SAXReader();
|
|
|
Document document;
|
|
|
try {
|
|
@@ -68,15 +70,16 @@ public class XmlUtil implements InitializingBean {
|
|
|
if (!file.exists()) {
|
|
|
boolean flag = file.mkdirs();
|
|
|
}
|
|
|
- /** 将document中的内容写入文件中 */
|
|
|
- XMLWriter writer = new XMLWriter(new FileWriter(file), format);
|
|
|
Path path = FileSystems.getDefault().getPath(file.getAbsoluteFile().getPath());
|
|
|
+ /** 将document中的内容写入文件中 */
|
|
|
+ XMLWriter writer = new XMLWriter(new FileWriter(new File(String.valueOf(path))), format);
|
|
|
FileInputStream fileInputStream = new FileInputStream(String.valueOf(path));
|
|
|
|
|
|
MultipartFile multipartFile = new MockMultipartFile(ContentType.APPLICATION_OCTET_STREAM.toString(), fileInputStream);
|
|
|
writer.write(document);
|
|
|
writer.close();
|
|
|
String returnFile = upload(multipartFile, name);
|
|
|
+ file.delete();
|
|
|
return returnFile;
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
@@ -84,7 +87,7 @@ public class XmlUtil implements InitializingBean {
|
|
|
return "NG";
|
|
|
}
|
|
|
|
|
|
- public static String readXml(PaymentManagement paymentManagement) {
|
|
|
+ public String readXml(PaymentManagement paymentManagement) {
|
|
|
String regEx = "[^0-9]";
|
|
|
Pattern p = Pattern.compile(regEx);
|
|
|
Matcher m = p.matcher(paymentManagement.getPaymentNo());
|
|
@@ -282,7 +285,7 @@ public class XmlUtil implements InitializingBean {
|
|
|
* @return
|
|
|
* @throws IOException
|
|
|
*/
|
|
|
- public static String upload(MultipartFile file, String name) throws IOException {
|
|
|
+ public String upload(MultipartFile file, String name) throws IOException {
|
|
|
ObjectMetadata objectMetadata = new ObjectMetadata();
|
|
|
objectMetadata.setContentLength(file.getSize());
|
|
|
objectMetadata.setContentType(file.getContentType());
|