aboutsummaryrefslogtreecommitdiff
path: root/pdf-as-common
diff options
context:
space:
mode:
authorAndreas Fitzek <andreas.fitzek@iaik.tugraz.at>2013-09-26 15:48:43 +0200
committerAndreas Fitzek <andreas.fitzek@iaik.tugraz.at>2013-09-26 15:48:43 +0200
commitfc44d4bcad00192f0df8f6086737b9b126094dcd (patch)
treea03a3018b6faba73309bf381337ea359ada10d01 /pdf-as-common
parent1eb95549f597e6dcb0d028768bbdcfb94d0a91ef (diff)
downloadpdf-as-4-fc44d4bcad00192f0df8f6086737b9b126094dcd.tar.gz
pdf-as-4-fc44d4bcad00192f0df8f6086737b9b126094dcd.tar.bz2
pdf-as-4-fc44d4bcad00192f0df8f6086737b9b126094dcd.zip
initial code commit
Diffstat (limited to 'pdf-as-common')
-rw-r--r--pdf-as-common/.gitignore1
-rw-r--r--pdf-as-common/build.gradle32
-rw-r--r--pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/exceptions/PDFIOException.java20
-rw-r--r--pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/exceptions/PdfAsException.java31
-rw-r--r--pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/exceptions/PdfAsSettingsException.java20
-rw-r--r--pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/exceptions/package-info.java8
-rw-r--r--pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/messages/MessageResolver.java42
-rw-r--r--pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/messages/package-info.java8
-rw-r--r--pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/package-info.java8
-rw-r--r--pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/IProfileConstants.java65
-rw-r--r--pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/ISettings.java13
-rw-r--r--pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/Settings.java124
-rw-r--r--pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/SignatureProfileEntry.java39
-rw-r--r--pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/SignatureProfileSettings.java121
-rw-r--r--pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/package-info.java8
-rw-r--r--pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/utils/DNUtils.java34
-rw-r--r--pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/utils/OgnlUtils.java22
-rw-r--r--pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/utils/PDFUtils.java94
-rw-r--r--pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/utils/StreamUtils.java28
-rw-r--r--pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/utils/StringUtils.java33
-rw-r--r--pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/utils/package-info.java8
-rw-r--r--pdf-as-common/src/main/resources/resources/log4j.properties15
-rw-r--r--pdf-as-common/src/main/resources/resources/messages/common.properties8
23 files changed, 782 insertions, 0 deletions
diff --git a/pdf-as-common/.gitignore b/pdf-as-common/.gitignore
new file mode 100644
index 00000000..5e56e040
--- /dev/null
+++ b/pdf-as-common/.gitignore
@@ -0,0 +1 @@
+/bin
diff --git a/pdf-as-common/build.gradle b/pdf-as-common/build.gradle
new file mode 100644
index 00000000..19d3dc90
--- /dev/null
+++ b/pdf-as-common/build.gradle
@@ -0,0 +1,32 @@
+apply plugin: 'java'
+apply plugin: 'eclipse'
+
+jar {
+ manifest {
+ attributes 'Implementation-Title': 'PDF-AS-4 Commons', 'Implementation-Version': version
+ }
+}
+
+repositories {
+ mavenCentral()
+}
+
+dependencies {
+ compile group: 'org.slf4j', name: 'slf4j-log4j12', version: '1.7.5'
+ compile group: 'org.apache.pdfbox', name: 'pdfbox', version: '1.8.2'
+ compile group: 'commons-collections', name: 'commons-collections', version: '3.2'
+ compile group: 'ognl', name: 'ognl', version: '3.0.6'
+ testCompile group: 'junit', name: 'junit', version: '4.+'
+}
+
+test {
+ systemProperties 'property': 'value'
+}
+
+uploadArchives {
+ repositories {
+ flatDir {
+ dirs 'repos'
+ }
+ }
+}
diff --git a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/exceptions/PDFIOException.java b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/exceptions/PDFIOException.java
new file mode 100644
index 00000000..57c1e7ab
--- /dev/null
+++ b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/exceptions/PDFIOException.java
@@ -0,0 +1,20 @@
+package at.gv.egiz.pdfas.common.exceptions;
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: afitzek
+ * Date: 8/28/13
+ * Time: 12:04 PM
+ * To change this template use File | Settings | File Templates.
+ */
+public class PDFIOException extends PdfAsException {
+
+ public PDFIOException(String msgId) {
+ super(msgId);
+ }
+
+
+ public PDFIOException(String msgId, Throwable e) {
+ super(msgId, e);
+ }
+}
diff --git a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/exceptions/PdfAsException.java b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/exceptions/PdfAsException.java
new file mode 100644
index 00000000..e36aa082
--- /dev/null
+++ b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/exceptions/PdfAsException.java
@@ -0,0 +1,31 @@
+package at.gv.egiz.pdfas.common.exceptions;
+
+import at.gv.egiz.pdfas.common.messages.MessageResolver;
+
+public class PdfAsException extends Exception {
+ public PdfAsException() {
+ super();
+ }
+
+ public PdfAsException(String msgId) {
+ super(msgId);
+ }
+
+ public PdfAsException(String msgId, Throwable e) {
+ super(msgId, e);
+ }
+
+ @Override
+ public String getMessage() {
+ return localizeMessage(super.getMessage());
+ }
+
+ @Override
+ public String getLocalizedMessage() {
+ return localizeMessage(super.getMessage());
+ }
+
+ protected String localizeMessage(String msgId) {
+ return MessageResolver.resolveMessage(msgId);
+ }
+}
diff --git a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/exceptions/PdfAsSettingsException.java b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/exceptions/PdfAsSettingsException.java
new file mode 100644
index 00000000..431ffa5d
--- /dev/null
+++ b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/exceptions/PdfAsSettingsException.java
@@ -0,0 +1,20 @@
+package at.gv.egiz.pdfas.common.exceptions;
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: afitzek
+ * Date: 9/10/13
+ * Time: 10:54 AM
+ * To change this template use File | Settings | File Templates.
+ */
+public class PdfAsSettingsException extends PdfAsException {
+
+ public PdfAsSettingsException(String msgId) {
+ super(msgId);
+ }
+
+
+ public PdfAsSettingsException(String msgId, Throwable e) {
+ super(msgId, e);
+ }
+}
diff --git a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/exceptions/package-info.java b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/exceptions/package-info.java
new file mode 100644
index 00000000..cfd6a993
--- /dev/null
+++ b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/exceptions/package-info.java
@@ -0,0 +1,8 @@
+/**
+ *
+ */
+/**
+ * @author afitzek
+ *
+ */
+package at.gv.egiz.pdfas.common.exceptions; \ No newline at end of file
diff --git a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/messages/MessageResolver.java b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/messages/MessageResolver.java
new file mode 100644
index 00000000..0bc1bab7
--- /dev/null
+++ b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/messages/MessageResolver.java
@@ -0,0 +1,42 @@
+package at.gv.egiz.pdfas.common.messages;
+
+import java.util.Locale;
+import java.util.ResourceBundle;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class MessageResolver {
+ private static final String messageResource = "resources.messages.common";
+ private static final String missingMsg = "Please add message ";
+
+ private static final Logger logger = LoggerFactory.getLogger(MessageResolver.class);
+
+ private static ResourceBundle bundle;
+
+ static {
+ ResourceBundle bundle = ResourceBundle.getBundle(messageResource);
+ if(bundle == null) {
+ logger.error("Failed to load resource bundle!!");
+ Runtime.getRuntime().exit(-1);
+ }
+ }
+
+ public static void forceLocale(Locale locale) {
+ bundle = ResourceBundle.getBundle(messageResource, locale);
+ }
+
+ public static String resolveMessage(String msgId) {
+ if(bundle == null) {
+ return missingMsg + msgId;
+ }
+ if(bundle.containsKey(msgId)) {
+ String value = bundle.getString(msgId);
+ if(value == null) {
+ return missingMsg + msgId;
+ }
+ return value;
+ }
+ return missingMsg + msgId;
+ }
+}
diff --git a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/messages/package-info.java b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/messages/package-info.java
new file mode 100644
index 00000000..0ac78c22
--- /dev/null
+++ b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/messages/package-info.java
@@ -0,0 +1,8 @@
+/**
+ *
+ */
+/**
+ * @author afitzek
+ *
+ */
+package at.gv.egiz.pdfas.common.messages; \ No newline at end of file
diff --git a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/package-info.java b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/package-info.java
new file mode 100644
index 00000000..58c99dad
--- /dev/null
+++ b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/package-info.java
@@ -0,0 +1,8 @@
+/**
+ *
+ */
+/**
+ * @author afitzek
+ *
+ */
+package at.gv.egiz.pdfas.common; \ No newline at end of file
diff --git a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/IProfileConstants.java b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/IProfileConstants.java
new file mode 100644
index 00000000..2e2ee024
--- /dev/null
+++ b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/IProfileConstants.java
@@ -0,0 +1,65 @@
+package at.gv.egiz.pdfas.common.settings;
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: afitzek
+ * Date: 9/10/13
+ * Time: 12:58 PM
+ * To change this template use File | Settings | File Templates.
+ */
+public interface IProfileConstants {
+ /**
+ * The settings key prefix for signature definitions. <code>"sig_obj."</code>
+ */
+ public static final String SIG_OBJ = "sig_obj.";
+
+ public static final String SIG_DATE = "SIG_DATE";
+
+ /**
+ * The settings key prefix for the signature table object definition
+ */
+ public static final String TABLE = "table.";
+
+ /**
+ * The settings value refering to a table
+ */
+ public final static String TYPE_TABLE = "TABLE";
+
+ /**
+ * The settings value refering to an image
+ */
+ public final static String TYPE_IMAGE = "i";
+
+ /**
+ * The settings value refering to a text caption
+ */
+ public final static String TYPE_CAPTION = "c";
+
+ /**
+ * The settings value refering to a text value
+ */
+ public final static String TYPE_VALUE = "v";
+
+ /**
+ * The settings key sub prefix getting the width of columns for a table
+ * definition
+ */
+ public final static String COLS_WITH = "ColsWidth";
+
+ /**
+ * The settings key sub prefix getting the style definition
+ */
+ public final static String STYLE = "Style";
+
+ public final static String PROFILE_VALUE = "value";
+
+ public final static String PROFILE_KEY = "key";
+
+ public final static String KEY_SEPARATOR = ".";
+
+ public final static String INCLUDE = "include";
+
+ public final static String CFG_DIR = "cfg";
+ public final static String CFG_FILE = "config.properties";
+
+}
diff --git a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/ISettings.java b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/ISettings.java
new file mode 100644
index 00000000..9e3291d2
--- /dev/null
+++ b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/ISettings.java
@@ -0,0 +1,13 @@
+package at.gv.egiz.pdfas.common.settings;
+
+import java.util.Map;
+import java.util.Vector;
+
+public interface ISettings {
+ public String getValue(String key);
+ public boolean hasValue(String key);
+ public boolean hasPrefix(String prefix);
+ public Map<String, String> getValuesPrefix(String prefix);
+ public Vector<String> getFirstLevelKeys(String prefix);
+ public String getWorkingDirectory();
+}
diff --git a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/Settings.java b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/Settings.java
new file mode 100644
index 00000000..da946215
--- /dev/null
+++ b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/Settings.java
@@ -0,0 +1,124 @@
+package at.gv.egiz.pdfas.common.settings;
+
+import at.gv.egiz.pdfas.common.exceptions.PdfAsSettingsException;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.*;
+
+public class Settings implements ISettings, IProfileConstants{
+
+ private static final Logger logger = LoggerFactory.getLogger(Settings.class);
+
+ protected Properties properties = new Properties();
+
+ protected File workDirectory;
+
+ public Settings(File workDirectory) {
+ try {
+ this.workDirectory = workDirectory;
+ loadSettings(workDirectory);
+ } catch (PdfAsSettingsException e) {
+ logger.error(e.getMessage(), e);
+ }
+ }
+
+ public void loadSettings(File workDirectory) throws PdfAsSettingsException {
+ try {
+
+ String configDir = workDirectory.getAbsolutePath() + File.separator + CFG_DIR;
+ String configFile = configDir + File.separator + CFG_FILE;
+ logger.debug("Loading cfg file: " + configFile);
+ properties.load(new FileInputStream(configFile));
+
+ Map<String, String> includes = this.getValuesPrefix(INCLUDE);
+
+ if(includes != null) {
+ Iterator<String> includeIterator = includes.values().iterator();
+ while(includeIterator.hasNext()) {
+ String includeFile = configDir + File.separator + includeIterator.next();
+ logger.debug("Loading included cfg file: " + includeFile);
+ properties.load(new FileInputStream(includeFile));
+ }
+ }
+
+ logger.debug("Configured Properties:");
+ if(logger.isDebugEnabled()) {
+ properties.list(System.out);
+ }
+
+ } catch (IOException e) {
+ throw new PdfAsSettingsException("Failed to read settings!", e);
+ }
+ }
+
+ public String getValue(String key) {
+ return properties.getProperty(key);
+ }
+
+ public boolean hasValue(String key) {
+ return properties.containsKey(key);
+ }
+
+ public Map<String, String> getValuesPrefix(String prefix) {
+ Iterator<Object> keyIterator = properties.keySet().iterator();
+ Map<String, String> valueMap = new HashMap<String, String>();
+ while(keyIterator.hasNext()) {
+ String key = keyIterator.next().toString();
+
+ if(key.startsWith(prefix)) {
+ valueMap.put(key, properties.getProperty(key));
+ }
+ }
+
+ if(valueMap.isEmpty()) {
+ return null;
+ }
+
+ return valueMap;
+ }
+
+ public Vector<String> getFirstLevelKeys(String prefix) {
+ String mPrefix = prefix.endsWith(".")?prefix:prefix+".";
+ Iterator<Object> keyIterator = properties.keySet().iterator();
+ Vector<String> valueMap = new Vector<String>();
+ while(keyIterator.hasNext()) {
+ String key = keyIterator.next().toString();
+
+ if(key.startsWith(prefix)) {
+ int keyIdx = key.indexOf('.', mPrefix.length()) > 0 ? key.indexOf('.', mPrefix.length()) : key.length();
+ String firstLevels = key.substring(0, keyIdx);
+ if(!valueMap.contains(firstLevels)) {
+ valueMap.add(firstLevels);
+ }
+ }
+ }
+
+ if(valueMap.isEmpty()) {
+ return null;
+ }
+
+ return valueMap;
+ }
+
+ public boolean hasPrefix(String prefix) {
+ Iterator<Object> keyIterator = properties.keySet().iterator();
+ while(keyIterator.hasNext()) {
+ String key = keyIterator.next().toString();
+
+ if(key.startsWith(prefix)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public String getWorkingDirectory() {
+ return this.workDirectory.getAbsolutePath();
+ }
+
+}
diff --git a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/SignatureProfileEntry.java b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/SignatureProfileEntry.java
new file mode 100644
index 00000000..3df929b1
--- /dev/null
+++ b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/SignatureProfileEntry.java
@@ -0,0 +1,39 @@
+package at.gv.egiz.pdfas.common.settings;
+
+public class SignatureProfileEntry {
+ private String key = null;
+ private String caption = null;
+ private String value = null;
+
+ public SignatureProfileEntry() {
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+ public void setKey(String key) {
+ this.key = key;
+ }
+
+ public String getCaption() {
+ return caption;
+ }
+
+ public void setCaption(String caption) {
+ this.caption = caption;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ @Override
+ public String toString() {
+ return getKey() + "[ " + getCaption() + " : " + getValue() + " ]";
+ }
+}
diff --git a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/SignatureProfileSettings.java b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/SignatureProfileSettings.java
new file mode 100644
index 00000000..46f2ed09
--- /dev/null
+++ b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/SignatureProfileSettings.java
@@ -0,0 +1,121 @@
+package at.gv.egiz.pdfas.common.settings;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.*;
+
+public class SignatureProfileSettings implements IProfileConstants {
+
+ private static final Logger logger = LoggerFactory.getLogger(SignatureProfileSettings.class);
+
+ private Map<String, SignatureProfileEntry> profileInformations = new HashMap<String, SignatureProfileEntry>();
+
+ private Map<String, String> profileSettings = new HashMap<String, String>();
+
+ private String profileID;
+
+ public SignatureProfileSettings(String profileID, ISettings configuration) {
+ this.profileID = profileID;
+ String profilePrefix = SIG_OBJ + profileID + KEY_SEPARATOR;
+ String keysPrefix = profilePrefix + PROFILE_KEY;
+ String valuesPrefix = profilePrefix + PROFILE_VALUE;
+ String tablePrefix = profilePrefix + TABLE;
+
+ logger.debug("Reading Profile: " + profileID);
+ logger.debug("Keys Prefix: " + keysPrefix);
+ logger.debug("Values Prefix: " + valuesPrefix);
+ logger.debug("Table Prefix: " + tablePrefix);
+
+ Map<String, String> keys = configuration.getValuesPrefix(keysPrefix);
+ Map<String, String> values = configuration.getValuesPrefix(valuesPrefix);
+
+ Iterator<String> keyIterator = keys.keySet().iterator();
+
+ while(keyIterator.hasNext()) {
+ String key = keyIterator.next();
+ key = key.substring(key.lastIndexOf('.') + 1);
+ String valueKey = keys.get(keysPrefix + KEY_SEPARATOR + key);
+
+ String valueValue = values.get(valuesPrefix + KEY_SEPARATOR + key);
+
+
+ SignatureProfileEntry entry = new SignatureProfileEntry();
+ entry.setKey(key);
+ entry.setCaption(valueKey);
+ entry.setValue(valueValue);
+ profileInformations.put(key, entry);
+ logger.debug(" " + entry.toString());
+ }
+
+ // Find entries where only values exists
+ Iterator<String> valuesIterator = values.keySet().iterator();
+
+ while(valuesIterator.hasNext()) {
+ String key = valuesIterator.next();
+ key = key.substring(key.lastIndexOf('.') + 1);
+
+ String valueValue = values.get(valuesPrefix + KEY_SEPARATOR + key);
+
+ SignatureProfileEntry entry = profileInformations.get(key);
+ if(entry == null) {
+ entry = new SignatureProfileEntry();
+ entry.setKey(key);
+ entry.setCaption(null);
+ entry.setValue(valueValue);
+ profileInformations.put(key, entry);
+ }
+
+ logger.debug(" " + entry.toString());
+ }
+
+ Map<String, String> others = configuration.getValuesPrefix(profilePrefix);
+
+ Iterator<String> otherIterator = others.keySet().iterator();
+
+ while(otherIterator.hasNext()) {
+ String key = otherIterator.next();
+
+ logger.trace("Checking key " + key);
+ if( key.startsWith(keysPrefix) ||
+ key.startsWith(valuesPrefix) ||
+ key.startsWith(tablePrefix)) {
+ continue;
+ }
+
+ String value = others.get(key);
+ key = key.substring(key.lastIndexOf('.') + 1);
+
+ profileSettings.put(key, others.get(value));
+
+ logger.debug(" Settings: " + key + " : " + value);
+ }
+ }
+
+ public String getCaption(String key) {
+ SignatureProfileEntry entry = profileInformations.get(key);
+ if(entry != null) {
+ return entry.getCaption();
+ }
+ return null;
+ }
+
+ public String getValue(String key) {
+ SignatureProfileEntry entry = profileInformations.get(key);
+ if(entry != null) {
+ String value = entry.getValue();
+
+ if(value == null) {
+ // TODO: try to find default value for key!
+ }
+
+ return value;
+ }
+ // TODO: try to find default value for key!
+ return null;
+ }
+
+ public String getProfileID() {
+ return profileID;
+ }
+}
diff --git a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/package-info.java b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/package-info.java
new file mode 100644
index 00000000..c2b123e2
--- /dev/null
+++ b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/package-info.java
@@ -0,0 +1,8 @@
+/**
+ *
+ */
+/**
+ * @author afitzek
+ *
+ */
+package at.gv.egiz.pdfas.common.settings; \ No newline at end of file
diff --git a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/utils/DNUtils.java b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/utils/DNUtils.java
new file mode 100644
index 00000000..429151ee
--- /dev/null
+++ b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/utils/DNUtils.java
@@ -0,0 +1,34 @@
+package at.gv.egiz.pdfas.common.utils;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.naming.InvalidNameException;
+import javax.naming.ldap.LdapName;
+import javax.naming.ldap.Rdn;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class DNUtils {
+ private static final Logger logger = LoggerFactory.getLogger(DNUtils.class);
+
+
+ public static Map<String, String> dnToMap(String dn) throws InvalidNameException {
+ Map<String, String> map = new HashMap<String, String>();
+
+ LdapName ldapName = new LdapName(dn);
+
+ Iterator<Rdn> rdnIterator = ldapName.getRdns().iterator();
+
+ while(rdnIterator.hasNext()) {
+ Rdn rdn = rdnIterator.next();
+
+ logger.debug(rdn.getType() + " = " + rdn.getValue().toString());
+ map.put(rdn.getType(), rdn.getValue().toString());
+ }
+
+ return map;
+ }
+}
diff --git a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/utils/OgnlUtils.java b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/utils/OgnlUtils.java
new file mode 100644
index 00000000..e98cb124
--- /dev/null
+++ b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/utils/OgnlUtils.java
@@ -0,0 +1,22 @@
+package at.gv.egiz.pdfas.common.utils;
+
+import ognl.OgnlContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: afitzek
+ * Date: 9/11/13
+ * Time: 1:05 PM
+ * To change this template use File | Settings | File Templates.
+ */
+public class OgnlUtils {
+
+ private static final Logger logger = LoggerFactory.getLogger(OgnlUtils.class);
+
+ public static String resolvsOgnlExpression(String expression, OgnlContext ctx) {
+ // TODO!
+ return expression;
+ }
+}
diff --git a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/utils/PDFUtils.java b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/utils/PDFUtils.java
new file mode 100644
index 00000000..155f9cfb
--- /dev/null
+++ b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/utils/PDFUtils.java
@@ -0,0 +1,94 @@
+package at.gv.egiz.pdfas.common.utils;
+
+import org.apache.pdfbox.pdmodel.PDDocument;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.List;
+
+
+public class PDFUtils {
+
+ private static final Logger logger = LoggerFactory.getLogger(PDFUtils.class);
+
+
+ private static final byte[] signature_pattern = new byte[] {
+ (byte) 0x0A, (byte) 0x2F, (byte) 0x43, (byte) 0x6F, // ./Co
+ (byte) 0x6E, (byte) 0x74, (byte) 0x65, (byte) 0x6E, // nten
+ (byte) 0x74, (byte) 0x73, (byte) 0x20, (byte) 0x0A, // ts .
+ (byte) 0x2F, (byte) 0x42, (byte) 0x79, (byte) 0x74, // /Byt
+ (byte) 0x65, (byte) 0x52, (byte) 0x61, (byte) 0x6E, // eRan
+ (byte) 0x67, (byte) 0x65, (byte) 0x20, (byte) 0x5B, // ge [
+
+ };
+
+ private static final byte range_seperation = (byte) 0x20;
+ private static final byte range_end = (byte) 0x5D;
+
+ private static int extractASCIIInteger(byte[] data, int offset) {
+ int nextsepp = nextSeperator(data, offset);
+
+ if(nextsepp < offset) {
+ return -1;
+ }
+
+ String asciiString = new String(data, offset, nextsepp - offset);
+
+ logger.debug("Extracted " + asciiString);
+
+ return Integer.parseInt(asciiString);
+ }
+
+ private static int nextSeperator(byte[] data, int offset) {
+ for(int i = offset; i < data.length; i++) {
+ if(data[i] == range_seperation) {
+ return i;
+ } else if(data[i] == range_end) {
+ return i;
+ }
+ }
+ return -2;
+ }
+
+ public static int[] extractSignatureByteRange(byte[] rawPdfData) {
+ int i = 0;
+ for(i = rawPdfData.length - 1; i >= 0; i--) {
+ if(rawPdfData[i] == signature_pattern[0] &&
+ i+signature_pattern.length < rawPdfData.length) {
+ boolean match = true;
+ for(int j = 0; j < signature_pattern.length; j++) {
+
+ if(rawPdfData[i+j] != signature_pattern[j]) {
+ match = false;
+ break;
+ }
+ }
+
+ if(match) {
+
+ int offset = i + signature_pattern.length;
+ List<Integer> byteRange = new ArrayList<Integer>();
+ while(offset > 0) {
+ byteRange.add(extractASCIIInteger(rawPdfData, offset));
+ offset = nextSeperator(rawPdfData, offset);
+ if(rawPdfData[offset] == range_end) {
+ break;
+ }
+ offset++;
+ }
+ int[] range = new int[byteRange.size()];
+ for(int j = 0; j < byteRange.size(); j++) {
+ range[j] = byteRange.get(j);
+ }
+ return range;
+ }
+ }
+ }
+ return null;
+ }
+
+ public static void checkPDFPermissions(PDDocument doc) {
+ // TODO: Check permission for document
+ }
+}
diff --git a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/utils/StreamUtils.java b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/utils/StreamUtils.java
new file mode 100644
index 00000000..0b15d700
--- /dev/null
+++ b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/utils/StreamUtils.java
@@ -0,0 +1,28 @@
+package at.gv.egiz.pdfas.common.utils;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: afitzek
+ * Date: 8/29/13
+ * Time: 9:54 AM
+ * To change this template use File | Settings | File Templates.
+ */
+public class StreamUtils {
+
+ public static byte[] inputStreamToByteArray(InputStream stream) throws IOException {
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ byte[] buffer = new byte[4096];
+ int readBytes = 0;
+
+ while((readBytes = stream.read(buffer)) != -1) {
+ bos.write(buffer, 0, readBytes);
+ }
+ stream.close();
+ bos.close();
+ return bos.toByteArray();
+ }
+}
diff --git a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/utils/StringUtils.java b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/utils/StringUtils.java
new file mode 100644
index 00000000..63aae211
--- /dev/null
+++ b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/utils/StringUtils.java
@@ -0,0 +1,33 @@
+package at.gv.egiz.pdfas.common.utils;
+
+import java.util.Formatter;
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: afitzek
+ * Date: 8/28/13
+ * Time: 12:42 PM
+ * To change this template use File | Settings | File Templates.
+ */
+public class StringUtils {
+
+ public static String bytesToHexString(byte[] bytes) {
+ StringBuilder sb = new StringBuilder(bytes.length * 2);
+
+ Formatter formatter = new Formatter(sb);
+ for (byte b : bytes) {
+ formatter.format("%02x", b);
+ }
+
+ return sb.toString();
+ }
+
+ public static String extractLastID(String id) {
+ int lastIDX = id.lastIndexOf('.');
+ String result = id;
+ if(lastIDX > 0) {
+ result = id.substring(lastIDX+1);
+ }
+ return result;
+ }
+}
diff --git a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/utils/package-info.java b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/utils/package-info.java
new file mode 100644
index 00000000..91b05145
--- /dev/null
+++ b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/utils/package-info.java
@@ -0,0 +1,8 @@
+/**
+ *
+ */
+/**
+ * @author afitzek
+ *
+ */
+package at.gv.egiz.pdfas.common.utils; \ No newline at end of file
diff --git a/pdf-as-common/src/main/resources/resources/log4j.properties b/pdf-as-common/src/main/resources/resources/log4j.properties
new file mode 100644
index 00000000..696db3ef
--- /dev/null
+++ b/pdf-as-common/src/main/resources/resources/log4j.properties
@@ -0,0 +1,15 @@
+# Set root logger level to DEBUG and its only appender to A1.
+log4j.rootLogger=INFO, A1
+
+log4j.logger.at.gv.egiz=DEBUG
+#log4j.A1.at.gv.egiz=true
+
+log4j.logger.developer=DEBUG
+#log4j.A1.developer=true
+
+# A1 is set to be a ConsoleAppender.
+log4j.appender.A1=org.apache.log4j.ConsoleAppender
+
+# A1 uses PatternLayout.
+log4j.appender.A1.layout=org.apache.log4j.PatternLayout
+log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n \ No newline at end of file
diff --git a/pdf-as-common/src/main/resources/resources/messages/common.properties b/pdf-as-common/src/main/resources/resources/messages/common.properties
new file mode 100644
index 00000000..a2729e21
--- /dev/null
+++ b/pdf-as-common/src/main/resources/resources/messages/common.properties
@@ -0,0 +1,8 @@
+# PDF Permission Errors
+error.pdf.perm.01=You do not have permission to extract images.
+
+#PDF IO Errors
+error.pdf.io.01=Failed to read original PDF Document into PDDocument.
+
+#Signature errors
+error.pdf.sig.01=Failed to create signature! \ No newline at end of file