Class JRXmlWriter


  • public class JRXmlWriter
    extends JRXmlBaseWriter
    A writer that produces the JRXML representation of an in-memory report.

    Sometimes report designs are generated automatically using the JasperReports API. Report design objects obtained this way can be serialized for disk storage or transferred over the network, but they also can be stored in JRXML format.

    The JRXML representation of a given report design object can be obtained by using one of the public static writeReport() methods exposed by this class.

    Author:
    Teodor Danciu (teodord@users.sourceforge.net), Minor enhancements by Barry Klawans (bklawans@users.sourceforge.net)
    • Field Detail

      • JASPERREPORTS_NAMESPACE

        public static final XmlNamespace JASPERREPORTS_NAMESPACE
      • EXCEPTION_MESSAGE_KEY_FILE_WRITE_ERROR

        public static final java.lang.String EXCEPTION_MESSAGE_KEY_FILE_WRITE_ERROR
        See Also:
        Constant Field Values
      • EXCEPTION_MESSAGE_KEY_OUTPUT_STREAM_WRITE_ERROR

        public static final java.lang.String EXCEPTION_MESSAGE_KEY_OUTPUT_STREAM_WRITE_ERROR
        See Also:
        Constant Field Values
      • EXCEPTION_MESSAGE_KEY_REPORT_DESIGN_WRITE_ERROR

        public static final java.lang.String EXCEPTION_MESSAGE_KEY_REPORT_DESIGN_WRITE_ERROR
        See Also:
        Constant Field Values
      • EXCEPTION_MESSAGE_KEY_UNSUPPORTED_CHART_TYPE

        public static final java.lang.String EXCEPTION_MESSAGE_KEY_UNSUPPORTED_CHART_TYPE
        See Also:
        Constant Field Values
      • PREFIX_EXCLUDE_PROPERTIES

        public static final java.lang.String PREFIX_EXCLUDE_PROPERTIES
        See Also:
        Constant Field Values
      • PROPERTY_EXCLUDE_UUIDS

        public static final java.lang.String PROPERTY_EXCLUDE_UUIDS
        See Also:
        Constant Field Values
    • Method Detail

      • getReport

        public JRReport getReport()
      • isExcludeUuids

        public boolean isExcludeUuids()
      • setExcludeUuids

        public void setExcludeUuids​(boolean excludeUuids)
      • write

        public java.lang.String write​(JRReport report,
                                      java.lang.String encoding)
      • write

        public void write​(JRReport report,
                          java.io.OutputStream outputStream,
                          java.lang.String encoding)
                   throws JRException
        Throws:
        JRException
      • writeReport

        protected void writeReport​(JRReport report,
                                   java.lang.String encoding,
                                   java.io.Writer out)
                            throws java.io.IOException
        Throws:
        java.io.IOException
      • writeProperties

        public void writeProperties​(JRPropertiesHolder propertiesHolder)
                             throws java.io.IOException
        Throws:
        java.io.IOException
      • isPropertyToWrite

        protected boolean isPropertyToWrite​(JRPropertiesHolder propertiesHolder,
                                            java.lang.String propertyName)
      • writeTemplates

        protected void writeTemplates​(JRReport report)
                               throws java.io.IOException
        Throws:
        java.io.IOException
      • writeTemplate

        protected void writeTemplate​(JRReportTemplate template)
                              throws java.io.IOException
        Parameters:
        template -
        Throws:
        java.io.IOException
      • writeSection

        protected void writeSection​(JRSection section)
                             throws java.io.IOException
        Throws:
        java.io.IOException
      • writeChildElements

        public void writeChildElements​(JRElementGroup elementContainer)
        Writes the contents (child elements) of an element container.
        Parameters:
        elementContainer - the element container
      • writeElementGroup

        public void writeElementGroup​(JRElementGroup elementGroup)
                               throws java.io.IOException
        Throws:
        java.io.IOException
      • writeBreak

        public void writeBreak​(JRBreak breakElement)
                        throws java.io.IOException
        Throws:
        java.io.IOException
      • writeLine

        public void writeLine​(JRLine line)
                       throws java.io.IOException
        Throws:
        java.io.IOException
      • writePropertyExpressions

        public void writePropertyExpressions​(JRPropertyExpression[] propertyExpressions)
                                      throws java.io.IOException
        Throws:
        java.io.IOException
      • writePropertyExpressions

        public void writePropertyExpressions​(DatasetPropertyExpression[] propertyExpressions)
                                      throws java.io.IOException
        Throws:
        java.io.IOException
      • writePropertyExpression

        protected void writePropertyExpression​(JRPropertyExpression propertyExpression)
                                        throws java.io.IOException
        Throws:
        java.io.IOException
      • writePropertyExpression

        protected void writePropertyExpression​(DatasetPropertyExpression propertyExpression)
                                        throws java.io.IOException
        Throws:
        java.io.IOException
      • writeRectangle

        public void writeRectangle​(JRRectangle rectangle)
                            throws java.io.IOException
        Throws:
        java.io.IOException
      • writeEllipse

        public void writeEllipse​(JREllipse ellipse)
                          throws java.io.IOException
        Throws:
        java.io.IOException
      • writeImage

        public void writeImage​(JRImage image)
                        throws java.io.IOException
        Throws:
        java.io.IOException
      • writeStaticText

        public void writeStaticText​(JRStaticText staticText)
                             throws java.io.IOException
        Throws:
        java.io.IOException
      • writeFont

        public void writeFont​(JRFont font)
                       throws java.io.IOException
        Throws:
        java.io.IOException
      • writeTextField

        public void writeTextField​(JRTextField textField)
                            throws java.io.IOException
        Throws:
        java.io.IOException
      • writeSubreport

        public void writeSubreport​(JRSubreport subreport)
                            throws java.io.IOException
        Throws:
        java.io.IOException
      • writeSubreportParameter

        public void writeSubreportParameter​(JRSubreportParameter subreportParameter,
                                            XmlNamespace namespace)
                                     throws java.io.IOException
        Throws:
        java.io.IOException
      • writeElementDataset

        public void writeElementDataset​(JRElementDataset dataset)
                                 throws java.io.IOException
        Writes the JRXML representation of an element dataset.

        The method produces a <dataset> XML element.

        Parameters:
        dataset - the element dataset
        Throws:
        java.io.IOException - any I/O exception that occurred while writing the XML output
      • writeElementDataset

        public void writeElementDataset​(JRElementDataset dataset,
                                        boolean skipIfEmpty)
                                 throws java.io.IOException
        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
        Throws:
        java.io.IOException - any I/O exception that occurred while writing the XML output
      • writeElementDataset

        public void writeElementDataset​(JRElementDataset dataset,
                                        DatasetResetTypeEnum defaultResetType,
                                        boolean skipIfEmpty)
                                 throws java.io.IOException
        Writes the JRXML representation of an element dataset.

        The method produces a <dataset> XML element.

        Parameters:
        dataset - the element dataset
        defaultResetType - the default dataset reset type
        skipIfEmpty - if set, no output will be produced if the element dataset only has default attribute values
        Throws:
        java.io.IOException - any I/O exception that occurred while writing the XML output
      • writePieDataset

        public void writePieDataset​(JRPieDataset dataset)
                             throws java.io.IOException
        Throws:
        java.io.IOException
      • writeValueDataset

        public void writeValueDataset​(JRValueDataset dataset)
                               throws java.io.IOException
        Writes the description of a value dataset to the output stream.
        Parameters:
        dataset - the value dataset to persist
        Throws:
        java.io.IOException
      • writeValueDisplay

        public void writeValueDisplay​(JRValueDisplay valueDisplay)
                               throws java.io.IOException
        Writes the description of how to display a value in a valueDataset.
        Parameters:
        valueDisplay - the description to save
        Throws:
        java.io.IOException
      • writeItemLabel

        public void writeItemLabel​(JRItemLabel itemLabel)
                            throws java.io.IOException
        Writes the description of how to display item labels in a category plot.
        Parameters:
        itemLabel - the description to save
        Throws:
        java.io.IOException
      • writeDataRange

        public void writeDataRange​(JRDataRange dataRange)
                            throws java.io.IOException
        Writes a data range block to the output stream.
        Parameters:
        dataRange - the range to write
        Throws:
        java.io.IOException
      • writePieChart

        public void writePieChart​(JRChart chart)
                           throws java.io.IOException
        Throws:
        java.io.IOException
      • writePie3DChart

        public void writePie3DChart​(JRChart chart)
                             throws java.io.IOException
        Throws:
        java.io.IOException
      • writeCategoryAxisFormat

        public void writeCategoryAxisFormat​(JRFont axisLabelFont,
                                            java.awt.Color axisLabelColor,
                                            JRFont axisTickLabelFont,
                                            java.awt.Color axisTickLabelColor,
                                            java.lang.String axisTickLabelMask,
                                            java.lang.Boolean axisVerticalTickLabels,
                                            java.lang.Double labelRotation,
                                            java.awt.Color axisLineColor)
                                     throws java.io.IOException
        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
        Throws:
        java.io.IOException
      • writeAxisFormat

        public void writeAxisFormat​(java.lang.String axisFormatElementName,
                                    JRFont axisLabelFont,
                                    java.awt.Color axisLabelColor,
                                    JRFont axisTickLabelFont,
                                    java.awt.Color axisTickLabelColor,
                                    java.lang.String axisTickLabelMask,
                                    java.lang.Boolean axisVerticalTickLabels,
                                    java.awt.Color axisLineColor)
                             throws java.io.IOException
        Writes out the axis format block for a chart axis.
        Parameters:
        axisFormatElementName - the name of the axis format element being written
        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
        Throws:
        java.io.IOException
      • writeAxisFormat

        public void writeAxisFormat​(JRFont axisLabelFont,
                                    java.awt.Color axisLabelColor,
                                    JRFont axisTickLabelFont,
                                    java.awt.Color axisTickLabelColor,
                                    java.lang.String axisTickLabelMask,
                                    java.lang.Boolean axisVerticalTickLabels,
                                    java.awt.Color axisLineColor)
                             throws java.io.IOException
        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
        Throws:
        java.io.IOException
      • writeBar3DPlot

        public void writeBar3DPlot​(JRBar3DPlot plot)
                            throws java.io.IOException
        Throws:
        java.io.IOException
      • writeBarChart

        public void writeBarChart​(JRChart chart)
                           throws java.io.IOException
        Throws:
        java.io.IOException
      • writeBar3DChart

        public void writeBar3DChart​(JRChart chart)
                             throws java.io.IOException
        Throws:
        java.io.IOException
      • writeBubbleChart

        public void writeBubbleChart​(JRChart chart)
                              throws java.io.IOException
        Throws:
        java.io.IOException
      • writeStackedBarChart

        public void writeStackedBarChart​(JRChart chart)
                                  throws java.io.IOException
        Throws:
        java.io.IOException
      • writeStackedBar3DChart

        public void writeStackedBar3DChart​(JRChart chart)
                                    throws java.io.IOException
        Throws:
        java.io.IOException
      • writeLineChart

        public void writeLineChart​(JRChart chart)
                            throws java.io.IOException
        Throws:
        java.io.IOException
      • writeTimeSeriesChart

        public void writeTimeSeriesChart​(JRChart chart)
                                  throws java.io.IOException
        Throws:
        java.io.IOException
      • writeHighLowDataset

        public void writeHighLowDataset​(JRHighLowDataset dataset)
                                 throws java.io.IOException
        Throws:
        java.io.IOException
      • writeHighLowChart

        public void writeHighLowChart​(JRChart chart)
                               throws java.io.IOException
        Throws:
        java.io.IOException
      • writeGanttChart

        public void writeGanttChart​(JRChart chart)
                             throws java.io.IOException
        Throws:
        java.io.IOException
      • writeCandlestickChart

        public void writeCandlestickChart​(JRChart chart)
                                   throws java.io.IOException
        Throws:
        java.io.IOException
      • writeAreaChart

        public void writeAreaChart​(JRChart chart)
                            throws java.io.IOException
        Throws:
        java.io.IOException
      • writeScatterChart

        public void writeScatterChart​(JRChart chart)
                               throws java.io.IOException
        Throws:
        java.io.IOException
      • writeXyAreaChart

        public void writeXyAreaChart​(JRChart chart)
                              throws java.io.IOException
        Throws:
        java.io.IOException
      • writeXyBarChart

        public void writeXyBarChart​(JRChart chart)
                             throws java.io.IOException
        Throws:
        java.io.IOException
      • writeXyLineChart

        public void writeXyLineChart​(JRChart chart)
                              throws java.io.IOException
        Throws:
        java.io.IOException
      • writeMeterChart

        public void writeMeterChart​(JRChart chart)
                             throws java.io.IOException
        Writes the definition of a meter chart to the output stream.
        Parameters:
        chart - the meter chart to write
        Throws:
        java.io.IOException
      • writeThermometerChart

        public void writeThermometerChart​(JRChart chart)
                                   throws java.io.IOException
        Writes the description of a thermometer chart to the output stream.
        Parameters:
        chart - the thermometer chart to write
        Throws:
        java.io.IOException
      • writeMultiAxisChart

        public void writeMultiAxisChart​(JRChart chart)
                                 throws java.io.IOException
        Writes the definition of a multiple axis chart to the output stream.
        Parameters:
        chart - the multiple axis chart to write
        Throws:
        java.io.IOException
      • writeStackedAreaChart

        public void writeStackedAreaChart​(JRChart chart)
                                   throws java.io.IOException
        Throws:
        java.io.IOException
      • writeChartTag

        public void writeChartTag​(JRChart chart)
                           throws java.io.IOException
        Throws:
        java.io.IOException
      • writeSubreportReturnValue

        public void writeSubreportReturnValue​(JRSubreportReturnValue returnValue,
                                              XmlNamespace namespace)
                                       throws java.io.IOException
        Throws:
        java.io.IOException
      • writeReturnValue

        protected void writeReturnValue​(VariableReturnValue returnValue)
                                 throws java.io.IOException
        Throws:
        java.io.IOException
      • writeReturnValue

        protected void writeReturnValue​(ExpressionReturnValue returnValue)
                                 throws java.io.IOException
        Throws:
        java.io.IOException
      • writeCrosstab

        public void writeCrosstab​(JRCrosstab crosstab)
                           throws java.io.IOException
        Throws:
        java.io.IOException
      • writeCrosstabRowGroup

        protected void writeCrosstabRowGroup​(JRCrosstabRowGroup group)
                                      throws java.io.IOException
        Throws:
        java.io.IOException
      • writeCrosstabColumnGroup

        protected void writeCrosstabColumnGroup​(JRCrosstabColumnGroup group)
                                         throws java.io.IOException
        Throws:
        java.io.IOException
      • writeBucket

        protected void writeBucket​(JRCrosstabBucket bucket)
                            throws java.io.IOException
        Throws:
        java.io.IOException
      • writeCrosstabMeasure

        protected void writeCrosstabMeasure​(JRCrosstabMeasure measure)
                                     throws java.io.IOException
        Throws:
        java.io.IOException
      • writeCrosstabCell

        protected void writeCrosstabCell​(JRCrosstabCell cell)
                                  throws java.io.IOException
        Throws:
        java.io.IOException
      • writeCellContents

        protected void writeCellContents​(JRCellContents contents)
                                  throws java.io.IOException
        Throws:
        java.io.IOException
      • writeCrosstabParameter

        protected void writeCrosstabParameter​(JRCrosstabParameter parameter)
                                       throws java.io.IOException
        Throws:
        java.io.IOException
      • writeDataset

        public void writeDataset​(JRDataset dataset)
                          throws java.io.IOException
        Throws:
        java.io.IOException
      • writeDatasetContents

        protected void writeDatasetContents​(JRDataset dataset)
                                     throws java.io.IOException
        Throws:
        java.io.IOException
      • writeDatasetRun

        public void writeDatasetRun​(JRDatasetRun datasetRun)
                             throws java.io.IOException
        Outputs the XML representation of a subdataset run object.
        Parameters:
        datasetRun - the subdataset run
        Throws:
        java.io.IOException
      • writeFrame

        public void writeFrame​(JRFrame frame)
                        throws java.io.IOException
        Throws:
        java.io.IOException
      • writeHyperlinkParameters

        protected void writeHyperlinkParameters​(JRHyperlinkParameter[] parameters)
                                         throws java.io.IOException
        Throws:
        java.io.IOException
      • writeHyperlinkParameter

        protected void writeHyperlinkParameter​(JRHyperlinkParameter parameter)
                                        throws java.io.IOException
        Throws:
        java.io.IOException
      • writeHyperlink

        public void writeHyperlink​(java.lang.String tagName,
                                   JRHyperlink hyperlink)
                            throws java.io.IOException
        Throws:
        java.io.IOException
      • writeHyperlink

        public void writeHyperlink​(java.lang.String tagName,
                                   XmlNamespace namespace,
                                   JRHyperlink hyperlink)
                            throws java.io.IOException
        Throws:
        java.io.IOException
      • toWriteConditionalStyles

        protected boolean toWriteConditionalStyles()
        Description copied from class: JRXmlBaseWriter
        Decides whether conditional styles are to be written.
        Specified by:
        toWriteConditionalStyles in class JRXmlBaseWriter
        Returns:
        whether conditional styles are to be written
      • getXmlWriteHelper

        public JRXmlWriteHelper getXmlWriteHelper()
        Returns the XML write helper used by this report writer. The helper can be used to output XML elements and attributes.
        Returns:
        the XML write helper used by this report writer
      • getUnderlyingWriter

        public java.io.Writer getUnderlyingWriter()
        Returns the underlying stream to which this writer outputs to.
        Returns:
        the underlying stream used by this writer
      • writeComponentElement

        public void writeComponentElement​(JRComponentElement componentElement)
                                   throws java.io.IOException
        Throws:
        java.io.IOException
      • writeGenericElement

        public void writeGenericElement​(JRGenericElement element)
                                 throws java.io.IOException
        Throws:
        java.io.IOException
      • writeMultiAxisData

        public void writeMultiAxisData​(MultiAxisData data)
                                throws java.io.IOException
        Throws:
        java.io.IOException
      • writeDataLevelBucket

        protected void writeDataLevelBucket​(DataLevelBucket bucket)
                                     throws java.io.IOException
        Throws:
        java.io.IOException
      • writeExpression

        protected void writeExpression​(java.lang.String name,
                                       JRExpression expression,
                                       boolean writeClass,
                                       java.lang.String defaultClassName)
                                throws java.io.IOException
        Throws:
        java.io.IOException
      • writeExpression

        protected void writeExpression​(java.lang.String name,
                                       XmlNamespace namespace,
                                       JRExpression expression,
                                       boolean writeClass)
                                throws java.io.IOException
        Throws:
        java.io.IOException