All Downloads are FREE. Search and download functionalities are using the official Maven repository.

liquibase.dbdoc.ChangeLogWriter Maven / Gradle / Ivy

There is a newer version: 3.6.2.5.inovus
Show newest version
package liquibase.dbdoc;

import liquibase.configuration.GlobalConfiguration;
import liquibase.configuration.LiquibaseConfiguration;
import liquibase.resource.ResourceAccessor;
import liquibase.util.StreamUtil;

import java.io.*;

public class ChangeLogWriter {
    protected File outputDir;
    private ResourceAccessor resourceAccessor;
    
    public ChangeLogWriter(ResourceAccessor resourceAccessor, File rootOutputDir) {
        this.outputDir = new File(rootOutputDir, "changelogs");
        this.resourceAccessor = resourceAccessor;
    }
    
    public void writeChangeLog(String changeLog, String physicalFilePath) throws IOException {
        String changeLogOutFile = changeLog.replace(":", "_");
        File xmlFile = new File(outputDir, changeLogOutFile.toLowerCase() + ".html");
        xmlFile.getParentFile().mkdirs();
        
        BufferedWriter changeLogStream = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(xmlFile,
        false), LiquibaseConfiguration.getInstance().getConfiguration(GlobalConfiguration.class).getOutputEncoding()));
        try (InputStream stylesheet = StreamUtil.singleInputStream(physicalFilePath, resourceAccessor);) {
            if (stylesheet == null) {
                throw new IOException("Can not find " + changeLog);
            }
            changeLogStream.write("
\n");
            changeLogStream.write(StreamUtil.getStreamContents(stylesheet).replace("<", "<").replace(">", ">"));
            changeLogStream.write("\n
"); } finally { changeLogStream.close(); } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy