diff options
Diffstat (limited to 'id/moa-id-webgui/src/main/java/at/gv/egovernment/moa/id/config/webgui/validation/task/AbstractTaskValidator.java')
-rw-r--r-- | id/moa-id-webgui/src/main/java/at/gv/egovernment/moa/id/config/webgui/validation/task/AbstractTaskValidator.java | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/id/moa-id-webgui/src/main/java/at/gv/egovernment/moa/id/config/webgui/validation/task/AbstractTaskValidator.java b/id/moa-id-webgui/src/main/java/at/gv/egovernment/moa/id/config/webgui/validation/task/AbstractTaskValidator.java new file mode 100644 index 000000000..a124949f1 --- /dev/null +++ b/id/moa-id-webgui/src/main/java/at/gv/egovernment/moa/id/config/webgui/validation/task/AbstractTaskValidator.java @@ -0,0 +1,106 @@ +/* + * Copyright 2014 Federal Chancellery Austria + * MOA-ID has been developed in a cooperation between BRZ, the Federal + * Chancellery Austria - ICT staff unit, and Graz University of Technology. + * + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by + * the European Commission - subsequent versions of the EUPL (the "Licence"); + * You may not use this work except in compliance with the Licence. + * You may obtain a copy of the Licence at: + * http://www.osor.eu/eupl/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the Licence is distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Licence for the specific language governing permissions and + * limitations under the Licence. + * + * This product combines work with different licenses. See the "NOTICE" text + * file for details on the various modules and licenses. + * The "NOTICE" text file is part of the distribution. Any derivative works + * that you distribute must include a readable copy of the "NOTICE" text file. + */ +package at.gv.egovernment.moa.id.config.webgui.validation.task; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.regex.Pattern; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import at.gv.egiz.components.configuration.api.Configuration; +import at.gv.egovernment.moa.id.config.webgui.exception.ConfigurationTaskValidationException; +import at.gv.egovernment.moa.id.config.webgui.exception.ValidationObjectIdentifier; + +/** + * @author tlenz + * + */ +public abstract class AbstractTaskValidator implements ITaskValidator { + private static final Logger logger = LoggerFactory.getLogger(AbstractTaskValidator.class); + + /* (non-Javadoc) + * @see at.gv.egovernment.moa.id.config.webgui.validation.task.ITaskValidator#validate(java.util.Map) + */ + @Override + public void validate(Map<String, String> input) + throws ConfigurationTaskValidationException { + + //start task specific validation + taskValidate(input); + + } + + /** + * Validate a specific set of key/value pairs without whitelist checks + * + * @param input Key/Value pairs of a module for validation + * @throws ConfigurationModulValidationException + */ + abstract protected void taskValidate(Map<String, String> input) + throws ConfigurationTaskValidationException; + + /* (non-Javadoc) + * @see at.gv.egovernment.moa.id.config.webgui.validation.task.ITaskValidator#postProcessing(java.util.Map, java.util.List, at.gv.egiz.components.configuration.api.Configuration) + */ + @Override + abstract public Map<String, String> postProcessing(Map<String, String> input, + List<String> keysToDelete, Configuration dbconfig); + + /* (non-Javadoc) + * @see at.gv.egovernment.moa.id.config.webgui.validation.task.ITaskValidator#getKeyPrefix() + */ + @Override + abstract public String getKeyPrefix(); + + /* (non-Javadoc) + * @see at.gv.egovernment.moa.id.config.webgui.validation.task.ITaskValidator#getName() + */ + @Override + abstract public String getName(); + + /* (non-Javadoc) + * @see at.gv.egovernment.moa.id.config.webgui.validation.task.ITaskValidator#getAllAllowedKeys() + */ + @Override + abstract public List<Pattern> getAllAllowedPatterns(); + + protected List<Pattern> generatePatternsFromKeys(List<String> keys) { + List<Pattern> patterns = new ArrayList<Pattern>(); + for (String key : keys) { + if (key != null) { + String patternKey; + if (key.contains(".")) { + patternKey = key.replaceAll("\\.", "\\\\."); + } else + patternKey = key; + + patterns.add(Pattern.compile(patternKey)); + } else + logger.info("Found NULL key in whitelist of task: " + getName()); + } + return patterns; + } +} |