diff options
Diffstat (limited to 'src/net/sourceforge/plantuml/classdiagram/command/CommandUrl.java')
-rw-r--r-- | src/net/sourceforge/plantuml/classdiagram/command/CommandUrl.java | 49 |
1 files changed, 36 insertions, 13 deletions
diff --git a/src/net/sourceforge/plantuml/classdiagram/command/CommandUrl.java b/src/net/sourceforge/plantuml/classdiagram/command/CommandUrl.java index 3fa22d7..c753872 100644 --- a/src/net/sourceforge/plantuml/classdiagram/command/CommandUrl.java +++ b/src/net/sourceforge/plantuml/classdiagram/command/CommandUrl.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009-2017, Arnaud Roques + * (C) Copyright 2009-2020, Arnaud Roques * * Project Info: http://plantuml.com * @@ -35,32 +35,55 @@ */ package net.sourceforge.plantuml.classdiagram.command; -import java.util.List; - +import net.sourceforge.plantuml.LineLocation; +import net.sourceforge.plantuml.OptionFlags; import net.sourceforge.plantuml.Url; import net.sourceforge.plantuml.UrlBuilder; import net.sourceforge.plantuml.UrlBuilder.ModeUrl; import net.sourceforge.plantuml.classdiagram.AbstractEntityDiagram; import net.sourceforge.plantuml.command.CommandExecutionResult; -import net.sourceforge.plantuml.command.SingleLineCommand; +import net.sourceforge.plantuml.command.SingleLineCommand2; +import net.sourceforge.plantuml.command.regex.IRegex; +import net.sourceforge.plantuml.command.regex.RegexConcat; +import net.sourceforge.plantuml.command.regex.RegexLeaf; +import net.sourceforge.plantuml.command.regex.RegexOptional; +import net.sourceforge.plantuml.command.regex.RegexResult; import net.sourceforge.plantuml.cucadiagram.Code; import net.sourceforge.plantuml.cucadiagram.IEntity; +import net.sourceforge.plantuml.cucadiagram.Ident; -public class CommandUrl extends SingleLineCommand<AbstractEntityDiagram> { +public class CommandUrl extends SingleLineCommand2<AbstractEntityDiagram> { public CommandUrl() { - super("(?i)^url[%s]*(?:of|for)?[%s]+([\\p{L}0-9_.]+|[%g][^%g]+[%g])[%s]+(?:is)?[%s]*(" + UrlBuilder.getRegexp() + ")$"); + super(getRegexConcat()); + } + + static IRegex getRegexConcat() { + return RegexConcat.build(CommandUrl.class.getName(), // + RegexLeaf.start(), // + new RegexLeaf("url"), // + RegexLeaf.spaceZeroOrMore(), // + new RegexOptional(new RegexLeaf("of|for")), // + RegexLeaf.spaceOneOrMore(), // + new RegexLeaf("CODE", "([\\p{L}0-9_.]+|[%g][^%g]+[%g])"), // + RegexLeaf.spaceOneOrMore(), // + new RegexOptional(new RegexLeaf("is")), // + RegexLeaf.spaceZeroOrMore(), // + new RegexLeaf("URL", "(" + UrlBuilder.getRegexp() + ")"), RegexLeaf.end()); // } @Override - protected CommandExecutionResult executeArg(AbstractEntityDiagram diagram, List<String> arg) { - final Code code = Code.of(arg.get(0)); - final String urlString = arg.get(1); + protected CommandExecutionResult executeArg(AbstractEntityDiagram diagram, LineLocation location, RegexResult arg) { + final String idShort = arg.get("CODE", 0); + final Ident ident = diagram.buildLeafIdent(idShort); + final Code code = diagram.V1972() ? ident : diagram.buildCode(idShort); + final String urlString = arg.get("URL", 0); final IEntity entity; - if (diagram.leafExist(code)) { - entity = diagram.getOrCreateLeaf(code, null, null); - } else if (diagram.isGroup(code)) { - entity = diagram.getGroup(code); + final boolean leafExist = diagram.V1972() ? diagram.leafExistSmart(ident) : diagram.leafExist(code); + if (leafExist) { + entity = diagram.getOrCreateLeaf(ident, code, null, null); + } else if (diagram.V1972() ? diagram.isGroupStrict(ident) : diagram.isGroup(code)) { + entity = diagram.V1972() ? diagram.getGroupStrict(ident) : diagram.getGroup(code); } else { return CommandExecutionResult.error(code + " does not exist"); } |