Package net.sf.jasperreports.engine.util
Class JRApiWriter
- java.lang.Object
-
- net.sf.jasperreports.engine.util.JRApiWriter
-
public class JRApiWriter extends Object
A writer that generates the Java code required to produce a given report template programmatically, using the JasperReports API.- Author:
- Teodor Danciu (teodord@users.sourceforge.net)
-
-
Field Summary
Fields Modifier and Type Field Description static StringEXCEPTION_MESSAGE_KEY_FILE_WRITE_ERRORstatic StringEXCEPTION_MESSAGE_KEY_OUTPUT_STREAM_WRITE_ERROR
-
Constructor Summary
Constructors Constructor Description JRApiWriter(JasperReportsContext jasperReportsContext)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidclose()protected voidflush()static voidmain(String[] args)protected booleantoWriteConditionalStyles()protected voidwrite(String text)protected voidwrite(String pattern, boolean value, boolean defaultValue)protected voidwrite(String pattern, byte value, byte defaultValue)protected voidwrite(String pattern, int value)protected voidwrite(String pattern, int value, int defaultValue)protected voidwrite(String pattern, Color value)protected voidwrite(String pattern, Color value, Color defaultValue)protected voidwrite(String pattern, Double value)protected voidwrite(String pattern, Double value, Double defaultValue)protected voidwrite(String pattern, Enum<?> value)protected voidwrite(String pattern, Enum<?> value, Enum<?> defaultValue)protected voidwrite(String pattern, Float value)protected voidwrite(String pattern, Float value, Float defaultValue)protected voidwrite(String pattern, Object value)protected voidwrite(String pattern, Object value, Object defaultValue)Stringwrite(JRReport report)voidwrite(JRReport report, OutputStream outputStream)voidwrite(JRReport report, String destFileName)voidwriteAreaChart(JRChart chart, String chartName)voidwriteAxisFormat(String indent, JRFont axisLabelFont, Color axisLabelColor, JRFont axisTickLabelFont, Color axisTickLabelColor, String axisTickLabelMask, Boolean axisVerticalTickLabels, Color axisLineColor, String parentName, String axisNameSuffix, boolean isToSet)Writes out the axis format block for a chart axis.voidwriteBar3DChart(JRChart chart, String chartName)voidwriteBar3DPlot(JRBar3DPlot plot, String chartName)voidwriteBarChart(JRChart chart, String chartName)protected voidwriteBox(JRLineBox box, String boxHolder)voidwriteBreak(JRBreak breakElement, String breakName)voidwriteBubbleChart(JRChart chart, String chartName)protected voidwriteBucket(JRCrosstabBucket bucket, String parentName)voidwriteCandlestickChart(JRChart chart, String chartName)voidwriteCategoryAxisFormat(String indent, JRFont axisLabelFont, Color axisLabelColor, JRFont axisTickLabelFont, Color axisTickLabelColor, String axisTickLabelMask, Boolean axisVerticalTickLabels, Double labelRotation, Color axisLineColor, String parentName)Writes out the category axis format block.protected voidwriteCellContents(JRCellContents contents, String cellName)voidwriteChartTag(JRChart chart, String chartName)voidwriteChildElements(JRElementGroup elementContainer, String parentName)Writes the contents (child elements) of an element container.voidwriteComponentElement(JRComponentElement componentElement, String componentName)protected voidwriteConditionalStyle(JRConditionalStyle style, String styleName)Writes a conditional style.voidwriteCrosstab(JRCrosstab crosstab, String crosstabName)protected voidwriteCrosstabCell(JRCrosstabCell cell, String cellName)protected voidwriteCrosstabColumnGroup(JRCrosstabColumnGroup group, String groupName)protected voidwriteCrosstabMeasure(JRCrosstabMeasure measure, String measureName)protected voidwriteCrosstabParameter(JRCrosstabParameter parameter, String parameterName)protected voidwriteCrosstabRowGroup(JRCrosstabRowGroup group, String groupName)protected voidwriteCrosstabTitleCell(JRCrosstab crosstab, String crosstabName)voidwriteDataRange(JRDataRange dataRange, String parentName, String dataRangeSuffix)Writes a data range block to the output stream.voidwriteDataset(JRDataset dataset, String datasetName)protected voidwriteDatasetContents(JRDataset dataset, String datasetName)voidwriteDatasetRun(JRDatasetRun datasetRun, String parentName)Outputs the XML representation of a subdataset run object.voidwriteElementDataset(JRElementDataset dataset, boolean skipIfEmpty, String datasetName)Writes the JRXML representation of anelement dataset.voidwriteElementDataset(JRElementDataset dataset, String datasetName)Writes the JRXML representation of anelement dataset.voidwriteElementGroup(JRElementGroup elementGroup, String groupName)voidwriteEllipse(JREllipse ellipse, String ellipseName)voidwriteExpression(JRExpression expression, String parentName, String expressionSuffix)voidwriteExpression(JRExpression expression, String parentName, String expressionSuffix, String defaultClassName)voidwriteFrame(JRFrame frame, String frameName)voidwriteGanttChart(JRChart chart, String chartName)voidwriteGenericElement(JRGenericElement element, String elementName)protected XmlNamespace getNamespace() { return JASPERREPORTS_NAMESPACE; } /**voidwriteHighLowChart(JRChart chart, String chartName)voidwriteHighLowDataset(JRHighLowDataset dataset, String parentName, String datasetNameSuffix)voidwriteHyperlink(JRHyperlink hyperlink, String parentName, String hyperlinkSuffix)public void writeHyperlink( String tagName, JRHyperlink hyperlink, String hyperlinkName) { writeHyperlink( tagName, null, hyperlink, hyperlinkName); } /** public void writeHyperlink( String tagName, XmlNamespace namespace, JRHyperlink hyperlink, String hyperlinkName) { if (hyperlink !protected voidwriteHyperlinkParameter(JRHyperlinkParameter parameter, String parameterName)protected voidwriteHyperlinkParameters(JRHyperlinkParameter[] parameters, String parentName)voidwriteImage(JRImage image, String imageName)voidwriteItemLabel(JRItemLabel itemLabel, String parentName, String itemLabelSuffix)Writes the description of how to display item labels in a category plot.voidwriteLine(JRLine line, String lineName)voidwriteLineChart(JRChart chart, String chartName)voidwriteMeterChart(JRChart chart, String chartName)Writes the definition of a meter chart to the output stream.voidwriteMultiAxisChart(JRChart chart, String chartName)Writes the definition of a multiple axis chart to the output stream.protected voidwriteParagraph(JRParagraph paragraph, String paragraphHolder)protected voidwritePattern(String pattern, Object... arguments)voidwritePie3DChart(JRChart chart, String chartName)voidwritePieChart(JRChart chart, String chartName)voidwritePieDataset(JRPieDataset dataset, String parentName, String datasetNameSuffix)protected voidwritePropertyExpression(DatasetPropertyExpression propertyExpression, String propertyExpressionName)protected voidwritePropertyExpression(JRPropertyExpression propertyExpression, String propertyExpressionName)protected voidwritePropertyExpressions(DatasetPropertyExpression[] propertyExpressions, String propertyHolderName)protected voidwritePropertyExpressions(JRPropertyExpression[] propertyExpressions, String propertyHolderName)voidwriteRectangle(JRRectangle rectangle, String rectangleName)static StringwriteReport(JRReport report)static voidwriteReport(JRReport report, OutputStream outputStream)protected voidwriteReport(JRReport report, Writer aWriter)static voidwriteReport(JRReport report, String destFileName)voidwriteScatterChart(JRChart chart, String chartName)protected voidwriteSection(JRSection section, String sectionName, String sectionBandListGetterName)voidwriteStackedAreaChart(JRChart chart, String chartName)voidwriteStackedBar3DChart(JRChart chart, String chartName)voidwriteStackedBarChart(JRChart chart, String chartName)voidwriteStaticText(JRStaticText staticText, String staticTextName)protected voidwriteStyleReferenceAttr(JRStyleContainer styleContainer, String styleName)voidwriteSubreport(JRSubreport subreport, String subreportName)protected voidwriteTemplate(JRReportTemplate template, String templateName)protected voidwriteTemplates(JRReport report, String indent)voidwriteTextField(JRTextField textField, String textFieldName)voidwriteThermometerChart(JRChart chart, String chartName)Writes the description of a thermometer chart to the output stream.voidwriteTimeSeriesChart(JRChart chart, String chartName)voidwriteValueDataset(JRValueDataset dataset, String parentName, String datasetNameSuffix)Writes the description of a value dataset to the output stream.voidwriteValueDisplay(JRValueDisplay valueDisplay, String parentName)Writes the description of how to display a value in a valueDataset.voidwriteXyAreaChart(JRChart chart, String chartName)voidwriteXyBarChart(JRChart chart, String chartName)voidwriteXyLineChart(JRChart chart, String chartName)
-
-
-
Field Detail
-
EXCEPTION_MESSAGE_KEY_OUTPUT_STREAM_WRITE_ERROR
public static final String EXCEPTION_MESSAGE_KEY_OUTPUT_STREAM_WRITE_ERROR
- See Also:
- Constant Field Values
-
EXCEPTION_MESSAGE_KEY_FILE_WRITE_ERROR
public static final String EXCEPTION_MESSAGE_KEY_FILE_WRITE_ERROR
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
JRApiWriter
public JRApiWriter(JasperReportsContext jasperReportsContext)
-
-
Method Detail
-
write
public void write(JRReport report, String destFileName) throws JRException
- Throws:
JRException
-
write
public void write(JRReport report, OutputStream outputStream) throws JRException
- Throws:
JRException
-
writeReport
public static String writeReport(JRReport report)
- See Also:
write(JRReport)
-
writeReport
public static void writeReport(JRReport report, String destFileName) throws JRException
- Throws:
JRException- See Also:
write(JRReport, String)
-
writeReport
public static void writeReport(JRReport report, OutputStream outputStream) throws JRException
- Throws:
JRException- See Also:
write(JRReport, OutputStream)
-
writeTemplate
protected void writeTemplate(JRReportTemplate template, String templateName)
-
writeSection
protected void writeSection(JRSection section, String sectionName, String sectionBandListGetterName)
-
writeChildElements
public void writeChildElements(JRElementGroup elementContainer, String parentName)
Writes the contents (child elements) of an element container.- Parameters:
elementContainer- the element container
-
writeElementGroup
public void writeElementGroup(JRElementGroup elementGroup, String groupName)
-
writePropertyExpressions
protected void writePropertyExpressions(JRPropertyExpression[] propertyExpressions, String propertyHolderName)
-
writePropertyExpressions
protected void writePropertyExpressions(DatasetPropertyExpression[] propertyExpressions, String propertyHolderName)
-
writePropertyExpression
protected void writePropertyExpression(JRPropertyExpression propertyExpression, String propertyExpressionName)
-
writePropertyExpression
protected void writePropertyExpression(DatasetPropertyExpression propertyExpression, String propertyExpressionName)
-
writeRectangle
public void writeRectangle(JRRectangle rectangle, String rectangleName)
-
writeStaticText
public void writeStaticText(JRStaticText staticText, String staticTextName)
-
writeTextField
public void writeTextField(JRTextField textField, String textFieldName)
-
writeSubreport
public void writeSubreport(JRSubreport subreport, String subreportName)
-
writeElementDataset
public void writeElementDataset(JRElementDataset dataset, String datasetName)
Writes the JRXML representation of anelement dataset.The method produces a
<dataset>XML element.- Parameters:
dataset- the element dataset
-
writeElementDataset
public void writeElementDataset(JRElementDataset dataset, boolean skipIfEmpty, String datasetName)
Writes the JRXML representation of anelement dataset.The method produces a
<dataset>XML element.- Parameters:
dataset- the element datasetskipIfEmpty- if set, no output will be produced if the element dataset only has default attribute values
-
writePieDataset
public void writePieDataset(JRPieDataset dataset, String parentName, String datasetNameSuffix)
-
writeValueDataset
public void writeValueDataset(JRValueDataset dataset, String parentName, String datasetNameSuffix)
Writes the description of a value dataset to the output stream.- Parameters:
dataset- the value dataset to persist
-
writeValueDisplay
public void writeValueDisplay(JRValueDisplay valueDisplay, String parentName)
Writes the description of how to display a value in a valueDataset.- Parameters:
valueDisplay- the description to save
-
writeItemLabel
public void writeItemLabel(JRItemLabel itemLabel, String parentName, String itemLabelSuffix)
Writes the description of how to display item labels in a category plot.- Parameters:
itemLabel- the description to save
-
writeDataRange
public void writeDataRange(JRDataRange dataRange, String parentName, String dataRangeSuffix)
Writes a data range block to the output stream.- Parameters:
dataRange- the range to write
-
writeCategoryAxisFormat
public void writeCategoryAxisFormat(String indent, JRFont axisLabelFont, Color axisLabelColor, JRFont axisTickLabelFont, Color axisTickLabelColor, String axisTickLabelMask, Boolean axisVerticalTickLabels, Double labelRotation, Color axisLineColor, String parentName)
Writes out the category axis format block.- Parameters:
axisLabelFont- font to use for the axis labelaxisLabelColor- color to use for the axis labelaxisTickLabelFont- font to use for the label of each tick markaxisTickLabelColor- color to use for the label of each tick markaxisTickLabelMask- formatting mask to use for the label of each tick markaxisVerticalTickLabels- flag to render tick labels at 90 degreeslabelRotation- label rotation angleaxisLineColor- the color to use for the axis line and any tick marks
-
writeAxisFormat
public void writeAxisFormat(String indent, JRFont axisLabelFont, Color axisLabelColor, JRFont axisTickLabelFont, Color axisTickLabelColor, String axisTickLabelMask, Boolean axisVerticalTickLabels, Color axisLineColor, String parentName, String axisNameSuffix, boolean isToSet)
Writes out the axis format block for a chart axis.- Parameters:
axisLabelFont- font to use for the axis labelaxisLabelColor- color to use for the axis labelaxisTickLabelFont- font to use for the label of each tick markaxisTickLabelColor- color to use for the label of each tick markaxisTickLabelMask- formatting mask to use for the label of each tick markaxisVerticalTickLabels- flag to render tick labels at 90 degreesaxisLineColor- the color to use for the axis line and any tick marks
-
writeBar3DPlot
public void writeBar3DPlot(JRBar3DPlot plot, String chartName)
-
writeHighLowDataset
public void writeHighLowDataset(JRHighLowDataset dataset, String parentName, String datasetNameSuffix)
-
writeMeterChart
public void writeMeterChart(JRChart chart, String chartName)
Writes the definition of a meter chart to the output stream.- Parameters:
chart- the meter chart to write
-
writeThermometerChart
public void writeThermometerChart(JRChart chart, String chartName)
Writes the description of a thermometer chart to the output stream.- Parameters:
chart- the thermometer chart to write
-
writeMultiAxisChart
public void writeMultiAxisChart(JRChart chart, String chartName)
Writes the definition of a multiple axis chart to the output stream.- Parameters:
chart- the multiple axis chart to write
-
writeCrosstab
public void writeCrosstab(JRCrosstab crosstab, String crosstabName)
-
writeCrosstabTitleCell
protected void writeCrosstabTitleCell(JRCrosstab crosstab, String crosstabName)
-
writeCrosstabRowGroup
protected void writeCrosstabRowGroup(JRCrosstabRowGroup group, String groupName)
-
writeCrosstabColumnGroup
protected void writeCrosstabColumnGroup(JRCrosstabColumnGroup group, String groupName)
-
writeBucket
protected void writeBucket(JRCrosstabBucket bucket, String parentName)
-
writeCrosstabMeasure
protected void writeCrosstabMeasure(JRCrosstabMeasure measure, String measureName)
-
writeCrosstabCell
protected void writeCrosstabCell(JRCrosstabCell cell, String cellName)
-
writeCellContents
protected void writeCellContents(JRCellContents contents, String cellName)
-
writeCrosstabParameter
protected void writeCrosstabParameter(JRCrosstabParameter parameter, String parameterName)
-
writeDatasetRun
public void writeDatasetRun(JRDatasetRun datasetRun, String parentName)
Outputs the XML representation of a subdataset run object.- Parameters:
datasetRun- the subdataset run
-
writeHyperlinkParameters
protected void writeHyperlinkParameters(JRHyperlinkParameter[] parameters, String parentName)
-
writeHyperlinkParameter
protected void writeHyperlinkParameter(JRHyperlinkParameter parameter, String parameterName)
-
writeHyperlink
public void writeHyperlink(JRHyperlink hyperlink, String parentName, String hyperlinkSuffix)
public void writeHyperlink( String tagName, JRHyperlink hyperlink, String hyperlinkName) { writeHyperlink( tagName, null, hyperlink, hyperlinkName); } /** public void writeHyperlink( String tagName, XmlNamespace namespace, JRHyperlink hyperlink, String hyperlinkName) { if (hyperlink != null) { writer.startElement(tagName, namespace); writer.addEncodedAttribute(JRApiConstants.ATTRIBUTE_hyperlinkType, hyperlink.getLinkType(), JRHyperlinkHelper.HYPERLINK_TYPE_NONE); writer.addEncodedAttribute(JRApiConstants.ATTRIBUTE_hyperlinkTarget, hyperlink.getLinkTarget(), JRHyperlinkHelper.HYPERLINK_TARGET_SELF); writer.writeExpression(JRApiConstants.ELEMENT_hyperlinkReferenceExpression, JASPERREPORTS_NAMESPACE, hyperlink.getHyperlinkReferenceExpression(), false); writer.writeExpression(JRApiConstants.ELEMENT_hyperlinkWhenExpression, JASPERREPORTS_NAMESPACE, hyperlink.getHyperlinkWhenExpression(), false); writer.writeExpression(JRApiConstants.ELEMENT_hyperlinkAnchorExpression, JASPERREPORTS_NAMESPACE, hyperlink.getHyperlinkAnchorExpression(), false); writer.writeExpression(JRApiConstants.ELEMENT_hyperlinkPageExpression, JASPERREPORTS_NAMESPACE, hyperlink.getHyperlinkPageExpression(), false); writer.writeExpression(JRApiConstants.ELEMENT_hyperlinkTooltipExpression, JASPERREPORTS_NAMESPACE, hyperlink.getHyperlinkTooltipExpression(), false); writeHyperlinkParameters(hyperlink.getHyperlinkParameters()); flush(); } } /**
-
toWriteConditionalStyles
protected boolean toWriteConditionalStyles()
-
writeConditionalStyle
protected void writeConditionalStyle(JRConditionalStyle style, String styleName)
Writes a conditional style.- Parameters:
style- the conditional style
-
writeComponentElement
public void writeComponentElement(JRComponentElement componentElement, String componentName)
-
writeGenericElement
public void writeGenericElement(JRGenericElement element, String elementName)
protected XmlNamespace getNamespace() { return JASPERREPORTS_NAMESPACE; } /**
-
writeStyleReferenceAttr
protected void writeStyleReferenceAttr(JRStyleContainer styleContainer, String styleName)
-
writeParagraph
protected void writeParagraph(JRParagraph paragraph, String paragraphHolder)
-
writeExpression
public void writeExpression(JRExpression expression, String parentName, String expressionSuffix)
-
writeExpression
public void writeExpression(JRExpression expression, String parentName, String expressionSuffix, String defaultClassName)
-
write
protected void write(String text)
-
write
protected void write(String pattern, int value)
-
write
protected void write(String pattern, int value, int defaultValue)
-
write
protected void write(String pattern, boolean value, boolean defaultValue)
-
write
protected void write(String pattern, byte value, byte defaultValue)
-
close
protected void close()
-
flush
protected void flush()
-
main
public static void main(String[] args)
-
-