diff options
| author | bculkin2442 <bjculkin@mix.wvu.edu> | 2016-03-30 09:34:34 -0400 |
|---|---|---|
| committer | bculkin2442 <bjculkin@mix.wvu.edu> | 2016-03-30 09:34:34 -0400 |
| commit | 3a80c78e801cb6227f058db22e87dc58fd0fd7f2 (patch) | |
| tree | beaa483da2afe26d6897effc3b1780ee754b2a7b /BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescriptionFileParser.java | |
| parent | 7ef3a2d28fd731a0f378b07a7d7f0c04911a3e8f (diff) | |
Added error-checking and input validation
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescriptionFileParser.java')
| -rw-r--r-- | BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescriptionFileParser.java | 41 |
1 files changed, 36 insertions, 5 deletions
diff --git a/BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescriptionFileParser.java b/BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescriptionFileParser.java index bae9790..bf49762 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescriptionFileParser.java +++ b/BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescriptionFileParser.java @@ -2,6 +2,7 @@ package bjc.utils.components; import java.io.InputStream; +import bjc.utils.exceptions.PragmaFormatException; import bjc.utils.funcutils.ListUtils; import bjc.utils.parserutils.RuleBasedConfigReader; @@ -23,20 +24,50 @@ public class ComponentDescriptionFileParser { }); reader.addPragma("name", (fst, stat) -> { - stat.setName(ListUtils.collapseTokens(fst.toList((s) -> s))); + if (!fst.hasMoreTokens()) { + throw new PragmaFormatException( + "Pragma name requires at least one argument"); + } else { + stat.setName( + ListUtils.collapseTokens(fst.toList((s) -> s))); + } }); reader.addPragma("author", (fst, stat) -> { - stat.setAuthor(ListUtils.collapseTokens(fst.toList((s) -> s))); + if (!fst.hasMoreTokens()) { + throw new PragmaFormatException( + "Pragma author requires at least one argument"); + } else { + stat.setAuthor( + ListUtils.collapseTokens(fst.toList((s) -> s))); + } }); reader.addPragma("description", (fst, stat) -> { - stat.setDescription( - ListUtils.collapseTokens(fst.toList((s) -> s))); + if (!fst.hasMoreTokens()) { + throw new PragmaFormatException( + "Pragma description requires at least one argument"); + } else { + stat.setDescription( + ListUtils.collapseTokens(fst.toList((s) -> s))); + } }); reader.addPragma("version", (fst, stat) -> { - stat.setVersion(Integer.parseInt(fst.nextToken())); + if (!fst.hasMoreTokens()) { + throw new PragmaFormatException( + "Pragma name requires at least one argument"); + } else { + String token = fst.nextToken(); + + try { + stat.setVersion(Integer.parseInt(token)); + } catch (NumberFormatException nfex) { + throw new PragmaFormatException("Argument " + token + + " to version pragma isn't a valid integer. " + + "This pragma requires a integer argument"); + } + } }); } |
