com.brsanthu.dataexporter.output.html.HtmlWriter Maven / Gradle / Ivy
/*
* #%L
* data-exporter
* %%
* Copyright (C) 2012 - 2013 http://www.brsanthu.com
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
package com.brsanthu.dataexporter.output.html;
import java.io.OutputStream;
import java.io.Writer;
import org.apache.commons.lang3.StringEscapeUtils;
import com.brsanthu.dataexporter.AbstractDataWriter;
import com.brsanthu.dataexporter.model.AlignType;
import com.brsanthu.dataexporter.model.CellDetails;
import com.brsanthu.dataexporter.model.HeaderCellDetails;
import com.brsanthu.dataexporter.model.RowDetails;
import com.brsanthu.dataexporter.model.Table;
public class HtmlWriter extends AbstractDataWriter {
public HtmlWriter(HtmlExportOptions options) {
super(options, System.out);
}
public HtmlWriter(HtmlExportOptions options, OutputStream out) {
super(options, out);
}
public HtmlWriter(OutputStream out) {
super(new HtmlExportOptions(), out);
}
public HtmlWriter(HtmlExportOptions options, Writer out) {
super(options, out);
}
public HtmlWriter(Writer out) {
super(new HtmlExportOptions(), out);
}
public HtmlExportOptions getHtmlExportOptions() {
return (HtmlExportOptions) getOptions();
}
@Override
public void beforeTable(Table table) {
print("");
prettyPrint(1);
print("");
prettyPrint(1);
print("");
prettyPrint(2);
print("");
}
@Override
public void beforeHeaderRow(Table table) {
prettyPrint(3);
print("");
}
@Override
public void beforeHeaderCell(HeaderCellDetails headerCell) {
prettyPrint(4);
print("");
}
@Override
public void writeHeaderCell(HeaderCellDetails headerCell) {
print(headerCell.getColumn().getTitle());
}
@Override
public void afterHeaderCell(HeaderCellDetails headerCell) {
print(" ");
}
@Override
public void afterHeaderRow(Table table) {
prettyPrint(3);
print(" ");
}
@Override
public void beforeRow(RowDetails rowDetails) {
prettyPrint(3);
print("");
}
@Override
public void beforeRowCell(CellDetails cellDetails) {
prettyPrint(4);
if (getHtmlExportOptions().isAlignCells()) {
AlignType alignType = cellDetails.getColumn().getAlign();
String style = "text-align:" + alignType.getHorizontalAlignment() + ";vertical-align:" + alignType.getVerticalAlignment();
print("");
} else {
print(" ");
}
}
@Override
public void writeRowCell(CellDetails cellDetails) {
print(StringEscapeUtils.escapeHtml4(cellDetails.getColumn().format(cellDetails)));
}
@Override
public void afterRowCell(CellDetails cellDetails) {
print(" ");
}
@Override
public void afterRow(RowDetails rowDetails) {
prettyPrint(3);
print(" ");
}
@Override
public void afterTable(Table table) {
prettyPrint(2);
print("
");
prettyPrint(1);
print("");
prettyPrint(0);
print("");
}
private void prettyPrint(int level) {
if (getHtmlExportOptions().isPrettyPrint()) {
print("\n");
for (int i = 0; i < level; i++) {
print('\t');
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy