1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package net.sourceforge.plantumldependency.cli.main.option.display.packagename.argument;
25
26 import static java.util.regex.Pattern.compile;
27 import static net.sourceforge.plantumldependency.cli.constants.log.ErrorConstants.BAD_PATTERN_ARGUMENT_ERROR;
28 import static net.sourceforge.plantumldependency.common.utils.log.LogUtils.buildLogString;
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.regex.Pattern;
33 import java.util.regex.PatternSyntaxException;
34
35 import net.sourceforge.plantumldependency.commoncli.exception.CommandLineException;
36 import net.sourceforge.plantumldependency.commoncli.option.argument.AbstractOptionArgument;
37
38
39
40
41
42
43
44
45
46 public class PlantUMLDependencyDisplayPackageNameOptionArgument extends AbstractOptionArgument < Pattern > {
47
48
49 private static final String MAIN_USAGE = "DISPLAY_PACKAGE_NAME_PATTERN";
50
51
52 private static final String USAGE_DESCRIPTION = MAIN_USAGE
53 + " specifies display package name pattern when generating the plantUML output file, it is a regular expression following the Java pattern (see http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html for description).";
54
55
56 private static final long serialVersionUID = -6205492935149580240L;
57
58
59
60
61
62
63 public PlantUMLDependencyDisplayPackageNameOptionArgument() {
64 super(true, new StringBuilder(USAGE_DESCRIPTION));
65 }
66
67
68
69
70
71
72 @Override
73 protected String getMainUsageDescription() {
74 return MAIN_USAGE;
75 }
76
77
78
79
80
81
82 @Override
83 public Pattern parseArgument(final String argument) throws CommandLineException {
84 Pattern displayPackageNameArgument = null;
85
86 if (isNotEmpty(argument)) {
87 try {
88 displayPackageNameArgument = compile(argument);
89 } catch (final PatternSyntaxException e) {
90 throw new CommandLineException(buildLogString(BAD_PATTERN_ARGUMENT_ERROR, argument), e);
91 }
92 } else {
93 throw new CommandLineException(EMPTY_OPTION_ARGUMENT_ERROR);
94 }
95
96 return displayPackageNameArgument;
97 }
98 }