From 4be6889e90dff021cc625649f013c428b2ef4a47 Mon Sep 17 00:00:00 2001 From: Andreas Fitzek Date: Thu, 12 Dec 2013 11:52:00 +0100 Subject: Reading log4j configuration from pdf-as workdir --- .../at/gv/egiz/pdfas/lib/api/PdfAsFactory.java | 41 ++++++++++++++++++++-- 1 file changed, 38 insertions(+), 3 deletions(-) (limited to 'pdf-as-lib/src/main/java/at/gv/egiz') diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/PdfAsFactory.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/PdfAsFactory.java index 963e4098..93fbbfea 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/PdfAsFactory.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/PdfAsFactory.java @@ -5,6 +5,8 @@ import iaik.security.provider.IAIK; import java.io.BufferedOutputStream; import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; @@ -15,6 +17,8 @@ import org.apache.log4j.PropertyConfigurator; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.sun.org.apache.bcel.internal.generic.NEW; + import at.gv.egiz.pdfas.lib.api.sign.SignParameter; import at.gv.egiz.pdfas.lib.api.verify.VerifyParameter; import at.gv.egiz.pdfas.lib.impl.PdfAsImpl; @@ -33,14 +37,45 @@ public class PdfAsFactory { .getSystemResourceAsStream("resources/log4j.properties")); // BasicConfigurator.configure(); - //iaik.security.ecc.provider.ECCProvider.addAsProvider(); - IAIK.addAsProvider();; - //ECCProvider.addAsProvider(); + // iaik.security.ecc.provider.ECCProvider.addAsProvider(); + IAIK.addAsProvider(); + ; + // ECCProvider.addAsProvider(); // install security provider ECCelerate.addAsProvider(); } + private static boolean log_configured = false; + private static Object log_mutex = new Object(); + + public static void dontConfigureLog4j() { + synchronized (log_mutex) { + log_configured = true; + } + } + public static PdfAs createPdfAs(File configuration) { + if (!log_configured) { + synchronized (log_mutex) { + if (!log_configured) { + File log4j = new File(configuration.getAbsolutePath() + + File.separator + "cfg" + File.separator + + "log4j.properties"); + logger.info("Loading log4j configuration: " + log4j.getAbsolutePath()); + if (log4j.exists()) { + try { + System.setProperty("pdf-as.work-dir", configuration.getAbsolutePath()); + PropertyConfigurator.configure(new FileInputStream( + log4j)); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + } + log_configured = true; + } + } + } + return new PdfAsImpl(configuration); } -- cgit v1.2.3