1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-06-02 16:40:49 +00:00
plantuml/src/net/sourceforge/plantuml/descdiagram/CommandCreateDomain.java

149 lines
5.9 KiB
Java
Raw Normal View History

2018-05-21 19:15:19 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
2023-02-22 18:43:48 +00:00
* (C) Copyright 2009-2024, Arnaud Roques
2018-05-21 19:15:19 +00:00
*
2023-02-22 18:43:48 +00:00
* Project Info: https://plantuml.com
2018-05-21 19:15:19 +00:00
*
* If you like this project or if you find it useful, you can support us at:
*
2023-02-22 18:43:48 +00:00
* https://plantuml.com/patreon (only 1$ per month!)
* https://plantuml.com/paypal
2018-05-21 19:15:19 +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: Yijun Yu
*
*
*/
package net.sourceforge.plantuml.descdiagram;
2023-02-22 18:43:48 +00:00
import net.sourceforge.plantuml.abel.Entity;
import net.sourceforge.plantuml.abel.GroupType;
import net.sourceforge.plantuml.abel.LeafType;
2018-05-21 19:15:19 +00:00
import net.sourceforge.plantuml.classdiagram.command.GenericRegexProducer;
import net.sourceforge.plantuml.command.CommandExecutionResult;
import net.sourceforge.plantuml.command.SingleLineCommand2;
2023-02-22 18:43:48 +00:00
import net.sourceforge.plantuml.decoration.symbol.USymbol;
import net.sourceforge.plantuml.decoration.symbol.USymbols;
2023-02-02 17:59:43 +00:00
import net.sourceforge.plantuml.klimt.color.ColorType;
import net.sourceforge.plantuml.klimt.color.NoSuchColorException;
2023-02-22 18:43:48 +00:00
import net.sourceforge.plantuml.klimt.creole.Display;
2023-02-02 17:59:43 +00:00
import net.sourceforge.plantuml.klimt.font.FontParam;
2023-02-06 21:04:53 +00:00
import net.sourceforge.plantuml.plasma.Quark;
2023-02-02 17:59:43 +00:00
import net.sourceforge.plantuml.regex.IRegex;
import net.sourceforge.plantuml.regex.RegexConcat;
import net.sourceforge.plantuml.regex.RegexLeaf;
import net.sourceforge.plantuml.regex.RegexResult;
2023-02-22 18:43:48 +00:00
import net.sourceforge.plantuml.stereo.Stereotype;
2023-12-11 17:34:23 +00:00
import net.sourceforge.plantuml.stereo.StereotypePattern;
2023-02-02 17:59:43 +00:00
import net.sourceforge.plantuml.url.Url;
import net.sourceforge.plantuml.url.UrlBuilder;
import net.sourceforge.plantuml.url.UrlMode;
2022-12-17 11:01:10 +00:00
import net.sourceforge.plantuml.utils.LineLocation;
2018-05-21 19:15:19 +00:00
public class CommandCreateDomain extends SingleLineCommand2<DescriptionDiagram> {
public static final String DISPLAY_WITH_GENERIC = "[%g](.+?)(?:\\<(" + GenericRegexProducer.PATTERN + ")\\>)?[%g]";
public static final String CODE = "[^%s{}%g<>]+";
public CommandCreateDomain() {
super(getRegexConcat());
}
2019-06-26 19:24:49 +00:00
private static IRegex getRegexConcat() {
return RegexConcat.build(CommandCreateDomain.class.getName(), RegexLeaf.start(), //
2019-07-14 20:09:26 +00:00
new RegexLeaf("TYPE", "(requirement|domain)"), //
RegexLeaf.spaceOneOrMore(), //
2019-06-26 19:24:49 +00:00
new RegexLeaf("DISPLAY", DISPLAY_WITH_GENERIC), //
RegexLeaf.spaceOneOrMore(), //
new RegexLeaf("as"), //
2023-12-11 17:34:23 +00:00
RegexLeaf.spaceOneOrMore(), //
new RegexLeaf("CODE", "([a-zA-Z0-9]+)"), //
StereotypePattern.optional("STEREO"), //
2018-05-21 19:15:19 +00:00
// domain: lexical, causal, biddable
// requirement: FR, NFR, quality
2019-06-26 19:24:49 +00:00
new RegexLeaf("GROUP", "(\\{)?"), RegexLeaf.end());
2018-05-21 19:15:19 +00:00
}
@Override
2021-05-06 21:23:05 +00:00
protected CommandExecutionResult executeArg(DescriptionDiagram diagram, LineLocation location, RegexResult arg)
throws NoSuchColorException {
String typeString = arg.get("TYPE", 0);
String displayString = arg.getLazzy("DISPLAY", 0);
2020-01-12 22:13:17 +00:00
String codeString = arg.getLazzy("CODE", 0);
2022-10-18 20:57:44 +00:00
if (codeString == null)
codeString = displayString;
2022-10-18 20:57:44 +00:00
2018-05-21 19:15:19 +00:00
final String stereotype = arg.get("STEREO", 0);
final GroupType type = typeString.equalsIgnoreCase("domain") ? GroupType.DOMAIN : GroupType.REQUIREMENT;
final LeafType type2 = typeString.equalsIgnoreCase("domain") ? LeafType.DOMAIN : LeafType.REQUIREMENT;
2018-05-21 19:15:19 +00:00
final Quark<Entity> quark = diagram.quarkInContext(true, diagram.cleanId(codeString));
if (quark.getData() != null)
2020-01-12 22:13:17 +00:00
return CommandExecutionResult.error("Object already exists : " + codeString);
2023-01-11 21:47:15 +00:00
Display display = Display.getWithNewlines(displayString);
2018-05-21 19:15:19 +00:00
final String urlString = arg.get("URL", 0);
final String group = arg.get("GROUP", 0);
2023-02-06 21:04:53 +00:00
Entity entity;
2018-05-21 19:15:19 +00:00
if (group != null) {
2023-02-08 18:38:46 +00:00
// final Entity currentGroup = diagram.getCurrentGroup();
diagram.gotoGroup(quark, display, type);
2018-05-21 19:15:19 +00:00
entity = diagram.getCurrentGroup();
} else {
entity = diagram.reallyCreateLeaf(quark, display, type2, null);
2018-05-21 19:15:19 +00:00
}
2023-02-08 18:38:46 +00:00
if (stereotype != null)
2021-10-07 16:51:26 +00:00
entity.setStereotype(Stereotype.build(stereotype, diagram.getSkinParam().getCircledCharacterRadius(),
2021-02-02 10:12:15 +00:00
diagram.getSkinParam().getFont(null, false, FontParam.CIRCLED_CHARACTER),
diagram.getSkinParam().getIHtmlColorSet()));
2023-02-08 18:38:46 +00:00
2018-05-21 19:15:19 +00:00
if (urlString != null) {
2022-03-13 12:22:51 +00:00
final UrlBuilder urlBuilder = new UrlBuilder(diagram.getSkinParam().getValue("topurl"), UrlMode.STRICT);
2018-05-21 19:15:19 +00:00
final Url url = urlBuilder.getUrl(urlString);
entity.addUrl(url);
}
2021-02-02 10:12:15 +00:00
final String s = arg.get("COLOR", 0);
2022-10-18 20:57:44 +00:00
entity.setSpecificColorTOBEREMOVED(ColorType.BACK,
s == null ? null : diagram.getSkinParam().getIHtmlColorSet().getColor(s));
if (typeString.equalsIgnoreCase("domain")) {
2022-10-18 20:57:44 +00:00
if (stereotype != null && stereotype.equalsIgnoreCase("<<Machine>>"))
typeString = "machine";
2022-10-18 20:57:44 +00:00
if (stereotype != null && stereotype.equalsIgnoreCase("<<Causal>>"))
typeString = "causal";
2022-10-18 20:57:44 +00:00
if (stereotype != null && stereotype.equalsIgnoreCase("<<Designed>>"))
typeString = "designed";
2022-10-18 20:57:44 +00:00
if (stereotype != null && stereotype.equalsIgnoreCase("<<Lexical>>"))
typeString = "lexical";
2022-10-18 20:57:44 +00:00
if (stereotype != null && stereotype.equalsIgnoreCase("<<Biddable>>"))
typeString = "biddable";
2022-10-18 20:57:44 +00:00
2018-05-21 19:15:19 +00:00
}
USymbol usymbol = USymbols.fromString(typeString, diagram.getSkinParam());
2018-05-21 19:15:19 +00:00
entity.setUSymbol(usymbol);
return CommandExecutionResult.ok();
}
}