Skip to content

Commit

Permalink
Enable RTF
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware committed Oct 2, 2024
1 parent 7acae82 commit 2592bf7
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
package io.quarkiverse.jasperreports.deployment;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.DotName;
import org.jboss.logging.Logger;

import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.CombinedIndexBuildItem;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem;
import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBundleBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import io.quarkus.deployment.builditem.nativeimage.RuntimeInitializedPackageBuildItem;
import io.quarkus.deployment.pkg.builditem.UberJarMergedResourceBuildItem;

class JasperReportsProcessor {

private static final Logger LOGGER = Logger.getLogger("JasperReports");
private static final String FEATURE = "jasperreports";
private static final String EXTENSIONS_FILE = "jasperreports_extension.properties";

Expand All @@ -29,6 +38,7 @@ UberJarMergedResourceBuildItem mergeResource() {
void runtimeInitializedClasses(BuildProducer<RuntimeInitializedPackageBuildItem> runtimeInitializedPackages) {
//@formatter:off
Stream.of(
com.ibm.icu.lang.UScript.class.getPackageName(),
javax.swing.plaf.metal.MetalIconFactory.class.getPackageName(),
net.sf.jasperreports.data.http.HttpDataService.class.getPackageName(),
net.sf.jasperreports.engine.SimpleReportContext.class.getPackageName(),
Expand All @@ -42,7 +52,9 @@ void runtimeInitializedClasses(BuildProducer<RuntimeInitializedPackageBuildItem>
net.sf.jasperreports.engine.util.ExifUtil.class.getPackageName(),
net.sf.jasperreports.engine.util.json.DefaultJsonQLExecuter.class.getPackageName(),
net.sf.jasperreports.renderers.AbstractSvgDataToGraphics2DRenderer.class.getPackageName(),
net.sf.jasperreports.renderers.util.SvgFontProcessor.class.getPackageName()
net.sf.jasperreports.renderers.RenderersCache.class.getPackageName(),
net.sf.jasperreports.renderers.util.SvgFontProcessor.class.getPackageName(),
net.sf.jasperreports.renderers.util.RendererUtil.class.getPackageName()
)
.map(RuntimeInitializedPackageBuildItem::new)
.forEach(runtimeInitializedPackages::produce);
Expand All @@ -64,4 +76,61 @@ void substrateResourceBuildItems(BuildProducer<NativeImageResourceBuildItem> nat
resourceBundleBuildItem.produce(new NativeImageResourceBundleBuildItem("metadata_messages"));
resourceBundleBuildItem.produce(new NativeImageResourceBundleBuildItem("metadata_messages-defaults"));
}

@BuildStep
void registerForReflection(BuildProducer<ReflectiveClassBuildItem> reflectiveClass,
CombinedIndexBuildItem combinedIndex) {

final List<String> classNames = new ArrayList<>();
// All utilities
classNames.addAll(collectClassesInPackage(combinedIndex,
net.sf.jasperreports.renderers.util.RendererUtil.class.getPackageName()));
classNames.addAll(
collectClassesInPackage(combinedIndex, net.sf.jasperreports.engine.util.ExifUtil.class.getPackageName()));
classNames.addAll(collectClassesInPackage(combinedIndex,
net.sf.jasperreports.engine.util.json.DefaultJsonQLExecuter.class.getPackageName()));
classNames.addAll(collectClassesInPackage(combinedIndex,
net.sf.jasperreports.renderers.WrappingSvgDataToGraphics2DRenderer.class.getPackageName()));

reflectiveClass.produce(
ReflectiveClassBuildItem.builder(classNames.toArray(new String[0])).constructors().methods().fields()
.serialization()
.build());
}

public List<String> collectClassesInPackage(CombinedIndexBuildItem combinedIndex, String packageName) {
final List<String> classes = new ArrayList<>();
final List<DotName> packages = new ArrayList<>(combinedIndex.getIndex().getSubpackages(packageName));
packages.add(DotName.createSimple(packageName));
for (DotName aPackage : packages) {
final List<String> packageClasses = combinedIndex.getIndex()
.getClassesInPackage(aPackage)
.stream()
.map(ClassInfo::toString)
.toList();
classes.addAll(packageClasses);
}
LOGGER.infof("Classes: %s", classes);
return classes;
}

private List<String> collectSubclasses(CombinedIndexBuildItem combinedIndex, String className) {
List<String> classes = combinedIndex.getIndex()
.getAllKnownSubclasses(DotName.createSimple(className))
.stream()
.map(ClassInfo::toString)
.collect(Collectors.toList());
classes.add(className);
return classes;
}

public List<String> collectImplementors(CombinedIndexBuildItem combinedIndex, String className) {
List<String> classes = combinedIndex.getIndex()
.getAllKnownImplementors(DotName.createSimple(className))
.stream()
.map(ClassInfo::toString)
.collect(Collectors.toList());
classes.add(className);
return classes;
}
}
2 changes: 1 addition & 1 deletion integration-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-reactive</artifactId>
<artifactId>quarkus-rest</artifactId>
</dependency>
<dependency>
<groupId>io.quarkiverse.jasperreports</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import net.sf.jasperreports.engine.design.JasperDesign;
import net.sf.jasperreports.engine.export.HtmlExporter;
import net.sf.jasperreports.engine.export.JRCsvExporter;
import net.sf.jasperreports.engine.export.JRRtfExporter;
import net.sf.jasperreports.engine.export.JRXmlExporter;
import net.sf.jasperreports.engine.fill.JRFiller;
import net.sf.jasperreports.engine.fill.SimpleJasperReportSource;
Expand Down Expand Up @@ -155,6 +156,22 @@ public byte[] html() throws JRException {
return outputStream.toByteArray();
}

@POST
@Path("rtf")
public byte[] rtf() throws JRException {
long start = System.currentTimeMillis();
JasperPrint jasperPrint = fill();

JRRtfExporter exporter = new JRRtfExporter();
exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
exporter.setExporterOutput(new SimpleWriterExporterOutput(outputStream));

exporter.exportReport();
Log.info("RTF creation time : " + (System.currentTimeMillis() - start));
return outputStream.toByteArray();
}

// @POST
// @Path("print")
// public void print() throws JRException {
Expand Down Expand Up @@ -182,27 +199,7 @@ public byte[] html() throws JRException {
//
// return outputStream.toByteArray();
// }
//
// @POST
// @Path("rtf")
// public byte[] rtf() throws JRException {
// long start = System.currentTimeMillis();
//
// JasperPrint jasperPrint = fill();
//
// JRRtfExporter exporter = new JRRtfExporter();
//
// exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
//
// ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
// exporter.setExporterOutput(new SimpleWriterExporterOutput(outputStream));
//
// exporter.exportReport();
//
// Log.info("RTF creation time : " + (System.currentTimeMillis() - start));
//
// return outputStream.toByteArray();
// }

//

//
Expand Down Expand Up @@ -329,4 +326,4 @@ public byte[] html() throws JRException {
//
// return outputStream.toByteArray();
// }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ void testExportHTML() {
.statusCode(200);
}

@Test
void testExportRTF() {
given()
.when().post("/jasperreports/rtf")
.then()
.statusCode(200);
}

// @Test
// void testExportPDF() {
// given()
Expand All @@ -46,13 +54,7 @@ void testExportHTML() {
// .statusCode(200);
// }
//
// @Test
// void testExportRTF() {
// given()
// .when().post("/jasperreports/rtf")
// .then()
// .statusCode(200);
// }

//

//
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<version.quarkus-poi>2.0.6</version.quarkus-poi>

<version.jasperreports>6.21.3</version.jasperreports><!-- Make sure to update the exclusions in quarkus-jasperreports when updating jasper -->
<version.jaxen>1.2.0</version.jaxen> <!-- Must match the jaxen version used in the given jasperreports version -->
<version.jaxen>2.0.0</version.jaxen> <!-- Must match the jaxen version used in the given jasperreports version -->
</properties>
<dependencyManagement>
<dependencies>
Expand Down
6 changes: 6 additions & 0 deletions runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@
<version>${version.jaxen}</version>
</dependency>

<dependency>
<groupId>com.ibm.icu</groupId>
<artifactId>icu4j</artifactId>
<version>75.1</version>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
Expand Down

0 comments on commit 2592bf7

Please sign in to comment.