|
|
@ -1,6 +1,7 @@ |
|
|
|
package com.fr.design.mainframe.template.info; |
|
|
|
package com.fr.design.mainframe.template.info; |
|
|
|
|
|
|
|
|
|
|
|
import com.fr.base.FRContext; |
|
|
|
import com.fr.base.FRContext; |
|
|
|
|
|
|
|
import com.fr.base.io.XMLReadHelper; |
|
|
|
import com.fr.design.DesignerEnvManager; |
|
|
|
import com.fr.design.DesignerEnvManager; |
|
|
|
import com.fr.log.FineLoggerFactory; |
|
|
|
import com.fr.log.FineLoggerFactory; |
|
|
|
import com.fr.stable.ProductConstants; |
|
|
|
import com.fr.stable.ProductConstants; |
|
|
@ -12,12 +13,15 @@ import com.fr.stable.xml.XMLTools; |
|
|
|
import com.fr.stable.xml.XMLWriter; |
|
|
|
import com.fr.stable.xml.XMLWriter; |
|
|
|
import com.fr.stable.xml.XMLableReader; |
|
|
|
import com.fr.stable.xml.XMLableReader; |
|
|
|
import com.fr.third.javax.xml.stream.XMLStreamException; |
|
|
|
import com.fr.third.javax.xml.stream.XMLStreamException; |
|
|
|
import com.fr.workspace.WorkContext; |
|
|
|
import com.fr.third.org.apache.commons.io.FileUtils; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.ByteArrayOutputStream; |
|
|
|
import java.io.File; |
|
|
|
import java.io.File; |
|
|
|
|
|
|
|
import java.io.FileInputStream; |
|
|
|
import java.io.FileNotFoundException; |
|
|
|
import java.io.FileNotFoundException; |
|
|
|
import java.io.FileOutputStream; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.FileReader; |
|
|
|
import java.io.InputStream; |
|
|
|
|
|
|
|
import java.nio.charset.StandardCharsets; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
@ -132,13 +136,24 @@ public class TemplateInfoCollector implements XMLReadable, XMLWriter { |
|
|
|
if (!getInfoFile().exists()) { |
|
|
|
if (!getInfoFile().exists()) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
XMLableReader reader = null; |
|
|
|
|
|
|
|
try (InputStream in = new FileInputStream(getInfoFile())) { |
|
|
|
|
|
|
|
// XMLableReader 还是应该考虑实现 Closable 接口的,这样就能使用 try-with 语句了
|
|
|
|
|
|
|
|
reader = XMLReadHelper.createXMLableReader(in, XMLPrintWriter.XML_ENCODER); |
|
|
|
|
|
|
|
reader.readXMLObject(this); |
|
|
|
|
|
|
|
} catch (FileNotFoundException e) { |
|
|
|
|
|
|
|
// do nothing
|
|
|
|
|
|
|
|
} catch (XMLStreamException | IOException e) { |
|
|
|
|
|
|
|
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
|
|
|
|
|
|
|
} finally { |
|
|
|
try { |
|
|
|
try { |
|
|
|
XMLableReader xmlReader = XMLableReader.createXMLableReader(new FileReader(getInfoFile())); |
|
|
|
if (reader != null) { |
|
|
|
xmlReader.readXMLObject(this); |
|
|
|
reader.close(); |
|
|
|
|
|
|
|
} |
|
|
|
} catch (XMLStreamException e) { |
|
|
|
} catch (XMLStreamException e) { |
|
|
|
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
|
|
|
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
|
|
|
} catch (FileNotFoundException e) { |
|
|
|
} |
|
|
|
// do nothing
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -160,8 +175,12 @@ public class TemplateInfoCollector implements XMLReadable, XMLWriter { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private void saveInfo() { |
|
|
|
private void saveInfo() { |
|
|
|
try { |
|
|
|
try { |
|
|
|
FileOutputStream out = new FileOutputStream(getInfoFile()); |
|
|
|
ByteArrayOutputStream out = new ByteArrayOutputStream(); |
|
|
|
XMLTools.writeOutputStreamXML(this, out); |
|
|
|
XMLTools.writeOutputStreamXML(this, out); |
|
|
|
|
|
|
|
out.flush(); |
|
|
|
|
|
|
|
out.close(); |
|
|
|
|
|
|
|
String fileContent = new String(out.toByteArray(), StandardCharsets.UTF_8); |
|
|
|
|
|
|
|
FileUtils.writeStringToFile(getInfoFile(), fileContent, StandardCharsets.UTF_8); |
|
|
|
} catch (Exception ex) { |
|
|
|
} catch (Exception ex) { |
|
|
|
FineLoggerFactory.getLogger().error(ex.getMessage()); |
|
|
|
FineLoggerFactory.getLogger().error(ex.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|