-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
ChangeLogWriter.java
37 lines (31 loc) · 1.52 KB
/
ChangeLogWriter.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package liquibase.dbdoc;
import liquibase.GlobalConfiguration;
import liquibase.resource.OpenOptions;
import liquibase.resource.Resource;
import liquibase.resource.ResourceAccessor;
import liquibase.util.StreamUtil;
import java.io.*;
public class ChangeLogWriter {
protected Resource outputDir;
private ResourceAccessor resourceAccessor;
public ChangeLogWriter(ResourceAccessor resourceAccessor, Resource rootOutputDir) {
this.outputDir = rootOutputDir.resolve("changelogs");
this.resourceAccessor = resourceAccessor;
}
public void writeChangeLog(String changeLog, String physicalFilePath) throws IOException {
String changeLogOutFile = changeLog.replace(":", "_");
Resource xmlFile = outputDir.resolve(changeLogOutFile.toLowerCase() + ".html");
try (BufferedWriter changeLogStream = new BufferedWriter(new OutputStreamWriter(xmlFile.openOutputStream(new OpenOptions()),
GlobalConfiguration.OUTPUT_FILE_ENCODING.getCurrentValue()))) {
Resource stylesheet = resourceAccessor.get(physicalFilePath);
if (stylesheet == null) {
throw new IOException("Can not find " + changeLog);
}
try (InputStream stream = stylesheet.openInputStream()) {
changeLogStream.write("<html><body><pre>\n");
changeLogStream.write(StreamUtil.readStreamAsString(stream).replace("<", "<").replace(">", ">"));
changeLogStream.write("\n</pre></body></html>");
}
}
}
}