ColorValueConverter colorValueConverter = new ColorValueConverter();
CellBackgroundProducer cellBackgroundProducer = new CellBackgroundProducer(true, true);
try
{
final XmlWriter writer = new XmlWriter(new OutputStreamWriter(System.out));
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 int sectionType = tableContentProducer.getSectionType(row, col);
final CellBackground bg =
cellBackgroundProducer.getBackgroundAt(logicalPage, sheetLayout, col, row, true, sectionType);
if (bg == null)
{
writer.writeTag(null, "empty-cell", XmlWriter.CLOSE);
continue;
}
if (bg.isOrigin() == false)
{
// A spanned cell ..
writer.writeTag(null, "covered-cell", XmlWriter.CLOSE);
continue;
}
final AttributeList attList = new AttributeList();
final ReportAttributeMap attrs = bg.getAttributes();
final Object nameAttr = attrs.getAttribute(AttributeNames.Core.NAMESPACE, AttributeNames.Core.NAME);
if (nameAttr instanceof String)
{
attList.setAttribute(null, "content-idref",
(String) nameAttr);
}
final String[] anchors = bg.getAnchors();
if (anchors != null)
{
final StringBuffer anchor = new StringBuffer(100);
for (int i = 0; i < anchors.length; i++)
{
if (i != 0)
{
anchor.append(", ");
}
anchor.append(anchors[i]);
}
attList.setAttribute(null, "anchor", anchor.toString());
}
if (bg.getBackgroundColor() != null)
{
attList.setAttribute(null, "background-color", ColorValueConverter.colorToString(bg.getBackgroundColor()));
}
// if (bg.getVerticalAlignment() != null)
// {
// attList.setAttribute(null, "vertical-alignment", String.valueOf(bg.getVerticalAlignment()));
// }
//
final BorderEdge top = bg.getTop();
if (top != null)
{
attList.setAttribute(null, "border-top-color",
ColorValueConverter.colorToString(top.getColor()));
attList.setAttribute(null, "border-top-width",
String.valueOf(StrictGeomUtility.toExternalValue(top.getWidth())));
attList.setAttribute(null, "border-top-style",
String.valueOf(top.getBorderStyle()));
}
final BorderEdge left = bg.getLeft();
if (left != null)
{
attList.setAttribute(null, "border-left-color",
ColorValueConverter.colorToString(left.getColor()));
attList.setAttribute(null, "border-left-width",
String.valueOf(StrictGeomUtility.toExternalValue(left.getWidth())));
attList.setAttribute(null, "border-left-style",
String.valueOf(left.getBorderStyle()));
}
final BorderEdge bottom = bg.getBottom();
if (bottom != null)
{
attList.setAttribute(null, "border-bottom-color",
ColorValueConverter.colorToString(bottom.getColor()));
attList.setAttribute(null, "border-bottom-width",
String.valueOf(StrictGeomUtility.toExternalValue(bottom.getWidth())));
attList.setAttribute(null, "border-bottom-style",
String.valueOf(bottom.getBorderStyle()));
}
final BorderEdge right = bg.getRight();
if (right != null)
{
attList.setAttribute(null, "border-right-color",
ColorValueConverter.colorToString(right.getColor()));
attList.setAttribute(null, "border-right-width",
String.valueOf(StrictGeomUtility.toExternalValue(right.getWidth())));
attList.setAttribute(null, "border-right-style",
String.valueOf(right.getBorderStyle()));
}
final BorderCorner topLeft = bg.getTopLeft();
if (topLeft != null)
{
attList.setAttribute(null, "border-top-left-x",
String.valueOf(StrictGeomUtility.toExternalValue(topLeft.getWidth())));
attList.setAttribute(null, "border-top-left-y",
String.valueOf(StrictGeomUtility.toExternalValue(topLeft.getHeight())));
}
final BorderCorner topRight = bg.getTopRight();
if (topRight != null)
{
attList.setAttribute(null, "border-top-right-x",
String.valueOf(StrictGeomUtility.toExternalValue(topRight.getWidth())));
attList.setAttribute(null, "border-top-right-y",
String.valueOf(StrictGeomUtility.toExternalValue(topRight.getHeight())));
}
final BorderCorner bottomLeft = bg.getBottomLeft();
if (bottomLeft != null)
{
attList.setAttribute(null, "border-bottom-left-x",
String.valueOf(StrictGeomUtility.toExternalValue(bottomLeft.getWidth())));
attList.setAttribute(null, "border-bottom-left-y",
String.valueOf(StrictGeomUtility.toExternalValue(bottomLeft.getHeight())));
}
final BorderCorner bottomRight = bg.getBottomRight();
if (bottomRight != null)
{
attList.setAttribute(null, "border-bottom-right-x",
String.valueOf(StrictGeomUtility.toExternalValue(bottomRight.getWidth())));
attList.setAttribute(null, "border-bottom-right-y",
String.valueOf(StrictGeomUtility.toExternalValue(bottomRight.getHeight())));
}
writer.writeTag(null, "cell", attList, XmlWriter.CLOSE);
}
writer.writeCloseTag();
}
writer.writeCloseTag();
writer.flush();
}
catch (IOException ioe)
{
// Cannot happen ..
throw new IllegalStateException("Failure while writing the debug-output");