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

liquibase.dbdoc.HTMLListWriter Maven / Gradle / Ivy

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

import liquibase.GlobalConfiguration;
import liquibase.resource.OpenOptions;
import liquibase.resource.Resource;
import liquibase.structure.core.Schema;
import liquibase.structure.core.Table;
import liquibase.util.StringUtil;

import java.io.*;
import java.util.SortedSet;

public class HTMLListWriter {
    private Resource outputDir;
    private String directory;
    private String filename;
    private String title;

    public HTMLListWriter(String title, String filename, String subdir, Resource outputDir) {
        this.title = title;
        this.outputDir = outputDir;
        this.filename = filename;
        this.directory = subdir;
    }

    public void writeHTML(SortedSet objects) throws IOException {

        try (Writer fileWriter = new OutputStreamWriter(outputDir.resolve(filename).openOutputStream(new OpenOptions()), GlobalConfiguration.OUTPUT_FILE_ENCODING.getCurrentValue())) {
            fileWriter.append("\n" + "\n" + "\n");
            fileWriter.append(title);
            fileWriter.append("\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "");
            fileWriter.append(title);
            fileWriter.append("\n" + "
\n" + "" + "\n" + "\n" + "\n" + "
"); String currentSchema = null; if (objects.size() > 0 && objects.first().getClass() == Table.class) { currentSchema = ((Table )objects.first()).getAttribute("schema", new Schema()).toString(); fileWriter.append("
" + currentSchema + "
"); } for (Object object : objects) { if (object.getClass() == Table.class) { String tableSchema = ((Table) object).getAttribute("schema", new Schema()).toString(); if (!tableSchema.equals(currentSchema)) { currentSchema = tableSchema; fileWriter.append("

"); fileWriter.append("" + currentSchema + "
"); } fileWriter.append(""); fileWriter.append(StringUtil.escapeHtml(object.toString())); fileWriter.append("
\n"); } fileWriter.append("

\n" + "\n" + "\n" + ""); } } public String getTargetExtension() { return ".html"; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy