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.cli.main.option.display.name.argument;
26
27 import static java.util.regex.Pattern.compile;
28 import static net.sourceforge.plantumldependency.cli.constants.log.ErrorConstants.BAD_PATTERN_ARGUMENT_ERROR;
29 import static net.sourceforge.plantumldependency.common.utils.log.LogUtils.buildLogString;
30 import static net.sourceforge.plantumldependency.common.utils.string.StringUtils.isNotEmpty;
31 import static net.sourceforge.plantumldependency.commoncli.constants.log.ErrorConstants.EMPTY_OPTION_ARGUMENT_ERROR;
32
33 import java.util.regex.Pattern;
34 import java.util.regex.PatternSyntaxException;
35
36 import net.sourceforge.plantumldependency.commoncli.exception.CommandLineException;
37 import net.sourceforge.plantumldependency.commoncli.option.argument.AbstractOptionArgument;
38
39
40
41
42
43
44
45
46
47 public class PlantUMLDependencyDisplayNameOptionArgument extends AbstractOptionArgument < Pattern > {
48
49
50 private static final String MAIN_USAGE = "DISPLAY_NAME_PATTERN";
51
52
53 private static final String USAGE_DESCRIPTION = MAIN_USAGE
54 + " specifies display 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).";
55
56
57 private static final long serialVersionUID = -8804026254773622257L;
58
59
60
61
62
63
64 public PlantUMLDependencyDisplayNameOptionArgument() {
65 super(true, new StringBuilder(USAGE_DESCRIPTION));
66 }
67
68
69
70
71
72
73 @Override
74 protected String getMainUsageDescription() {
75 return MAIN_USAGE;
76 }
77
78
79
80
81
82
83 @Override
84 public Pattern parseArgument(final String argument) throws CommandLineException {
85 Pattern displayNameArgument = null;
86
87 if (isNotEmpty(argument)) {
88 try {
89 displayNameArgument = compile(argument);
90 } catch (final PatternSyntaxException e) {
91 throw new CommandLineException(buildLogString(BAD_PATTERN_ARGUMENT_ERROR, argument), e);
92 }
93 } else {
94 throw new CommandLineException(EMPTY_OPTION_ARGUMENT_ERROR);
95 }
96
97 return displayNameArgument;
98 }
99 }