1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-06-02 08:30:49 +00:00
plantuml/src/net/sourceforge/plantuml/activitydiagram3/command/CommandActivity3.java

150 lines
5.1 KiB
Java
Raw Normal View History

2011-01-09 19:00:05 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
2023-02-22 18:43:48 +00:00
* (C) Copyright 2009-2024, Arnaud Roques
2011-01-09 19:00:05 +00:00
*
2023-02-22 18:43:48 +00:00
* Project Info: https://plantuml.com
2011-01-09 19:00:05 +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:
*
2023-02-22 18:43:48 +00:00
* https://plantuml.com/patreon (only 1$ per month!)
* https://plantuml.com/paypal
2017-03-15 19:13:31 +00:00
*
2011-01-09 19:00:05 +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
2011-01-09 19:00:05 +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
*
*
*/
2013-12-10 19:36:50 +00:00
package net.sourceforge.plantuml.activitydiagram3.command;
2011-01-09 19:00:05 +00:00
import java.util.regex.Matcher;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.activitydiagram3.ActivityDiagram3;
import net.sourceforge.plantuml.activitydiagram3.ftile.BoxStyle;
2011-01-09 19:00:05 +00:00
import net.sourceforge.plantuml.command.CommandExecutionResult;
2011-01-23 19:36:52 +00:00
import net.sourceforge.plantuml.command.SingleLineCommand2;
2023-02-02 17:59:43 +00:00
import net.sourceforge.plantuml.klimt.color.ColorParser;
import net.sourceforge.plantuml.klimt.color.ColorType;
2023-02-22 18:43:48 +00:00
import net.sourceforge.plantuml.klimt.color.Colors;
2023-02-02 17:59:43 +00:00
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.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.skin.ColorParam;
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;
2013-12-10 19:36:50 +00:00
public class CommandActivity3 extends SingleLineCommand2<ActivityDiagram3> {
2011-01-09 19:00:05 +00:00
public static final String endingGroup() {
return "(" //
+ ";[%s]*(\\<\\<\\w+\\>\\>(?:[%s]*\\<\\<\\w+\\>\\>)*)?" //
+ "|" //
+ Matcher.quoteReplacement("\\\\") // that is simply \ character
+ "|" //
2023-01-13 17:36:46 +00:00
+ "(?<![/|<}\\]])[/<}]" // About /<}
+ "|" //
+ "(?<![/|}\\]])\\]" // About ]
+ "|" //
2020-11-21 17:33:24 +00:00
+ "(?<!\\</?\\w{1,5})(?<!\\<img[^>]{1,999})(?<!\\<[&$]\\w{1,999})(?<!\\>)\\>" // About >
+ "|" //
+ "(?<!\\|.{1,999})\\|" // About |
+ ")";
}
2023-01-13 17:36:46 +00:00
private static final String endingGroupShort() {
return "(" //
+ ";[%s]*(\\<\\<\\w+\\>\\>(?:[%s]*\\<\\<\\w+\\>\\>)*)?" //
2023-01-13 17:36:46 +00:00
+ "|" //
+ Matcher.quoteReplacement("\\\\") // that is simply \ character
+ "|" //
+ "(?<![/|<}\\]])[/<}]" // About /<}
+ "|" //
+ "(?<![/|}\\]])\\]" // About ]
+ "|" //
+ "(?<!\\</?\\w{1,5})(?<!\\<img[^>]{1,999})(?<!\\<[&$]\\w{1,999})(?<!\\>)\\>" // About >
+ "|" //
+ "\\|" // About |
+ ")";
}
public static void main(String[] args) {
System.err.println(Matcher.quoteReplacement("\\\\"));
System.err.println(Matcher.quoteReplacement("\\\\").equals("\\\\\\\\"));
}
2011-01-09 19:00:05 +00:00
2013-12-10 19:36:50 +00:00
public CommandActivity3() {
super(getRegexConcat());
2011-01-23 19:36:52 +00:00
}
2019-06-26 19:24:49 +00:00
static IRegex getRegexConcat() {
return RegexConcat.build(CommandActivity3.class.getName(), RegexLeaf.start(), //
2022-12-17 11:01:10 +00:00
UrlBuilder.OPTIONAL, //
2015-09-28 20:42:17 +00:00
color().getRegex(), //
2023-12-11 17:34:23 +00:00
StereotypePattern.optional("STEREO"), //
2013-12-10 19:36:50 +00:00
new RegexLeaf(":"), //
2023-01-13 17:36:46 +00:00
new RegexLeaf("LABEL", "(.*?)"), //
new RegexLeaf("STYLE", endingGroupShort()), //
2019-06-26 19:24:49 +00:00
RegexLeaf.end());
2011-01-09 19:00:05 +00:00
}
2015-09-28 20:42:17 +00:00
private static ColorParser color() {
return ColorParser.simpleColor(ColorType.BACK);
}
2011-01-09 19:00:05 +00:00
@Override
2021-02-02 10:12:15 +00:00
protected CommandExecutionResult executeArg(ActivityDiagram3 diagram, LineLocation location, RegexResult arg)
throws NoSuchColorException {
2015-04-07 18:18:37 +00:00
final Url url;
if (arg.get("URL", 0) == null) {
url = null;
} else {
2022-03-13 12:22:51 +00:00
final UrlBuilder urlBuilder = new UrlBuilder(diagram.getSkinParam().getValue("topurl"), UrlMode.STRICT);
2015-04-07 18:18:37 +00:00
url = urlBuilder.getUrl(arg.get("URL", 0));
}
2022-09-18 17:08:06 +00:00
Colors colors = color().getColor(arg, diagram.getSkinParam().getIHtmlColorSet());
String stereo = arg.get("STEREO", 0);
if (stereo == null)
stereo = arg.get("STYLE", 1);
2020-11-21 17:33:24 +00:00
Stereotype stereotype = null;
2019-08-26 17:07:21 +00:00
if (stereo != null) {
2021-10-07 16:51:26 +00:00
stereotype = Stereotype.build(stereo);
2019-08-26 17:07:21 +00:00
colors = colors.applyStereotype(stereotype, diagram.getSkinParam(), ColorParam.activityBackground);
}
BoxStyle style = BoxStyle.fromString(arg.get("STEREO", 0));
if (style == BoxStyle.PLAIN)
style = BoxStyle.fromString(arg.get("STYLE", 0));
2021-02-02 10:12:15 +00:00
final Display display = Display.getWithNewlines2(arg.get("LABEL", 0));
2021-07-25 10:41:36 +00:00
return diagram.addActivity(display, style, url, colors, stereotype);
2011-01-09 19:00:05 +00:00
}
}