public static void print(final LogicalPageBox logicalPage,
final SheetLayout sheetLayout,
final TableContentProducer contentProducer)
{
final CellBackgroundProducer cellBackgroundProducer = new CellBackgroundProducer(true, true);
try
{
final DefaultTagDescription tagDescription = new DefaultTagDescription();
tagDescription.setNamespaceHasCData(null, false);
final XmlWriter writer = new XmlWriter(new OutputStreamWriter(System.out), tagDescription);
writer.writeComment("Table Layout: ");
writer.writeComment("Rows: " + sheetLayout.getRowCount());
writer.writeComment("Columns: " + sheetLayout.getColumnCount());
final int rows = sheetLayout.getRowCount();
final int cols = sheetLayout.getColumnCount();
writer.writeTag(null, "table", XmlWriter.OPEN);
for (int row = 0; row < rows; row++)
{
writer.writeTag(null, "row", XmlWriter.OPEN);
for (int col = 0; col < cols; col++)
{
final RenderBox content = contentProducer.getContent(row, col);
final CellMarker.SectionType sectionType = contentProducer.getSectionType(row, col);
if (content == null)
{
final CellBackground bg =
cellBackgroundProducer.getBackgroundAt(logicalPage, sheetLayout, col, row, true, sectionType);
if (bg == null)
{
writer.writeTag(null, "empty-cell", XmlWriter.CLOSE);
}
else
{
final AttributeList attList = computeCellAttributes(bg);
writer.writeTag(null, "cell", attList, XmlWriter.CLOSE);
}
continue;
}
final long contentOffset = contentProducer.getContentOffset(row, col);
final long colPos = sheetLayout.getXPosition(col);
final long rowPos = sheetLayout.getYPosition(row);
if (content.getX() != colPos || (content.getY() + contentOffset) != rowPos)
{
// A spanned cell ..
writer.writeTag(null, "covered-cell", XmlWriter.CLOSE);
continue;
}
final CellBackground bg =
cellBackgroundProducer.getBackgroundAt(logicalPage, sheetLayout, col, row, true, sectionType);
final AttributeList attList = computeCellAttributes(bg);
writer.writeTag(null, "cell", attList, XmlWriter.CLOSE);
}
writer.writeCloseTag();
}