1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.openehealth.ipf.commons.ihe.xds.core.validate;
17
18 import static org.apache.commons.lang3.Validate.notNull;
19 import static org.openehealth.ipf.commons.ihe.xds.core.validate.ValidationMessage.*;
20 import static org.openehealth.ipf.commons.ihe.xds.core.validate.ValidatorAssertions.*;
21
22 import java.util.regex.Pattern;
23
24
25
26
27
28
29 public class LanguageCodeValidator implements ValueValidator {
30 private static final Pattern CODE_PATTERN =
31 Pattern.compile("[a-zA-Z]{1,8}(-[a-zA-Z0-9]{1,8})*");
32
33 @Override
34 public void validate(String value) throws XDSMetaDataException {
35 notNull(value, "value cannot be null");
36 metaDataAssert(CODE_PATTERN.matcher(value).matches(),
37 INVALID_LANGUAGE_CODE, value);
38 }
39 }