01: package liquibase.dbdoc;
02:
03: import liquibase.FileOpener;
04: import liquibase.util.StreamUtil;
05:
06: import java.io.File;
07: import java.io.FileOutputStream;
08: import java.io.IOException;
09: import java.io.InputStream;
10:
11: public class ChangeLogWriter {
12: protected File outputDir;
13: private FileOpener fileOpener;
14:
15: public ChangeLogWriter(FileOpener fileOpener, File rootOutputDir) {
16: this .outputDir = new File(rootOutputDir, "changelogs");
17: this .fileOpener = fileOpener;
18: }
19:
20: public void writeChangeLog(String changeLog, String physicalFilePath)
21: throws IOException {
22: InputStream stylesheet = fileOpener
23: .getResourceAsStream(physicalFilePath);
24: if (stylesheet == null) {
25: throw new IOException("Can not find " + changeLog);
26: }
27:
28: // File file = outputDir;
29: // String[] splitPath = (changeLog.getFilePath() + ".xml").split("/");
30: // for (int i =0; i < splitPath.length; i++) {
31: // String pathPart = splitPath[i];
32: // file = new File(file, pathPart);
33: // if (i < splitPath.length - 1) {
34: // file.mkdirs();
35: // }
36: // }
37:
38: File xmlFile = new File(outputDir, changeLog + ".xml");
39: xmlFile.getParentFile().mkdirs();
40:
41: FileOutputStream changeLogStream = new FileOutputStream(
42: xmlFile, false);
43: try {
44: StreamUtil.copy(stylesheet, changeLogStream);
45: } finally {
46: changeLogStream.close();
47: }
48:
49: }
50:
51: }
|