com.softicar.platform.common.core.i18n.key.container.validator.I18nKeyContainerValidator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of platform-common Show documentation
Show all versions of platform-common Show documentation
The SoftiCAR Platform is a lightweight, Java-based library to create interactive business web applications.
package com.softicar.platform.common.core.i18n.key.container.validator;
import com.softicar.platform.common.core.constant.container.field.IConstantContainerField;
import com.softicar.platform.common.core.constant.container.validator.AbstractConstantContainerValidator;
import com.softicar.platform.common.core.constant.container.validator.IConstantContainerValidator;
import com.softicar.platform.common.core.i18n.LanguageEnum;
import com.softicar.platform.common.core.i18n.key.II18nKey;
import com.softicar.platform.common.core.i18n.key.computer.I18nKeyComputer;
import java.util.Set;
import java.util.TreeSet;
/**
* Validates a given class with respect to the I18n class requirements.
*
*
* - The class must be an interface.
* - The class may not have a super class.
* - The class may not declare any methods.
*
*
* - All fields must be public and static and final.
* - All fields must be in alphabetic order.
* - All field names must obey the Java conventions for constants.
* - All field names must match the key strings according to
* {@link I18nKeyComputer}.
* - All field types must match the format specifier count.
*
*
* - No key string may be empty.
* - No key string may have leading or trailing whitespace.
* - No key string may contain more than one sentence.
*
*
* @author Oliver Richers
*/
class I18nKeyContainerValidator extends AbstractConstantContainerValidator {
private final Set mandatoryLanguages;
public I18nKeyContainerValidator(Class containerClass) {
super(containerClass, II18nKey.class);
this.mandatoryLanguages = new TreeSet<>();
}
public I18nKeyContainerValidator addMandatoryLanguages(Set languages) {
languages.forEach(this::addMandatoryLanguage);
return this;
}
public I18nKeyContainerValidator addMandatoryLanguage(String language) {
this.mandatoryLanguages.add(LanguageEnum.getByIso6391(language));
return this;
}
@Override
protected IConstantContainerValidator createFieldValidator(IConstantContainerField currentField,
IConstantContainerField previousField) {
return new I18nKeyContainerFieldValidator(currentField, previousField, mandatoryLanguages);
}
}