diff options
Diffstat (limited to 'pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/utils/CheckSignatureBlockParameters.java')
-rw-r--r-- | pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/utils/CheckSignatureBlockParameters.java | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/utils/CheckSignatureBlockParameters.java b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/utils/CheckSignatureBlockParameters.java new file mode 100644 index 00000000..756a240c --- /dev/null +++ b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/utils/CheckSignatureBlockParameters.java @@ -0,0 +1,42 @@ +package at.gv.egiz.pdfas.common.utils; + +import at.gv.egiz.pdfas.common.settings.DefaultSignatureProfileSettings; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Map; + +public class CheckSignatureBlockParameters { + + private static final Logger logger = LoggerFactory + .getLogger(CheckSignatureBlockParameters.class); + public static boolean checkSignatureBlockParameterMapIsValid(Map<String, String> map, String keyRegex, + String valueRegex) { + + logger.trace("regex1:"+keyRegex+", regex1:"+valueRegex); + if(keyRegex == null || keyRegex.length() == 0) { + keyRegex = DefaultSignatureProfileSettings.SIG_BLOCK_PARAMETER_DEFAULT_KEY_REGEX; + } + if(valueRegex == null || valueRegex.length() == 0) { + valueRegex = DefaultSignatureProfileSettings.SIG_BLOCK_PARAMETER_DEFAULT_VALUE_REGEX; + } + logger.trace("regex2:"+keyRegex+", regex2:"+valueRegex); + for(String key : map.keySet()){ + if(isValid(key, keyRegex) == false) { + logger.error("Invalid key:"+key+", regex:"+keyRegex); + return false; + } + if(isValid(map.get(key), valueRegex) == false) { + logger.error("Invalid value:"+map.get(key)+", regex:"+valueRegex); + return false; + } + } + + return true; + } + + public static boolean isValid(String s, String regex) { + return s.matches(regex); + } + +} |