📄 htmlproducer.java
字号:
/**
* Start a new page, start a new table.
*
* @param name the page name
*/
public void beginPage(final String name)
{
super.beginPage(name);
if (isDummy() == false)
{
if (name != null)
{
pout.println(isGenerateXHTML() ? "<hr />" : "<hr>");
pout.println("<h3>");
pout.println(name);
pout.println("</h3>");
pout.println(isGenerateXHTML() ? "<hr />" : "<hr>");
}
pout.println("<p>");
pout.println("<table cellspacing=\"0\" cellpadding=\"0\">");
}
}
/**
* Gets the TableProducer implementation of this TableProducer.
*
* @return the TableProducers TableCellDataFactory, which is used to create
* the TableCellData.
*/
public TableCellDataFactory getCellDataFactory()
{
return cellDataFactory;
}
/**
* Returns true, if the TableProducer is open. Only open producers
* are able to write TableCells or to create TableCellData from Elements.
*
* @return checks, whether the TableProducer is open.
*/
public boolean isOpen()
{
return isOpen;
}
/**
* Merges the backgrounds and creates the StyleSheet information for
* the cell background.
*
* @param background the (unmerged) background styles.
* @param cellbounds the bounds of the cell for which we create the background.
* @return the background style sheet definition.
*/
protected String createHtmlBackgroundStyle(final List background,
final Rectangle2D cellbounds)
{
final TableCellBackground bg = createTableCellStyle(background, cellbounds);
if (bg == null)
{
return null;
}
return styleCollection.getBackgroundStyle(bg);
}
/**
* Generates and writes the HTML table specified by the given TableGridLayout.
*
* @param layout the layouted cells.
*/
private void generatePage(final TableGridLayout layout)
{
pout.println();
final StringBuffer styleBuilder = new StringBuffer();
final StringBuffer spanBuilder = new StringBuffer();
Rectangle2D cellBounds = new Rectangle2D.Float();
for (int y = 0; y < layout.getHeight(); y++)
{
final int lastRowHeight = layout.getRowEnd(y) -
layout.getRowStart(y);
styleBuilder.delete(0, styleBuilder.length());
styleBuilder.append("height: ");
styleBuilder.append(lastRowHeight);
styleBuilder.append("pt");
final String trStyle = styleBuilder.toString();
pout.print("<tr style=\"");
pout.print(trStyle);
pout.println("\">");
for (int x = 0; x < layout.getWidth(); x++)
{
final TableGridLayout.Element gridElement =
layout.getData(x, y);
// no element defined for the given cell...
if (gridElement == null)
{
final int width = layout.getColumnEnd(x) -
layout.getColumnStart(x);
styleBuilder.delete(0, styleBuilder.length());
styleBuilder.append("width: ");
styleBuilder.append(width);
styleBuilder.append("pt");
pout.println(" <!-- No Element -->");
final String tdStyle = styleBuilder.toString();
pout.print(" <td style=\"");
pout.print(tdStyle);
pout.println("\">");
continue;
}
// no data cell defined, but there exists a background defintion
// for that cell.
final TableGridPosition gridPosition =
gridElement.getRoot();
if (gridPosition == null)
{
pout.println("<!-- gridpos null -->");
}
else if (gridPosition.isInvalidCell())
{
pout.println("<!-- invalid cell -->");
}
else if (gridPosition.isOrigin(x, y) == false)
{
// this is a spanned field, skip everything ...
continue;
}
cellBounds = createCellBounds(layout, x, y, cellBounds);
final String backgroundStyle =
createHtmlBackgroundStyle(gridElement.getBackground(), cellBounds);
// Something's wrong with the given grid position, we can't handle that
if (gridPosition == null ||
gridPosition.isInvalidCell())
{
final int width = layout.getColumnEnd(x) - layout.getColumnStart(x);
styleBuilder.delete(0, styleBuilder.length());
styleBuilder.append("width: ");
styleBuilder.append(width);
styleBuilder.append("pt");
if ((backgroundStyle != null) && (backgroundStyle.trim().length() != 0))
{
styleBuilder.append("; ");
styleBuilder.append(backgroundStyle);
}
String tdStyle = styleBuilder.toString();
pout.print(" <td style=\"");
pout.print(tdStyle);
pout.println("\">");
continue;
}
spanBuilder.delete(0, spanBuilder.length());
if (gridPosition.getRowSpan() > 1)
{
spanBuilder.append(" rowspan=\"");
spanBuilder.append(gridPosition.getRowSpan());
spanBuilder.append("\"");
}
// if we have a colspan, we have to compute the width over the all
// columns (thanks to the anonymous patch implementor)
if (gridPosition.getColSpan() > 1)
{
final int widthColSpan =
layout.getColumnEnd(x + gridPosition.getColSpan() - 1) -
layout.getColumnStart(x);
styleBuilder.delete(0, styleBuilder.length());
styleBuilder.append("width: ");
styleBuilder.append(widthColSpan);
styleBuilder.append("pt");
// replace old value for width in tdStyle
spanBuilder.append(" colspan=\"");
spanBuilder.append(gridPosition.getColSpan());
spanBuilder.append("\"");
}
else
{
final int width = layout.getColumnEnd(x) - layout.getColumnStart(x);
styleBuilder.delete(0, styleBuilder.length());
styleBuilder.append("width: ");
styleBuilder.append(width);
styleBuilder.append("pt");
}
pout.print(" <td style=\"");
pout.print(styleBuilder.toString());
pout.print("\" ");
// add spanBuilder
pout.print(spanBuilder.toString());
pout.print(">");
// finally we print real data ...
HtmlCellData cellData = (HtmlCellData) gridPosition.getElement();
if (isCreateBodyFragment() == false &&
styleCollection.isRegistered(cellData.getStyle()))
{
// stylesheet defined in the header
pout.print("<div class=\"");
pout.print(styleCollection.lookupName(cellData.getStyle()));
pout.print("\">");
}
else
{
// stylesheet defined as inline style
pout.print("<div style=\"");
pout.print(styleCollection.createStyleSheetDefinition(cellData.getStyle()));
pout.print("\">");
}
cellData.write(pout, filesystem);
pout.print("</div>");
pout.println("</td>");
x += gridPosition.getColSpan() - 1;
}
pout.println("</tr>");
}
}
// /**
// * Generates and writes the HTML table specified by the given TableGridLayout.
// *
// * @param layout the layouted cells.
// */
// private void generateTableLayout(final TableGridLayout layout)
// {
// StringBuffer styleBuilder = new StringBuffer();
// for (int y = 0; y < layout.getHeight(); y++)
// {
// final int lastRowHeight = layout.getRowEnd(y) - layout.getRowStart(y);
//
// styleBuilder.delete(0, styleBuilder.length());
// styleBuilder.append("height");
// styleBuilder.append(lastRowHeight);
// styleBuilder.append("pt");
// styleCollection.registerTableStyle(styleBuilder.toString(), true);
//
// for (int x = 0; x < layout.getWidth(); x++)
// {
// final TableGridLayout.Element gridElement = layout.getData(x, y);
// // no element defined for the given cell...
// if (gridElement == null)
// {
// final int width = layout.getColumnEnd(x) - layout.getColumnStart(x);
// styleBuilder.delete(0, styleBuilder.length());
// styleBuilder.append("width");
// styleBuilder.append(width);
// styleBuilder.append("pt");
// styleCollection.registerTableStyle(styleBuilder.toString(), false);
// continue;
// }
//
// // no data cell defined, but there exists a background defintion
// // for that cell.
// final TableGridPosition gridPosition = gridElement.getRoot();
// if (gridPosition == null || gridPosition.isInvalidCell())
// {
// final int width = layout.getColumnEnd(x) - layout.getColumnStart(x);
// styleBuilder.delete(0, styleBuilder.length());
// styleBuilder.append("width");
// styleBuilder.append(width);
// styleBuilder.append("pt");
//
// final String style = createHtmlBackgroundStyle(gridElement.getBackground());
// if (style != null)
// {
// styleBuilder.append("; ");
// styleBuilder.append(style);
// }
// styleCollection.registerTableStyle(styleBuilder.toString(), false);
// continue;
// }
//
// // a spanned field
// if (gridPosition.isOrigin(x, y) == false)
// {
// // this is a spanned field.
// continue;
// }
// styleBuilder.delete(0, styleBuilder.length());
// styleBuilder.append("width");
// styleBuilder.append((int) gridPosition.getBounds().getWidth());
// styleBuilder.append("pt");
// styleBuilder.append("; height:");
// styleBuilder.append((int) gridPosition.getBounds().getHeight());
// styleBuilder.append("pt");
// final String style = createHtmlBackgroundStyle(gridElement.getBackground());
// if (style != null)
// {
// styleBuilder.append("; ");
// styleBuilder.append(style);
// }
//
// x += gridPosition.getColSpan() - 1;
// }
// }
// }
/**
* Checks, whether to create a html body fragment. This fragment contains
* no html header an generates no global CSS section.
*
* @return true, if a body fragment is used, false otherwise.
*/
public boolean isCreateBodyFragment()
{
return getProperty(BODY_FRAGMENT, "false").equals("true");
}
/**
* Defines, whether to create a html body fragment. This fragment contains
* no html header an generates no global CSS section.
*
* @param createBodyFragment true, if a body fragment should be created,
* false otherwise.
*/
public void setCreateBodyFragment(final boolean createBodyFragment)
{
setProperty(BODY_FRAGMENT, String.valueOf(createBodyFragment));
}
/**
* Configures the table producer by reading the configuration settings from
* the given map.
*
* @param configuration the configuration supplied by the table processor.
*/
public void configure(final Properties configuration)
{
super.configure(configuration);
this.cellDataFactory = new HtmlCellDataFactory(styleCollection, isGenerateXHTML());
}
/**
* Checks, whether this target should generate XHTML instead of HTML4 code.
*
* @return true, if XHTML code should be generated, false otherwise.
*/
protected boolean isGenerateXHTML()
{
return getProperty(GENERATE_XHTML, "false").equals("true");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -