reportdescriptionwriter.java
来自「swing编写的库存管理程序。毕业设计类」· Java 代码 · 共 533 行 · 第 1/2 页
JAVA
533 行
/**
* ========================================
* JFreeReport : a free Java report library
* ========================================
*
* Project Info: http://www.jfree.org/jfreereport/index.html
* Project Lead: Thomas Morgner;
*
* (C) Copyright 2000-2003, by Simba Management Limited and Contributors.
*
* This library is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation;
* either version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
* ----------------------------
* ReportDescriptionWriter.java
* ----------------------------
* (C)opyright 2003, by Thomas Morgner and Contributors.
*
* Original Author: Thomas Morgner;
* Contributor(s): David Gilbert (for Simba Management Limited);
*
* $Id: ReportDescriptionWriter.java,v 1.5.2.1 2003/12/21 23:28:46 taqua Exp $
*
* Changes
* -------
* 21-Feb-2003 : Added standard header and Javadocs (DG);
*
*/
package org.jfree.report.modules.parser.extwriter;
import java.io.IOException;
import java.io.Writer;
import java.util.Iterator;
import java.util.List;
import org.jfree.report.Band;
import org.jfree.report.Element;
import org.jfree.report.Group;
import org.jfree.report.filter.DataSource;
import org.jfree.report.filter.EmptyDataSource;
import org.jfree.report.filter.templates.Template;
import org.jfree.report.layout.BandLayoutManager;
import org.jfree.report.modules.parser.base.CommentHandler;
import org.jfree.report.modules.parser.base.CommentHintPath;
import org.jfree.report.modules.parser.ext.BandHandler;
import org.jfree.report.modules.parser.ext.DataSourceHandler;
import org.jfree.report.modules.parser.ext.ElementHandler;
import org.jfree.report.modules.parser.ext.ExtParserModuleInit;
import org.jfree.report.modules.parser.ext.ExtReportHandler;
import org.jfree.report.modules.parser.ext.GroupHandler;
import org.jfree.report.modules.parser.ext.GroupsHandler;
import org.jfree.report.modules.parser.ext.ReportDescriptionHandler;
import org.jfree.report.modules.parser.ext.TemplatesHandler;
import org.jfree.report.modules.parser.ext.factory.datasource.DataSourceCollector;
import org.jfree.report.modules.parser.ext.factory.templates.TemplateCollector;
import org.jfree.report.modules.parser.ext.factory.templates.TemplateDescription;
import org.jfree.report.style.ElementStyleSheet;
import org.jfree.report.style.StyleKey;
import org.jfree.xml.factory.objects.ObjectDescription;
import org.jfree.xml.factory.objects.ObjectFactoryException;
import org.jfree.xml.writer.AttributeList;
/**
* A report description writer. The
* {@link org.jfree.report.modules.parser.extwriter.ReportDefinitionWriter} class is
* responsible for writing the complete XML report definition file, but it delegates
* one large section (the report description) to this class.
*
* @author Thomas Morgner.
*/
public class ReportDescriptionWriter extends AbstractXMLDefinitionWriter
{
/** The comment hint path used to store comments from the ext-parser. */
private static final CommentHintPath REPORT_DESCRIPTION_HINT_PATH =
new CommentHintPath(new String[]
{ExtParserModuleInit.REPORT_DEFINITION_TAG,
ExtReportHandler.REPORT_DESCRIPTION_TAG});
/**
* Creates a new report description writer.
*
* @param reportWriter the report writer.
* @param indent the current indention level.
*/
public ReportDescriptionWriter(final ReportWriter reportWriter, final int indent)
{
super(reportWriter, indent);
}
/**
* Writes a report description element to a character stream writer.
*
* @param writer the character stream writer.
*
* @throws IOException if there is an I/O problem.
* @throws ReportWriterException if there is a problem writing the report.
*/
public void write(final Writer writer) throws IOException, ReportWriterException
{
writeComment(writer, REPORT_DESCRIPTION_HINT_PATH, CommentHandler.OPEN_TAG_COMMENT);
writeTag(writer, ExtReportHandler.REPORT_DESCRIPTION_TAG);
writeBand(writer, ReportDescriptionHandler.REPORT_HEADER_TAG,
getReport().getReportHeader(), null, REPORT_DESCRIPTION_HINT_PATH);
writeBand(writer, ReportDescriptionHandler.REPORT_FOOTER_TAG,
getReport().getReportFooter(), null, REPORT_DESCRIPTION_HINT_PATH);
writeBand(writer, ReportDescriptionHandler.PAGE_HEADER_TAG,
getReport().getPageHeader(), null, REPORT_DESCRIPTION_HINT_PATH);
writeBand(writer, ReportDescriptionHandler.PAGE_FOOTER_TAG,
getReport().getPageFooter(), null, REPORT_DESCRIPTION_HINT_PATH);
writeBand(writer, ReportDescriptionHandler.WATERMARK_TAG,
getReport().getWatermark(), null, REPORT_DESCRIPTION_HINT_PATH);
writeGroups(writer);
writeBand(writer, ReportDescriptionHandler.ITEMBAND_TAG,
getReport().getItemBand(), null, REPORT_DESCRIPTION_HINT_PATH);
writeComment(writer, REPORT_DESCRIPTION_HINT_PATH, CommentHandler.CLOSE_TAG_COMMENT);
writeCloseTag(writer, ExtReportHandler.REPORT_DESCRIPTION_TAG);
}
/**
* Writes an element for a report band.
*
* @param writer a character stream writer.
* @param tagName the tag name (for the band).
* @param band the band.
* @param parent the parent band.
* @param path the comment path used to read stored comments from the ext-parser.
*
* @throws IOException if there is an I/O problem.
* @throws ReportWriterException if there is a problem writing the report.
*/
private void writeBand(final Writer writer, final String tagName,
final Band band, final Band parent,
final CommentHintPath path)
throws IOException, ReportWriterException
{
if (isBandEmpty(band))
{
return;
}
final CommentHintPath newPath = path.getInstance();
newPath.addName(band);
writeComment(writer, newPath, CommentHandler.OPEN_TAG_COMMENT);
if (band.getName().startsWith(Band.ANONYMOUS_BAND_PREFIX))
{
writeTag(writer, tagName);
}
else
{
writeTag(writer, tagName, "name", band.getName(), OPEN);
}
final ElementStyleSheet styleSheet = band.getStyle();
if (isStyleSheetEmpty(styleSheet) == false)
{
final CommentHintPath stylePath = newPath.getInstance();
stylePath.addName(ElementHandler.STYLE_TAG);
writeComment(writer, stylePath, CommentHandler.OPEN_TAG_COMMENT);
writeTag(writer, ElementHandler.STYLE_TAG);
ElementStyleSheet parentSheet = null;
if (parent != null)
{
parentSheet = parent.getBandDefaults();
}
final StyleWriter styleWriter =
new StyleWriter(getReportWriter(), band.getStyle(),
parentSheet, getIndentLevel(), stylePath);
styleWriter.write(writer);
writeComment(writer, stylePath, CommentHandler.CLOSE_TAG_COMMENT);
writeCloseTag(writer, ElementHandler.STYLE_TAG);
}
final ElementStyleSheet bandDefaults = band.getBandDefaults();
if (isStyleSheetEmpty(bandDefaults) == false)
{
final CommentHintPath defaultStylePath = newPath.getInstance();
defaultStylePath.addName(BandHandler.DEFAULT_STYLE_TAG);
writeComment(writer, defaultStylePath, CommentHandler.OPEN_TAG_COMMENT);
writeTag(writer, BandHandler.DEFAULT_STYLE_TAG);
final StyleWriter defaultStyleWriter =
new StyleWriter(getReportWriter(), band.getBandDefaults(),
null, getIndentLevel(), defaultStylePath);
defaultStyleWriter.write(writer);
writeComment(writer, defaultStylePath, CommentHandler.CLOSE_TAG_COMMENT);
writeCloseTag(writer, BandHandler.DEFAULT_STYLE_TAG);
}
writeDataSourceForElement(band, writer, newPath);
final Element[] list = band.getElementArray();
for (int i = 0; i < list.length; i++)
{
if (list[i] instanceof Band)
{
final Band b = (Band) list[i];
writeBand(writer, BandHandler.BAND_TAG, b, band, newPath);
}
else
{
writeElement(writer, list[i], band, newPath);
}
}
writeComment(writer, newPath, CommentHandler.CLOSE_TAG_COMMENT);
writeCloseTag(writer, tagName);
}
/**
* Checks, whether the given stylesheet is empty and does not inherit values
* from modifiable or userdefined parents.
*
* @param es the element stylesheet to test
* @return true, if the sheet is empty, false otherwise.
*/
private boolean isStyleSheetEmpty(final ElementStyleSheet es)
{
if (es.getParents().isEmpty() &&
es.getDefinedPropertyNames().hasNext() == false)
{
return true;
}
return false;
}
/**
* Writes an element to a character stream writer.
*
* @param writer the character stream writer.
* @param element the element.
* @param parent the band.
* @param path the comment hint path used to read the stored comments of the ext-parser.
*
* @throws IOException if there is an I/O problem.
* @throws ReportWriterException if there is a problem writing the report.
*/
private void writeElement(final Writer writer, final Element element,
final Band parent, final CommentHintPath path)
throws IOException, ReportWriterException
{
if (parent.getElements().indexOf(element) == -1)
{
throw new IllegalArgumentException("The given Element is no child of the band");
}
final CommentHintPath newPath = path.getInstance();
newPath.addName(element);
writeComment(writer, newPath, CommentHandler.OPEN_TAG_COMMENT);
final AttributeList p = new AttributeList();
if (element.getName().startsWith(Element.ANONYMOUS_ELEMENT_PREFIX) == false)
{
p.setAttribute("name", element.getName());
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?