liquibase.dbdoc.HTMLListWriter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of liquibase-core Show documentation
Show all versions of liquibase-core Show documentation
Liquibase is a tool for managing and executing database changes.
The 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 final Resource outputDir;
private final String directory;
private final String filename;
private final 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" + "");
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" +
"\n" +
"\n" +
"");
}
}
public String getTargetExtension() {
return ".html";
}
}