1 | |
package liquibase.dbdoc; |
2 | |
|
3 | |
import liquibase.resource.ResourceAccessor; |
4 | |
import liquibase.util.StreamUtil; |
5 | |
|
6 | |
import java.io.File; |
7 | |
import java.io.FileOutputStream; |
8 | |
import java.io.IOException; |
9 | |
import java.io.InputStream; |
10 | |
|
11 | |
public class ChangeLogWriter { |
12 | |
protected File outputDir; |
13 | |
private ResourceAccessor resourceAccessor; |
14 | |
|
15 | 0 | public ChangeLogWriter(ResourceAccessor resourceAccessor, File rootOutputDir) { |
16 | 0 | this.outputDir = new File(rootOutputDir, "changelogs"); |
17 | 0 | this.resourceAccessor = resourceAccessor; |
18 | 0 | } |
19 | |
|
20 | |
public void writeChangeLog(String changeLog, String physicalFilePath) throws IOException { |
21 | 0 | InputStream stylesheet = resourceAccessor.getResourceAsStream(physicalFilePath); |
22 | 0 | if (stylesheet == null) { |
23 | 0 | throw new IOException("Can not find " + changeLog); |
24 | |
} |
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | 0 | File xmlFile = new File(outputDir, changeLog + ".xml"); |
37 | 0 | xmlFile.getParentFile().mkdirs(); |
38 | |
|
39 | 0 | FileOutputStream changeLogStream = new FileOutputStream(xmlFile, false); |
40 | |
try { |
41 | 0 | StreamUtil.copy(stylesheet, changeLogStream); |
42 | |
} finally { |
43 | 0 | changeLogStream.close(); |
44 | 0 | } |
45 | |
|
46 | 0 | } |
47 | |
|
48 | |
} |