}
private void processElement(final AttributeMap attrs, final String namespace, final String elementType)
throws IOException, ReportProcessingException
{
final XmlWriter xmlWriter = getXmlWriter();
if (ReportTargetUtil.isElementOfType(OfficeNamespaces.TABLE_NS, "table", attrs))
{
// a new table means we must clear our "calculated" table boundary array cache
boundariesForTableArray = null;
final String tableStyle = (String) attrs.getAttribute(OfficeNamespaces.TABLE_NS, "style-name");
if (tableStyle == null)
{
tableBackgroundColor = null;
}
else
{
final Object raw = StyleUtilities.queryStyle(getPredefinedStylesCollection(), "table", tableStyle,
"table-properties", OfficeNamespaces.FO_NS, "background-color");
if (raw == null || "transparent".equals(raw))
{
tableBackgroundColor = null;
}
else
{
tableBackgroundColor = String.valueOf(raw);
}
}
return;
}
if (ReportTargetUtil.isElementOfType(OfficeNamespaces.TABLE_NS, "table-column", attrs)
|| ReportTargetUtil.isElementOfType(OfficeNamespaces.TABLE_NS, "table-columns", attrs))
{
return;
}
// covered-table-cell elements may appear in the input from row or column spans. In the event that we hit a
// column-span we simply ignore these elements because we are going to adjust the span to fit the uniform table.
if (ReportTargetUtil.isElementOfType(OfficeNamespaces.TABLE_NS, "covered-table-cell", attrs))
{
if (columnSpanCounter > 0)
{
columnSpanCounter--;
}
if (columnSpanCounter == 0)
{
// if we weren't expecting a covered-table-cell, let's use it, it's probably from a row-span
columnCounter++;
final int span = getColumnSpanForCell(tableCounter, columnCounter, 1);
// use the calculated span for the column in the uniform table to create any additional covered-table-cell
// elements
for (int i = 0; i < span; i++)
{
xmlWriter.writeTag(namespace, "covered-table-cell", null, XmlWriter.CLOSE);
}
}
return;
}
if (ReportTargetUtil.isElementOfType(OfficeNamespaces.TABLE_NS, "table-row", attrs))
{
// a new row means our column counter gets reset
columnCounter = 0;
// Lets make sure the color of the table is ok ..
if (tableBackgroundColor != null)
{
final String styleName = (String) attrs.getAttribute(OfficeNamespaces.TABLE_NS, "style-name");
final OfficeStyle style = deriveStyle("table-row", styleName);
Element tableRowProperties = style.getTableRowProperties();
if (tableRowProperties == null)
{
tableRowProperties = new Section();
tableRowProperties.setNamespace(OfficeNamespaces.STYLE_NS);
tableRowProperties.setType("table-row-properties");
tableRowProperties.setAttribute(OfficeNamespaces.FO_NS, "background-color", tableBackgroundColor);
style.addNode(tableRowProperties);
}
else
{
final Object oldValue = tableRowProperties.getAttribute(OfficeNamespaces.FO_NS, "background-color");
if (oldValue == null || "transparent".equals(oldValue))
{
tableRowProperties.setAttribute(OfficeNamespaces.FO_NS, "background-color", tableBackgroundColor);
}
}
attrs.setAttribute(OfficeNamespaces.TABLE_NS, "style-name", style.getStyleName());
}
}
else if (ReportTargetUtil.isElementOfType(OfficeNamespaces.TABLE_NS, "table-cell", attrs))
{
columnCounter++;
final String numColSpanStr = (String) attrs.getAttribute(namespace, "number-columns-spanned");
int initialColumnSpan = columnSpanCounter = 1;
if (numColSpanStr != null)
{
initialColumnSpan = Integer.parseInt(numColSpanStr);
columnSpanCounter = initialColumnSpan;
}
final int span = getColumnSpanForCell(tableCounter, columnCounter, initialColumnSpan);
if (initialColumnSpan > 1)
{
// add the initial column span to our column counter index (subtract 1, since it is counted by default)
columnCounter += initialColumnSpan - 1;
}
// if (span < initialColumnSpan)
// {
// // ColumnBoundary cbs[] = getBoundariesForTable(tableCounter);
// // for (int i = 0; i < cbs.length; i++)
// // {
// // System.out.print(cbs[i].getBoundary() + " ");
// // }
// // System.out.println();
//
// Log.error("A cell cannot span less than the declared columns: Declared=" + initialColumnSpan + " Computed="
// + span);
// }
// there's no point to create number-columns-spanned attributes if we only span 1 column
if (span > 1)
{
attrs.setAttribute(namespace, "number-columns-spanned", "" + span);
}
// we must also generate "covered-table-cell" elements for each column spanned
// but we'll do this in the endElement, after we close this "table-cell"
}
// All styles have to be processed or you will loose the paragraph-styles and inline text-styles.
// ..
performStyleProcessing(attrs);
final AttributeList attrList = buildAttributeList(attrs);
xmlWriter.writeTag(namespace, elementType, attrList, XmlWriter.OPEN);
// System.out.println("elementType = " + elementType);
}