Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions Services/WebServices/RPC/lib/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ On Debian-based systems try:
````shell
> apt-get install php-curl php-xmlrpc openjdk-17-jdk-headless
````
If you plan to use the RPC server for the generation of PDF documents,
please install `openjdk-17-jre` or `openjdk-17-jdk`.

Dependencies and the build process is managed via maven
```shell
> apt-get install maven
Expand All @@ -45,7 +48,7 @@ Dependencies and the build process is managed via maven
<a name="build-java-server"></a>
## Build the Java RPC Server
```shell
> cd Services/WebServervices/RPC/lib
> cd Services/WebServices/RPC/lib
> mvn clean install
```
To build/compile the jar file for older LTS release than v17, start the maven build process with the following parameters:
Expand Down Expand Up @@ -84,7 +87,7 @@ IliasIniPath = /var/www/html/ilias/ilias.ini.php
```

- IpAddress: normally localhost is sufficient
- Port: any free non pivileged port
- Port: any free non privileged port
- IndexPath: any directory with read/write access for the webserver user
- LogFile: Directory must exist. Read/write access for the webserver is required
- LogLevel: one of INFO, DEBUG, WARN, ERROR, FATAL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,21 @@
import org.apache.fop.apps.*;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.xml.sax.SAXException;

import javax.xml.transform.*;
import javax.xml.transform.sax.SAXResult;
import javax.xml.transform.stream.StreamSource;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import org.xml.sax.SAXException;

public class FO2PDF {

Expand All @@ -51,12 +55,45 @@ public class FO2PDF {
* Singleton constructor
*/
public FO2PDF() {
final String pathToConfigFile = "/de/ilias/config/fopConfig.xml";

try {
fopFactory = FopFactory.newInstance(getClass().getResource("/de/ilias/config/fopConfig.xml").toURI());
} catch (URISyntaxException | NullPointerException ex) {
logger.error("Cannot load fop configuration:" + ex);
}
logger.info("Trying to read fopConfig from: {}", pathToConfigFile);

logger.info("Extract resource as temporary file ..");

File jarFile = new File(FO2PDF.class
.getProtectionDomain()
.getCodeSource()
.getLocation()
.toURI());
File jarDir = jarFile.getParentFile();

if (jarDir == null || !jarDir.isDirectory()) {
throw new IllegalStateException("Cannot determine the directory of the running JAR file.");
}

logger.info("Determined JAR directory path: {}", jarDir.toPath());

File tempConfigFile = new File(jarDir, "fopConfig.xml");

if (!tempConfigFile.exists()) {
try (InputStream inputStream = FO2PDF.class.getResourceAsStream(pathToConfigFile)) {
if (inputStream == null) {
throw new IllegalStateException("Resource stream is null");
}

Files.copy(inputStream, tempConfigFile.toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING);
}
}

Path configFilePath = tempConfigFile.toPath();

logger.info("fopConfig Path: {}", configFilePath.toUri());
fopFactory = FopFactory.newInstance(new File(configFilePath.toUri()));
} catch (SAXException | IOException | URISyntaxException | NullPointerException ex) {
logger.error("Cannot load fop configuration: {}", pathToConfigFile, ex);
}
}

/**
Expand Down Expand Up @@ -104,20 +141,22 @@ public void transform()
List pageSequences = foResults.getPageSequences();
for (Object pageSequence : pageSequences) {
PageSequenceResults pageSequenceResults = (PageSequenceResults) pageSequence;
logger.debug("PageSequence "
+ (String.valueOf(pageSequenceResults.getID()).length() > 0
? pageSequenceResults.getID() : "<no id>")
+ " generated " + pageSequenceResults.getPageCount() + " pages.");
logger.debug(
"PageSequence {} generated {} pages.",
!String.valueOf(pageSequenceResults.getID()).isEmpty()
? pageSequenceResults.getID()
: "<no id>", pageSequenceResults.getPageCount()
);
}
logger.info("Generated " + foResults.getPageCount() + " pages in total.");
logger.info("Generated {} pages in total.", foResults.getPageCount());

this.setPdf(out.toByteArray());

} catch (TransformerConfigurationException e) {
logger.warn("Configuration exception: " + e);
logger.warn("Configuration exception: {}", String.valueOf(e));
throw new TransformationException(e);
} catch (TransformerException e) {
logger.warn("Transformer exception: " + e);
logger.warn("Transformer exception: {}", String.valueOf(e));
throw new TransformationException(e);
} catch (FOPException e) {
throw new TransformationException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,24 @@ public boolean ping() {
return true;
}

public byte[] ilFO2PDF(String foString) {
FO2PDF fo = null;

try {
fo = new FO2PDF();
fo.clearCache();
fo.setFoString(foString);
fo.transform();
return fo.getPdf();
}
catch (TransformationException e) {
public byte[] ilFO2PDF(String foString) {

FO2PDF fo = null;

try {

fo = new FO2PDF();
fo.clearCache();
fo.setFoString(foString);
logger.info("FO String:" + foString);

fo.transform();

return fo.getPdf();
} catch (TransformationException e) {
logger.warn("Transformation failed:" + e);
}
return null;
}

return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<fop version="1.0">
<strict-configuration>true</strict-configuration>
<use-cache>false</use-cache>
<font-base>.</font-base>
<renderers>
<renderer mime="application/pdf">
<fonts>
Expand Down
Loading