Base abstract class for simple export views.
A class that extends BaseExportView simply need to provide delimiters for rows and columns.
| Method from org.displaytag.export.BaseExportView Detail: |
public void doExport(Writer out) throws IOException, JspException {
if (log.isDebugEnabled())
{
log.debug(getClass().getName());
}
final String DOCUMENT_START = getDocumentStart();
final String DOCUMENT_END = getDocumentEnd();
final String ROW_START = getRowStart();
final String ROW_END = getRowEnd();
final String CELL_START = getCellStart();
final String CELL_END = getCellEnd();
final boolean ALWAYS_APPEND_CELL_END = getAlwaysAppendCellEnd();
final boolean ALWAYS_APPEND_ROW_END = getAlwaysAppendRowEnd();
// document start
write(out, DOCUMENT_START);
if (this.header)
{
write(out, doHeaders());
}
// get the correct iterator (full or partial list according to the exportFull field)
RowIterator rowIterator = this.model.getRowIterator(this.exportFull);
// iterator on rows
while (rowIterator.hasNext())
{
Row row = rowIterator.next();
if (this.model.getTableDecorator() != null)
{
String stringStartRow = this.model.getTableDecorator().startRow();
write(out, stringStartRow);
}
// iterator on columns
ColumnIterator columnIterator = row.getColumnIterator(this.model.getHeaderCellList());
write(out, ROW_START);
while (columnIterator.hasNext())
{
Column column = columnIterator.nextColumn();
// Get the value to be displayed for the column
String value = escapeColumnValue(column.getValue(this.decorated));
write(out, CELL_START);
write(out, value);
if (ALWAYS_APPEND_CELL_END || columnIterator.hasNext())
{
write(out, CELL_END);
}
}
if (ALWAYS_APPEND_ROW_END || rowIterator.hasNext())
{
write(out, ROW_END);
}
}
// document end
write(out, DOCUMENT_END);
}
|
protected String doHeaders() {
final String ROW_START = getRowStart();
final String ROW_END = getRowEnd();
final String CELL_START = getCellStart();
final String CELL_END = getCellEnd();
final boolean ALWAYS_APPEND_CELL_END = getAlwaysAppendCellEnd();
StringBuffer buffer = new StringBuffer(1000);
Iterator iterator = this.model.getHeaderCellList().iterator();
// start row
if (ROW_START != null)
{
buffer.append(ROW_START);
}
while (iterator.hasNext())
{
HeaderCell headerCell = (HeaderCell) iterator.next();
String columnHeader = headerCell.getTitle();
if (columnHeader == null)
{
columnHeader = StringUtils.capitalize(headerCell.getBeanPropertyName());
}
columnHeader = escapeColumnValue(columnHeader);
if (CELL_START != null)
{
buffer.append(CELL_START);
}
if (columnHeader != null)
{
buffer.append(columnHeader);
}
if (CELL_END != null && (ALWAYS_APPEND_CELL_END || iterator.hasNext()))
{
buffer.append(CELL_END);
}
}
// end row
if (ROW_END != null)
{
buffer.append(ROW_END);
}
return buffer.toString();
}
|
abstract protected String escapeColumnValue(Object value)
can be implemented to escape values for different output. |
abstract protected boolean getAlwaysAppendCellEnd()
always append cell end string? |
abstract protected boolean getAlwaysAppendRowEnd()
always append row end string? |
abstract protected String getCellEnd()
String to add after a cell. |
protected String getCellStart() {
return null;
}
String to add before a cell. |
protected String getDocumentEnd() {
return null;
}
String to add to the end of document. |
protected String getDocumentStart() {
return null;
}
String to add to the top of document. |
protected String getRowEnd() {
return null;
}
String to add after a row. |
protected String getRowStart() {
return null;
}
String to add before a row. |
public boolean outputPage() {
return false;
}
|
public void setParameters(TableModel tableModel,
boolean exportFullList,
boolean includeHeader,
boolean decorateValues) {
this.model = tableModel;
this.exportFull = exportFullList;
this.header = includeHeader;
this.decorated = decorateValues;
}
|