Skip to content

Commit 10d2d6f

Browse files
committed
Fop AOT module
1 parent 37732a3 commit 10d2d6f

File tree

15 files changed

+286
-3
lines changed

15 files changed

+286
-3
lines changed

code-samples-base/src/test/java/test/org/fugerit/java/code/samples/base/TestAgeCheck.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,49 @@
55
import org.junit.jupiter.api.Assertions;
66
import org.junit.jupiter.api.Test;
77

8+
import javax.xml.datatype.DatatypeConfigurationException;
9+
import javax.xml.datatype.DatatypeFactory;
10+
import javax.xml.datatype.XMLGregorianCalendar;
811
import java.time.LocalDate;
12+
import java.time.Period;
13+
import java.time.ZoneId;
914
import java.time.temporal.ChronoUnit;
15+
import java.util.Calendar;
16+
import java.util.GregorianCalendar;
1017

1118
@Slf4j
1219
class TestAgeCheck {
1320

21+
22+
@Test
23+
void testFormat() {
24+
Assertions.assertEquals( "Test 1", "Test %s".formatted( "1" ) );
25+
26+
}
27+
28+
@Test
29+
void testMaggiorenne1() throws DatatypeConfigurationException {
30+
Assertions.assertFalse( Character.isUpperCase( '1' ) );
31+
32+
}
33+
34+
private static boolean maggiorenne(XMLGregorianCalendar datanascita){
35+
LocalDate d = datanascita.toGregorianCalendar().getTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
36+
return Period.between(d, LocalDate.now()).getYears() >= 18;
37+
}
38+
39+
@Test
40+
void testMaggiorenne() throws DatatypeConfigurationException {
41+
GregorianCalendar calendar = new GregorianCalendar();
42+
Assertions.assertFalse( maggiorenne( DatatypeFactory.newInstance().newXMLGregorianCalendar( calendar ) ) );
43+
// Subtract 20 years from the current date
44+
calendar.add(Calendar.YEAR, -20);
45+
// Create a new XMLGregorianCalendar from the updated GregorianCalendar
46+
XMLGregorianCalendar xmlCalendar = DatatypeFactory.newInstance().newXMLGregorianCalendar(calendar);
47+
Assertions.assertTrue( maggiorenne( xmlCalendar ) );
48+
49+
}
50+
1451
private boolean testWorkerModule7( LocalDate d1, LocalDate d2 ) {
1552
boolean result = (ChronoUnit.DAYS.between( d1, d2 )%7==0);
1653
log.info( "d1 {}, d2 {}, res : {}", d1, d2, result );

code-samples-fop/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ And the two junit testing version 2.9 and 2.10 output :
2424

2525
`test.org.fugerit.java.codesamples.fop.fop29.TestFopPOC29`
2626

27-
`test.org.fugerit.java.codesamples.fop.latest.TestFopPOCLatest`
27+
`org.fugerit.java.codesamples.fop.aot.TestFopPOCAOT`
2828

2929
The issue seems to be actually fixed.
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<artifactId>code-samples-fop-aot</artifactId>
6+
7+
<parent>
8+
<groupId>org.fugerit.java</groupId>
9+
<artifactId>code-samples-fop</artifactId>
10+
<version>1.0.0-SNAPSHOT</version>
11+
</parent>
12+
13+
<name>Fugerit Code Samples Fop AOT</name>
14+
<description>My code samples for AOT version of fop</description>
15+
16+
<properties>
17+
<fop-version>2.10</fop-version>
18+
<native.maven.plugin.version>0.10.6</native.maven.plugin.version>
19+
</properties>
20+
21+
<dependencies>
22+
23+
<dependency>
24+
<groupId>org.apache.xmlgraphics</groupId>
25+
<artifactId>fop</artifactId>
26+
<version>${fop-version}</version>
27+
</dependency>
28+
29+
</dependencies>
30+
31+
<profiles>
32+
<profile>
33+
<id>native</id>
34+
<build>
35+
<plugins>
36+
<plugin>
37+
<groupId>org.graalvm.buildtools</groupId>
38+
<artifactId>native-maven-plugin</artifactId>
39+
<version>${native.maven.plugin.version}</version>
40+
<extensions>true</extensions>
41+
<executions>
42+
<execution>
43+
<id>build-native</id>
44+
<goals>
45+
<goal>compile-no-fork</goal>
46+
</goals>
47+
<phase>package</phase>
48+
</execution>
49+
</executions>
50+
<configuration>
51+
<mainClass>org.fugerit.java.codesamples.fop.aot.MainFopAOT</mainClass>
52+
</configuration>
53+
</plugin>
54+
</plugins>
55+
</build>
56+
</profile>
57+
</profiles>
58+
59+
</project>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package org.fugerit.java.codesamples.fop.aot;
2+
3+
import org.apache.fop.apps.FOUserAgent;
4+
import org.apache.fop.apps.Fop;
5+
import org.apache.fop.apps.FopFactory;
6+
import org.apache.xmlgraphics.util.MimeConstants;
7+
import org.fugerit.java.core.function.SafeFunction;
8+
import org.fugerit.java.core.lang.helpers.ClassHelper;
9+
10+
import javax.xml.transform.Result;
11+
import javax.xml.transform.Transformer;
12+
import javax.xml.transform.TransformerFactory;
13+
import javax.xml.transform.sax.SAXResult;
14+
import javax.xml.transform.stream.StreamSource;
15+
import java.io.File;
16+
import java.io.InputStreamReader;
17+
import java.io.OutputStream;
18+
19+
public class FopAOTPoc {
20+
21+
private FopAOTPoc() {}
22+
23+
public static void generatePdfATest1(OutputStream os) {
24+
String xslFoPath = "test-xsl-fo/pdf-a-test-1.fo";
25+
generate( xslFoPath, os );
26+
}
27+
28+
public static void generate(String xslFoPath, OutputStream os ) {
29+
SafeFunction.apply( () -> {
30+
FopFactory fopFactory = FopFactory.newInstance(new File(".").toURI());
31+
FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
32+
foUserAgent.setAccessibility( true );
33+
foUserAgent.setKeepEmptyTags( true );
34+
Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, os);
35+
TransformerFactory factory = TransformerFactory.newInstance();
36+
Transformer transformer = factory.newTransformer();
37+
Result res = new SAXResult(fop.getDefaultHandler());
38+
try (InputStreamReader xslFoReader = new InputStreamReader(ClassHelper.loadFromDefaultClassLoader( xslFoPath )) ) {
39+
transformer.transform(new StreamSource(xslFoReader), res);
40+
}
41+
} );
42+
}
43+
44+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package org.fugerit.java.codesamples.fop.aot;
2+
3+
import org.fugerit.java.core.function.SafeFunction;
4+
5+
import java.io.File;
6+
import java.io.FileOutputStream;
7+
8+
public class MainFopAOT {
9+
10+
public static void main(String[] args) {
11+
String filePath = args[0];
12+
SafeFunction.apply(() -> {
13+
File outputFile = new File( filePath );
14+
try (FileOutputStream fos = new FileOutputStream( outputFile )) {
15+
FopAOTPoc.generatePdfATest1( fos );
16+
}
17+
});
18+
}
19+
20+
}
52.6 KB
Binary file not shown.
61.4 KB
Binary file not shown.
63.8 KB
Binary file not shown.
56 KB
Binary file not shown.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<fop version="1.0">
2+
3+
<!-- Strict user configuration -->
4+
<strict-configuration>true</strict-configuration>
5+
6+
<!-- Strict FO validation -->
7+
<strict-validation>true</strict-validation>
8+
9+
<!-- Base URL for resolving relative URLs -->
10+
<base>.</base>
11+
12+
<!-- Font Base URL for resolving relative font URLs -->
13+
<font-base>.</font-base>
14+
15+
<!--
16+
NOTE: for PDF/A format all fonts, even the basic ones, myst be fully embdedded.
17+
https://xmlgraphics.apache.org/fop/2.10/pdfa.htm
18+
-->
19+
<renderers>
20+
<renderer mime="application/pdf">
21+
<pdf-ua-mode>PDF/UA-1</pdf-ua-mode>
22+
<pdf-a-mode>PDF/A-1b</pdf-a-mode>
23+
<version>1.4</version>
24+
<fonts>
25+
<font embed-url="classpath://font/TitilliumWeb-Regular.ttf" embedding-mode="full">
26+
<font-triplet name="TitilliumWeb" style="normal" weight="normal"/>
27+
</font>
28+
<font embed-url="classpath://font/TitilliumWeb-Bold.ttf" embedding-mode="full">
29+
<font-triplet name="TitilliumWeb" style="normal" weight="bold"/>
30+
</font>
31+
<font embed-url="classpath://font/TitilliumWeb-Italic.ttf" embedding-mode="full">
32+
<font-triplet name="TitilliumWeb" style="italic" weight="normal"/>
33+
</font>
34+
<font embed-url="classpath://font/TitilliumWeb-BoldItalic.ttf" embedding-mode="full">
35+
<font-triplet name="TitilliumWeb" style="italic" weight="bold"/>
36+
</font>
37+
</fonts>
38+
</renderer>
39+
</renderers>
40+
41+
42+
<!-- Source resolution in dpi (dots/pixels per inch) for determining the size of pixels in SVG and bitmap images, default: 72dpi -->
43+
<source-resolution>72</source-resolution>
44+
<!-- Target resolution in dpi (dots/pixels per inch) for specifying the target resolution for generated bitmaps, default: 72dpi -->
45+
<target-resolution>72</target-resolution>
46+
47+
<!-- default page-height and page-width, in case
48+
value is specified as auto -->
49+
<default-page-settings height="11in" width="8.26in"/>
50+
51+
</fop>

0 commit comments

Comments
 (0)