private static void writeToXml(String filePath, XmlNode xmlNode,
String encoding) {
try {
if (StringUtil.isBlank(encoding)) {
encoding = FlowComponentConstants.DEFAULT_ENCODING;
}
FileObject fileObject = VFS.resolveFile(filePath);
XmlNode xn = new XmlNode(XmlNodeType.XML_DECLARATION);
xn.setAttribute("version", "1.0");
xn.setAttribute("encoding", encoding);
StringBuffer sb = new StringBuffer();
sb.append(xn);
sb.append(xmlNode);
StreamUtil.writeText(sb.toString(), fileObject.getOutputStream(),
encoding, true);
} catch (Exception e) {
LOGGER.logMessage(LogLevel.ERROR, "将修改后的xml内容导出到xml树:{0}时失败,错误信息:{1}",
filePath, e);
throw new FlowComponentException(
FlowComponentExceptionErrorCode.OBJECT_SAVE_TO_FILE_FAILED,
xmlNode.getClass().getName(), filePath, e);
}
}