Commit ce3562cf authored by Matthias Betz's avatar Matthias Betz
Browse files

fixing more lint issues

Adding event handler so logging is not different
parent d3fb0ee6
Pipeline #2013 failed with stage
......@@ -41,6 +41,10 @@ import org.apache.fop.apps.FOPException;
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.Fop;
import org.apache.fop.apps.FopFactory;
import org.apache.fop.events.EventFormatter;
import org.apache.fop.events.model.EventSeverity;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.xmlgraphics.util.MimeConstants;
import org.jdom2.Document;
import org.jdom2.Element;
......@@ -57,6 +61,8 @@ import de.hft.stuttgart.citydoctor2.checkresult.utility.CheckReportWriteExceptio
*/
public class PdfReport {
private static final Logger logger = LogManager.getLogger(PdfReport.class);
private static final String FRONT_PAGE = "front-page";
private static final String REGION_BODY = "region-body";
private static final String MASTER_NAME = "master-name";
......@@ -160,16 +166,28 @@ public class PdfReport {
try {
FOUserAgent userAgent = FOP_FACTORY.newFOUserAgent();
userAgent.getEventBroadcaster().addEventListener(event -> {
EventSeverity severity = event.getSeverity();
String msg = EventFormatter.format(event);
if (severity == EventSeverity.ERROR) {
logger.error(msg);
} else if (severity == EventSeverity.FATAL) {
logger.fatal(msg);
} else if (severity == EventSeverity.INFO) {
logger.info(msg);
} else if (severity == EventSeverity.WARN) {
logger.warn(msg);
}
});
Fop fop = FOP_FACTORY.newFop(MimeConstants.MIME_PDF, userAgent, outFile);
TransformerFactory factory = TransformerFactory.newInstance();
// deactivate external dtds because of security issues
factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
// identity transformer
Transformer transformer = factory.newTransformer();
DOMOutputter domOutputter = new DOMOutputter();
Source src = new DOMSource(domOutputter.output(doc));
Result res = new SAXResult(fop.getDefaultHandler());
transformer.transform(src, res);
......
......@@ -29,6 +29,10 @@ import org.jdom2.Namespace;
*/
public class PdfUtils {
private static final String HEIGHT_STRING = "height";
private static final String WIDTH_STRING = "width";
private static final Namespace svgNs = Namespace.getNamespace("svg", "http://www.w3.org/2000/svg");
private static final int WIDTH = 450;
......@@ -46,8 +50,8 @@ public class PdfUtils {
String val2LengthString = "" + val2Length;
Element svgElement = new Element("svg", svgNs);
svgElement.setAttribute("width", "450px");
svgElement.setAttribute("height", "30px");
svgElement.setAttribute(WIDTH_STRING, "450px");
svgElement.setAttribute(HEIGHT_STRING, "30px");
if (val1 > 0) {
Element gVal1Style = new Element("g", svgNs);
......@@ -58,8 +62,8 @@ public class PdfUtils {
gVal1Style.addContent(val1Rect);
val1Rect.setAttribute("x", "0");
val1Rect.setAttribute("y", "0");
val1Rect.setAttribute("width", val1LengthString);
val1Rect.setAttribute("height", "30");
val1Rect.setAttribute(WIDTH_STRING, val1LengthString);
val1Rect.setAttribute(HEIGHT_STRING, "30");
Element val1Text = new Element("text", svgNs);
svgElement.addContent(val1Text);
val1Text.setAttribute("x", "5");
......@@ -76,8 +80,8 @@ public class PdfUtils {
gVal2Style.addContent(val2Rect);
val2Rect.setAttribute("x", val1LengthString);
val2Rect.setAttribute("y", "0");
val2Rect.setAttribute("width", val2LengthString);
val2Rect.setAttribute("height", "30");
val2Rect.setAttribute(WIDTH_STRING, val2LengthString);
val2Rect.setAttribute(HEIGHT_STRING, "30");
Element val2Text = new Element("text", svgNs);
svgElement.addContent(val2Text);
String val2String = "" + val2;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment