diff options
author | tkellner <tkellner@174cde9d-5d70-4d2a-aa98-46368bc2aaf7> | 2013-04-10 18:49:01 +0000 |
---|---|---|
committer | tkellner <tkellner@174cde9d-5d70-4d2a-aa98-46368bc2aaf7> | 2013-04-10 18:49:01 +0000 |
commit | 3f5eda3adbea29aa8ad2cca5d300cef3f3a444a5 (patch) | |
tree | bf4948a55beed5a9ab64bc59caa1898703ce5e2b /pdf-over/pdf-signer-interface/src/main/java/at/asit/pdfover/pdfsignator/profileproperties/validators | |
parent | 93d4e1db036224b937fc03fdb3ef0ea7bbaa25a2 (diff) | |
download | mocca-3f5eda3adbea29aa8ad2cca5d300cef3f3a444a5.tar.gz mocca-3f5eda3adbea29aa8ad2cca5d300cef3f3a444a5.tar.bz2 mocca-3f5eda3adbea29aa8ad2cca5d300cef3f3a444a5.zip |
Added Maven project for PDF-OVER 4.0 (Includes Spezification Diagramms)
git-svn-id: https://joinup.ec.europa.eu/svn/pdf-over/trunk@2 174cde9d-5d70-4d2a-aa98-46368bc2aaf7
Diffstat (limited to 'pdf-over/pdf-signer-interface/src/main/java/at/asit/pdfover/pdfsignator/profileproperties/validators')
5 files changed, 209 insertions, 0 deletions
diff --git a/pdf-over/pdf-signer-interface/src/main/java/at/asit/pdfover/pdfsignator/profileproperties/validators/FloatRangeValidator.java b/pdf-over/pdf-signer-interface/src/main/java/at/asit/pdfover/pdfsignator/profileproperties/validators/FloatRangeValidator.java new file mode 100644 index 00000000..8cca9230 --- /dev/null +++ b/pdf-over/pdf-signer-interface/src/main/java/at/asit/pdfover/pdfsignator/profileproperties/validators/FloatRangeValidator.java @@ -0,0 +1,57 @@ +package at.asit.pdfover.pdfsignator.profileproperties.validators; + +import at.asit.pdfover.pdfsignator.InvalidPropertyTypeException; +import at.asit.pdfover.pdfsignator.InvalidPropertyValueException; +import at.asit.pdfover.pdfsignator.profileproperties.FloatProfileProperty; +import at.asit.pdfover.pdfsignator.profileproperties.ProfileProperty; + +public class FloatRangeValidator extends PropertyValidator { + + /** + * The maximum value + */ + protected float max; + + /** + * The minimum value + */ + protected float min; + + /** + * Constructor + * @param min The minimum allowed value + * @param max The maximum allowed value + */ + public FloatRangeValidator(float min, float max) { + this.max = max; + this.min = min; + } + + @Override + public void validate(ProfileProperty property) + throws InvalidPropertyValueException, InvalidPropertyTypeException { + this.CheckPropertyType(property); + + FloatProfileProperty prop = (FloatProfileProperty) property; + + if (prop.GetValue() == null) { + throw new InvalidPropertyValueException(property, + "Value is not set!"); + } + + float value = prop.GetValue(); + + if (value < min || value > max) { + throw new InvalidPropertyValueException(property, String.format( + "Value has to be between %f and %f", min, max)); + } + } + + @Override + public void CheckPropertyType(ProfileProperty property) + throws InvalidPropertyTypeException { + if (!(property instanceof FloatProfileProperty)) { + throw new InvalidPropertyTypeException(property, this); + } + } +} diff --git a/pdf-over/pdf-signer-interface/src/main/java/at/asit/pdfover/pdfsignator/profileproperties/validators/IntegerRangeValidator.java b/pdf-over/pdf-signer-interface/src/main/java/at/asit/pdfover/pdfsignator/profileproperties/validators/IntegerRangeValidator.java new file mode 100644 index 00000000..504cb482 --- /dev/null +++ b/pdf-over/pdf-signer-interface/src/main/java/at/asit/pdfover/pdfsignator/profileproperties/validators/IntegerRangeValidator.java @@ -0,0 +1,58 @@ +package at.asit.pdfover.pdfsignator.profileproperties.validators; + +import at.asit.pdfover.pdfsignator.InvalidPropertyTypeException; +import at.asit.pdfover.pdfsignator.InvalidPropertyValueException; +import at.asit.pdfover.pdfsignator.profileproperties.IntegerProfileProperty; +import at.asit.pdfover.pdfsignator.profileproperties.ProfileProperty; + +public class IntegerRangeValidator extends PropertyValidator { + + /** + * Maximum value of property + */ + protected int max; + + /** + * Minimum value of property + */ + protected int min; + + /** + * Constructor + * @param min The minimum allowed value + * @param max The maximum allowed value + */ + public IntegerRangeValidator(int min, int max) { + this.max = max; + this.min = min; + } + + @Override + public void validate(ProfileProperty property) + throws InvalidPropertyValueException, InvalidPropertyTypeException { + this.CheckPropertyType(property); + + IntegerProfileProperty prop = (IntegerProfileProperty) property; + + if(prop.GetValue() == null) + { + throw new InvalidPropertyValueException(property, "Value is not set!"); + } + + int value = prop.GetValue(); + + if(value < min || value > max) { + throw new InvalidPropertyValueException(property, + String.format("Value has to be between %d and %d", min, max)); + } + } + + @Override + public void CheckPropertyType(ProfileProperty property) + throws InvalidPropertyTypeException { + if(!(property instanceof IntegerProfileProperty)) { + throw new InvalidPropertyTypeException(property, this); + } + } + +} diff --git a/pdf-over/pdf-signer-interface/src/main/java/at/asit/pdfover/pdfsignator/profileproperties/validators/PropertyValidator.java b/pdf-over/pdf-signer-interface/src/main/java/at/asit/pdfover/pdfsignator/profileproperties/validators/PropertyValidator.java new file mode 100644 index 00000000..8da9babc --- /dev/null +++ b/pdf-over/pdf-signer-interface/src/main/java/at/asit/pdfover/pdfsignator/profileproperties/validators/PropertyValidator.java @@ -0,0 +1,41 @@ +package at.asit.pdfover.pdfsignator.profileproperties.validators; + +import at.asit.pdfover.pdfsignator.InvalidPropertyTypeException; +import at.asit.pdfover.pdfsignator.InvalidPropertyValueException; +import at.asit.pdfover.pdfsignator.profileproperties.ProfileProperty; + +/** + * Validates the value of a property + */ +public abstract class PropertyValidator { + + /** + * The priority of this property should determine the order of validations + */ + protected int priority = 1; + + /** + * Called to validate the value of the given property and throws an InvalidPropertyValueException if value is invalid + * @param propety + * @throws InvalidPropertyValueException + */ + public abstract void validate(ProfileProperty property) throws InvalidPropertyValueException, InvalidPropertyTypeException; + + /** + * Sets the priority of this validator + * @param value The new priority + */ + public void SetPriority(int value) { + this.priority = value; + } + + /** + * Gets the priority of this validator + * @return The priority of this validator + */ + public int GetPriority() { + return this.priority; + } + + public abstract void CheckPropertyType(ProfileProperty property) throws InvalidPropertyTypeException; +} diff --git a/pdf-over/pdf-signer-interface/src/main/java/at/asit/pdfover/pdfsignator/profileproperties/validators/PropertyValidatorComparer.java b/pdf-over/pdf-signer-interface/src/main/java/at/asit/pdfover/pdfsignator/profileproperties/validators/PropertyValidatorComparer.java new file mode 100644 index 00000000..76c7f0e2 --- /dev/null +++ b/pdf-over/pdf-signer-interface/src/main/java/at/asit/pdfover/pdfsignator/profileproperties/validators/PropertyValidatorComparer.java @@ -0,0 +1,16 @@ +package at.asit.pdfover.pdfsignator.profileproperties.validators; + +import java.util.Comparator; + +/** + * Compares the Priority of two PropertyValidators + * @author afitzek + * + */ +public class PropertyValidatorComparer implements Comparator<PropertyValidator> { + + public int compare(PropertyValidator o1, PropertyValidator o2) { + return o1.GetPriority() - o2.GetPriority(); + } + +} diff --git a/pdf-over/pdf-signer-interface/src/main/java/at/asit/pdfover/pdfsignator/profileproperties/validators/RegExValidator.java b/pdf-over/pdf-signer-interface/src/main/java/at/asit/pdfover/pdfsignator/profileproperties/validators/RegExValidator.java new file mode 100644 index 00000000..9ca8d113 --- /dev/null +++ b/pdf-over/pdf-signer-interface/src/main/java/at/asit/pdfover/pdfsignator/profileproperties/validators/RegExValidator.java @@ -0,0 +1,37 @@ +package at.asit.pdfover.pdfsignator.profileproperties.validators; + +import at.asit.pdfover.pdfsignator.InvalidPropertyTypeException; +import at.asit.pdfover.pdfsignator.InvalidPropertyValueException; +import at.asit.pdfover.pdfsignator.profileproperties.ProfileProperty; + +public class RegExValidator extends PropertyValidator { + + /** + * The regex value + */ + protected String regex; + + /** + * Constructor + * @param regex The regex to check + */ + public RegExValidator(String regex) { + this.regex = regex; + } + + @Override + public void validate(ProfileProperty property) + throws InvalidPropertyValueException, InvalidPropertyTypeException { + + if(!property.GetTextValue().matches(this.regex)) { + throw new InvalidPropertyValueException(property, String.format( + "Value is invalid!")); + } + } + + @Override + public void CheckPropertyType(ProfileProperty property) + throws InvalidPropertyTypeException { + // Is valid on all Property Types + } +} |