📄 htmltablewriter.java
字号:
/**
* Licensed under the Artistic License; you may not use this file
* except in compliance with the License.
* You may obtain a copy of the License at
*
* http://displaytag.sourceforge.net/license.html
*
* THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
package org.displaytag.render;
import java.io.IOException;
import java.text.MessageFormat;
import java.util.Iterator;
import java.util.Map;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.displaytag.exception.DecoratorException;
import org.displaytag.exception.ObjectLookupException;
import org.displaytag.exception.WrappedRuntimeException;
import org.displaytag.model.Column;
import org.displaytag.model.HeaderCell;
import org.displaytag.model.Row;
import org.displaytag.model.TableModel;
import org.displaytag.pagination.PaginatedList;
import org.displaytag.pagination.SmartListHelper;
import org.displaytag.properties.MediaTypeEnum;
import org.displaytag.properties.SortOrderEnum;
import org.displaytag.properties.TableProperties;
import org.displaytag.tags.CaptionTag;
import org.displaytag.tags.TableTagParameters;
import org.displaytag.util.Anchor;
import org.displaytag.util.Href;
import org.displaytag.util.HtmlAttributeMap;
import org.displaytag.util.ParamEncoder;
import org.displaytag.util.TagConstants;
/**
* A table writer that formats a table in HTML and writes it to a JSP page.
* @author Fabrizio Giustina
* @author Jorge L. Barroso
* @version $Id$
* @see org.displaytag.render.TableWriterTemplate
* @since 1.1
*/
public class HtmlTableWriter extends TableWriterAdapter
{
/**
* Logger.
*/
private static Log log = LogFactory.getLog(HtmlTableWriter.class);
/**
* <code>TableModel</code>
*/
private TableModel tableModel;
/**
* <code>TableProperties</code>
*/
private TableProperties properties;
/**
* Output destination.
*/
private JspWriter out;
/**
* The param encoder used to generate unique parameter names. Initialized at the first use of encodeParameter().
*/
private ParamEncoder paramEncoder;
/**
* base href used for links.
*/
private Href baseHref;
/**
* add export links.
*/
private boolean export;
private CaptionTag captionTag;
/**
* The paginated list containing the external pagination and sort parameters The presence of this paginated list is
* what determines if external pagination and sorting is used or not.
*/
private PaginatedList paginatedList;
/**
* Used by various functions when the person wants to do paging.
*/
private SmartListHelper listHelper;
/**
* page size.
*/
private int pagesize;
private HtmlAttributeMap attributeMap;
/**
* Unique table id.
*/
private String uid;
/**
* This table writer uses a <code>TableTag</code> and a <code>JspWriter</code> to do its work.
* @param tableTag <code>TableTag</code> instance called back by this writer.
* @param out The output destination.
*/
public HtmlTableWriter(
TableModel tableModel,
TableProperties tableProperties,
Href baseHref,
boolean export,
JspWriter out,
CaptionTag captionTag,
PaginatedList paginatedList,
SmartListHelper listHelper,
int pagesize,
HtmlAttributeMap attributeMap,
String uid)
{
this.tableModel = tableModel;
this.properties = tableProperties;
this.baseHref = baseHref;
this.export = export;
this.out = out;
this.captionTag = captionTag;
this.paginatedList = paginatedList;
this.listHelper = listHelper;
this.pagesize = pagesize;
this.attributeMap = attributeMap;
this.uid = uid;
}
/**
* Writes a banner containing search result and paging navigation above an HTML table to a JSP page.
* @see org.displaytag.render.TableWriterTemplate#writeTopBanner(org.displaytag.model.TableModel)
*/
protected void writeTopBanner(TableModel model)
{
writeSearchResultAndNavigation();
}
/**
* Writes an HTML table's opening tags to a JSP page.
* @see org.displaytag.render.TableWriterTemplate#writeTableOpener(org.displaytag.model.TableModel)
*/
protected void writeTableOpener(TableModel model)
{
this.write(getOpenTag());
}
/**
* Writes an HTML table's caption to a JSP page.
* @see org.displaytag.render.TableWriterTemplate#writeCaption(org.displaytag.model.TableModel)
*/
protected void writeCaption(TableModel model)
{
this.write(captionTag.getOpenTag() + model.getCaption() + captionTag.getCloseTag());
}
/**
* Writes an HTML table's footer to a JSP page; HTML requires tfoot to appear before tbody.
* @see org.displaytag.render.TableWriterTemplate#writeFooter(org.displaytag.model.TableModel)
*/
protected void writePreBodyFooter(TableModel model)
{
this.write(TagConstants.TAG_TFOOTER_OPEN);
this.write(model.getFooter());
this.write(TagConstants.TAG_TFOOTER_CLOSE);
}
/**
* Writes the start of an HTML table's body to a JSP page.
* @see org.displaytag.render.TableWriterTemplate#writeTableBodyOpener(org.displaytag.model.TableModel)
*/
protected void writeTableBodyOpener(TableModel model)
{
this.write(TagConstants.TAG_TBODY_OPEN);
}
/**
* Writes the end of an HTML table's body to a JSP page.
* @see org.displaytag.render.TableWriterTemplate#writeTableBodyCloser(org.displaytag.model.TableModel)
*/
protected void writeTableBodyCloser(TableModel model)
{
this.write(TagConstants.TAG_TBODY_CLOSE);
}
/**
* Writes the closing structure of an HTML table to a JSP page.
* @see org.displaytag.render.TableWriterTemplate#writeTableCloser(org.displaytag.model.TableModel)
*/
protected void writeTableCloser(TableModel model)
{
this.write(TagConstants.TAG_OPENCLOSING);
this.write(TagConstants.TABLE_TAG_NAME);
this.write(TagConstants.TAG_CLOSE);
}
/**
* Writes a banner containing search result, paging navigation, and export links below an HTML table to a JSP page.
* @see org.displaytag.render.TableWriterTemplate#writeBottomBanner(org.displaytag.model.TableModel)
*/
protected void writeBottomBanner(TableModel model)
{
writeNavigationAndExportLinks();
}
/**
* @see org.displaytag.render.TableWriterTemplate#writeDecoratedTableFinish(org.displaytag.model.TableModel)
*/
protected void writeDecoratedTableFinish(TableModel model)
{
model.getTableDecorator().finish();
}
/**
* @see org.displaytag.render.TableWriterTemplate#writeDecoratedRowStart(org.displaytag.model.TableModel)
*/
protected void writeDecoratedRowStart(TableModel model)
{
this.write(model.getTableDecorator().startRow());
}
/**
* Writes an HTML table's row-opening tag to a JSP page.
* @see org.displaytag.render.TableWriterTemplate#writeRowOpener(org.displaytag.model.Row)
*/
protected void writeRowOpener(Row row)
{
this.write(row.getOpenTag());
}
/**
* Writes an HTML table's column-opening tag to a JSP page.
* @see org.displaytag.render.TableWriterTemplate#writeColumnOpener(org.displaytag.model.Column)
*/
protected void writeColumnOpener(Column column) throws ObjectLookupException, DecoratorException
{
this.write(column.getOpenTag());
}
/**
* Writes an HTML table's column-closing tag to a JSP page.
* @see org.displaytag.render.TableWriterTemplate#writeColumnCloser(org.displaytag.model.Column)
*/
protected void writeColumnCloser(Column column)
{
this.write(column.getCloseTag());
}
/**
* Writes to a JSP page an HTML table row that has no columns.
* @see org.displaytag.render.TableWriterTemplate#writeRowWithNoColumns(java.lang.String)
*/
protected void writeRowWithNoColumns(String rowValue)
{
this.write(TagConstants.TAG_TD_OPEN);
this.write(rowValue);
this.write(TagConstants.TAG_TD_CLOSE);
}
/**
* Writes an HTML table's row-closing tag to a JSP page.
* @see org.displaytag.render.TableWriterTemplate#writeRowCloser(org.displaytag.model.Row)
*/
protected void writeRowCloser(Row row)
{
this.write(row.getCloseTag());
}
/**
* @see org.displaytag.render.TableWriterTemplate#writeDecoratedRowFinish(org.displaytag.model.TableModel)
*/
protected void writeDecoratedRowFinish(TableModel model)
{
this.write(model.getTableDecorator().finishRow());
}
/**
* Writes an HTML message to a JSP page explaining that the table model contains no data.
* @see org.displaytag.render.TableWriterTemplate#writeEmptyListMessage(java.lang.String)
*/
protected void writeEmptyListMessage(String emptyListMessage)
{
this.write(emptyListMessage);
}
/**
* Writes a HTML table column value to a JSP page.
* @see org.displaytag.render.TableWriterTemplate#writeColumnValue(java.lang.String,org.displaytag.model.Column)
*/
protected void writeColumnValue(Object value, Column column)
{
this.write(value);
}
/**
* Writes an HTML message to a JSP page explaining that the row contains no data.
* @see org.displaytag.render.TableWriterTemplate#writeEmptyListRowMessage(java.lang.String)
*/
protected void writeEmptyListRowMessage(String message)
{
this.write(message);
}
/**
* Writes an HTML table's column header to a JSP page.
* @see org.displaytag.render.TableWriterTemplate#writeTableHeader(org.displaytag.model.TableModel)
*/
protected void writeTableHeader(TableModel model)
{
if (log.isDebugEnabled())
{
log.debug("[" + tableModel.getId() + "] getTableHeader called");
}
// open thead
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -