|
|
@@ -10,7 +10,6 @@ import java.io.FileWriter;
|
|
|
import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
|
import java.io.OutputStream;
|
|
|
-import java.util.Collection;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Iterator;
|
|
|
import java.util.List;
|
|
|
@@ -20,6 +19,7 @@ import java.util.Properties;
|
|
|
import org.dom4j.Attribute;
|
|
|
import org.dom4j.Document;
|
|
|
import org.dom4j.DocumentException;
|
|
|
+import org.dom4j.DocumentHelper;
|
|
|
import org.dom4j.Element;
|
|
|
import org.dom4j.io.OutputFormat;
|
|
|
import org.dom4j.io.SAXReader;
|
|
|
@@ -39,7 +39,7 @@ public class XmlConfigPathService {
|
|
|
public void load(ApplicationSetting setting) {
|
|
|
Map<String, String> contentMap = new HashMap<String, String>();
|
|
|
XmlConfigPath xmlConfigPath = setting.getXmlConfigPath();
|
|
|
- String xmlFilePath = setting.getInstallPath() + "/" + xmlConfigPath.getXmlFileName();
|
|
|
+ String xmlFilePath = setting.getInstallPath() + "\\" + xmlConfigPath.getXmlFileName();
|
|
|
File file = new File(xmlFilePath);
|
|
|
if (file.exists()) {
|
|
|
try {
|
|
|
@@ -54,7 +54,7 @@ public class XmlConfigPathService {
|
|
|
throw new RuntimeException("在文件:"+xmlFilePath+",中未找到id="+s+"的标签");
|
|
|
}
|
|
|
String asXML = dataSource.asXML();
|
|
|
- String result = asXML.substring(asXML.indexOf(">"), asXML.lastIndexOf("<"));
|
|
|
+ String result = asXML.substring(asXML.indexOf(">") + 1 , asXML.lastIndexOf("<"));
|
|
|
/*StringBuilder sb = new StringBuilder();
|
|
|
List<Element> propertys = dataSource.elements();
|
|
|
for (Element e : propertys) {
|
|
|
@@ -153,7 +153,7 @@ public class XmlConfigPathService {
|
|
|
try {
|
|
|
SAXReader reader = new SAXReader();
|
|
|
OutputFormat format = OutputFormat.createPrettyPrint();
|
|
|
- //format.setEncoding("utf-8");// 设置XML文件的编码格式
|
|
|
+ format.setEncoding("utf-8");// 设置XML文件的编码格式
|
|
|
Document document = reader.read(file);
|
|
|
Element root = document.getRootElement();
|
|
|
List<String> nodeNames = xmlConfigPath.getNodeNames();
|
|
|
@@ -162,7 +162,26 @@ public class XmlConfigPathService {
|
|
|
if (dataSource == null) {
|
|
|
throw new RuntimeException("在文件:"+xmlFilePath+",中未找到id="+s+"的标签");
|
|
|
}
|
|
|
- dataSource.setText(contents.get(s));
|
|
|
+ //清空bean节点
|
|
|
+ dataSource.clearContent();
|
|
|
+ /*List<Element> dataSources = dataSource.elements();
|
|
|
+ for (Element e : dataSources) {
|
|
|
+ dataSource.remove(e);
|
|
|
+ }*/
|
|
|
+ String xmlText = contents.get(s).replaceAll("\n|\t", "");
|
|
|
+ //将xml文本转换为document对象
|
|
|
+ Document parseText = DocumentHelper.parseText("<myroot>" + xmlText.trim() + "</myroot>");
|
|
|
+ Element rootElement = parseText.getRootElement();
|
|
|
+ dataSource.setContent(rootElement.content());
|
|
|
+ /*List<Element> elements = rootElement.elements();
|
|
|
+ for (Element e : elements) {
|
|
|
+ dataSource.addElement("property");
|
|
|
+
|
|
|
+ }*/
|
|
|
+
|
|
|
+ //dataSource.addCDATA(contents.get(s));
|
|
|
+ //dataSource.addText(contents.get(s));
|
|
|
+ //dataSource.setText("<![CDATA["+contents.get(s)+"]]>");
|
|
|
|
|
|
}
|
|
|
writer = new XMLWriter(new FileWriter(file), format);
|