aboutsummaryrefslogtreecommitdiff
path: root/pdf-as-common/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'pdf-as-common/src/main')
-rw-r--r--pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/Profiles.java42
-rw-r--r--pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/Settings.java230
2 files changed, 210 insertions, 62 deletions
diff --git a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/Profiles.java b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/Profiles.java
new file mode 100644
index 00000000..9969fdf0
--- /dev/null
+++ b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/Profiles.java
@@ -0,0 +1,42 @@
+package at.gv.egiz.pdfas.common.settings;
+
+import java.util.Map;
+import java.util.Properties;
+
+public class Profiles {
+
+ private String name;
+ private Profiles parent;
+ private boolean initialized;
+
+ private static final String PARENT_CONFIG = ".parent";
+
+ public Profiles(String name) {
+ this.name = name;
+ this.initialized = false;
+ this.parent = null;
+ }
+
+ public String getName() {
+ return this.name;
+ }
+
+ public void findParent(Properties props, Map<String, Profiles> profiles) {
+ String parentString = props.getProperty("sig_obj." + this.name + PARENT_CONFIG);
+ if(parentString != null) {
+ this.parent = profiles.get(parentString);
+ }
+ }
+
+ public Profiles getParent() {
+ return this.parent;
+ }
+
+ public boolean isInitialized() {
+ return initialized;
+ }
+
+ public void setInitialized(boolean initialized) {
+ this.initialized = initialized;
+ }
+}
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
index 31dd6676..26505e50 100644
--- 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
@@ -23,7 +23,18 @@
******************************************************************************/
package at.gv.egiz.pdfas.common.settings;
-import at.gv.egiz.pdfas.common.exceptions.PdfAsSettingsException;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Properties;
+import java.util.Vector;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOCase;
@@ -31,11 +42,7 @@ import org.apache.commons.io.filefilter.WildcardFileFilter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.io.File;
-import java.io.FileFilter;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.util.*;
+import at.gv.egiz.pdfas.common.exceptions.PdfAsSettingsException;
public class Settings implements ISettings, IProfileConstants {
@@ -74,11 +81,12 @@ public class Settings implements ISettings, IProfileConstants {
while (includeIterator.hasNext()) {
contextFolder = new File(configDir);
String includeFileName = includeIterator.next();
-
- File includeInstruction = new File(contextFolder, includeFileName);
+
+ File includeInstruction = new File(contextFolder,
+ includeFileName);
contextFolder = includeInstruction.getParentFile();
String includeName = includeInstruction.getName();
-
+
WildcardFileFilter fileFilter = new WildcardFileFilter(
includeName, IOCase.SENSITIVE);
Collection<File> includeFiles = null;
@@ -102,65 +110,150 @@ public class Settings implements ISettings, IProfileConstants {
}
}
- public void loadSettings(File workDirectory) throws PdfAsSettingsException {
- //try {
- String configDir = workDirectory.getAbsolutePath() + File.separator
- + CFG_DIR;
- String configFile = configDir + File.separator + CFG_FILE;
- loadSettingsRecursive(workDirectory, new File(configFile));
-
- /*
- logger.debug("Loading cfg file: " + configFile);
-
-
- properties.load(new FileInputStream(configFile));
+ private void buildProfiles() {
+ Map<String, Profiles> profiles = new HashMap<String, Profiles>();
+
+ Iterator<String> itKeys = this.getFirstLevelKeys("sig_obj.types.")
+ .iterator();
+ while (itKeys.hasNext()) {
+ String key = itKeys.next();
+ String profile = key.substring("sig_obj.types.".length());
+ //System.out.println("[" + profile + "]: " + this.getValue(key));
+ if (this.getValue(key).equals("on")) {
+ Profiles prof = new Profiles(profile);
+ profiles.put(profile, prof);
+ }
+ }
- Map<String, String> includes = this.getValuesPrefix(INCLUDE);
- File contextFolder = new File(configDir);
- if (includes != null) {
- Iterator<String> includeIterator = includes.values().iterator();
- while (includeIterator.hasNext()) {
- String includeFileName = includeIterator.next();
- if (includeFileName.contains("*")) {
- WildcardFileFilter fileFilter = new WildcardFileFilter(
- includeFileName, IOCase.SENSITIVE);
- Collection<File> includeFiles = null;
-
- if (contextFolder != null && contextFolder.exists()
- && contextFolder.isDirectory()) {
- includeFiles = FileUtils.listFiles(contextFolder,
- fileFilter, null);
- }
- if (includeFiles != null && !includeFiles.isEmpty()) {
- logger.info("Including '" + includeFileName + "'.");
- for (File includeFile : includeFiles) {
- properties
- .load(new FileInputStream(includeFile));
+ // Initialize Parent Structure ...
+ Iterator<Entry<String, Profiles>> profileIterator = profiles.entrySet()
+ .iterator();
+ while (profileIterator.hasNext()) {
+ Entry<String, Profiles> entry = profileIterator.next();
+ entry.getValue().findParent(properties, profiles);
+ }
+
+ // Debug Output
+ Iterator<Entry<String, Profiles>> profileIteratorDbg = profiles.entrySet()
+ .iterator();
+ while (profileIteratorDbg.hasNext()) {
+ Entry<String, Profiles> entry = profileIteratorDbg.next();
+ if(entry.getValue().getParent() == null) {
+ logger.debug("Got Profile: [{}] : {}", entry.getKey(), entry.getValue().getName());
+ } else {
+ logger.debug("Got Profile: [{}] : {} (Parent {})", entry.getKey(),
+ entry.getValue().getName(), entry.getValue().getParent().getName());
+ }
+ }
+
+ // Resolve Parent Structures ...
+ while (!profiles.isEmpty()) {
+ List<String> removes = new ArrayList<String>();
+ Iterator<Entry<String, Profiles>> profileIt = profiles.entrySet()
+ .iterator();
+ while (profileIt.hasNext()) {
+ Entry<String, Profiles> entry = profileIt.next();
+
+ // Remove all base Profiles ...
+ if (entry.getValue().getParent() == null) {
+ entry.getValue().setInitialized(true);
+ removes.add(entry.getKey());
+ } else {
+ Profiles parent = entry.getValue().getParent();
+ if (parent.isInitialized()) {
+ // If Parent is initialized Copy Properties from Parent
+ // to this profile
+ String parentBase = "sig_obj." + parent.getName();
+ String childBase = "sig_obj."
+ + entry.getValue().getName();
+ Iterator<String> parentKeyIt = this.getKeys(
+ parentBase).iterator();
+ while (parentKeyIt.hasNext()) {
+ String key = parentKeyIt.next();
+ String keyToCopy = key.substring(parentBase
+ .length());
+ if(!this.hasValue(childBase+keyToCopy)) {
+ properties.setProperty(childBase+keyToCopy,
+ this.getValue(parentBase+keyToCopy));
+ //logger.debug("Replaced: {} with Value from {}",
+ // childBase+keyToCopy, parentBase+keyToCopy);
+ } else {
+ //logger.debug("NOT Replaced: {} with Value from {}",
+ // childBase+keyToCopy, parentBase+keyToCopy);
}
}
- } else {
- String includeFile = configDir + File.separator
- + includeFileName;
- logger.debug("Loading included cfg file: "
- + includeFile);
- try {
- properties.load(new FileInputStream(includeFile));
- } catch (Throwable e) {
- logger.error("Failed to load cfg file "
- + includeFile, e);
- }
+
+ // Copy done
+ entry.getValue().setInitialized(true);
+ removes.add(entry.getKey());
}
}
}
- */
- logger.debug("Configured Properties:");
- /*
- * if(logger.isDebugEnabled()) { properties.list(System.out); }
- */
-
- //} catch (IOException e) {
- // throw new PdfAsSettingsException("Failed to read settings!", e);
- //}
+
+
+ // Remove all Profiles from Remove List
+
+ if(removes.isEmpty() && !profiles.isEmpty()) {
+ logger.error("Failed to build inheritant Profiles, running in infinite loop! (aborting ...)");
+ logger.error("Profiles that cannot be resolved completly:");
+ Iterator<Entry<String, Profiles>> failedProfiles = profiles.entrySet().iterator();
+ while (failedProfiles.hasNext()) {
+ Entry<String, Profiles> entry = failedProfiles.next();
+ logger.error("Problem Profile: [{}] : {}", entry.getKey(), entry.getValue().getName());
+ }
+ return;
+ }
+
+ Iterator<String> removeIt = removes.iterator();
+ while(removeIt.hasNext()) {
+ profiles.remove(removeIt.next());
+ }
+ }
+ }
+
+ public void loadSettings(File workDirectory) throws PdfAsSettingsException {
+ // try {
+ String configDir = workDirectory.getAbsolutePath() + File.separator
+ + CFG_DIR;
+ String configFile = configDir + File.separator + CFG_FILE;
+ loadSettingsRecursive(workDirectory, new File(configFile));
+ buildProfiles();
+ /*
+ * logger.debug("Loading cfg file: " + configFile);
+ *
+ *
+ * properties.load(new FileInputStream(configFile));
+ *
+ * Map<String, String> includes = this.getValuesPrefix(INCLUDE); File
+ * contextFolder = new File(configDir); if (includes != null) {
+ * Iterator<String> includeIterator = includes.values().iterator();
+ * while (includeIterator.hasNext()) { String includeFileName =
+ * includeIterator.next(); if (includeFileName.contains("*")) {
+ * WildcardFileFilter fileFilter = new WildcardFileFilter(
+ * includeFileName, IOCase.SENSITIVE); Collection<File> includeFiles =
+ * null;
+ *
+ * if (contextFolder != null && contextFolder.exists() &&
+ * contextFolder.isDirectory()) { includeFiles =
+ * FileUtils.listFiles(contextFolder, fileFilter, null); } if
+ * (includeFiles != null && !includeFiles.isEmpty()) {
+ * logger.info("Including '" + includeFileName + "'."); for (File
+ * includeFile : includeFiles) { properties .load(new
+ * FileInputStream(includeFile)); } } } else { String includeFile =
+ * configDir + File.separator + includeFileName;
+ * logger.debug("Loading included cfg file: " + includeFile); try {
+ * properties.load(new FileInputStream(includeFile)); } catch (Throwable
+ * e) { logger.error("Failed to load cfg file " + includeFile, e); } } }
+ * }
+ */
+ // 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) {
@@ -193,6 +286,19 @@ public class Settings implements ISettings, IProfileConstants {
return getValuesPrefix(prefix, properties);
}
+ public Vector<String> getKeys(String 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)) {
+ valueMap.add(key);
+ }
+ }
+ return valueMap;
+ }
+
public Vector<String> getFirstLevelKeys(String prefix) {
String mPrefix = prefix.endsWith(".") ? prefix : prefix + ".";
Iterator<Object> keyIterator = properties.keySet().iterator();