diff options
Diffstat (limited to 'pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api')
-rw-r--r-- | pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/IConfigurationConstants.java | 4 | ||||
-rw-r--r-- | pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/PdfAsFactory.java | 117 |
2 files changed, 107 insertions, 14 deletions
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/IConfigurationConstants.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/IConfigurationConstants.java index 59515937..21f8c81e 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/IConfigurationConstants.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/IConfigurationConstants.java @@ -3,6 +3,7 @@ package at.gv.egiz.pdfas.lib.api; public interface IConfigurationConstants { public static final String TRUE = "true"; + public static final String FALSE = "false"; public static final String SIG_OBJECT = "sig_obj"; public static final String TYPE = "type"; @@ -11,6 +12,9 @@ public interface IConfigurationConstants { public static final String POS = "pos"; public static final String DEFAULT = "default"; public static final String SEPERATOR = "."; + + + public static final String LEGACY_POSITIONING = ".legacy.pos"; public static final String PLACEHOLDER_SEARCH_ENABLED = "enable_placeholder_search"; public static final String DEFAULT_SIGNATURE_PROFILE = SIG_OBJECT + SEPERATOR + TYPE + SEPERATOR + DEFAULT; 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 b303a139..963e4098 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 @@ -1,12 +1,19 @@ package at.gv.egiz.pdfas.lib.api; -import iaik.security.ecc.provider.ECCProvider; +import iaik.security.ec.provider.ECCelerate; import iaik.security.provider.IAIK; +import java.io.BufferedOutputStream; import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; -import org.apache.log4j.BasicConfigurator; import org.apache.log4j.PropertyConfigurator; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import at.gv.egiz.pdfas.lib.api.sign.SignParameter; import at.gv.egiz.pdfas.lib.api.verify.VerifyParameter; @@ -15,26 +22,108 @@ import at.gv.egiz.pdfas.lib.impl.SignParameterImpl; import at.gv.egiz.pdfas.lib.impl.VerifyParameterImpl; public class PdfAsFactory { - + + private static final Logger logger = LoggerFactory + .getLogger(PdfAsFactory.class); + + private static final String DEFAULT_CONFIG_RES = "config/config.zip"; + static { - PropertyConfigurator.configure(ClassLoader.getSystemResourceAsStream("resources/log4j.properties")); - //BasicConfigurator.configure(); - - IAIK.getInstance(); - ECCProvider.addAsProvider(); + PropertyConfigurator.configure(ClassLoader + .getSystemResourceAsStream("resources/log4j.properties")); + // BasicConfigurator.configure(); + + //iaik.security.ecc.provider.ECCProvider.addAsProvider(); + IAIK.addAsProvider();; + //ECCProvider.addAsProvider(); + // install security provider + ECCelerate.addAsProvider(); } - + public static PdfAs createPdfAs(File configuration) { return new PdfAsImpl(configuration); } - - public static SignParameter createSignParameter(Configuration configuration, DataSource dataSource) { + + public static SignParameter createSignParameter( + Configuration configuration, DataSource dataSource) { SignParameter param = new SignParameterImpl(configuration, dataSource); return param; } - - public static VerifyParameter createVerifyParameter(Configuration configuration, DataSource dataSource) { - VerifyParameter param = new VerifyParameterImpl(configuration, dataSource); + + public static VerifyParameter createVerifyParameter( + Configuration configuration, DataSource dataSource) { + VerifyParameter param = new VerifyParameterImpl(configuration, + dataSource); return param; } + + public static void deployDefaultConfiguration(File targetDirectory) + throws Exception { + if (targetDirectory.exists()) { + targetDirectory.delete(); + } + + if (!targetDirectory.exists()) { + targetDirectory.mkdir(); + } + InputStream is = ClassLoader + .getSystemResourceAsStream(DEFAULT_CONFIG_RES); + // URL zipUrl = ClassLoader.getSystemResource(DEFAULT_CONFIG_RES); + // logger.debug("CONFIG URI: " + zipUrl.toURI().toString()); + // File zipFile = new File(zipUrl.toURI()); + // ZipFile zip = null; + ZipInputStream zip = null; + try { + zip = new ZipInputStream(is); + + ZipEntry entry = zip.getNextEntry(); + while (entry != null) { + + File destinationPath = new File( + targetDirectory.getAbsolutePath(), entry.getName()); + + // create parent directories + destinationPath.getParentFile().mkdirs(); + + // if the entry is a file extract it + if (entry.isDirectory()) { + destinationPath.mkdir(); + zip.closeEntry(); + entry = zip.getNextEntry(); + continue; + } else { + + logger.debug("Extracting file: " + destinationPath); + + int b; + byte buffer[] = new byte[1024]; + + FileOutputStream fos = new FileOutputStream(destinationPath); + + BufferedOutputStream bos = new BufferedOutputStream(fos, + 1024); + + while ((b = zip.read(buffer, 0, 1024)) != -1) { + bos.write(buffer, 0, b); + } + + bos.close(); + zip.closeEntry(); + + } + entry = zip.getNextEntry(); + } + + } catch (IOException ioe) { + System.out.println("Error opening zip file" + ioe); + } finally { + try { + if (zip != null) { + zip.close(); + } + } catch (IOException ioe) { + System.out.println("Error while closing zip file" + ioe); + } + } + } } |