Cleanups
This commit is contained in:
@@ -130,13 +130,14 @@ public abstract class AbstractMarkupDocBuilder implements MarkupDocBuilder {
|
||||
return documentBuilder.toString();
|
||||
}
|
||||
|
||||
protected void writeToFileWithExtension(String directory, String fileNameWithExtension, Charset charset) throws IOException {
|
||||
@Override
|
||||
public void writeToFileWithoutExtension(String directory, String fileName, Charset charset) throws IOException {
|
||||
Files.createDirectories(Paths.get(directory));
|
||||
try (BufferedWriter writer = Files.newBufferedWriter(Paths.get(directory, fileNameWithExtension), charset)){
|
||||
try (BufferedWriter writer = Files.newBufferedWriter(Paths.get(directory, fileName), charset)){
|
||||
writer.write(documentBuilder.toString());
|
||||
}
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("{} was written to: {}", fileNameWithExtension, directory);
|
||||
logger.info("{} was written to: {}", fileName, directory);
|
||||
}
|
||||
documentBuilder = new StringBuilder();
|
||||
}
|
||||
|
||||
@@ -94,21 +94,14 @@ public interface MarkupDocBuilder {
|
||||
*/
|
||||
void writeToFile(String directory, String fileName, Charset charset) throws IOException;
|
||||
|
||||
class TableColumnSpec {
|
||||
public String header;
|
||||
public Integer widthRatio = 0;
|
||||
public TableColumnSpec() {}
|
||||
public TableColumnSpec(String header, Integer widthRatio) {
|
||||
this.header = header;
|
||||
this.widthRatio = widthRatio;
|
||||
}
|
||||
public TableColumnSpec withHeader(String header) {
|
||||
this.header = header;
|
||||
return this;
|
||||
}
|
||||
public TableColumnSpec withWidthRatio(Integer widthRatio) {
|
||||
this.widthRatio = widthRatio;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Writes the content of the builder to a file and clears the builder.
|
||||
*
|
||||
* @param directory the directory where the generated file should be stored
|
||||
* @param fileName the name of the file
|
||||
* @param charset the the charset to use for encoding
|
||||
* @throws java.io.IOException if the file cannot be written
|
||||
*/
|
||||
void writeToFileWithoutExtension(String directory, String fileName, Charset charset) throws IOException;
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package io.github.robwin.markup.builder;
|
||||
|
||||
public class TableColumnSpec {
|
||||
public String header;
|
||||
public Integer widthRatio = 0;
|
||||
|
||||
public TableColumnSpec() {
|
||||
}
|
||||
|
||||
public TableColumnSpec(String header, Integer widthRatio) {
|
||||
this.header = header;
|
||||
this.widthRatio = widthRatio;
|
||||
}
|
||||
|
||||
public TableColumnSpec withHeader(String header) {
|
||||
this.header = header;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TableColumnSpec withWidthRatio(Integer widthRatio) {
|
||||
this.widthRatio = widthRatio;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,7 @@ import com.google.common.base.Function;
|
||||
import com.google.common.collect.Collections2;
|
||||
import io.github.robwin.markup.builder.AbstractMarkupDocBuilder;
|
||||
import io.github.robwin.markup.builder.MarkupDocBuilder;
|
||||
import io.github.robwin.markup.builder.TableColumnSpec;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -204,6 +205,6 @@ public class AsciiDocBuilder extends AbstractMarkupDocBuilder {
|
||||
|
||||
@Override
|
||||
public void writeToFile(String directory, String fileName, Charset charset) throws IOException {
|
||||
writeToFileWithExtension(directory, fileName + "." + ASCIIDOC_FILE_EXTENSION, charset);
|
||||
writeToFileWithoutExtension(directory, fileName + "." + ASCIIDOC_FILE_EXTENSION, charset);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import com.google.common.base.Function;
|
||||
import com.google.common.collect.Collections2;
|
||||
import io.github.robwin.markup.builder.AbstractMarkupDocBuilder;
|
||||
import io.github.robwin.markup.builder.MarkupDocBuilder;
|
||||
import io.github.robwin.markup.builder.TableColumnSpec;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
@@ -222,6 +223,6 @@ public class MarkdownBuilder extends AbstractMarkupDocBuilder
|
||||
|
||||
@Override
|
||||
public void writeToFile(String directory, String fileName, Charset charset) throws IOException {
|
||||
writeToFileWithExtension(directory, fileName + "." + MARKDOWN_FILE_EXTENSION, charset);
|
||||
writeToFileWithoutExtension(directory, fileName + "." + MARKDOWN_FILE_EXTENSION, charset);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user