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 Details

    • EXCEPTION_MESSAGE_KEY_OUTPUT_STREAM_WRITE_ERROR

      public static final String EXCEPTION_MESSAGE_KEY_OUTPUT_STREAM_WRITE_ERROR
      See Also:
    • EXCEPTION_MESSAGE_KEY_FILE_WRITE_ERROR

      public static final String EXCEPTION_MESSAGE_KEY_FILE_WRITE_ERROR
      See Also:
  • Constructor Details

  • Method Details

    • write

      public String write(JRReport report)
    • 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:
    • writeReport

      public static void writeReport(JRReport report, String destFileName) throws JRException
      Throws:
      JRException
      See Also:
    • writeReport

      public static void writeReport(JRReport report, OutputStream outputStream) throws JRException
      Throws:
      JRException
      See Also:
    • writeReport

      protected void writeReport(JRReport report, Writer aWriter)
    • writeTemplates

      protected void writeTemplates(JRReport report, String indent)
    • 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)
    • writeBreak

      public void writeBreak(JRBreak breakElement, String breakName)
    • writeLine

      public void writeLine(JRLine line, String lineName)
    • 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)
    • writeEllipse

      public void writeEllipse(JREllipse ellipse, String ellipseName)
    • writeImage

      public void writeImage(JRImage image, String imageName)
    • 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 an element 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 an element dataset.

      The method produces a <dataset> XML element.

      Parameters:
      dataset - the element dataset
      skipIfEmpty - 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
    • writePieChart

      public void writePieChart(JRChart chart, String chartName)
    • writePie3DChart

      public void writePie3DChart(JRChart chart, String chartName)
    • 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 label
      axisLabelColor - color to use for the axis label
      axisTickLabelFont - font to use for the label of each tick mark
      axisTickLabelColor - color to use for the label of each tick mark
      axisTickLabelMask - formatting mask to use for the label of each tick mark
      axisVerticalTickLabels - flag to render tick labels at 90 degrees
      labelRotation - label rotation angle
      axisLineColor - 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 label
      axisLabelColor - color to use for the axis label
      axisTickLabelFont - font to use for the label of each tick mark
      axisTickLabelColor - color to use for the label of each tick mark
      axisTickLabelMask - formatting mask to use for the label of each tick mark
      axisVerticalTickLabels - flag to render tick labels at 90 degrees
      axisLineColor - the color to use for the axis line and any tick marks
    • writeBar3DPlot

      public void writeBar3DPlot(JRBar3DPlot plot, String chartName)
    • writeBarChart

      public void writeBarChart(JRChart chart, String chartName)
    • writeBar3DChart

      public void writeBar3DChart(JRChart chart, String chartName)
    • writeBubbleChart

      public void writeBubbleChart(JRChart chart, String chartName)
    • writeStackedBarChart

      public void writeStackedBarChart(JRChart chart, String chartName)
    • writeStackedBar3DChart

      public void writeStackedBar3DChart(JRChart chart, String chartName)
    • writeLineChart

      public void writeLineChart(JRChart chart, String chartName)
    • writeTimeSeriesChart

      public void writeTimeSeriesChart(JRChart chart, String chartName)
    • writeHighLowDataset

      public void writeHighLowDataset(JRHighLowDataset dataset, String parentName, String datasetNameSuffix)
    • writeHighLowChart

      public void writeHighLowChart(JRChart chart, String chartName)
    • writeGanttChart

      public void writeGanttChart(JRChart chart, String chartName)
    • writeCandlestickChart

      public void writeCandlestickChart(JRChart chart, String chartName)
    • writeAreaChart

      public void writeAreaChart(JRChart chart, String chartName)
    • writeScatterChart

      public void writeScatterChart(JRChart chart, String chartName)
    • writeXyAreaChart

      public void writeXyAreaChart(JRChart chart, String chartName)
    • writeXyBarChart

      public void writeXyBarChart(JRChart chart, String chartName)
    • writeXyLineChart

      public void writeXyLineChart(JRChart chart, String chartName)
    • 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
    • writeStackedAreaChart

      public void writeStackedAreaChart(JRChart chart, String chartName)
    • writeChartTag

      public void writeChartTag(JRChart chart, String chartName)
    • 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)
    • writeDataset

      public void writeDataset(JRDataset dataset, String datasetName)
    • writeDatasetContents

      protected void writeDatasetContents(JRDataset dataset, String datasetName)
    • writeDatasetRun

      public void writeDatasetRun(JRDatasetRun datasetRun, String parentName)
      Outputs the XML representation of a subdataset run object.
      Parameters:
      datasetRun - the subdataset run
    • writeFrame

      public void writeFrame(JRFrame frame, String frameName)
    • 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)
    • writeBox

      protected void writeBox(JRLineBox box, String boxHolder)
    • 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, Object value)
    • write

      protected void write(String pattern, Object value, Object defaultValue)
    • write

      protected void write(String pattern, Enum<?> value)
    • write

      protected void write(String pattern, Enum<?> value, Enum<?> defaultValue)
    • write

      protected void write(String pattern, int value)
    • write

      protected void write(String pattern, int value, int defaultValue)
    • write

      protected void write(String pattern, Float value)
    • write

      protected void write(String pattern, Float value, Float defaultValue)
    • write

      protected void write(String pattern, Double value)
    • write

      protected void write(String pattern, Double value, Double defaultValue)
    • write

      protected void write(String pattern, boolean value, boolean defaultValue)
    • write

      protected void write(String pattern, byte value, byte defaultValue)
    • write

      protected void write(String pattern, Color value)
    • write

      protected void write(String pattern, Color value, Color defaultValue)
    • writePattern

      protected void writePattern(String pattern, Object... arguments)
    • close

      protected void close()
    • flush

      protected void flush()
    • main

      public static void main(String[] args)