|
@@ -6,6 +6,7 @@ import java.io.File;
|
|
|
import java.io.FileInputStream;
|
|
import java.io.FileInputStream;
|
|
|
import java.io.FileNotFoundException;
|
|
import java.io.FileNotFoundException;
|
|
|
import java.io.FileOutputStream;
|
|
import java.io.FileOutputStream;
|
|
|
|
|
+import java.io.FileWriter;
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
import java.io.InputStream;
|
|
|
import java.io.OutputStream;
|
|
import java.io.OutputStream;
|
|
@@ -20,7 +21,10 @@ import org.dom4j.Attribute;
|
|
|
import org.dom4j.Document;
|
|
import org.dom4j.Document;
|
|
|
import org.dom4j.DocumentException;
|
|
import org.dom4j.DocumentException;
|
|
|
import org.dom4j.Element;
|
|
import org.dom4j.Element;
|
|
|
|
|
+import org.dom4j.io.OutputFormat;
|
|
|
import org.dom4j.io.SAXReader;
|
|
import org.dom4j.io.SAXReader;
|
|
|
|
|
+import org.dom4j.io.XMLWriter;
|
|
|
|
|
+
|
|
|
import com.leanwo.management.model.ApplicationSetting;
|
|
import com.leanwo.management.model.ApplicationSetting;
|
|
|
import com.leanwo.management.model.XmlConfigPath;
|
|
import com.leanwo.management.model.XmlConfigPath;
|
|
|
|
|
|
|
@@ -152,9 +156,12 @@ public class XmlConfigPathService {
|
|
|
//Collection<String> values = contents.values();
|
|
//Collection<String> values = contents.values();
|
|
|
String xmlFilePath = setting.getInstallPath() + "/" + xmlConfigPath.getXmlFileName();
|
|
String xmlFilePath = setting.getInstallPath() + "/" + xmlConfigPath.getXmlFileName();
|
|
|
File file = new File(xmlFilePath);
|
|
File file = new File(xmlFilePath);
|
|
|
|
|
+ XMLWriter writer = null;// 声明写XML的对象
|
|
|
if (file.exists()) {
|
|
if (file.exists()) {
|
|
|
try {
|
|
try {
|
|
|
- SAXReader reader = new SAXReader();
|
|
|
|
|
|
|
+ SAXReader reader = new SAXReader();
|
|
|
|
|
+ OutputFormat format = OutputFormat.createPrettyPrint();
|
|
|
|
|
+ //format.setEncoding("utf-8");// 设置XML文件的编码格式
|
|
|
Document document = reader.read(file);
|
|
Document document = reader.read(file);
|
|
|
Element root = document.getRootElement();
|
|
Element root = document.getRootElement();
|
|
|
List<String> nodeNames = xmlConfigPath.getNodeNames();
|
|
List<String> nodeNames = xmlConfigPath.getNodeNames();
|
|
@@ -164,9 +171,25 @@ public class XmlConfigPathService {
|
|
|
throw new RuntimeException("在文件:"+xmlFilePath+",中未找到id="+s+"的标签");
|
|
throw new RuntimeException("在文件:"+xmlFilePath+",中未找到id="+s+"的标签");
|
|
|
}
|
|
}
|
|
|
dataSource.setText(contents.get(s));
|
|
dataSource.setText(contents.get(s));
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
+ writer = new XMLWriter(new FileWriter(file), format);
|
|
|
|
|
+ writer.write(document);
|
|
|
|
|
+
|
|
|
} catch (DocumentException e) {
|
|
} catch (DocumentException e) {
|
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
|
+ // TODO Auto-generated catch block
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }finally {
|
|
|
|
|
+ if (writer != null){
|
|
|
|
|
+ try {
|
|
|
|
|
+ writer.close();
|
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
|
+ // TODO Auto-generated catch block
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -180,9 +203,10 @@ public class XmlConfigPathService {
|
|
|
OutputStream out = null;
|
|
OutputStream out = null;
|
|
|
if (file2.exists()) {
|
|
if (file2.exists()) {
|
|
|
try {
|
|
try {
|
|
|
- out = new BufferedOutputStream(new FileOutputStream(file2,true));
|
|
|
|
|
|
|
+ out = new BufferedOutputStream(new FileOutputStream(file2));
|
|
|
properties.setProperty("token", token);
|
|
properties.setProperty("token", token);
|
|
|
properties.setProperty("port", port.toString());
|
|
properties.setProperty("port", port.toString());
|
|
|
|
|
+ properties.store(out, "修改");
|
|
|
} catch (FileNotFoundException e) {
|
|
} catch (FileNotFoundException e) {
|
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
|
} catch (IOException e) {
|
|
} catch (IOException e) {
|