1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 package net.sourceforge.plantumldependency.commoncli.option.argument.impl.locale;
26
27 import static java.util.Locale.ENGLISH;
28 import static java.util.Locale.FRENCH;
29 import static net.sourceforge.plantumldependency.common.utils.string.StringUtils.isNotEmpty;
30 import static net.sourceforge.plantumldependency.commoncli.constants.log.ErrorConstants.EMPTY_OPTION_ARGUMENT_ERROR;
31
32 import java.util.Locale;
33
34 import net.sourceforge.plantumldependency.commoncli.exception.CommandLineException;
35 import net.sourceforge.plantumldependency.commoncli.option.argument.AbstractOptionArgument;
36
37
38
39
40
41
42
43
44
45
46 public class LocaleOptionArgumentImpl extends AbstractOptionArgument < Locale > {
47
48
49 private static final long serialVersionUID = 5730167187613883418L;
50
51
52 private static final String MAIN_USAGE = "LOCALE";
53
54
55 private static final String USAGE_DESCRIPTION = MAIN_USAGE + " specifies a locale, with the form \""
56 + FRENCH.getLanguage() + "\", \"" + ENGLISH.getLanguage() + "\"";
57
58
59
60
61
62
63
64
65 public LocaleOptionArgumentImpl(final boolean optionArgumentIsMandatory) {
66 super(optionArgumentIsMandatory, new StringBuilder(USAGE_DESCRIPTION));
67 }
68
69
70
71
72
73
74 @Override
75 protected String getMainUsageDescription() {
76 return MAIN_USAGE;
77 }
78
79
80
81
82
83
84 @Override
85 public Locale parseArgument(final String argument) throws CommandLineException {
86 Locale locale = null;
87
88 if (isNotEmpty(argument)) {
89 locale = new Locale(argument);
90 } else {
91 throw new CommandLineException(EMPTY_OPTION_ARGUMENT_ERROR);
92 }
93
94 return locale;
95 }
96 }