1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-06-01 08:00:48 +00:00
plantuml/src/net/sourceforge/plantuml/classdiagram/command/CommandLinkClass.java

619 lines
20 KiB
Java
Raw Normal View History

2013-12-10 19:36:50 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
2016-01-09 12:15:40 +00:00
* (C) Copyright 2009-2017, Arnaud Roques
2013-12-10 19:36:50 +00:00
*
2016-03-06 16:47:34 +00:00
* Project Info: http://plantuml.com
2013-12-10 19:36:50 +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
*
2013-12-10 19:36:50 +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
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
* 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.classdiagram.command;
import java.util.StringTokenizer;
import net.sourceforge.plantuml.Direction;
2015-05-31 18:56:03 +00:00
import net.sourceforge.plantuml.StringUtils;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.UmlDiagramType;
2017-03-12 17:22:02 +00:00
import net.sourceforge.plantuml.Url;
import net.sourceforge.plantuml.UrlBuilder;
import net.sourceforge.plantuml.UrlBuilder.ModeUrl;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.command.CommandExecutionResult;
import net.sourceforge.plantuml.command.SingleLineCommand2;
2016-05-31 19:41:55 +00:00
import net.sourceforge.plantuml.command.regex.Matcher2;
2015-04-07 18:18:37 +00:00
import net.sourceforge.plantuml.command.regex.MyPattern;
2016-05-31 19:41:55 +00:00
import net.sourceforge.plantuml.command.regex.Pattern2;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.command.regex.RegexConcat;
import net.sourceforge.plantuml.command.regex.RegexLeaf;
import net.sourceforge.plantuml.command.regex.RegexOr;
import net.sourceforge.plantuml.command.regex.RegexResult;
import net.sourceforge.plantuml.cucadiagram.Code;
import net.sourceforge.plantuml.cucadiagram.Display;
import net.sourceforge.plantuml.cucadiagram.IEntity;
import net.sourceforge.plantuml.cucadiagram.Link;
import net.sourceforge.plantuml.cucadiagram.LinkArrow;
import net.sourceforge.plantuml.cucadiagram.LinkDecor;
import net.sourceforge.plantuml.cucadiagram.LinkType;
2015-09-28 20:42:17 +00:00
import net.sourceforge.plantuml.graphic.HtmlColorSet;
import net.sourceforge.plantuml.graphic.color.ColorParser;
import net.sourceforge.plantuml.graphic.color.ColorType;
import net.sourceforge.plantuml.graphic.color.Colors;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.objectdiagram.AbstractClassOrObjectDiagram;
final public class CommandLinkClass extends SingleLineCommand2<AbstractClassOrObjectDiagram> {
2016-12-14 21:01:03 +00:00
private static final String SINGLE = "[.\\\\]{0,2}[\\p{L}0-9_]+(?:[.\\\\]{1,2}[\\p{L}0-9_]+)*";
private static final String COUPLE = "\\([%s]*(" + SINGLE + ")[%s]*,[%s]*(" + SINGLE + ")[%s]*\\)";
2013-12-10 19:36:50 +00:00
public CommandLinkClass(UmlDiagramType umlDiagramType) {
super(getRegexConcat(umlDiagramType));
}
static private RegexConcat getRegexConcat(UmlDiagramType umlDiagramType) {
return new RegexConcat(
2015-04-07 18:18:37 +00:00
new RegexLeaf("HEADER", "^(?:@([\\d.]+)[%s]+)?"), //
2016-12-14 21:01:03 +00:00
new RegexOr( //
2017-03-12 17:22:02 +00:00
new RegexLeaf("ENT1", getClassIdentifier()),//
2016-12-14 21:01:03 +00:00
new RegexLeaf("COUPLE1", COUPLE)),
2015-04-07 18:18:37 +00:00
new RegexLeaf("[%s]*"), //
new RegexLeaf("FIRST_LABEL", "(?:[%g]([^%g]+)[%g])?"), //
new RegexLeaf("[%s]*"), //
2013-12-10 19:36:50 +00:00
new RegexConcat(
//
2017-03-21 21:37:59 +00:00
new RegexLeaf("ARROW_HEAD1", "([%s]+[ox]|[)#\\[<*+^}]|[<\\[]\\||\\}o|\\}\\||\\|o|\\|\\|)?"), //
2013-12-10 19:36:50 +00:00
new RegexLeaf("ARROW_BODY1", "([-=.]+)"), //
new RegexLeaf("ARROW_STYLE1",
2016-03-06 16:47:34 +00:00
"(?:\\[((?:#\\w+|dotted|dashed|plain|bold|hidden|norank)(?:,#\\w+|,dotted|,dashed|,plain|,bold|,hidden|,norank)*)\\])?"),
2013-12-10 19:36:50 +00:00
new RegexLeaf("ARROW_DIRECTION", "(left|right|up|down|le?|ri?|up?|do?)?"), //
2015-04-07 18:18:37 +00:00
new RegexLeaf("INSIDE", "(?:(0|\\(0\\)|\\(0|0\\))(?=[-=.~]))?"), //
2013-12-10 19:36:50 +00:00
new RegexLeaf("ARROW_STYLE2",
2016-03-06 16:47:34 +00:00
"(?:\\[((?:#\\w+|dotted|dashed|plain|bold|hidden|norank)(?:,#\\w+|,dotted|,dashed|,plain|,bold|,hidden|,norank)*)\\])?"),
2013-12-10 19:36:50 +00:00
new RegexLeaf("ARROW_BODY2", "([-=.]*)"), //
2017-03-21 21:37:59 +00:00
new RegexLeaf("ARROW_HEAD2", "([ox][%s]+|[(#\\]>*+^\\{]|\\|[>\\]]|o\\{|\\|\\{|o\\||\\|\\|)?")), //
2013-12-10 19:36:50 +00:00
2015-04-07 18:18:37 +00:00
new RegexLeaf("[%s]*"), //
2016-12-14 21:01:03 +00:00
new RegexLeaf("SECOND_LABEL", "(?:[%g]([^%g]+)[%g])?"), new RegexLeaf("[%s]*"), //
new RegexOr( //
2017-03-12 17:22:02 +00:00
new RegexLeaf("ENT2", getClassIdentifier()), //
2016-12-14 21:01:03 +00:00
new RegexLeaf("COUPLE2", COUPLE)), //
2015-04-07 18:18:37 +00:00
new RegexLeaf("[%s]*"), //
2015-09-28 20:42:17 +00:00
color().getRegex(), //
2017-03-12 17:22:02 +00:00
new RegexLeaf("URL", "[%s]*(" + UrlBuilder.getRegexp() + ")?"), //
2015-09-28 20:42:17 +00:00
new RegexLeaf("[%s]*"), //
2015-04-07 18:18:37 +00:00
new RegexLeaf("LABEL_LINK", "(?::[%s]*(.+))?"), //
2013-12-10 19:36:50 +00:00
new RegexLeaf("$"));
}
2015-09-28 20:42:17 +00:00
private static ColorParser color() {
return ColorParser.simpleColor(ColorType.LINE);
}
2015-04-07 18:18:37 +00:00
private static String getClassIdentifier() {
2015-09-28 20:42:17 +00:00
return "(" + getSeparator() + "?[\\p{L}0-9_$]+(?:" + getSeparator() + "[\\p{L}0-9_$]+)*|[%g][^%g]+[%g])";
2015-04-07 18:18:37 +00:00
}
2016-02-07 21:13:01 +00:00
public static String getSeparator() {
return "(?:\\.|::|\\\\|\\\\\\\\)";
2015-04-07 18:18:37 +00:00
}
2017-03-12 17:22:02 +00:00
// private static String optionalKeywords(UmlDiagramType type) {
// if (type == UmlDiagramType.CLASS) {
// return "(interface|enum|annotation|abstract[%s]+class|abstract|class|object|entity)";
// }
// if (type == UmlDiagramType.OBJECT) {
// return "(object)";
// }
// throw new IllegalArgumentException();
// }
//
// private LeafType getTypeIfObject(String type) {
// if ("object".equalsIgnoreCase(type)) {
// return LeafType.OBJECT;
// }
// return null;
// }
2016-01-09 12:15:40 +00:00
2013-12-10 19:36:50 +00:00
@Override
protected CommandExecutionResult executeArg(AbstractClassOrObjectDiagram diagram, RegexResult arg) {
2016-07-04 19:06:50 +00:00
2017-03-12 17:22:02 +00:00
Code ent1 = Code.of(arg.get("ENT1", 0));
Code ent2 = Code.of(arg.get("ENT2", 0));
2016-01-09 12:15:40 +00:00
2013-12-10 19:36:50 +00:00
if (ent1 == null) {
return executeArgSpecial1(diagram, arg);
}
if (ent2 == null) {
return executeArgSpecial2(diagram, arg);
}
2015-04-07 18:18:37 +00:00
ent1 = ent1.eventuallyRemoveStartingAndEndingDoubleQuote("\"");
ent2 = ent2.eventuallyRemoveStartingAndEndingDoubleQuote("\"");
2016-12-14 21:01:03 +00:00
if (isGroupButNotTheCurrentGroup(diagram, ent1) && isGroupButNotTheCurrentGroup(diagram, ent2)) {
2013-12-10 19:36:50 +00:00
return executePackageLink(diagram, arg);
}
2016-07-04 19:06:50 +00:00
String port1 = null;
String port2 = null;
if (removeMemberPart(diagram, ent1) != null) {
port1 = ent1.getPortMember();
ent1 = removeMemberPart(diagram, ent1);
}
if (removeMemberPart(diagram, ent2) != null) {
port2 = ent2.getPortMember();
ent2 = removeMemberPart(diagram, ent2);
}
2016-12-14 21:01:03 +00:00
final IEntity cl1 = isGroupButNotTheCurrentGroup(diagram, ent1) ? diagram.getGroup(Code.of(StringUtils
2017-03-12 17:22:02 +00:00
.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get("ENT1", 0), "\""))) : diagram.getOrCreateLeaf(
ent1, null, null);
2016-01-09 12:15:40 +00:00
2016-12-14 21:01:03 +00:00
final IEntity cl2 = isGroupButNotTheCurrentGroup(diagram, ent2) ? diagram.getGroup(Code.of(StringUtils
2017-03-12 17:22:02 +00:00
.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get("ENT2", 0), "\""))) : diagram.getOrCreateLeaf(
ent2, null, null);
2015-09-28 20:42:17 +00:00
Colors colors = color().getColor(arg, diagram.getSkinParam().getIHtmlColorSet());
2013-12-10 19:36:50 +00:00
final LinkType linkType = getLinkType(arg);
final Direction dir = getDirection(arg);
final int queue;
if (dir == Direction.LEFT || dir == Direction.RIGHT) {
queue = 1;
} else {
queue = getQueueLength(arg);
}
String firstLabel = arg.get("FIRST_LABEL", 0);
String secondLabel = arg.get("SECOND_LABEL", 0);
String labelLink = null;
if (arg.get("LABEL_LINK", 0) != null) {
labelLink = arg.get("LABEL_LINK", 0);
if (firstLabel == null && secondLabel == null) {
2016-05-31 19:41:55 +00:00
final Pattern2 p1 = MyPattern.cmpile("^[%g]([^%g]+)[%g]([^%g]+)[%g]([^%g]+)[%g]$");
final Matcher2 m1 = p1.matcher(labelLink);
2013-12-10 19:36:50 +00:00
if (m1.matches()) {
firstLabel = m1.group(1);
2015-05-31 18:56:03 +00:00
labelLink = StringUtils.trin(StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(
StringUtils.trin(m1.group(2)), "\""));
2013-12-10 19:36:50 +00:00
secondLabel = m1.group(3);
} else {
2016-05-31 19:41:55 +00:00
final Pattern2 p2 = MyPattern.cmpile("^[%g]([^%g]+)[%g]([^%g]+)$");
final Matcher2 m2 = p2.matcher(labelLink);
2013-12-10 19:36:50 +00:00
if (m2.matches()) {
firstLabel = m2.group(1);
2015-05-31 18:56:03 +00:00
labelLink = StringUtils.trin(StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(
StringUtils.trin(m2.group(2)), "\""));
2013-12-10 19:36:50 +00:00
secondLabel = null;
} else {
2016-05-31 19:41:55 +00:00
final Pattern2 p3 = MyPattern.cmpile("^([^%g]+)[%g]([^%g]+)[%g]$");
final Matcher2 m3 = p3.matcher(labelLink);
2013-12-10 19:36:50 +00:00
if (m3.matches()) {
firstLabel = null;
2015-05-31 18:56:03 +00:00
labelLink = StringUtils.trin(StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(
StringUtils.trin(m3.group(1)), "\""));
2013-12-10 19:36:50 +00:00
secondLabel = m3.group(2);
}
}
}
}
2015-04-07 18:18:37 +00:00
labelLink = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(labelLink, "\"");
2013-12-10 19:36:50 +00:00
}
LinkArrow linkArrow = LinkArrow.NONE;
if ("<".equals(labelLink)) {
linkArrow = LinkArrow.BACKWARD;
labelLink = null;
} else if (">".equals(labelLink)) {
linkArrow = LinkArrow.DIRECT_NORMAL;
labelLink = null;
} else if (labelLink != null && labelLink.startsWith("< ")) {
linkArrow = LinkArrow.BACKWARD;
2015-05-31 18:56:03 +00:00
labelLink = StringUtils.trin(labelLink.substring(2));
2013-12-10 19:36:50 +00:00
} else if (labelLink != null && labelLink.startsWith("> ")) {
linkArrow = LinkArrow.DIRECT_NORMAL;
2015-05-31 18:56:03 +00:00
labelLink = StringUtils.trin(labelLink.substring(2));
2013-12-10 19:36:50 +00:00
} else if (labelLink != null && labelLink.endsWith(" >")) {
linkArrow = LinkArrow.DIRECT_NORMAL;
2015-05-31 18:56:03 +00:00
labelLink = StringUtils.trin(labelLink.substring(0, labelLink.length() - 2));
2013-12-10 19:36:50 +00:00
} else if (labelLink != null && labelLink.endsWith(" <")) {
linkArrow = LinkArrow.BACKWARD;
2015-05-31 18:56:03 +00:00
labelLink = StringUtils.trin(labelLink.substring(0, labelLink.length() - 2));
2013-12-10 19:36:50 +00:00
}
Link link = new Link(cl1, cl2, linkType, Display.getWithNewlines(labelLink), queue, firstLabel, secondLabel,
diagram.getLabeldistance(), diagram.getLabelangle());
2017-03-12 17:22:02 +00:00
if (arg.get("URL", 0) != null) {
final UrlBuilder urlBuilder = new UrlBuilder(diagram.getSkinParam().getValue("topurl"), ModeUrl.STRICT);
final Url url = urlBuilder.getUrl(arg.get("URL", 0));
link.setUrl(url);
}
2016-07-04 19:06:50 +00:00
link.setPortMembers(port1, port2);
2013-12-10 19:36:50 +00:00
if (dir == Direction.LEFT || dir == Direction.UP) {
link = link.getInv();
}
link.setLinkArrow(linkArrow);
2015-09-28 20:42:17 +00:00
colors = applyStyle(arg.getLazzy("ARROW_STYLE", 0), link, colors);
link.setColors(colors);
2013-12-10 19:36:50 +00:00
addLink(diagram, link, arg.get("HEADER", 0));
return CommandExecutionResult.ok();
}
2016-12-14 21:01:03 +00:00
private boolean isGroupButNotTheCurrentGroup(AbstractClassOrObjectDiagram diagram, Code code) {
if (diagram.getCurrentGroup().getCode().equals(code)) {
return false;
}
return diagram.isGroup(code);
}
2016-07-04 19:06:50 +00:00
private Code removeMemberPart(AbstractClassOrObjectDiagram diagram, Code code) {
if (diagram.leafExist(code)) {
return null;
}
final Code before = code.removeMemberPart();
if (before == null) {
return null;
}
if (diagram.leafExist(before) == false) {
return null;
}
return before;
}
// private CommandExecutionResult executeLinkFields(AbstractClassOrObjectDiagram diagram, RegexResult arg) {
// System.err.println("field1=" + arg.get("ENT1", 1));
// System.err.println("field2=" + arg.get("ENT2", 1));
// return CommandExecutionResult.error("not working yet");
// }
2013-12-10 19:36:50 +00:00
private void addLink(AbstractClassOrObjectDiagram diagram, Link link, String weight) {
diagram.addLink(link);
if (weight == null) {
// final LinkType type = link.getType();
// --|> highest
// --*, -->, --o normal
// ..*, ..>, ..o lowest
// if (type.isDashed() == false) {
// if (type.contains(LinkDecor.EXTENDS)) {
// link.setWeight(3);
// }
// if (type.contains(LinkDecor.ARROW) ||
// type.contains(LinkDecor.COMPOSITION)
// || type.contains(LinkDecor.AGREGATION)) {
// link.setWeight(2);
// }
// }
} else {
link.setWeight(Double.parseDouble(weight));
}
}
private CommandExecutionResult executePackageLink(AbstractClassOrObjectDiagram diagram, RegexResult arg) {
2015-04-07 18:18:37 +00:00
final IEntity cl1 = diagram.getGroup(Code.of(StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(
2017-03-12 17:22:02 +00:00
arg.get("ENT1", 0), "\"")));
2015-04-07 18:18:37 +00:00
final IEntity cl2 = diagram.getGroup(Code.of(StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(
2017-03-12 17:22:02 +00:00
arg.get("ENT2", 0), "\"")));
2013-12-10 19:36:50 +00:00
final LinkType linkType = getLinkType(arg);
final Direction dir = getDirection(arg);
final int queue;
if (dir == Direction.LEFT || dir == Direction.RIGHT) {
queue = 1;
} else {
queue = getQueueLength(arg);
}
2015-09-28 20:42:17 +00:00
Colors colors = color().getColor(arg, diagram.getSkinParam().getIHtmlColorSet());
2013-12-10 19:36:50 +00:00
final Display labelLink = Display.getWithNewlines(arg.get("LABEL_LINK", 0));
final String firstLabel = arg.get("FIRST_LABEL", 0);
final String secondLabel = arg.get("SECOND_LABEL", 0);
final Link link = new Link(cl1, cl2, linkType, labelLink, queue, firstLabel, secondLabel,
diagram.getLabeldistance(), diagram.getLabelangle());
diagram.resetPragmaLabel();
2015-09-28 20:42:17 +00:00
colors = applyStyle(arg.getLazzy("ARROW_STYLE", 0), link, colors);
link.setColors(colors);
2013-12-10 19:36:50 +00:00
addLink(diagram, link, arg.get("HEADER", 0));
return CommandExecutionResult.ok();
}
private CommandExecutionResult executeArgSpecial1(AbstractClassOrObjectDiagram diagram, RegexResult arg) {
final Code clName1 = Code.of(arg.get("COUPLE1", 0));
final Code clName2 = Code.of(arg.get("COUPLE1", 1));
if (diagram.leafExist(clName1) == false) {
return CommandExecutionResult.error("No class " + clName1);
}
if (diagram.leafExist(clName2) == false) {
return CommandExecutionResult.error("No class " + clName2);
}
2017-03-12 17:22:02 +00:00
final Code ent2 = Code.of(StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get("ENT2", 0), "\""));
2015-04-07 18:18:37 +00:00
final IEntity cl2 = diagram.getOrCreateLeaf(ent2, null, null);
2013-12-10 19:36:50 +00:00
final LinkType linkType = getLinkType(arg);
final Display label = Display.getWithNewlines(arg.get("LABEL_LINK", 0));
// final int length = getQueueLength(arg);
// final String weight = arg.get("HEADER").get(0);
final boolean result = diagram.associationClass(1, clName1, clName2, cl2, linkType, label);
if (result == false) {
return CommandExecutionResult.error("Cannot have more than 2 assocications");
}
return CommandExecutionResult.ok();
}
private CommandExecutionResult executeArgSpecial2(AbstractClassOrObjectDiagram diagram, RegexResult arg) {
final Code clName1 = Code.of(arg.get("COUPLE2", 0));
final Code clName2 = Code.of(arg.get("COUPLE2", 1));
if (diagram.leafExist(clName1) == false) {
return CommandExecutionResult.error("No class " + clName1);
}
if (diagram.leafExist(clName2) == false) {
return CommandExecutionResult.error("No class " + clName2);
}
2017-03-12 17:22:02 +00:00
final Code ent1 = Code.of(StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get("ENT1", 0), "\""));
2015-04-07 18:18:37 +00:00
final IEntity cl1 = diagram.getOrCreateLeaf(ent1, null, null);
2013-12-10 19:36:50 +00:00
final LinkType linkType = getLinkType(arg);
final Display label = Display.getWithNewlines(arg.get("LABEL_LINK", 0));
// final int length = getQueueLength(arg);
// final String weight = arg.get("HEADER").get(0);
final boolean result = diagram.associationClass(2, clName1, clName2, cl1, linkType, label);
if (result == false) {
return CommandExecutionResult.error("Cannot have more than 2 assocications");
}
return CommandExecutionResult.ok();
}
private LinkDecor getDecors1(String s) {
if (s == null) {
return LinkDecor.NONE;
}
2015-05-31 18:56:03 +00:00
s = StringUtils.trin(s);
2013-12-10 19:36:50 +00:00
if ("<|".equals(s)) {
return LinkDecor.EXTENDS;
}
2016-12-01 20:29:25 +00:00
if ("}".equals(s)) {
return LinkDecor.CROWFOOT;
}
2017-01-21 22:25:28 +00:00
if ("}o".equals(s)) {
return LinkDecor.CIRCLE_CROWFOOT;
}
if ("}|".equals(s)) {
return LinkDecor.LINE_CROWFOOT;
}
if ("|o".equals(s)) {
return LinkDecor.CIRCLE_LINE;
}
if ("||".equals(s)) {
return LinkDecor.DOUBLE_LINE;
}
2013-12-10 19:36:50 +00:00
if ("<".equals(s)) {
return LinkDecor.ARROW;
}
if ("^".equals(s)) {
return LinkDecor.EXTENDS;
}
if ("+".equals(s)) {
return LinkDecor.PLUS;
}
if ("o".equals(s)) {
return LinkDecor.AGREGATION;
}
2016-09-29 19:51:18 +00:00
if ("x".equals(s)) {
return LinkDecor.NOT_NAVIGABLE;
}
2013-12-10 19:36:50 +00:00
if ("*".equals(s)) {
return LinkDecor.COMPOSITION;
}
2015-04-07 18:18:37 +00:00
if ("#".equals(s)) {
return LinkDecor.SQUARRE;
}
2017-03-21 21:37:59 +00:00
if (")".equals(s)) {
return LinkDecor.PARENTHESIS;
}
2013-12-10 19:36:50 +00:00
return LinkDecor.NONE;
}
private LinkDecor getDecors2(String s) {
if (s == null) {
return LinkDecor.NONE;
}
2015-05-31 18:56:03 +00:00
s = StringUtils.trin(s);
2013-12-10 19:36:50 +00:00
if ("|>".equals(s)) {
return LinkDecor.EXTENDS;
}
if (">".equals(s)) {
return LinkDecor.ARROW;
}
2016-12-01 20:29:25 +00:00
if ("{".equals(s)) {
return LinkDecor.CROWFOOT;
}
2017-01-21 22:25:28 +00:00
if ("o{".equals(s)) {
return LinkDecor.CIRCLE_CROWFOOT;
}
if ("|{".equals(s)) {
return LinkDecor.LINE_CROWFOOT;
}
if ("o|".equals(s)) {
return LinkDecor.CIRCLE_LINE;
}
if ("||".equals(s)) {
return LinkDecor.DOUBLE_LINE;
}
2013-12-10 19:36:50 +00:00
if ("^".equals(s)) {
return LinkDecor.EXTENDS;
}
if ("+".equals(s)) {
return LinkDecor.PLUS;
}
if ("o".equals(s)) {
return LinkDecor.AGREGATION;
}
2016-09-29 19:51:18 +00:00
if ("x".equals(s)) {
return LinkDecor.NOT_NAVIGABLE;
}
2013-12-10 19:36:50 +00:00
if ("*".equals(s)) {
return LinkDecor.COMPOSITION;
}
2015-04-07 18:18:37 +00:00
if ("#".equals(s)) {
return LinkDecor.SQUARRE;
}
2017-03-21 21:37:59 +00:00
if ("(".equals(s)) {
return LinkDecor.PARENTHESIS;
}
2013-12-10 19:36:50 +00:00
return LinkDecor.NONE;
}
private LinkType getLinkType(RegexResult arg) {
final LinkDecor decors1 = getDecors1(arg.get("ARROW_HEAD1", 0));
final LinkDecor decors2 = getDecors2(arg.get("ARROW_HEAD2", 0));
LinkType result = new LinkType(decors2, decors1);
if (arg.get("ARROW_BODY1", 0).contains(".") || arg.get("ARROW_BODY2", 0).contains(".")) {
result = result.getDashed();
}
2015-04-07 18:18:37 +00:00
final String middle = arg.get("INSIDE", 0);
if ("0".equals(middle)) {
result = result.withMiddleCircle();
} else if ("0)".equals(middle)) {
result = result.withMiddleCircleCircled1();
} else if ("(0".equals(middle)) {
result = result.withMiddleCircleCircled2();
} else if ("(0)".equals(middle)) {
result = result.withMiddleCircleCircled();
}
2013-12-10 19:36:50 +00:00
return result;
}
private int getQueueLength(RegexResult arg) {
String s = getFullArrow(arg);
s = s.replaceAll("[^-.=]", "");
return s.length();
}
private Direction getDirection(RegexResult arg) {
final LinkDecor decors1 = getDecors1(arg.get("ARROW_HEAD1", 0));
final LinkDecor decors2 = getDecors2(arg.get("ARROW_HEAD2", 0));
String s = getFullArrow(arg);
s = s.replaceAll("[^-.=\\w]", "");
if (s.startsWith("o")) {
s = s.substring(1);
}
if (s.endsWith("o")) {
s = s.substring(0, s.length() - 1);
}
Direction result = StringUtils.getQueueDirection(s);
if (isInversed(decors1, decors2) && s.matches(".*\\w.*")) {
result = result.getInv();
}
return result;
}
private String getFullArrow(RegexResult arg) {
return notNull(arg.get("ARROW_HEAD1", 0)) + notNull(arg.get("ARROW_BODY1", 0))
+ notNull(arg.get("ARROW_DIRECTION", 0)) + notNull(arg.get("ARROW_BODY2", 0))
+ notNull(arg.get("ARROW_HEAD2", 0));
}
public static String notNull(String s) {
if (s == null) {
return "";
}
return s;
}
2015-09-28 20:42:17 +00:00
@Deprecated
public static Colors applyStyle(String arrowStyle, Link link) {
return applyStyle(arrowStyle, link, null);
}
public static Colors applyStyle(String arrowStyle, Link link, Colors colors) {
2013-12-10 19:36:50 +00:00
if (arrowStyle == null) {
2015-09-28 20:42:17 +00:00
return colors;
2013-12-10 19:36:50 +00:00
}
final StringTokenizer st = new StringTokenizer(arrowStyle, ",");
while (st.hasMoreTokens()) {
final String s = st.nextToken();
if (s.equalsIgnoreCase("dashed")) {
link.goDashed();
} else if (s.equalsIgnoreCase("bold")) {
link.goBold();
} else if (s.equalsIgnoreCase("dotted")) {
link.goDotted();
} else if (s.equalsIgnoreCase("hidden")) {
link.goHidden();
2016-03-06 16:47:34 +00:00
} else if (s.equalsIgnoreCase("plain")) {
// Do nothing
2015-04-07 18:18:37 +00:00
} else if (s.equalsIgnoreCase("norank")) {
link.goNorank();
2013-12-10 19:36:50 +00:00
} else {
link.setSpecificColor(s);
2015-09-28 20:42:17 +00:00
if (colors != null) {
colors = colors.add(ColorType.LINE, HtmlColorSet.getInstance().getColorIfValid(s));
}
2013-12-10 19:36:50 +00:00
}
}
2015-09-28 20:42:17 +00:00
return colors;
2013-12-10 19:36:50 +00:00
}
private boolean isInversed(LinkDecor decors1, LinkDecor decors2) {
if (decors1 == LinkDecor.ARROW && decors2 != LinkDecor.ARROW) {
return true;
}
if (decors2 == LinkDecor.AGREGATION) {
return true;
}
if (decors2 == LinkDecor.COMPOSITION) {
return true;
}
if (decors2 == LinkDecor.PLUS) {
return true;
}
// if (decors2 == LinkDecor.EXTENDS) {
// return true;
// }
return false;
}
}