1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-05-28 22:20:49 +00:00
plantuml/src/net/sourceforge/plantuml/activitydiagram/command/CommandLinkLongActivity.java

242 lines
9.1 KiB
Java
Raw Normal View History

2010-11-15 20:35:36 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
2019-01-16 18:34:41 +00:00
* (C) Copyright 2009-2020, Arnaud Roques
2010-11-15 20:35:36 +00:00
*
2016-03-06 16:47:34 +00:00
* Project Info: http://plantuml.com
2010-11-15 20:35:36 +00:00
*
2017-03-15 19:13:31 +00:00
* If you like this project or if you find it useful, you can support us at:
*
* http://plantuml.com/patreon (only 1$ per month!)
* http://plantuml.com/paypal
*
2010-11-15 20:35:36 +00:00
* This file is part of PlantUML.
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlantUML distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
2013-12-10 19:36:50 +00:00
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
2010-11-15 20:35:36 +00:00
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
*
* Original Author: Arnaud Roques
*
*
*/
package net.sourceforge.plantuml.activitydiagram.command;
import java.util.List;
2017-06-05 11:27:21 +00:00
import net.sourceforge.plantuml.BackSlash;
2010-11-15 20:35:36 +00:00
import net.sourceforge.plantuml.Direction;
2019-03-29 22:14:07 +00:00
import net.sourceforge.plantuml.StringLocated;
2015-06-20 10:54:49 +00:00
import net.sourceforge.plantuml.StringUtils;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.Url;
import net.sourceforge.plantuml.UrlBuilder;
import net.sourceforge.plantuml.UrlBuilder.ModeUrl;
2010-11-15 20:35:36 +00:00
import net.sourceforge.plantuml.activitydiagram.ActivityDiagram;
2015-06-20 10:54:49 +00:00
import net.sourceforge.plantuml.classdiagram.command.CommandLinkClass;
import net.sourceforge.plantuml.command.BlocLines;
2010-11-15 20:35:36 +00:00
import net.sourceforge.plantuml.command.CommandExecutionResult;
2011-01-05 18:23:06 +00:00
import net.sourceforge.plantuml.command.CommandMultilines2;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.command.MultilinesStrategy;
2019-06-26 19:24:49 +00:00
import net.sourceforge.plantuml.command.regex.IRegex;
2015-04-07 18:18:37 +00:00
import net.sourceforge.plantuml.command.regex.MyPattern;
2011-01-05 18:23:06 +00:00
import net.sourceforge.plantuml.command.regex.RegexConcat;
import net.sourceforge.plantuml.command.regex.RegexLeaf;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.command.regex.RegexOptional;
2011-01-05 18:23:06 +00:00
import net.sourceforge.plantuml.command.regex.RegexOr;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.command.regex.RegexResult;
import net.sourceforge.plantuml.cucadiagram.Code;
import net.sourceforge.plantuml.cucadiagram.Display;
import net.sourceforge.plantuml.cucadiagram.GroupType;
2010-11-15 20:35:36 +00:00
import net.sourceforge.plantuml.cucadiagram.IEntity;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.cucadiagram.LeafType;
2010-11-15 20:35:36 +00:00
import net.sourceforge.plantuml.cucadiagram.Link;
import net.sourceforge.plantuml.cucadiagram.LinkDecor;
import net.sourceforge.plantuml.cucadiagram.LinkType;
2018-03-09 21:37:34 +00:00
import net.sourceforge.plantuml.cucadiagram.NamespaceStrategy;
2011-01-05 18:23:06 +00:00
import net.sourceforge.plantuml.cucadiagram.Stereotype;
2017-10-07 09:46:53 +00:00
import net.sourceforge.plantuml.descdiagram.command.CommandLinkElement;
2015-09-28 20:42:17 +00:00
import net.sourceforge.plantuml.graphic.color.ColorType;
2010-11-15 20:35:36 +00:00
2011-01-05 18:23:06 +00:00
public class CommandLinkLongActivity extends CommandMultilines2<ActivityDiagram> {
2010-11-15 20:35:36 +00:00
2013-12-10 19:36:50 +00:00
public CommandLinkLongActivity() {
super(getRegexConcat(), MultilinesStrategy.REMOVE_STARTING_QUOTE);
2010-11-15 20:35:36 +00:00
}
2013-12-10 19:36:50 +00:00
@Override
public String getPatternEnd() {
2015-04-07 18:18:37 +00:00
return "(?i)^[%s]*([^%g]*)[%g](?:[%s]+as[%s]+([\\p{L}0-9][\\p{L}0-9_.]*))?[%s]*(\\<\\<.*\\>\\>)?[%s]*(?:in[%s]+([%g][^%g]+[%g]|\\S+))?[%s]*(#\\w+)?$";
2013-12-10 19:36:50 +00:00
}
2019-06-26 19:24:49 +00:00
static IRegex getRegexConcat() {
return RegexConcat.build(CommandLinkLongActivity.class.getName(), RegexLeaf.start(), //
2013-12-10 19:36:50 +00:00
new RegexOptional(//
new RegexOr("FIRST", //
new RegexLeaf("STAR", "(\\(\\*(top)?\\))"), //
new RegexLeaf("CODE", "([\\p{L}0-9][\\p{L}0-9_.]*)"), //
2015-04-07 18:18:37 +00:00
new RegexLeaf("BAR", "(?:==+)[%s]*([\\p{L}0-9_.]+)[%s]*(?:==+)"), //
new RegexLeaf("QUOTED", "[%g]([^%g]+)[%g](?:[%s]+as[%s]+([\\p{L}0-9_.]+))?"))), //
2019-06-26 19:24:49 +00:00
RegexLeaf.spaceZeroOrMore(), //
2013-12-10 19:36:50 +00:00
new RegexLeaf("STEREOTYPE", "(\\<\\<.*\\>\\>)?"), //
2019-06-26 19:24:49 +00:00
RegexLeaf.spaceZeroOrMore(), //
2013-12-10 19:36:50 +00:00
new RegexLeaf("BACKCOLOR", "(#\\w+)?"), //
2019-06-26 19:24:49 +00:00
RegexLeaf.spaceZeroOrMore(), //
2013-12-10 19:36:50 +00:00
new RegexLeaf("URL", "(" + UrlBuilder.getRegexp() + ")?"), //
2015-06-20 10:54:49 +00:00
new RegexLeaf("ARROW_BODY1", "([-.]+)"), //
2017-10-07 09:46:53 +00:00
new RegexLeaf("ARROW_STYLE1", "(?:\\[(" + CommandLinkElement.LINE_STYLE + ")\\])?"), //
2015-06-20 10:54:49 +00:00
new RegexLeaf("ARROW_DIRECTION", "(\\*|left|right|up|down|le?|ri?|up?|do?)?"), //
2017-10-07 09:46:53 +00:00
new RegexLeaf("ARROW_STYLE2", "(?:\\[(" + CommandLinkElement.LINE_STYLE + ")\\])?"), //
2019-07-14 20:09:26 +00:00
new RegexLeaf("ARROW_BODY2", "([-.]*)"), //
new RegexLeaf("\\>"), //
2015-06-20 10:54:49 +00:00
2019-06-26 19:24:49 +00:00
RegexLeaf.spaceZeroOrMore(), //
new RegexOptional(new RegexLeaf("BRACKET", "\\[([^\\]*]+[^\\]]*)\\]")), //
RegexLeaf.spaceZeroOrMore(), //
2019-07-14 20:09:26 +00:00
new RegexLeaf("[%g]"), //
new RegexLeaf("DESC", "([^%g]*?)"), //
2019-06-26 19:24:49 +00:00
RegexLeaf.spaceZeroOrMore(), //
RegexLeaf.end());
2010-11-15 20:35:36 +00:00
}
2019-09-22 17:20:16 +00:00
@Override
2018-06-12 20:50:45 +00:00
protected CommandExecutionResult executeNow(final ActivityDiagram diagram, BlocLines lines) {
2015-06-20 10:54:49 +00:00
lines = lines.trim(false);
2019-06-26 19:24:49 +00:00
final RegexResult line0 = getStartingPattern().matcher(lines.getFirst499().getTrimmed().getString());
2013-12-10 19:36:50 +00:00
final IEntity entity1 = CommandLinkActivity.getEntity(diagram, line0, true);
2018-05-21 13:07:09 +00:00
if (entity1 == null) {
return CommandExecutionResult.error("No such entity");
}
2013-12-10 19:36:50 +00:00
if (line0.get("STEREOTYPE", 0) != null) {
entity1.setStereotype(new Stereotype(line0.get("STEREOTYPE", 0)));
2011-01-05 18:23:06 +00:00
}
2019-06-26 19:24:49 +00:00
final String stringColor = line0.get("BACKCOLOR", 0);
if (stringColor != null) {
2015-09-28 20:42:17 +00:00
entity1.setSpecificColorTOBEREMOVED(ColorType.BACK, diagram.getSkinParam().getIHtmlColorSet()
2019-06-26 19:24:49 +00:00
.getColorIfValid(stringColor));
2011-01-05 18:23:06 +00:00
}
2010-11-15 20:35:36 +00:00
final StringBuilder sb = new StringBuilder();
2013-12-10 19:36:50 +00:00
final String desc0 = line0.get("DESC", 0);
Url urlActivity = null;
if (StringUtils.isNotEmpty(desc0)) {
2019-03-29 22:14:07 +00:00
urlActivity = extractUrlString(diagram, desc0);
2013-12-10 19:36:50 +00:00
if (urlActivity == null) {
sb.append(desc0);
2017-06-05 11:27:21 +00:00
sb.append(BackSlash.BS_BS_N);
2013-12-10 19:36:50 +00:00
}
2010-11-15 20:35:36 +00:00
}
2015-06-20 10:54:49 +00:00
int i = 0;
2019-03-29 22:14:07 +00:00
for (StringLocated cs : lines.subExtract(1, 1)) {
2015-06-20 10:54:49 +00:00
i++;
2013-12-10 19:36:50 +00:00
if (i == 1 && urlActivity == null) {
2015-06-20 10:54:49 +00:00
urlActivity = extractUrl(diagram, cs);
2013-12-10 19:36:50 +00:00
if (urlActivity != null) {
continue;
}
}
2019-03-29 22:14:07 +00:00
sb.append(cs.getString());
2010-11-15 20:35:36 +00:00
if (i < lines.size() - 2) {
2017-06-05 11:27:21 +00:00
sb.append(BackSlash.BS_BS_N);
2010-11-15 20:35:36 +00:00
}
}
2015-06-20 10:54:49 +00:00
final List<String> lineLast = StringUtils.getSplit(MyPattern.cmpile(getPatternEnd()), lines.getLast499()
2019-03-29 22:14:07 +00:00
.getString());
2010-11-15 20:35:36 +00:00
if (StringUtils.isNotEmpty(lineLast.get(0))) {
2017-06-05 11:27:21 +00:00
if (sb.length() > 0 && sb.toString().endsWith(BackSlash.BS_BS_N) == false) {
sb.append(BackSlash.BS_BS_N);
2011-01-05 18:23:06 +00:00
}
2010-11-15 20:35:36 +00:00
sb.append(lineLast.get(0));
}
final String display = sb.toString();
2013-12-10 19:36:50 +00:00
final Code code = Code.of(lineLast.get(1) == null ? display : lineLast.get(1));
2010-11-15 20:35:36 +00:00
2013-12-10 19:36:50 +00:00
String partition = null;
if (lineLast.get(3) != null) {
partition = lineLast.get(3);
partition = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(partition);
}
if (partition != null) {
2018-03-09 21:37:34 +00:00
diagram.gotoGroup2(Code.of(partition), Display.getWithNewlines(partition), GroupType.PACKAGE, null,
NamespaceStrategy.SINGLE);
2013-12-10 19:36:50 +00:00
}
2018-05-21 13:07:09 +00:00
final IEntity entity2 = diagram.getOrCreate(code, Display.getWithNewlines(display), LeafType.ACTIVITY);
if (entity2 == null) {
return CommandExecutionResult.error("No such entity");
}
2013-12-10 19:36:50 +00:00
if (partition != null) {
diagram.endGroup();
}
if (urlActivity != null) {
entity2.addUrl(urlActivity);
}
if (lineLast.get(2) != null) {
2011-01-05 18:23:06 +00:00
entity2.setStereotype(new Stereotype(lineLast.get(2)));
}
2013-12-10 19:36:50 +00:00
if (lineLast.get(4) != null) {
2017-10-07 09:46:53 +00:00
entity2.setSpecificColorTOBEREMOVED(ColorType.BACK, diagram.getSkinParam().getIHtmlColorSet()
.getColorIfValid(lineLast.get(4)));
2011-01-05 18:23:06 +00:00
}
2010-11-15 20:35:36 +00:00
2015-06-20 10:54:49 +00:00
final String arrowBody1 = CommandLinkClass.notNull(line0.get("ARROW_BODY1", 0));
final String arrowBody2 = CommandLinkClass.notNull(line0.get("ARROW_BODY2", 0));
final String arrowDirection = CommandLinkClass.notNull(line0.get("ARROW_DIRECTION", 0));
final String arrow = StringUtils.manageArrowForCuca(arrowBody1 + arrowDirection + arrowBody2 + ">");
2010-11-15 20:35:36 +00:00
final int lenght = arrow.length() - 1;
2013-12-10 19:36:50 +00:00
final Display linkLabel = Display.getWithNewlines(line0.get("BRACKET", 0));
2010-11-15 20:35:36 +00:00
2013-12-10 19:36:50 +00:00
LinkType type = new LinkType(LinkDecor.ARROW, LinkDecor.NONE);
2015-06-20 10:54:49 +00:00
if (arrow.contains(".")) {
2017-10-07 09:46:53 +00:00
type = type.goDotted();
2013-12-10 19:36:50 +00:00
}
2019-07-14 20:09:26 +00:00
Link link = new Link(entity1, entity2, type, linkLabel, lenght, diagram.getSkinParam().getCurrentStyleBuilder());
2015-06-20 10:54:49 +00:00
final Direction direction = StringUtils.getArrowDirection(arrowBody1 + arrowDirection + arrowBody2 + ">");
2010-11-15 20:35:36 +00:00
if (direction == Direction.LEFT || direction == Direction.UP) {
link = link.getInv();
}
2013-12-10 19:36:50 +00:00
if (line0.get("URL", 0) != null) {
final UrlBuilder urlBuilder = new UrlBuilder(diagram.getSkinParam().getValue("topurl"), ModeUrl.STRICT);
final Url urlLink = urlBuilder.getUrl(line0.get("URL", 0));
link.setUrl(urlLink);
}
2018-06-25 19:05:58 +00:00
link.applyStyle(line0.getLazzy("ARROW_STYLE", 0));
2013-12-10 19:36:50 +00:00
diagram.addLink(link);
2010-11-15 20:35:36 +00:00
return CommandExecutionResult.ok();
}
2019-03-29 22:14:07 +00:00
public Url extractUrl(final ActivityDiagram diagram, StringLocated string) {
return extractUrlString(diagram, string.getString());
}
public Url extractUrlString(final ActivityDiagram diagram, String string) {
2015-06-20 10:54:49 +00:00
final UrlBuilder urlBuilder = new UrlBuilder(diagram.getSkinParam().getValue("topurl"), ModeUrl.STRICT);
2019-03-29 22:14:07 +00:00
return urlBuilder.getUrl(string);
2015-06-20 10:54:49 +00:00
}
2010-11-15 20:35:36 +00:00
}