Class JRXmlExporter
- java.lang.Object
-
- net.sf.jasperreports.engine.JRAbstractExporter<ReportExportConfiguration,ExporterConfiguration,XmlExporterOutput,JRXmlExporterContext>
-
- net.sf.jasperreports.engine.export.JRXmlExporter
-
- All Implemented Interfaces:
JRExporter<ExporterInput,ReportExportConfiguration,ExporterConfiguration,XmlExporterOutput>,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 aJasperPrintobject, 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*.jrpxmlextension. Such XML files can be parsed back intoJasperPrintobject using theJRPrintXmlLoaderutility class. Their structure is validated against an internal XSD file calledjasperprint.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 theGraphics2Dexporter 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 aJasperPrintobject 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 theJRPrintXmlLoaderto load the document back into aJasperPrintobject 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
_filessuffix, 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 ajava.lang.Boolean. By default, the images are embedded in the resulting XML.- Author:
- Teodor Danciu (teodord@users.sourceforge.net)
- See Also:
JasperPrint,JRPrintXmlLoader
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classJRXmlExporter.ExporterContext-
Nested classes/interfaces inherited from class net.sf.jasperreports.engine.JRAbstractExporter
JRAbstractExporter.BaseExporterContext, JRAbstractExporter.PageRange
-
-
Field Summary
Fields Modifier and Type Field Description protected static StringDEFAULT_OBJECT_TYPEstatic StringEXCEPTION_MESSAGE_KEY_EMBEDDING_IMAGE_ERRORstatic StringEXCEPTION_MESSAGE_KEY_REPORT_STYLE_NOT_FOUNDprotected static StringIMAGE_PREFIXprotected booleanisEmbeddingImagesstatic XmlNamespaceJASPERPRINT_NAMESPACEstatic StringPROPERTY_END_PAGE_INDEXstatic StringPROPERTY_PAGE_COUNTstatic StringPROPERTY_REPLACE_INVALID_CHARSStores the text sequence used to replace invalid XML charactersstatic StringPROPERTY_START_PAGE_INDEXprotected RenderersCacherenderersCacheprotected Map<String,String>rendererToImagePathMapprotected Map<String,JRStyle>stylesMapprotected Stringversionprotected VersionComparatorversionComparatorstatic StringXML_EXPORTER_KEYThe exporter key, as used inGenericElementHandlerEnviroment.getElementHandler(JRGenericElementType, String).protected JRXmlWriteHelperxmlWriter-
Fields inherited from class net.sf.jasperreports.engine.JRAbstractExporter
allSelector, crtCompositeConfiguration, crtCompositeItemConfiguration, crtItem, dateFormatCache, EXCEPTION_MESSAGE_KEY_END_PAGE_INDEX_OUT_OF_RANGE, EXCEPTION_MESSAGE_KEY_INVALID_IMAGE_NAME, EXCEPTION_MESSAGE_KEY_INVALID_ZOOM_RATIO, EXCEPTION_MESSAGE_KEY_MIXED_CALLS_NOT_ALLOWED, 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, parameters, propertiesUtil, PROPERTY_DEFAULT_FILTER_FACTORY, PROPERTY_SUFFIX_DEFAULT_FILTER_FACTORY, rendererUtil, styledTextUtil, textValueClasses
-
-
Constructor Summary
Constructors Constructor Description JRXmlExporter()JRXmlExporter(JasperReportsContext jasperReportsContext)
-
Method Summary
-
Methods inherited from class net.sf.jasperreports.engine.JRAbstractExporter
checkInterrupted, createFilter, defaultParseNumber, ensureInput, ensureJasperReportsContext, getBooleanCellValue, getCurrentConfiguration, getCurrentItemConfiguration, getCurrentJasperPrint, getDateCellValue, getDateFormat, getExporterContext, getExporterInput, getExporterOutput, getHyperlinkProducer, getJasperReportsContext, getLocale, getNumberCellValue, getNumberFormat, getOffsetX, getOffsetY, getPageRange, getParameter, getParameters, getPropertiesUtil, getRendererUtil, getReportContext, getRepository, getStyledText, getStyledText, getTextFormatFactoryClass, getTextLocale, getTextTimeZone, getTextValue, getTextValueString, insideFrame, reset, resetClassLoader, resetExportContext, restoreElementOffsets, setClassLoader, setConfiguration, setConfiguration, setCurrentExporterInputItem, setExporterInput, setExporterOutput, setFrameElementsOffset, setJasperReportsContext, setOffset, setOffset, setParameter, setParameters, setReportContext
-
-
-
-
Field Detail
-
EXCEPTION_MESSAGE_KEY_EMBEDDING_IMAGE_ERROR
public static final String EXCEPTION_MESSAGE_KEY_EMBEDDING_IMAGE_ERROR
- See Also:
- Constant Field Values
-
EXCEPTION_MESSAGE_KEY_REPORT_STYLE_NOT_FOUND
public static final String EXCEPTION_MESSAGE_KEY_REPORT_STYLE_NOT_FOUND
- See Also:
- Constant Field Values
-
XML_EXPORTER_KEY
public static final String XML_EXPORTER_KEY
The exporter key, as used inGenericElementHandlerEnviroment.getElementHandler(JRGenericElementType, String).- See Also:
- Constant Field Values
-
PROPERTY_START_PAGE_INDEX
public static final String PROPERTY_START_PAGE_INDEX
- See Also:
- Constant Field Values
-
PROPERTY_END_PAGE_INDEX
public static final String PROPERTY_END_PAGE_INDEX
- See Also:
- Constant Field Values
-
PROPERTY_PAGE_COUNT
public static final String PROPERTY_PAGE_COUNT
- See Also:
- Constant Field Values
-
PROPERTY_REPLACE_INVALID_CHARS
public static final String PROPERTY_REPLACE_INVALID_CHARS
Stores the text sequence used to replace invalid XML characters- See Also:
- Constant Field Values
-
DEFAULT_OBJECT_TYPE
protected static final String DEFAULT_OBJECT_TYPE
- See Also:
- Constant Field Values
-
IMAGE_PREFIX
protected static final String IMAGE_PREFIX
- See Also:
- Constant Field Values
-
JASPERPRINT_NAMESPACE
public static final XmlNamespace JASPERPRINT_NAMESPACE
-
xmlWriter
protected JRXmlWriteHelper xmlWriter
-
version
protected String version
-
versionComparator
protected VersionComparator versionComparator
-
renderersCache
protected RenderersCache renderersCache
-
isEmbeddingImages
protected boolean isEmbeddingImages
-
-
Constructor Detail
-
JRXmlExporter
public JRXmlExporter()
- See Also:
JRXmlExporter(JasperReportsContext)
-
JRXmlExporter
public JRXmlExporter(JasperReportsContext jasperReportsContext)
-
-
Method Detail
-
getConfigurationInterface
protected Class<ExporterConfiguration> getConfigurationInterface()
- Specified by:
getConfigurationInterfacein classJRAbstractExporter<ReportExportConfiguration,ExporterConfiguration,XmlExporterOutput,JRXmlExporterContext>
-
getItemConfigurationInterface
protected Class<ReportExportConfiguration> getItemConfigurationInterface()
-
ensureOutput
protected void ensureOutput()
- Specified by:
ensureOutputin classJRAbstractExporter<ReportExportConfiguration,ExporterConfiguration,XmlExporterOutput,JRXmlExporterContext>
-
exportReport
public void exportReport() throws JRExceptionDescription copied from interface:ExporterPerforms the export.- Specified by:
exportReportin interfaceExporter<ExporterInput,ReportExportConfiguration,ExporterConfiguration,XmlExporterOutput>- Specified by:
exportReportin classJRAbstractExporter<ReportExportConfiguration,ExporterConfiguration,XmlExporterOutput,JRXmlExporterContext>- Throws:
JRException
-
initExport
protected void initExport()
- Overrides:
initExportin classJRAbstractExporter<ReportExportConfiguration,ExporterConfiguration,XmlExporterOutput,JRXmlExporterContext>
-
initReport
protected void initReport()
- Overrides:
initReportin classJRAbstractExporter<ReportExportConfiguration,ExporterConfiguration,XmlExporterOutput,JRXmlExporterContext>
-
getNamespace
protected XmlNamespace getNamespace()
-
exportReportToStream
protected void exportReportToStream(Writer writer) throws JRException, IOException
- Throws:
JRExceptionIOException
-
exportProperties
protected void exportProperties(JRPropertiesHolder propertiesHolder) throws IOException
- Throws:
IOException
-
exportStyle
protected void exportStyle(JRStyle style) throws IOException
- Throws:
IOException
-
exportOrigin
protected void exportOrigin(JROrigin origin) throws IOException
- Throws:
IOException
-
exportBookmarks
protected void exportBookmarks(List<PrintBookmark> bookmarks) throws IOException
- Throws:
IOException
-
exportBookmark
protected void exportBookmark(PrintBookmark bookmark) throws IOException
- Throws:
IOException
-
exportPart
protected void exportPart(Integer pageIndex, PrintPart part) throws JRException, IOException
- Throws:
JRExceptionIOException
-
exportPage
protected void exportPage(JRPrintPage page) throws JRException, IOException
- Throws:
IOExceptionJRException
-
exportElements
protected void exportElements(Collection<JRPrintElement> elements) throws IOException, JRException
- Throws:
IOExceptionJRException
-
exportElement
public void exportElement(JRPrintElement element) throws IOException, JRException
- Throws:
IOExceptionJRException
-
exportLine
protected void exportLine(JRPrintLine line) throws IOException
- Throws:
IOException
-
exportReportElement
protected void exportReportElement(JRPrintElement element) throws IOException
- Throws:
IOException
-
exportGraphicElement
protected void exportGraphicElement(JRPrintGraphicElement element) throws IOException
- Throws:
IOException
-
exportPen
protected void exportPen(JRPen pen) throws IOException
- Throws:
IOException
-
exportPen
protected void exportPen(String element, JRPen pen) throws IOException
- Throws:
IOException
-
exportRectangle
protected void exportRectangle(JRPrintRectangle rectangle) throws IOException
- Throws:
IOException
-
exportEllipse
protected void exportEllipse(JRPrintEllipse ellipse) throws IOException
- Throws:
IOException
-
exportImage
public void exportImage(JRPrintImage image) throws JRException, IOException
- Throws:
JRExceptionIOException
-
exportText
public void exportText(JRPrintText text) throws IOException
- Throws:
IOException
-
formatTextLineBreakOffsets
protected StringBuilder formatTextLineBreakOffsets(short[] lineBreakOffsets)
-
exportTabStop
public void exportTabStop(TabStop tabStop) throws IOException
- Throws:
IOException
-
exportFont
protected void exportFont(JRFont font) throws IOException
- Throws:
IOException
-
exportFrame
protected void exportFrame(JRPrintFrame frame) throws IOException, JRException
- Throws:
IOExceptionJRException
-
exportHyperlinkParameters
protected void exportHyperlinkParameters(JRPrintHyperlink hyperlink) throws IOException
- Throws:
IOException
-
exportHyperlinkParameter
protected void exportHyperlinkParameter(JRPrintHyperlinkParameter parameter) throws IOException
- Throws:
IOException
-
exportGenericElement
protected void exportGenericElement(JRGenericPrintElement element) throws IOException
- Throws:
IOException
-
getExporterPropertiesPrefix
public String getExporterPropertiesPrefix()
Description copied from class:JRAbstractExporterReturns the properties prefix for the current exporter.- Specified by:
getExporterPropertiesPrefixin classJRAbstractExporter<ReportExportConfiguration,ExporterConfiguration,XmlExporterOutput,JRXmlExporterContext>- Returns:
- the properties prefix for the current exporter
-
getExporterKey
public String getExporterKey()
- Specified by:
getExporterKeyin classJRAbstractExporter<ReportExportConfiguration,ExporterConfiguration,XmlExporterOutput,JRXmlExporterContext>
-
getXmlWriteHelper
public JRXmlWriteHelper 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
protected boolean isNewerVersionOrEqual(String oldVersion)
-
isOlderVersionThan
protected boolean isOlderVersionThan(String version)
-
-