Class JRXmlExporter
java.lang.Object
net.sf.jasperreports.engine.JRAbstractExporter<ReportExportConfiguration,ExporterConfiguration,XmlExporterOutput,JRXmlExporterContext>
net.sf.jasperreports.engine.export.JRXmlExporter
- All Implemented Interfaces:
Exporter<ExporterInput,
ReportExportConfiguration, ExporterConfiguration, XmlExporterOutput>
public class JRXmlExporter
extends JRAbstractExporter<ReportExportConfiguration,ExporterConfiguration,XmlExporterOutput,JRXmlExporterContext>
Exports a JasperReports document to an XML file that contains the same data as a
JasperPrint
object, but in XML format, instead
of a serialized class. As report templates are defined using the
special XML syntax JRXML, the JasperReports library also has a special XML structure
for storing generated documents in XML format. This format is called JRPXML because
the files produced by the JRXmlExporter usually have the *.jrpxml
extension.
Such XML files can be parsed back into
JasperPrint
object using the JRPrintXmlLoader
utility class.
Their structure is validated against an internal XSD file called jasperprint.xsd
,
that provides the details of the JRPXML structure. Valid JRPXML files
should point to the internal XSD file using a public location, as follows:
<?xml version="1.0" encoding="UTF-8"?> <jasperPrint xmlns="http://jasperreports.sourceforge.net/jasperreports/print" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/print http://jasperreports.sourceforge.net/xsd/jasperprint.xsd" ...>The root element of a JRPXML document is
<jasperPrint>
, which contains a list of
report custom properties (<property>
tags), a list of element origins
(<origin>
tags), a list of
report style definitions (<style>
tags) that are reused by report elements throughout
the document, and a list of pages (<page>
tags), each of which contains a nested list of
elements like lines, rectangles, ellipses, images, and texts.
The quality of this exporter is equal to the Graphics2D
exporter because it preserves
100% of the initial document content and properties. There is no loss in document
quality when exporting to XML because the resulting XML content can be loaded back
into a JasperPrint
object that will look the same as the original one.
The built-in viewers can display documents exported in JRPXML format because they
actually rely on the JRPrintXmlLoader
to load the
document back into a JasperPrint
object before
rendering it on the screen.
Embedding Images
When exporting XML, pay special attention to how images are stored. The two ways are as follows:- If the exporter outputs to a file on disk, it stores the images contained by the source
document in separate files that accompany the main JRPXML file. The image files
are put in a directory that takes its name from the original destination file name
plus the
_files
suffix, the same directory as the JRPXML file. - The exporter can embed images in the JRPXML file itself by encoding their binary data using a Base64 encoder. This simplifies transfer over the network or by direct output to streams.
isEmbeddingImages()
exporter output flag,
which expects a java.lang.Boolean
. By default, the images are embedded in the
resulting XML.- Author:
- Teodor Danciu (teodord@users.sourceforge.net)
- See Also:
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class net.sf.jasperreports.engine.JRAbstractExporter
JRAbstractExporter.BaseExporterContext, JRAbstractExporter.PageRange
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final String
static final String
static final String
protected static final String
protected boolean
static final XmlNamespace
static final String
static final String
static final String
Stores the text sequence used to replace invalid XML charactersstatic final String
protected RenderersCache
protected String
protected VersionComparator
static final String
The exporter key, as used inGenericElementHandlerEnviroment.getElementHandler(JRGenericElementType, String)
.protected JRXmlWriteHelper
Fields inherited from class net.sf.jasperreports.engine.JRAbstractExporter
allSelector, crtCompositeConfiguration, crtCompositeItemConfiguration, crtItem, dateFormatCache, EXCEPTION_MESSAGE_KEY_EMPTY_INPUT_SOURCE_IN_BATCH_MODE, EXCEPTION_MESSAGE_KEY_END_PAGE_INDEX_OUT_OF_RANGE, EXCEPTION_MESSAGE_KEY_INVALID_IMAGE_NAME, EXCEPTION_MESSAGE_KEY_INVALID_ZOOM_RATIO, EXCEPTION_MESSAGE_KEY_NO_INPUT_SOURCE, EXCEPTION_MESSAGE_KEY_NO_OUTPUT_SPECIFIED, EXCEPTION_MESSAGE_KEY_OUTPUT_WRITER_ERROR, EXCEPTION_MESSAGE_KEY_PAGE_INDEX_OUT_OF_RANGE, EXCEPTION_MESSAGE_KEY_START_PAGE_INDEX_OUT_OF_RANGE, exporterConfiguration, exporterContext, exporterInput, exporterOutput, filter, fontUtil, hyperlinkProducerFactory, itemConfiguration, jasperPrint, jasperReportsContext, noBackcolorSelector, noneSelector, numberFormatCache, propertiesUtil, PROPERTY_DEFAULT_FILTER_FACTORY, PROPERTY_SUFFIX_DEFAULT_FILTER_FACTORY, rendererUtil, styledTextUtil, textValueClasses
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
exportBookmark
(PrintBookmark bookmark) protected void
exportBookmarks
(List<PrintBookmark> bookmarks) void
exportElement
(JRPrintElement element) protected void
exportElements
(Collection<JRPrintElement> elements) protected void
exportEllipse
(JRPrintEllipse ellipse) protected void
exportFont
(JRFont font) protected void
exportFrame
(JRPrintFrame frame) protected void
protected void
protected void
protected void
exportHyperlinkParameters
(JRPrintHyperlink hyperlink) void
exportImage
(JRPrintImage image) protected void
exportLine
(JRPrintLine line) protected void
exportOrigin
(JROrigin origin) protected void
exportPage
(JRPrintPage page) protected void
exportPart
(Integer pageIndex, PrintPart part) protected void
protected void
protected void
exportProperties
(JRPropertiesHolder propertiesHolder) protected void
exportRectangle
(JRPrintRectangle rectangle) void
Performs the export.protected void
exportReportElement
(JRPrintElement element) protected void
exportReportToStream
(Writer writer) protected void
exportStyle
(JRStyle style) void
exportTabStop
(TabStop tabStop) void
exportText
(JRPrintText text) protected StringBuilder
formatTextLineBreakOffsets
(short[] lineBreakOffsets) protected Class
<ExporterConfiguration> Returns the properties prefix for the current exporter.protected Class
<ReportExportConfiguration> protected XmlNamespace
Returns the XML write helper used by this exporter.protected void
protected void
protected boolean
isNewerVersionOrEqual
(String oldVersion) protected boolean
isOlderVersionThan
(String version) Methods inherited from class net.sf.jasperreports.engine.JRAbstractExporter
checkInterrupted, createFilter, defaultParseNumber, ensureInput, ensureJasperReportsContext, ensureOutput, getBooleanCellValue, getCurrentConfiguration, getCurrentItemConfiguration, getCurrentJasperPrint, getDateCellValue, getDateFormat, getExporterConfiguration, getExporterContext, getExporterInput, getExporterOutput, getHyperlinkProducer, getJasperReportsContext, getLocale, getNumberCellValue, getNumberFormat, getOffsetX, getOffsetY, getPageRange, getPropertiesUtil, getRendererUtil, getReportContext, getReportExportConfiguration, getRepository, getStyledText, getStyledText, getTextFormatFactoryClass, getTextLocale, getTextTimeZone, getTextValue, getTextValueString, insideFrame, reset, resetExportContext, restoreElementOffsets, setConfiguration, setConfiguration, setCurrentExporterInputItem, setExporterInput, setExporterOutput, setFrameElementsOffset, setJasperReportsContext, setOffset, setOffset, setReportContext
-
Field Details
-
EXCEPTION_MESSAGE_KEY_EMBEDDING_IMAGE_ERROR
- See Also:
-
EXCEPTION_MESSAGE_KEY_REPORT_STYLE_NOT_FOUND
- See Also:
-
XML_EXPORTER_KEY
The exporter key, as used inGenericElementHandlerEnviroment.getElementHandler(JRGenericElementType, String)
.- See Also:
-
PROPERTY_START_PAGE_INDEX
- See Also:
-
PROPERTY_END_PAGE_INDEX
- See Also:
-
PROPERTY_PAGE_COUNT
- See Also:
-
PROPERTY_REPLACE_INVALID_CHARS
Stores the text sequence used to replace invalid XML characters- See Also:
-
DEFAULT_OBJECT_TYPE
- See Also:
-
IMAGE_PREFIX
- See Also:
-
JASPERPRINT_NAMESPACE
-
xmlWriter
-
version
-
versionComparator
-
rendererToImagePathMap
-
renderersCache
-
stylesMap
-
isEmbeddingImages
protected boolean isEmbeddingImages
-
-
Constructor Details
-
JRXmlExporter
public JRXmlExporter()- See Also:
-
JRXmlExporter
-
-
Method Details
-
getConfigurationInterface
-
getItemConfigurationInterface
-
exportReport
Description copied from interface:Exporter
Performs the export.- Specified by:
exportReport
in interfaceExporter<ExporterInput,
ReportExportConfiguration, ExporterConfiguration, XmlExporterOutput> - Specified by:
exportReport
in classJRAbstractExporter<ReportExportConfiguration,
ExporterConfiguration, XmlExporterOutput, JRXmlExporterContext> - Throws:
JRException
-
initExport
protected void initExport() -
initReport
protected void initReport() -
getNamespace
-
exportReportToStream
- Throws:
JRException
IOException
-
exportProperties
- Throws:
IOException
-
exportStyle
- Throws:
IOException
-
exportOrigin
- Throws:
IOException
-
exportBookmarks
- Throws:
IOException
-
exportBookmark
- Throws:
IOException
-
exportPart
- Throws:
JRException
IOException
-
exportPage
- Throws:
IOException
JRException
-
exportElements
- Throws:
IOException
JRException
-
exportElement
- Throws:
IOException
JRException
-
exportLine
- Throws:
IOException
-
exportReportElement
- Throws:
IOException
-
exportGraphicElement
- Throws:
IOException
-
exportPen
- Throws:
IOException
-
exportPen
- Throws:
IOException
-
exportRectangle
- Throws:
IOException
-
exportEllipse
- Throws:
IOException
-
exportImage
- Throws:
JRException
IOException
-
exportText
- Throws:
IOException
-
formatTextLineBreakOffsets
-
exportTabStop
- Throws:
IOException
-
exportFont
- Throws:
IOException
-
exportFrame
- Throws:
IOException
JRException
-
exportHyperlinkParameters
- Throws:
IOException
-
exportHyperlinkParameter
- Throws:
IOException
-
exportGenericElement
- Throws:
IOException
-
getExporterPropertiesPrefix
Description copied from class:JRAbstractExporter
Returns the properties prefix for the current exporter.- Specified by:
getExporterPropertiesPrefix
in classJRAbstractExporter<ReportExportConfiguration,
ExporterConfiguration, XmlExporterOutput, JRXmlExporterContext> - Returns:
- the properties prefix for the current exporter
-
getExporterKey
- Specified by:
getExporterKey
in classJRAbstractExporter<ReportExportConfiguration,
ExporterConfiguration, XmlExporterOutput, JRXmlExporterContext>
-
getXmlWriteHelper
Returns the XML write helper used by this exporter. The helper can be used to output XML elements and attributes.- Returns:
- the XML write helper used by this exporter
-
isNewerVersionOrEqual
-
isOlderVersionThan
-