diff --git a/configuration/nb-configuration.xml b/configuration/nb-configuration.xml
new file mode 100644
index 0000000..8e1e369
--- /dev/null
+++ b/configuration/nb-configuration.xml
@@ -0,0 +1,18 @@
+
+
+
+
+
+ true
+
+
diff --git a/configuration/pom.xml b/configuration/pom.xml
new file mode 100644
index 0000000..5df76a8
--- /dev/null
+++ b/configuration/pom.xml
@@ -0,0 +1,44 @@
+
+ 4.0.0
+
+ de.muehlencord.shared
+ shared-configuration
+ 1.0-SNAPSHOT
+ jar
+
+
+ shared
+ de.muehlencord
+ 1.0-SNAPSHOT
+
+
+ shared-configuration
+ http://maven.apache.org
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 2.3.2
+
+ 1.6
+ 1.6
+ true
+
+
+
+
+
+ UTF-8
+
+
+
+
+ junit
+ junit
+ 4.10
+ test
+
+
+
diff --git a/configuration/src/main/java/de/muehlencord/shared/configuration/BooleanParameter.java b/configuration/src/main/java/de/muehlencord/shared/configuration/BooleanParameter.java
new file mode 100644
index 0000000..2e5f38f
--- /dev/null
+++ b/configuration/src/main/java/de/muehlencord/shared/configuration/BooleanParameter.java
@@ -0,0 +1,51 @@
+package de.muehlencord.shared.configuration;
+
+import de.muehlencord.shared.configuration.converter.BooleanStringConverter;
+
+/**
+ * A Boolean parameter
+ * @author joern@muehlencord.de
+ */
+public class BooleanParameter extends Parameter {
+
+ /**
+ * creates a new mandatory parameter object using default string converter
+ *
+ * @param name the name of the parameter
+ */
+ public BooleanParameter(String name) {
+ super(name, new BooleanStringConverter(), true);
+ }
+
+ /**
+ * creates a new mandatory parameter object
+ *
+ * @param name the name of the parameter
+ * @param converter the converter object to convert the value of the parameter to string and vice versa
+ */
+ public BooleanParameter(String name, StringConverter converter) {
+ super(name, converter, true);
+ }
+
+ /**
+ * creates a new parameter object using default string converter
+ *
+ * @param name the name of the parameter
+ * @param mandatory detremines if this is a mandatory parameter or not
+ */
+ public BooleanParameter(String name, boolean mandatory) {
+ super(name, new BooleanStringConverter(), mandatory);
+ }
+
+ /**
+ * creates a new parameter object
+ *
+ * @param name the name of the parameter
+ * @param converter the converter object to convert the value of the parameter to string and vice versa
+ * @param mandatory detremines if this is a mandatory parameter or not
+ */
+ public BooleanParameter(String name, StringConverter converter, boolean mandatory) {
+ super(name, converter, mandatory);
+ }
+
+}
diff --git a/configuration/src/main/java/de/muehlencord/shared/configuration/Configuration.java b/configuration/src/main/java/de/muehlencord/shared/configuration/Configuration.java
new file mode 100644
index 0000000..8a43e27
--- /dev/null
+++ b/configuration/src/main/java/de/muehlencord/shared/configuration/Configuration.java
@@ -0,0 +1,79 @@
+package de.muehlencord.shared.configuration;
+
+/**
+ *
+ * @author jomu
+ */
+public interface Configuration {
+
+ /**
+ * adds a new parameter to the configuration
+ *
+ * @param p the parameter to add
+ * @throws ConfigurationException if the parameter cannot be added
+ */
+ public void addParameter(Parameter p) throws ConfigurationException;
+
+ /**
+ * sets the value of the given parameter
+ *
+ * @param p parameter to set
+ * @param value value to set
+ * @throws ConfigurationException if the parameter is not defined
+ */
+ public void setParameterValue(Parameter p, V value) throws ConfigurationException;
+
+ /**
+ * sets the value of parameter with given name
+ *
+ * @param parameterName parameter to set
+ * @param value value to set
+ * @throws ConfigurationException if the parameter is not defined
+ */
+ public void setParameterValue(String parameterName, V value) throws ConfigurationException;
+
+ /**
+ * sets the value of the given parameter
+ *
+ * @param p parameter to set
+ * @param value value to set
+ * @throws ConfigurationException if the parameter is not defined
+ */
+ public void setParameterValueByString(Parameter p, String value) throws ConfigurationException;
+
+ /**
+ * sets the value of the given parameter
+ *
+ * @param parameterName the name of the parameter to set the value for
+ * @param stringValue the value of the parameter as string
+ * @throws ConfigurationException if the parameter cannot be found or set
+ */
+ public void setParameterValueByString(String parameterName, String stringValue) throws ConfigurationException;
+
+ /**
+ * returns the value of the given parameter
+ *
+ * @param p the parameter to return the value for
+ * @return the value of the given parameter; null if not set
+ *
+ * @throws ConfigurationException if the parameter is not defined or if the value is not set
+ */
+ public V getParameterValue(Parameter p) throws ConfigurationException;
+
+ /**
+ * returns the value of the given parameter
+ *
+ * @param parameterName the name of the parameter to return the value for
+ * @return the value of the given parameter; null if not set
+ *
+ * @throws ConfigurationException if the parameter is not defined or if the value is not set
+ */
+ public V getParameterValue(String parameterName) throws ConfigurationException;
+
+ /**
+ * validates the configuration
+ *
+ * @throws ConfigurationException if the configuration is invalid
+ */
+ public void validateConfiguration() throws ConfigurationException;
+}
diff --git a/configuration/src/main/java/de/muehlencord/shared/configuration/ConfigurationException.java b/configuration/src/main/java/de/muehlencord/shared/configuration/ConfigurationException.java
new file mode 100644
index 0000000..799ec68
--- /dev/null
+++ b/configuration/src/main/java/de/muehlencord/shared/configuration/ConfigurationException.java
@@ -0,0 +1,36 @@
+package de.muehlencord.shared.configuration;
+
+/**
+ *
+ * @author jomu
+ */
+public class ConfigurationException extends Exception {
+
+ /**
+ * Creates a new instance of
+ * ParameterException without detail message.
+ */
+ public ConfigurationException() {
+ }
+
+ /**
+ * Constructs an instance of
+ * ParameterException with the specified detail message.
+ *
+ * @param msg the detail message.
+ */
+ public ConfigurationException(String msg) {
+ super(msg);
+ }
+
+ /**
+ * Constructs an instance of
+ * ParameterException with the specified detail message.
+ *
+ * @param msg the detail message.
+ * @param th the root cause
+ */
+ public ConfigurationException(String msg, Throwable th) {
+ super(msg, th);
+ }
+}
diff --git a/configuration/src/main/java/de/muehlencord/shared/configuration/ConverterException.java b/configuration/src/main/java/de/muehlencord/shared/configuration/ConverterException.java
new file mode 100644
index 0000000..9c25f99
--- /dev/null
+++ b/configuration/src/main/java/de/muehlencord/shared/configuration/ConverterException.java
@@ -0,0 +1,36 @@
+package de.muehlencord.shared.configuration;
+
+/**
+ *
+ * @author jomu
+ */
+public class ConverterException extends Exception {
+
+ /**
+ * Creates a new instance of
+ * ConverterException without detail message.
+ */
+ public ConverterException() {
+ }
+
+ /**
+ * Constructs an instance of
+ * ConverterException with the specified detail message.
+ *
+ * @param msg the detail message.
+ */
+ public ConverterException(String msg) {
+ super(msg);
+ }
+
+ /**
+ * Constructs an instance of
+ * ConverterException with the specified detail message.
+ *
+ * @param msg the detail message.
+ * @param th the causing exception
+ */
+ public ConverterException(String msg, Throwable th) {
+ super(msg, th);
+ }
+}
diff --git a/configuration/src/main/java/de/muehlencord/shared/configuration/DateParameter.java b/configuration/src/main/java/de/muehlencord/shared/configuration/DateParameter.java
new file mode 100644
index 0000000..da8f132
--- /dev/null
+++ b/configuration/src/main/java/de/muehlencord/shared/configuration/DateParameter.java
@@ -0,0 +1,52 @@
+package de.muehlencord.shared.configuration;
+
+import de.muehlencord.shared.configuration.converter.DateStringConverter;
+import java.util.Date;
+
+/**
+ * A Date parameter
+ * @author joern@muehlencord.de
+ */
+public class DateParameter extends Parameter {
+
+ /**
+ * creates a new mandatory parameter object using default string converter
+ *
+ * @param name the name of the parameter
+ */
+ public DateParameter(String name) {
+ super(name, new DateStringConverter(), true);
+ }
+
+ /**
+ * creates a new mandatory parameter object
+ *
+ * @param name the name of the parameter
+ * @param converter the converter object to convert the value of the parameter to string and vice versa
+ */
+ public DateParameter(String name, StringConverter converter) {
+ super(name, converter, true);
+ }
+
+ /**
+ * creates a new parameter object using default string converter
+ *
+ * @param name the name of the parameter
+ * @param mandatory detremines if this is a mandatory parameter or not
+ */
+ public DateParameter(String name, boolean mandatory) {
+ super(name, new DateStringConverter(), mandatory);
+ }
+
+ /**
+ * creates a new parameter object
+ *
+ * @param name the name of the parameter
+ * @param converter the converter object to convert the value of the parameter to string and vice versa
+ * @param mandatory detremines if this is a mandatory parameter or not
+ */
+ public DateParameter(String name, StringConverter converter, boolean mandatory) {
+ super(name, converter, mandatory);
+ }
+
+}
diff --git a/configuration/src/main/java/de/muehlencord/shared/configuration/DefaultConfiguration.java b/configuration/src/main/java/de/muehlencord/shared/configuration/DefaultConfiguration.java
new file mode 100644
index 0000000..2e7f1a1
--- /dev/null
+++ b/configuration/src/main/java/de/muehlencord/shared/configuration/DefaultConfiguration.java
@@ -0,0 +1,224 @@
+package de.muehlencord.shared.configuration;
+
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ *
+ * @param the type of the parameter
+ * @param the value of the parameter - must be the same class as the type class of the parameter
+ * @author joern@muehlencord.de
+ */
+public class DefaultConfiguration implements Configuration {
+
+ /**
+ * the parameter map
+ */
+ private Map, V> parameterMap;
+ /** mapping from name to parameter */
+ private Map> parameterNameMap;
+
+ /**
+ * creates a new instance of a configuration
+ */
+ public DefaultConfiguration() {
+ parameterMap = new HashMap, V>();
+ parameterNameMap = new HashMap>();
+ }
+
+ /**
+ * returns the map of parameters and values
+ *
+ * @return the map of parameters and values
+ */
+ protected Map, V> getParameterMap() {
+ return parameterMap;
+ }
+
+ /**
+ * adds a new parameter to the configuration
+ *
+ * @param p the parameter to add
+ * @throws ConfigurationException if the parameter cannot be added
+ */
+ @Override
+ public void addParameter(Parameter p) throws ConfigurationException {
+ if (parameterMap.containsKey(p)) {
+ throw new ConfigurationException("Parameter named " + p.getName() + " already defined");
+ } else {
+ parameterMap.put(p, null);
+ parameterNameMap.put(p.getName(), p);
+ }
+ }
+
+ /**
+ * validates the configuration
+ *
+ * @throws ConfigurationException if the configuration is invalid
+ */
+ @Override
+ public void validateConfiguration() throws ConfigurationException {
+ List missingMandatoryParameters = new LinkedList();
+ for (Parameter p : parameterMap.keySet()) {
+ if ((!validateParameter(p)) && (!missingMandatoryParameters.contains(p))) {
+ missingMandatoryParameters.add(p);
+ }
+ }
+
+ if (!missingMandatoryParameters.isEmpty()) {
+ throw new ConfigurationException("Configuration invalid, mandatory parameters missing: " + missingMandatoryParameters.toString());
+ }
+ }
+
+ /**
+ * sets the value of the given parameter
+ *
+ * @param p parameter to set
+ * @param value value to set
+ * @throws ConfigurationException if the parameter is not defined
+ */
+ @Override
+ public void setParameterValue(Parameter p, V value) throws ConfigurationException {
+ if (parameterMap.containsKey(p)) {
+ parameterMap.put(p, value);
+ } else {
+ throw new ConfigurationException("Parameter " + p.getName() + " not defined");
+ }
+ }
+
+ /**
+ * sets the value of parameter with given name
+ *
+ * @param parameterName parameter to set
+ * @param value value to set
+ * @throws ConfigurationException if the parameter is not defined
+ */
+ @Override
+ public void setParameterValue(String parameterName, V value) throws ConfigurationException {
+ if (parameterNameMap.containsKey(parameterName)) {
+ Parameter p = parameterNameMap.get(parameterName);
+ parameterMap.put(p, value);
+ } else {
+ throw new ConfigurationException("Parameter " + parameterName + " not defined");
+ }
+
+ }
+
+ /**
+ * sets the value of the given parameter
+ *
+ * @param p parameter to set
+ * @param stringValue value to set
+ * @throws ConfigurationException if the parameter is not defined
+ */
+ @Override
+ public void setParameterValueByString(Parameter p, String stringValue) throws ConfigurationException {
+ if (parameterMap.containsKey(p)) {
+ try {
+ V value = p.getStringConverter().fromString(stringValue);
+ parameterMap.put(p, value);
+ } catch (ConverterException ex) {
+ throw new ConfigurationException("Error while setting parameter value for parameter " + p.getName() + ". Reason:" + ex.getMessage(), ex);
+ }
+ } else {
+ throw new ConfigurationException("Parameter " + p.getName() + " not defined");
+ }
+ }
+
+ /**
+ * sets the value of the given parameter
+ *
+ * @param parameterName name of parameter to set the value for
+ * @param stringValue value to set
+ * @throws ConfigurationException if the parameter is not defined
+ */
+ @Override
+ public void setParameterValueByString(String parameterName, String stringValue) throws ConfigurationException {
+ if (parameterNameMap.containsKey(parameterName)) {
+ Parameter p = parameterNameMap.get(parameterName);
+
+ if (parameterMap.containsKey(p)) {
+ try {
+ V value = p.getStringConverter().fromString(stringValue);
+ parameterMap.put(p, value);
+ } catch (ConverterException ex) {
+ throw new ConfigurationException("Error while setting parameter value for parameter " + p.getName() + ". Reason:" + ex.getMessage(), ex);
+ }
+ } else {
+ throw new ConfigurationException("Parameter " + p.getName() + " not defined");
+ }
+ } else {
+ throw new ConfigurationException("Parameter with name " + parameterName + " not found in configuration");
+ }
+ }
+
+ /**
+ * returns the value of the given parameter
+ *
+ * @param p the parameter to return the value for
+ * @return the value of the given parameter
+ *
+ * @throws ConfigurationException if the value cannot be determined
+ */
+ @Override
+ public V getParameterValue(Parameter p) throws ConfigurationException {
+ if (parameterMap.containsKey(p)) {
+ return parameterMap.get(p);
+ } else {
+ throw new ConfigurationException("Parameter " + p.getName() + " not defined");
+ }
+ }
+
+ /**
+ * returns the value of the given parameter
+ *
+ * @param parameterName the name of the parameter to return the value for
+ * @return the value of the given parameter; null if not set
+ *
+ * @throws ConfigurationException if the parameter is not defined or if the value is not set
+ */
+ @Override
+ public V getParameterValue(String parameterName) throws ConfigurationException {
+ if (parameterNameMap.containsKey(parameterName)) {
+ Parameter p = parameterNameMap.get(parameterName);
+ return getParameterValue(p);
+ } else {
+ throw new ConfigurationException("Parameter " + parameterName + " not defined");
+ }
+ }
+
+ /**
+ * validates a parameter. Returns true, if the parameter setup is valid; false otherwise
+ *
+ * @param p the parameter to validate
+ * @return true, if the parameter is valid (mandatory parameter set, depending parameters set); false otherwise
+ *
+ * @throws ConfigurationException if a check fails
+ */
+ private boolean validateParameter(Parameter p) throws ConfigurationException {
+ // check if parameter is mandatory and available
+ if ((p.isMandatory()) && (parameterMap.get(p) == null)) {
+ return false;
+ }
+
+ // check if parameter has required parameters and if these are set
+ V parameterValue = getParameterValue(p);
+ if (parameterValue != null) {
+ for (Parameter rp : p.getRequiredParameter()) {
+ if (getParameterValue(rp) == null) {
+ return false;
+ }
+ }
+ }
+
+ // check if parameter has uses value list -if yes ensure only valid value is selected
+ if (!p.isValid(parameterValue)) {
+ throw new ConfigurationException("Value for paramter " + p.getName() + " is invalid.");
+ }
+
+ return true;
+
+ }
+}
diff --git a/configuration/src/main/java/de/muehlencord/shared/configuration/IntegerParameter.java b/configuration/src/main/java/de/muehlencord/shared/configuration/IntegerParameter.java
new file mode 100644
index 0000000..430517b
--- /dev/null
+++ b/configuration/src/main/java/de/muehlencord/shared/configuration/IntegerParameter.java
@@ -0,0 +1,51 @@
+package de.muehlencord.shared.configuration;
+
+import de.muehlencord.shared.configuration.converter.IntegerStringConverter;
+
+/**
+ * A Integer parameter
+ *
+ * @author joern@muehlencord.de
+ */
+public class IntegerParameter extends Parameter {
+
+ /**
+ * creates a new mandatory parameter object using default string converter
+ *
+ * @param name the name of the parameter
+ */
+ public IntegerParameter(String name) {
+ super(name, new IntegerStringConverter(), true);
+ }
+
+ /**
+ * creates a new mandatory parameter object
+ *
+ * @param name the name of the parameter
+ * @param converter the converter object to convert the value of the parameter to string and vice versa
+ */
+ public IntegerParameter(String name, StringConverter converter) {
+ super(name, converter, true);
+ }
+
+ /**
+ * creates a new parameter object using default string converter
+ *
+ * @param name the name of the parameter
+ * @param mandatory detremines if this is a mandatory parameter or not
+ */
+ public IntegerParameter(String name, boolean mandatory) {
+ super(name, new IntegerStringConverter(), mandatory);
+ }
+
+ /**
+ * creates a new parameter object
+ *
+ * @param name the name of the parameter
+ * @param converter the converter object to convert the value of the parameter to string and vice versa
+ * @param mandatory detremines if this is a mandatory parameter or not
+ */
+ public IntegerParameter(String name, StringConverter converter, boolean mandatory) {
+ super(name, converter, mandatory);
+ }
+}
diff --git a/configuration/src/main/java/de/muehlencord/shared/configuration/Parameter.java b/configuration/src/main/java/de/muehlencord/shared/configuration/Parameter.java
new file mode 100644
index 0000000..8cc673b
--- /dev/null
+++ b/configuration/src/main/java/de/muehlencord/shared/configuration/Parameter.java
@@ -0,0 +1,168 @@
+package de.muehlencord.shared.configuration;
+
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ *
+ * @param type of parameter
+ * @author jomu
+ */
+public abstract class Parameter {
+
+ /** the name of the parameter */
+ private String name;
+ /** the long description of this parameter */
+ private String description;
+ /** boolean flag if this is a mandatory parameter or not */
+ private boolean mandatory;
+ /** the type of the value object for this paramterer */
+ // private T type;
+ /** the string converter to convert the object to string and back again */
+ private StringConverter stringConverter;
+ /** list of mandatory parameters, if this parameter is active */
+ private List> requiredParameters;
+ /** optional validator */
+ private Validator validator;
+
+ /**
+ * creates a new mandatory string parameter object
+ *
+ * @param name the name of the parameter
+ * @param converter the converter object to convert the value of the parameter to string and vice versa
+ */
+ public Parameter(String name, StringConverter converter) {
+ this.name = name;
+ this.description = name;
+ this.mandatory = true;
+ this.stringConverter = converter;
+ this.requiredParameters = new LinkedList>();
+ this.validator = null;
+ }
+
+ /**
+ * creates a new parameter object
+ *
+ * @param name the name of the parameter
+ * @param converter the converter object to convert the value of the parameter to string and vice versa
+ * @param mandatory detremines if this is a mandatory parameter or not
+ */
+ public Parameter(String name, StringConverter converter, boolean mandatory) {
+ this(name, converter);
+ this.mandatory = mandatory;
+ }
+
+ /**
+ * creates a new parameter object
+ *
+ * @param name the name of the parameter
+ * @param converter the converter object to convert the value of the parameter to string and vice versa
+ * @param description the long text description of this parameter
+ * @param mandatory detremines if this is a mandatory parameter or not
+ */
+ public Parameter(String name, StringConverter converter, String description, boolean mandatory) {
+ this(name, converter);
+ this.description = description;
+ this.mandatory = mandatory;
+ }
+
+ @Override
+ public String toString() {
+ return name;
+ }
+
+ /**
+ * @return the name
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * @return the description
+ */
+ public String getDescription() {
+ return description;
+ }
+
+ /**
+ * @return the mandatory
+ */
+ public boolean isMandatory() {
+ return mandatory;
+ }
+
+ /**
+ * @return the stringConverter
+ */
+ public StringConverter getStringConverter() {
+ return stringConverter;
+ }
+
+ /**
+ * adds a parameter to the list of required parameters
+ *
+ * @param param the parameter to add
+ */
+ public void addRequiredParameter(Parameter param) {
+ if (!requiredParameters.contains(param)) {
+ requiredParameters.add(param);
+ }
+ }
+
+ /**
+ * returns the list of parameters the given parameter requires
+ *
+ * @return the list of parameters the given parameter requires
+ */
+ public List> getRequiredParameter() {
+ return requiredParameters;
+ }
+
+ /**
+ * returns true, if the given value is part of the possible value list or if the given value list is true
+ *
+ * @param value the value to validate
+ * @return true if no value list is defined or value is part of the value list; false otherwise
+ */
+ public boolean isValid(T value) {
+ if (validator == null) {
+ return true;
+ } else {
+ try {
+ validator.validate(value);
+ return true;
+ } catch (ValidationException ex) {
+ return false;
+ }
+ }
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (o == null) {
+ return false;
+ }
+ if (o instanceof Parameter) {
+ Parameter param = (Parameter) o;
+ return param.getName().equals(getName());
+
+ } else {
+ return false;
+ }
+ }
+
+ @Override
+ public int hashCode() {
+ int hash = 7;
+ hash = 97 * hash + (this.name != null ? this.name.hashCode() : 0);
+ return hash;
+ }
+
+ /**
+ * @param validator the validator to set
+ */
+ public void setValidator(Validator validator) {
+ this.validator = validator;
+ }
+}
diff --git a/configuration/src/main/java/de/muehlencord/shared/configuration/ParameterFactory.java b/configuration/src/main/java/de/muehlencord/shared/configuration/ParameterFactory.java
new file mode 100644
index 0000000..25cb003
--- /dev/null
+++ b/configuration/src/main/java/de/muehlencord/shared/configuration/ParameterFactory.java
@@ -0,0 +1,49 @@
+package de.muehlencord.shared.configuration;
+
+import java.net.URI;
+import java.util.Date;
+
+/**
+ *
+ * @author jomu
+ */
+public abstract class ParameterFactory {
+
+ private ParameterFactory() {
+ // hide public constructor to force factory
+ }
+
+ public static Parameter getParameterInstance(String name, boolean mandatory, Class clazz) throws ConfigurationException {
+ if (clazz.equals(String.class)) {
+ return new StringParameter(name, mandatory);
+
+ } else if (clazz.equals(Boolean.class)) {
+ return new BooleanParameter(name, mandatory);
+
+ } else if (clazz.equals(Date.class)) {
+ return new DateParameter(name, mandatory);
+
+ } else if (clazz.equals(Integer.class)) {
+ return new IntegerParameter(name, mandatory);
+
+ } else if (clazz.equals(URI.class)) {
+ return new URIParameter(name, mandatory);
+
+
+ } else {
+ throw new ConfigurationException("Unsupported type " + clazz);
+ }
+ }
+
+ public static Parameter getParameterInstance(String name, boolean mandatory, Object value) throws ConfigurationException {
+ return getParameterInstance(name, mandatory, value.getClass());
+ }
+
+ public static Parameter getParameterInstance(String name) throws ConfigurationException {
+ return getParameterInstance(name, true, String.class);
+ }
+
+ public static Parameter getParameterInstance(String name, boolean mandatory) throws ConfigurationException {
+ return getParameterInstance(name, mandatory, String.class);
+ }
+}
diff --git a/configuration/src/main/java/de/muehlencord/shared/configuration/StringConverter.java b/configuration/src/main/java/de/muehlencord/shared/configuration/StringConverter.java
new file mode 100644
index 0000000..d361a31
--- /dev/null
+++ b/configuration/src/main/java/de/muehlencord/shared/configuration/StringConverter.java
@@ -0,0 +1,27 @@
+package de.muehlencord.shared.configuration;
+
+/**
+ *
+ * @param the class type of the parameter value to convert
+ * @author jomu
+ */
+public interface StringConverter {
+
+ /**
+ * Converter a parameter object to a string representation
+ * @param o the parameter value to convert
+ * @return the parameter value as string
+ * @throws ConverterException if the conversion fails
+ */
+ public String toString (T o) throws ConverterException;
+
+ /**
+ * Converter a string to a the given type
+ * @param the type of the converter
+ * @param s string representation of a parameter value to convert to an object
+ * @return the parameter value as object
+ * @throws ConverterException if the conversion fails
+ */
+ public V fromString (String s) throws ConverterException;
+
+}
diff --git a/configuration/src/main/java/de/muehlencord/shared/configuration/StringParameter.java b/configuration/src/main/java/de/muehlencord/shared/configuration/StringParameter.java
new file mode 100644
index 0000000..06fb87c
--- /dev/null
+++ b/configuration/src/main/java/de/muehlencord/shared/configuration/StringParameter.java
@@ -0,0 +1,50 @@
+package de.muehlencord.shared.configuration;
+
+import de.muehlencord.shared.configuration.converter.StringStringConverter;
+
+/**
+ * A String parameter
+ * @author joern@muehlencord.de
+ */
+public class StringParameter extends Parameter {
+
+ /**
+ * creates a new mandatory parameter object using default string converter
+ *
+ * @param name the name of the parameter
+ */
+ public StringParameter(String name) {
+ super(name, new StringStringConverter(), true);
+ }
+
+ /**
+ * creates a new mandatory parameter object
+ *
+ * @param name the name of the parameter
+ * @param converter the converter object to convert the value of the parameter to string and vice versa
+ */
+ public StringParameter(String name, StringConverter converter) {
+ super(name, converter, true);
+ }
+
+ /**
+ * creates a new parameter object using default string converter
+ *
+ * @param name the name of the parameter
+ * @param mandatory detremines if this is a mandatory parameter or not
+ */
+ public StringParameter(String name, boolean mandatory) {
+ super(name, new StringStringConverter(), mandatory);
+ }
+
+ /**
+ * creates a new parameter object
+ *
+ * @param name the name of the parameter
+ * @param converter the converter object to convert the value of the parameter to string and vice versa
+ * @param mandatory detremines if this is a mandatory parameter or not
+ */
+ public StringParameter(String name, StringConverter converter, boolean mandatory) {
+ super(name, converter, mandatory);
+ }
+}
diff --git a/configuration/src/main/java/de/muehlencord/shared/configuration/URIParameter.java b/configuration/src/main/java/de/muehlencord/shared/configuration/URIParameter.java
new file mode 100644
index 0000000..5e00496
--- /dev/null
+++ b/configuration/src/main/java/de/muehlencord/shared/configuration/URIParameter.java
@@ -0,0 +1,52 @@
+package de.muehlencord.shared.configuration;
+
+import de.muehlencord.shared.configuration.converter.URIStringConverter;
+import java.net.URI;
+
+/**
+ * A URI parameter
+ * @author joern@muehlencord.de
+ */
+public class URIParameter extends Parameter {
+
+ /**
+ * creates a new mandatory parameter object using default string converter
+ *
+ * @param name the name of the parameter
+ */
+ public URIParameter(String name) {
+ super(name, new URIStringConverter(), true);
+ }
+
+ /**
+ * creates a new mandatory parameter object
+ *
+ * @param name the name of the parameter
+ * @param converter the converter object to convert the value of the parameter to string and vice versa
+ */
+ public URIParameter(String name, StringConverter converter) {
+ super(name, converter, true);
+ }
+
+ /**
+ * creates a new parameter object using default string converter
+ *
+ * @param name the name of the parameter
+ * @param mandatory detremines if this is a mandatory parameter or not
+ */
+ public URIParameter(String name, boolean mandatory) {
+ super(name, new URIStringConverter(), mandatory);
+ }
+
+ /**
+ * creates a new parameter object
+ *
+ * @param name the name of the parameter
+ * @param converter the converter object to convert the value of the parameter to string and vice versa
+ * @param mandatory detremines if this is a mandatory parameter or not
+ */
+ public URIParameter(String name, StringConverter converter, boolean mandatory) {
+ super(name, converter, mandatory);
+ }
+
+}
diff --git a/configuration/src/main/java/de/muehlencord/shared/configuration/ValidationException.java b/configuration/src/main/java/de/muehlencord/shared/configuration/ValidationException.java
new file mode 100644
index 0000000..ccafdd7
--- /dev/null
+++ b/configuration/src/main/java/de/muehlencord/shared/configuration/ValidationException.java
@@ -0,0 +1,36 @@
+package de.muehlencord.shared.configuration;
+
+/**
+ *
+ * @author joern@muehlencord.de
+ */
+public class ValidationException extends Exception {
+
+ /**
+ * Creates a new instance of
+ * ValidationException without detail message.
+ */
+ public ValidationException() {
+ }
+
+ /**
+ * Constructs an instance of
+ * ValidationException with the specified detail message.
+ *
+ * @param msg the detail message.
+ */
+ public ValidationException(String msg) {
+ super(msg);
+ }
+
+ /**
+ * Constructs an instance of
+ * ValidationException with the specified detail message.
+ *
+ * @param msg the detail message.
+ * @param th the root cause
+ */
+ public ValidationException(String msg, Throwable th) {
+ super(msg, th);
+ }
+}
diff --git a/configuration/src/main/java/de/muehlencord/shared/configuration/Validator.java b/configuration/src/main/java/de/muehlencord/shared/configuration/Validator.java
new file mode 100644
index 0000000..44de24b
--- /dev/null
+++ b/configuration/src/main/java/de/muehlencord/shared/configuration/Validator.java
@@ -0,0 +1,17 @@
+package de.muehlencord.shared.configuration;
+
+/**
+ *
+ * @param the type of the validator
+ * @author joern@muehlencord.de
+ */
+public interface Validator {
+
+ /**
+ * validates the parameter value
+ *
+ * @param value the value of the parameter to validate
+ * @throws ValidationException if the value is not valid according to the validator configuration
+ */
+ public void validate(T value) throws ValidationException;
+}
diff --git a/configuration/src/main/java/de/muehlencord/shared/configuration/converter/BooleanStringConverter.java b/configuration/src/main/java/de/muehlencord/shared/configuration/converter/BooleanStringConverter.java
new file mode 100644
index 0000000..2791d4c
--- /dev/null
+++ b/configuration/src/main/java/de/muehlencord/shared/configuration/converter/BooleanStringConverter.java
@@ -0,0 +1,21 @@
+package de.muehlencord.shared.configuration.converter;
+
+import de.muehlencord.shared.configuration.ConverterException;
+import de.muehlencord.shared.configuration.StringConverter;
+
+/**
+ *
+ * @author joern@muehlencord.de
+ */
+public class BooleanStringConverter implements StringConverter {
+
+ @Override
+ public String toString(Boolean o) throws ConverterException {
+ return o.toString();
+ }
+
+ @Override
+ public Boolean fromString(String s) throws ConverterException {
+ return Boolean.parseBoolean(s);
+ }
+}
diff --git a/configuration/src/main/java/de/muehlencord/shared/configuration/converter/DateStringConverter.java b/configuration/src/main/java/de/muehlencord/shared/configuration/converter/DateStringConverter.java
new file mode 100644
index 0000000..f180327
--- /dev/null
+++ b/configuration/src/main/java/de/muehlencord/shared/configuration/converter/DateStringConverter.java
@@ -0,0 +1,49 @@
+package de.muehlencord.shared.configuration.converter;
+
+import de.muehlencord.shared.configuration.ConverterException;
+import de.muehlencord.shared.configuration.StringConverter;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Locale;
+
+/**
+ *
+ * @author jomu
+ */
+public class DateStringConverter implements StringConverter {
+
+ /**
+ * dateformat to convert from string to date and vice versa
+ */
+ private static final String format = "yyyy-MM-dd HH:mm:ss";
+
+ /**
+ * Converter a parameter object to a string representation
+ *
+ * @param d the parameter value to convert
+ * @return the parameter value as string
+ */
+ @Override
+ public String toString(Date d) {
+ SimpleDateFormat sdf = new SimpleDateFormat(format, Locale.US);
+ return sdf.format(d);
+ }
+
+ /**
+ * Converter a string to date
+ *
+ * @param s string representation of a parameter value to convert to an object
+ * @return the parameter value as date
+ *
+ * @throws ConverterException if the conversion fails
+ */
+ @Override
+ public Date fromString(String s) throws ConverterException {
+ try {
+ SimpleDateFormat sdf = new SimpleDateFormat(format, Locale.US);
+ return sdf.parse(s);
+ } catch (Exception ex) {
+ throw new ConverterException("Error while converting " + s + "*to date. Reason: " + ex.getMessage(), ex);
+ }
+ }
+}
diff --git a/configuration/src/main/java/de/muehlencord/shared/configuration/converter/IntegerStringConverter.java b/configuration/src/main/java/de/muehlencord/shared/configuration/converter/IntegerStringConverter.java
new file mode 100644
index 0000000..7ec9d56
--- /dev/null
+++ b/configuration/src/main/java/de/muehlencord/shared/configuration/converter/IntegerStringConverter.java
@@ -0,0 +1,20 @@
+package de.muehlencord.shared.configuration.converter;
+
+import de.muehlencord.shared.configuration.ConverterException;
+import de.muehlencord.shared.configuration.StringConverter;
+
+/**
+ *
+ * @author jomu
+ */
+public class IntegerStringConverter implements StringConverter {
+
+ public String toString(Integer o) throws ConverterException {
+ return o.toString();
+ }
+
+ public Integer fromString(String s) throws ConverterException {
+ return Integer.parseInt(s);
+ }
+
+}
diff --git a/configuration/src/main/java/de/muehlencord/shared/configuration/converter/StringStringConverter.java b/configuration/src/main/java/de/muehlencord/shared/configuration/converter/StringStringConverter.java
new file mode 100644
index 0000000..8737052
--- /dev/null
+++ b/configuration/src/main/java/de/muehlencord/shared/configuration/converter/StringStringConverter.java
@@ -0,0 +1,22 @@
+package de.muehlencord.shared.configuration.converter;
+
+import de.muehlencord.shared.configuration.ConverterException;
+import de.muehlencord.shared.configuration.StringConverter;
+
+/**
+ *
+ * @author jomu
+ */
+public class StringStringConverter implements StringConverter {
+
+ @Override
+ public String toString(String o) throws ConverterException {
+ return o;
+ }
+
+ @Override
+ public String fromString(String s) throws ConverterException {
+ return s;
+ }
+
+}
diff --git a/configuration/src/main/java/de/muehlencord/shared/configuration/converter/URIStringConverter.java b/configuration/src/main/java/de/muehlencord/shared/configuration/converter/URIStringConverter.java
new file mode 100644
index 0000000..d49cf6a
--- /dev/null
+++ b/configuration/src/main/java/de/muehlencord/shared/configuration/converter/URIStringConverter.java
@@ -0,0 +1,23 @@
+package de.muehlencord.shared.configuration.converter;
+
+import de.muehlencord.shared.configuration.ConverterException;
+import de.muehlencord.shared.configuration.StringConverter;
+import java.net.URI;
+
+/**
+ *
+ * @author jomu
+ */
+public class URIStringConverter implements StringConverter {
+
+ @Override
+ public String toString(URI o) throws ConverterException {
+ return o.toString();
+ }
+
+ @Override
+ public URI fromString(String s) throws ConverterException {
+ return URI.create(s);
+ }
+
+}
diff --git a/configuration/src/main/java/de/muehlencord/shared/configuration/validator/IntgerRangeValidator.java b/configuration/src/main/java/de/muehlencord/shared/configuration/validator/IntgerRangeValidator.java
new file mode 100644
index 0000000..a55331b
--- /dev/null
+++ b/configuration/src/main/java/de/muehlencord/shared/configuration/validator/IntgerRangeValidator.java
@@ -0,0 +1,27 @@
+package de.muehlencord.shared.configuration.validator;
+
+import de.muehlencord.shared.configuration.ValidationException;
+import de.muehlencord.shared.configuration.Validator;
+
+/**
+ *
+ * @author joern@muehlencord.de
+ */
+public class IntgerRangeValidator implements Validator {
+
+ private Integer lowerBoundary;
+ private Integer upperBoundary;
+
+ public IntgerRangeValidator(Integer lb, Integer ub) {
+ this.lowerBoundary = lb;
+ this.upperBoundary = ub;
+ }
+
+ @Override
+ public void validate(Integer value) throws ValidationException {
+ if ((value > upperBoundary) || (value < lowerBoundary)) {
+ throw new ValidationException("Value must be between " + lowerBoundary + " and " + upperBoundary + " but is " + value);
+
+ }
+ }
+}
diff --git a/configuration/src/main/java/de/muehlencord/shared/configuration/validator/StringValueListValidator.java b/configuration/src/main/java/de/muehlencord/shared/configuration/validator/StringValueListValidator.java
new file mode 100644
index 0000000..96b7dd1
--- /dev/null
+++ b/configuration/src/main/java/de/muehlencord/shared/configuration/validator/StringValueListValidator.java
@@ -0,0 +1,32 @@
+package de.muehlencord.shared.configuration.validator;
+
+import de.muehlencord.shared.configuration.ValidationException;
+import de.muehlencord.shared.configuration.Validator;
+import java.util.Arrays;
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ *
+ * @author joern@muehlencord.de
+ */
+public class StringValueListValidator implements Validator {
+
+ private List valueList;
+
+ public StringValueListValidator() {
+ this.valueList = new LinkedList();
+ }
+
+ public StringValueListValidator(String... values) {
+ this();
+ valueList.addAll(Arrays.asList(values));
+ }
+
+ @Override
+ public void validate(String value) throws ValidationException {
+ if (!valueList.contains(value)) {
+ throw new ValidationException("Value " + value + " not valid. One of " + valueList.toString() + " expected");
+ }
+ }
+}
diff --git a/configuration/src/test/java/de/muehlencord/shared/configuration/AppTest.java b/configuration/src/test/java/de/muehlencord/shared/configuration/AppTest.java
new file mode 100644
index 0000000..774ca4f
--- /dev/null
+++ b/configuration/src/test/java/de/muehlencord/shared/configuration/AppTest.java
@@ -0,0 +1,38 @@
+package de.muehlencord.shared.configuration;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Unit test for simple App.
+ */
+public class AppTest
+ extends TestCase
+{
+ /**
+ * Create the test case
+ *
+ * @param testName name of the test case
+ */
+ public AppTest( String testName )
+ {
+ super( testName );
+ }
+
+ /**
+ * @return the suite of tests being tested
+ */
+ public static Test suite()
+ {
+ return new TestSuite( AppTest.class );
+ }
+
+ /**
+ * Rigourous Test :-)
+ */
+ public void testApp()
+ {
+ assertTrue( true );
+ }
+}
diff --git a/jeeutil/pom.xml b/jeeutil/pom.xml
new file mode 100644
index 0000000..a229e03
--- /dev/null
+++ b/jeeutil/pom.xml
@@ -0,0 +1,81 @@
+
+
+ 4.0.0
+
+ shared
+ de.muehlencord
+ 1.0-SNAPSHOT
+
+
+ de.muehlencord.app
+ shared-jeeutil
+ 1.0-SNAPSHOT
+ ejb
+
+ shared-jeeutil
+
+
+ ${project.build.directory}/endorsed
+ UTF-8
+
+
+
+
+ javax
+ javaee-api
+ 6.0
+ provided
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 2.3.2
+
+ 1.6
+ 1.6
+
+ ${endorsed.dir}
+
+
+
+
+ org.apache.maven.plugins
+ maven-ejb-plugin
+ 2.3
+
+ 3.1
+
+
+
+ org.apache.maven.plugins
+ maven-dependency-plugin
+ 2.1
+
+
+ validate
+
+ copy
+
+
+ ${endorsed.dir}
+ true
+
+
+ javax
+ javaee-endorsed-api
+ 6.0
+ jar
+
+
+
+
+
+
+
+
+
+
diff --git a/jeeutil/src/main/java/de/muehlencord/app/sharedjeeutil/ClickJackFIlter.java b/jeeutil/src/main/java/de/muehlencord/app/sharedjeeutil/ClickJackFIlter.java
new file mode 100644
index 0000000..f791741
--- /dev/null
+++ b/jeeutil/src/main/java/de/muehlencord/app/sharedjeeutil/ClickJackFIlter.java
@@ -0,0 +1,58 @@
+package de.muehlencord.app.sharedjeeutil;
+
+import java.io.IOException;
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * Filter to suppress ClickJacking by adding X-FRAME-OPTIONS to header.
+ * see https://www.owasp.org/index.php/Clickjacking_Defense_Cheat_Sheet for details
+ *
+ * @author joern@muehlencord.de
+ */
+public class ClickJackFIlter implements Filter {
+
+ /** mode to use */
+ private String mode = "DENY";
+
+ /**
+ * inits the filter. Checks if a parameter "mode" is available in parameter map tp use instead default "DENY"
+ *
+ * @param filterConfig
+ * @throws ServletException
+ */
+ @Override
+ public void init(FilterConfig filterConfig) throws ServletException {
+ String configMode = filterConfig.getInitParameter("mode");
+ if (configMode != null) {
+ mode = configMode;
+ }
+ }
+
+ /**
+ * Add X-FRAME-OPTIONS response header to tell IE8 (and any other browsers who decide to implement) not to display this content in a frame. For details,
+ * please refer to http://blogs.msdn.com/sdl/archive/2009/02/05/clickjacking-defense-in-ie8.aspx.
+ *
+ * @param request
+ * @param response
+ * @param chain
+ * @throws IOException
+ * @throws ServletException
+ */
+ @Override
+ public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
+ HttpServletResponse res = (HttpServletResponse) response;
+ res.addHeader("X-FRAME-OPTIONS", mode);
+ chain.doFilter(request, response);
+ }
+
+ @Override
+ public void destroy() {
+ // nothing todo here
+ }
+}
diff --git a/jeeutil/src/main/resources/META-INF/MANIFEST.MF b/jeeutil/src/main/resources/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..59499bc
--- /dev/null
+++ b/jeeutil/src/main/resources/META-INF/MANIFEST.MF
@@ -0,0 +1,2 @@
+Manifest-Version: 1.0
+
diff --git a/jmpass/pom.xml b/jmpass/pom.xml
new file mode 100644
index 0000000..b825b3c
--- /dev/null
+++ b/jmpass/pom.xml
@@ -0,0 +1,30 @@
+
+ 4.0.0
+
+ de.muehlencord.shared
+ jmpass
+ 1.0-SNAPSHOT
+ jar
+
+ jmpass
+ http://www.mühlencord.de/
+
+
+ Bugzilla
+ https://jomu.timelord.de/bugzilla/
+
+
+
+ UTF-8
+
+
+
+
+ junit
+ junit
+ 4.10
+ test
+
+
+
diff --git a/jmpass/src/main/java/de/muehlencord/shared/jmpass/Bcrypt.java b/jmpass/src/main/java/de/muehlencord/shared/jmpass/Bcrypt.java
new file mode 100644
index 0000000..fed5abc
--- /dev/null
+++ b/jmpass/src/main/java/de/muehlencord/shared/jmpass/Bcrypt.java
@@ -0,0 +1,56 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package de.muehlencord.shared.jmpass;
+
+/**
+ *
+ * @author jomu
+ */
+public class Bcrypt {
+
+ // http://en.wikipedia.org/wiki/Bcrypt
+
+ public String bcrypt(long cost, byte[] salt, String input) {
+ String state = eksBlowfishSetup(cost, salt, input);
+ String cText = "OrpheanBeholderScryDoubt"; // FIXME - what is this string for, 3 64 bit blocks
+ for (int i=0; i<64; i++) { // FIXME - why 64?
+ cText = encryptECB(state, cText);
+ }
+ return concatenate(cost, salt, cText);
+ }
+
+ private String eksBlowfishSetup(long cost, String salt, String key) {
+ String state = initState();
+ state = expandKey (state, salt, key);
+ // TODO buffer overflow check, max size of cost
+ long rounds = Math.round(Math.pow(2, cost));
+ for (int i=0; i=UTF-8
diff --git a/network/.settings/org.eclipse.jdt.core.prefs b/network/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..60105c1
--- /dev/null
+++ b/network/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,5 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
+org.eclipse.jdt.core.compiler.source=1.6
diff --git a/network/.settings/org.eclipse.m2e.core.prefs b/network/.settings/org.eclipse.m2e.core.prefs
new file mode 100644
index 0000000..d046678
--- /dev/null
+++ b/network/.settings/org.eclipse.m2e.core.prefs
@@ -0,0 +1,5 @@
+#Thu Jul 05 02:27:48 CEST 2012
+activeProfiles=
+eclipse.preferences.version=1
+resolveWorkspaceProjects=true
+version=1
diff --git a/network/nb-configuration.xml b/network/nb-configuration.xml
new file mode 100644
index 0000000..3486bc9
--- /dev/null
+++ b/network/nb-configuration.xml
@@ -0,0 +1,18 @@
+
+
+
+
+
+ all
+
+
diff --git a/network/pom.xml b/network/pom.xml
new file mode 100644
index 0000000..c71c08d
--- /dev/null
+++ b/network/pom.xml
@@ -0,0 +1,78 @@
+
+
+ 4.0.0
+
+ de.muehlencord.shared
+ shared-network
+ 1.0-SNAPSHOT
+ jar
+ shared-network
+
+
+ shared
+ de.muehlencord
+ 1.0-SNAPSHOT
+
+
+ http://maven.apache.org
+
+ hudson
+ http://sunrise.muehlencord.intra:8088/jenkins/job/shared-util/
+
+
+ UTF-8
+
+
+
+ ${project.artifactId}
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 2.5.1
+
+ 1.6
+ 1.6
+
+
+
+
+
+
+
+ junit
+ junit
+ 4.10
+ jar
+ test
+
+
+ com.enterprisedt
+ edtFTPj
+ 1.5.3
+ compile
+
+
+ log4j
+ log4j
+ 1.2.17
+ provided
+
+
+
+ de.muehlencord.shared
+ shared-util
+ 1.0-SNAPSHOT
+ jar
+
+
+
+ javax.mail
+ mail
+ 1.4.5
+ jar
+ compile
+
+
+
diff --git a/network/src/main/java/de/muehlencord/shared/network/ftp/FTPConnection.java b/network/src/main/java/de/muehlencord/shared/network/ftp/FTPConnection.java
new file mode 100644
index 0000000..ea73b31
--- /dev/null
+++ b/network/src/main/java/de/muehlencord/shared/network/ftp/FTPConnection.java
@@ -0,0 +1,241 @@
+package de.muehlencord.shared.network.ftp;
+
+import com.enterprisedt.net.ftp.FTPClient;
+import com.enterprisedt.net.ftp.FTPConnectMode;
+import com.enterprisedt.net.ftp.FTPException;
+import com.enterprisedt.net.ftp.FTPFile;
+import de.muehlencord.shared.util.StringUtil;
+import java.io.File;
+import java.io.IOException;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Locale;
+import org.apache.log4j.Logger;
+
+/**
+ *
+ * @author joern@muehlencord.de
+ */
+public class FTPConnection {
+
+ /** the default timeout in ms */
+ public static final int DEFAULTTIMEOUT = 30000;
+ /** the logger object */
+ private final Logger logger = Logger.getLogger(FTPConnection.class);
+ /** the username to connect with */
+ private String userName;
+ /** the password to connect with */
+ private String password;
+ /** the ftp client to use */
+ private FTPClient client;
+ /** the remote host to connect to */
+ private String remoteHost;
+ /** the locale of the client to use */
+ private Locale clientLocale;
+
+ /**
+ * creates a new ftp connection
+ *
+ * @param remoteHost the host to connect to
+ * @param userName the user to connect with
+ * @param password the password to connect with
+ */
+ public FTPConnection(String remoteHost, String userName, String password) {
+ this(remoteHost, userName, password, Locale.getDefault());
+ }
+
+ /**
+ * creates a new ftp connection
+ *
+ * @param remoteHost the host to connect to
+ * @param userName the user to connect with
+ * @param password the password to connect with
+ * @param clientLocale the locale to use for the client
+ */
+ public FTPConnection(String remoteHost, String userName, String password, Locale clientLocale) {
+ this.remoteHost = remoteHost;
+ this.userName = userName;
+ this.password = password;
+ this.clientLocale = clientLocale;
+ }
+
+ /**
+ * connects the ftp client to the remote host
+ *
+ * @throws FTPConnectionException if the command cannot be executed
+ */
+ public void connect() throws FTPConnectionException {
+ try {
+ client = new FTPClient();
+ client.setConnectMode(FTPConnectMode.PASV);
+ client.setParserLocale(clientLocale);
+ client.setRemoteHost(remoteHost);
+ client.setTimeout(DEFAULTTIMEOUT);
+ client.connect();
+ client.login(userName, password);
+ } catch (Exception ex) {
+ throw new FTPConnectionException("Error while connecting to ftp client. Reason: " + ex.getMessage(), ex);
+ }
+ }
+
+ /** disconnects the ftp client from the remote host */
+ public void disconnect() {
+ try {
+ client.quit();
+ } catch (IOException ex) {
+ logger.error(ex.getMessage());
+ logger.debug(StringUtil.getStackTraceString(ex));
+ } catch (FTPException ex) {
+ logger.error(ex.getMessage());
+ logger.debug(StringUtil.getStackTraceString(ex));
+ }
+ }
+
+ /**
+ * returns a list of files (as string) found in the given directory
+ *
+ * @param dir the directory to return the list for
+ * @return a list of files (as string) found in the given directory
+ *
+ * @throws FTPConnectionException if the command cannot be executed
+ */
+ public List list(String dir) throws FTPConnectionException {
+ List returnValue = new LinkedList();
+ try {
+ FTPFile[] files = client.dirDetails(dir);
+ for (int i = 0; i < files.length; i++) {
+ returnValue.add(files[i].getName());
+ }
+ } catch (Exception ex) {
+ logger.error(ex.getMessage());
+ logger.debug(StringUtil.getStackTraceString(ex));
+ throw new FTPConnectionException("Error while getting diretoy listing. Reason: " + ex.getMessage(), ex);
+ }
+
+ return returnValue;
+ }
+
+ /**
+ * returns a list of directories contained in given directory
+ *
+ * @param dir the directory to return the subfolders for
+ * @return a list of subfolders of the given directory
+ *
+ * @throws FTPConnectionException if the command cannot be executed
+ */
+ public List listDirsOnly(String dir) throws FTPConnectionException {
+ List returnValue = new LinkedList();
+ try {
+ FTPFile[] files = client.dirDetails(dir);
+ for (int i = 0; i < files.length; i++) {
+ if (files[i].isDir()) {
+ returnValue.add(files[i].getName());
+ }
+ }
+ } catch (Exception ex) {
+ logger.error(ex.getMessage());
+ logger.debug(StringUtil.getStackTraceString(ex));
+ throw new FTPConnectionException("Error while getting diretoy listing. Reason: " + ex.getMessage(), ex);
+
+ }
+
+ return returnValue;
+ }
+
+ /**
+ * returns a list of files contained in the given folder
+ *
+ * @param dir the directory to list
+ * @return a list of files contained in the given folder
+ *
+ * @throws FTPConnectionException if the command cannot be executed
+ */
+ public List listFilesOnly(String dir) throws FTPConnectionException {
+ List returnValue = new LinkedList();
+ try {
+ FTPFile[] files = client.dirDetails(dir);
+ for (int i = 0; i < files.length; i++) {
+ if (!files[i].isDir()) {
+ returnValue.add(files[i].getName());
+ }
+ }
+ } catch (Exception ex) {
+ logger.error(ex.getMessage());
+ logger.debug(StringUtil.getStackTraceString(ex));
+ throw new FTPConnectionException("Error while getting diretoy listing. Reason: " + ex.getMessage(), ex);
+
+ }
+
+ return returnValue;
+ }
+
+ /**
+ * returns a list of links contained in the given folder
+ *
+ * @param dir the directory to list
+ * @return a list of links contained in the given folder
+ *
+ * @throws FTPConnectionException if the command cannot be executed
+ */
+ public List listLinksOnly(String dir) throws FTPConnectionException {
+ List returnValue = new LinkedList();
+ try {
+ FTPFile[] files = client.dirDetails(dir);
+ for (int i = 0; i < files.length; i++) {
+ if (files[i].isLink()) {
+ returnValue.add(files[i].getName());
+ }
+ }
+ } catch (Exception ex) {
+ logger.error(ex.getMessage());
+ logger.debug(StringUtil.getStackTraceString(ex));
+ throw new FTPConnectionException("Error while getting diretoy listing. Reason: " + ex.getMessage(), ex);
+
+ }
+
+ return returnValue;
+ }
+
+ /**
+ * uploads the given file and stores it under the given remote filename - including path
+ *
+ * @param localFilename the path and filename of the source file
+ * @param remoteFileName the path and filename of the destination file
+ * @throws FTPConnectionException if the command cannot be executed
+ */
+ public void uploadFile(String localFilename, String remoteFileName) throws FTPConnectionException {
+
+ try {
+ client.setDetectTransferMode(true);
+ if ((remoteFileName != null) && !remoteFileName.equals("")) {
+ client.put(localFilename, remoteFileName, false);
+ } else {
+ File f = new File(localFilename);
+ String remoteName = f.getName();
+ client.put(localFilename, remoteName, false);
+ }
+ } catch (Exception ex) {
+ logger.error(ex.getMessage());
+ logger.debug(StringUtil.getStackTraceString(ex));
+ throw new FTPConnectionException("Error while uploading file. Reason: " + ex.getMessage(), ex);
+
+ }
+ }
+
+ /**
+ * renames a file on the remote host
+ *
+ * @param remoteOldName the current file name
+ * @param remoteNewName the new file name
+ * @throws FTPConnectionException if the command cannot be executed
+ */
+ public void rename(String remoteOldName, String remoteNewName) throws FTPConnectionException {
+ try {
+ client.rename(remoteOldName, remoteNewName);
+ } catch (Exception ex) {
+ logger.error(ex.getMessage());
+ logger.debug(StringUtil.getStackTraceString(ex));
+ throw new FTPConnectionException("Error while renaming file. Reason: " + ex.getMessage(), ex);
+ }
+ }
+}
diff --git a/network/src/main/java/de/muehlencord/shared/network/ftp/FTPConnectionException.java b/network/src/main/java/de/muehlencord/shared/network/ftp/FTPConnectionException.java
new file mode 100644
index 0000000..8b6bacd
--- /dev/null
+++ b/network/src/main/java/de/muehlencord/shared/network/ftp/FTPConnectionException.java
@@ -0,0 +1,45 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package de.muehlencord.shared.network.ftp;
+
+/**
+ *
+ * @author jomu
+ */
+public class FTPConnectionException extends Exception {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 4393979078434188521L;
+
+ /**
+ * Creates a new instance of
+ * FTPConnectionException without detail message.
+ */
+ public FTPConnectionException() {
+ }
+
+ /**
+ * Constructs an instance of
+ * FTPConnectionException with the specified detail message.
+ *
+ * @param msg the detail message.
+ */
+ public FTPConnectionException(String msg) {
+ super(msg);
+ }
+
+ /**
+ * Constructs an instance of
+ * FTPConnectionException with the specified detail message.
+ *
+ * @param msg the detail message.
+ * @param th the causing exception
+ */
+ public FTPConnectionException(String msg, Throwable th) {
+ super(msg, th);
+ }
+}
diff --git a/network/src/main/java/de/muehlencord/shared/network/http/HttpLayer.java b/network/src/main/java/de/muehlencord/shared/network/http/HttpLayer.java
new file mode 100644
index 0000000..0833e46
--- /dev/null
+++ b/network/src/main/java/de/muehlencord/shared/network/http/HttpLayer.java
@@ -0,0 +1,263 @@
+package de.muehlencord.shared.network.http;
+
+import java.io.BufferedReader;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.net.URLEncoder;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import org.apache.log4j.Logger;
+
+/**
+ * Communication endpoint for posting a messages
+ *
+ * @author joern@muehlencord.de
+ */
+public class HttpLayer {
+
+ private static final Logger logger = Logger.getLogger(HttpLayer.class);
+ /** the url to post to */
+ private String destinationUrlString;
+ /** the encoding to use */
+ private String encoding;
+
+ /**
+ * creates a new http layer which can communicate with the given url
+ *
+ * @param urlString
+ * the url to communicate with
+ */
+ public HttpLayer(String urlString) {
+ this.destinationUrlString = urlString;
+ this.encoding = "UTF-8";
+ }
+
+ /**
+ * posts the value of message into the varialbe parameter
+ *
+ * @param parameter
+ * the parameter to write the message to
+ * @param message
+ * the message to post
+ * @throws MessageNotSendException
+ * if the message cannot be sent
+ */
+ public void post(String parameter, String message)
+ throws MessageNotSendException {
+ Map parameterMap = new HashMap();
+ String[] valueArray = { message };
+ parameterMap.put(parameter, valueArray);
+ post(parameterMap);
+ }
+
+ public void post(List