I have recently upgraded Jasper Report API from 4.5.1 to 6.3. With 4.5.1, reports are exported to HTML, PDF format. For HTML reports, there is a facility to drill down to child report. In order to customise links to handle request parameters and pre processing of opening child report have created ExtensionRegistryFactory
and registered JRHyperlinkProducerMapFactory
to handle Hyperlinks.
I've noticed that extension is registered properly but it does not getting used. Checked source code of Jasper Report 6.3 and try to debug why, then observed that method: net.sf.jasperreports.engine.JRAbstractExporter.getHyperlinkProducer(JRPrintHyperlink)
does not return JRHyperlinkProducer
.
Here is the code of ExtensionsRegistryFactory
:
public class HyperlinkExtensionsRegistryFactory implements ExtensionsRegistryFactory
{
@Override
public ExtensionsRegistry createRegistry(String registryId, JRPropertiesMap properties)
{
return new ExtensionsRegistry()
{
@Override
public List getExtensions(Class extensionType)
{
if (extensionType.equals(JRHyperlinkProducerFactory.class))
{
JRHyperlinkProducerMapFactory producerFactory = new JRHyperlinkProducerMapFactory();
producerFactory.addProducer("ReportExecution", new RemoteExecutionHyperlinkProducer());
producerFactory.addProducer("Custom", new ExpandCollapseHyperlinkProducer());
return Arrays.asList(producerFactory);
}
return null;
}
};
}
public static class RemoteExecutionHyperlinkProducer implements JRHyperlinkProducer
{
@Override
public String getHyperlink(JRPrintHyperlink hyperlink)
{
return [custom link generation logic];
}
}
public static class ExpandCollapseHyperlinkProducer implements JRHyperlinkProducer
{
@Override
public String getHyperlink(JRPrintHyperlink hyperlink)
{
return [custom link generation logic];
}
}
}
With this class, have created an entry for jasperreports_extension.properties
file. Here is its content:
net.sf.jasperreports.extension.registry.factory.HyperlinkExtensionFactory=<fully_qualified_path_to_HyperlinkExtensionsRegistryFactory>
Am I missing anything? If there is any mistake I am making then kindly help to find out the one.
Thanks Narcis for input.
I've checked source code of Jasper Report 6.3.0 and tried to understand how Hyperlink registry is replaced. Found a work around for this one. Hope it will be helpful to others. Here is code snippet to register Hyperlink extension.
Exporter
AbstractHtmlExporter<HtmlReportConfiguration,HtmlExporterConfiguration> exporter = new HtmlExporter();
SimpleHtmlReportConfiguration htmlReportConfig = new SimpleHtmlReportConfiguration();
htmlReportConfig.setHyperlinkProducerFactory(HyperlinkExtensionsRegistryFactory.hyperlinkProducerFactory());
exporter.setConfiguration(htmlReportConfig);
HyperlinkExtensionsRegistryFactory.hyperlinkProducerFactory()
public JRHyperlinkProducerFactory hyperlinkProducerFactory() {
JRHyperlinkProducerMapFactory producerFactory = new JRHyperlinkProducerMapFactory();
producerFactory.addProducer("ReportExecution", new <Class_implements_JRHyperlinkProducer>());
producerFactory.addProducer("Custom", new <Class_implements_JRHyperlinkProducer>());
return producerFactory;
}