final boolean incremental)
throws ContentProcessingException
{
try
{
final SheetLayout sheetLayout = contentProducer.getSheetLayout();
if (documentContentItem == null)
{
this.cellBackgroundProducer = new CellBackgroundProducer
(metaData.isFeatureSupported(AbstractTableOutputProcessor.TREAT_ELLIPSE_AS_RECTANGLE),
metaData.isFeatureSupported(OutputProcessorFeature.UNALIGNED_PAGEBANDS));
this.configuration = metaData.getConfiguration();
this.allowRawLinkTargets = "true".equals
(configuration.getConfigProperty(HtmlTableModule.ALLOW_RAW_LINK_TARGETS));
this.copyExternalImages = "true".equals
(configuration.getConfigProperty(HtmlTableModule.COPY_EXTERNAL_IMAGES));
documentContentItem = contentLocation.createItem
(contentNameGenerator.generateName(null, "text/html"));
final OutputStream out = documentContentItem.getOutputStream();
final String encoding = configuration.getConfigProperty
(HtmlTableModule.ENCODING, EncodingRegistry.getPlatformDefaultEncoding());
writer = new BufferedWriter(new OutputStreamWriter(out, encoding));
final DefaultTagDescription td = new DefaultTagDescription();
td.configure(getConfiguration(), "org.pentaho.reporting.engine.classic.core.modules.output.table.html.");
if (isCreateBodyFragment() == false)
{
if (isInlineStylesRequested())
{
this.styleManager = new InlineStyleManager();
this.xmlWriter = new XmlWriter(writer, td);
this.xmlWriter.addImpliedNamespace(HtmlPrinter.XHTML_NAMESPACE, "");
this.xmlWriter.setHtmlCompatiblityMode(true);
writeCompleteHeader(xmlWriter, writer, contentProducer, logicalPage, null, null);
}
else
{
if (isExternalStyleSheetRequested())
{
this.styleFile = dataLocation.createItem(dataNameGenerator.generateName("style", "text/css"));
this.styleFileUrl = urlRewriter.rewrite(documentContentItem, styleFile);
}
this.styleManager = new GlobalStyleManager();
if (isForceBufferedWriting() == false && styleFile != null)
{
this.xmlWriter = new XmlWriter(writer, td);
this.xmlWriter.addImpliedNamespace(HtmlPrinter.XHTML_NAMESPACE, "");
this.xmlWriter.setHtmlCompatiblityMode(true);
writeCompleteHeader(xmlWriter, writer, contentProducer, logicalPage, styleFileUrl, null);
}
else
{
this.bufferWriter = new MemoryStringWriter(1024 * 512);
this.xmlWriter = new XmlWriter(bufferWriter, td);
this.xmlWriter.setAdditionalIndent(1);
this.xmlWriter.addImpliedNamespace(HtmlPrinter.XHTML_NAMESPACE, "");
this.xmlWriter.setHtmlCompatiblityMode(true);
}
}
this.xmlWriter.writeTag(HtmlPrinter.XHTML_NAMESPACE, "body", XmlWriterSupport.OPEN);
}
else
{
this.styleManager = new InlineStyleManager();
this.xmlWriter = new XmlWriter(writer, td);
this.xmlWriter.addImpliedNamespace(HtmlPrinter.XHTML_NAMESPACE, "");
this.xmlWriter.setHtmlCompatiblityMode(true);
}
final ReportAttributeMap map = logicalPage.getAttributes();
final Object rawContent = map.getAttribute(AttributeNames.Html.NAMESPACE,
AttributeNames.Html.EXTRA_RAW_CONTENT);
if (rawContent != null)
{
xmlWriter.writeText(String.valueOf(rawContent));
}
// table name
final String sheetName = contentProducer.getSheetName();
if (sheetName != null)
{
xmlWriter.writeTag(HtmlPrinter.XHTML_NAMESPACE, "h1", createSheetNameAttributes(), XmlWriterSupport.OPEN);
xmlWriter.writeTextNormalized(sheetName, true);
xmlWriter.writeCloseTag();
}
// table
xmlWriter.writeTag(HtmlPrinter.XHTML_NAMESPACE, "table", createTableAttributes(sheetLayout, logicalPage),
XmlWriterSupport.OPEN);
writeColumnDeclaration(sheetLayout);
}
final int colCount = sheetLayout.getColumnCount();
final boolean emptyCellsUseCSS = isEmptyCellsUseCSS();
final int startRow = contentProducer.getFinishedRows();
final int finishRow = contentProducer.getFilledRows();
if (textExtractor == null)
{
textExtractor = new HtmlTextExtractor(metaData, xmlWriter, styleManager, this);
}
for (int row = startRow; row < finishRow; row++)
{
xmlWriter.writeTag(HtmlPrinter.XHTML_NAMESPACE, "tr",
createRowAttributes(logicalPage, sheetLayout, row, contentProducer), XmlWriterSupport.OPEN);
for (int col = 0; col < colCount; col++)
{
final RenderBox content = contentProducer.getContent(row, col);
final int sectionType = contentProducer.getSectionType(row, col);
if (content == null)
{
final CellBackground background = cellBackgroundProducer.getBackgroundAt
(logicalPage, sheetLayout, col, row, true, sectionType);
if (background == null)
{
if (emptyCellsUseCSS)
{
xmlWriter.writeTag(HtmlPrinter.XHTML_NAMESPACE, "td", XmlWriterSupport.CLOSE);
}
else
{
final AttributeList attrs = new AttributeList();
attrs.setAttribute(HtmlPrinter.XHTML_NAMESPACE, "style", "font-size: 1pt");
xmlWriter.writeTag(HtmlPrinter.XHTML_NAMESPACE, "td", attrs, XmlWriterSupport.OPEN);
xmlWriter.writeText(" ");
xmlWriter.writeCloseTag();
}
continue;
}
// Background cannot be null at this point ..
final String[] anchor = background.getAnchors();
if (anchor.length == 0 && emptyCellsUseCSS)
{
final AttributeList cellAttributes = createCellAttributes(1, 1, null, background, null, null);
xmlWriter.writeTag(HtmlPrinter.XHTML_NAMESPACE, "td", cellAttributes, XmlWriterSupport.CLOSE);
}
else
{
final AttributeList cellAttributes =
createCellAttributes(1, 1, null, background, HtmlPrinter.EMPTY_CELL_ATTRNAMES,
HtmlPrinter.EMPTY_CELL_ATTRVALS);
xmlWriter.writeTag(HtmlPrinter.XHTML_NAMESPACE, "td", cellAttributes, XmlWriterSupport.OPEN);
for (int i = 0; i < anchor.length; i++)
{
xmlWriter.writeTag(HtmlPrinter.XHTML_NAMESPACE, "a", "name", anchor[i], XmlWriterSupport.CLOSE);
}
xmlWriter.writeText(" ");
xmlWriter.writeCloseTag();
}
continue;
}
if (content.isCommited() == false)
{
throw new InvalidReportStateException(
"Uncommited content encountered: " + row + ", " + col + ' ' + content);
}
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 ..
if (content.isFinished())
{
continue;
}
}
final int colSpan = sheetLayout.getColSpan(col, content.getX() + content.getWidth());
final int rowSpan = sheetLayout.getRowSpan(row, content.getY() + content.getHeight() + contentOffset);
final CellBackground realBackground = cellBackgroundProducer.getBackgroundAt
(logicalPage, sheetLayout, col, row, colSpan, rowSpan, true, sectionType);