plantuml/src/net/sourceforge/plantuml/style/CommandStyleMultilinesCSS.java

88 lines
3.2 KiB
Java
Raw Normal View History

2019-08-26 17:07:21 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
2022-03-07 19:33:46 +00:00
* (C) Copyright 2009-2023, Arnaud Roques
2019-08-26 17:07:21 +00:00
*
* Project Info: http://plantuml.com
2022-08-17 17:34:24 +00:00
*
2019-08-26 17:07:21 +00:00
* If you like this project or if you find it useful, you can support us at:
2022-08-17 17:34:24 +00:00
*
2019-08-26 17:07:21 +00:00
* http://plantuml.com/patreon (only 1$ per month!)
* http://plantuml.com/paypal
2022-08-17 17:34:24 +00:00
*
2019-08-26 17:07:21 +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.style;
import net.sourceforge.plantuml.SkinParam;
2020-08-25 17:24:17 +00:00
import net.sourceforge.plantuml.TitledDiagram;
2019-08-26 17:07:21 +00:00
import net.sourceforge.plantuml.command.CommandExecutionResult;
import net.sourceforge.plantuml.command.CommandMultilines2;
import net.sourceforge.plantuml.command.MultilinesStrategy;
2022-09-23 16:53:33 +00:00
import net.sourceforge.plantuml.command.Trim;
2019-08-26 17:07:21 +00:00
import net.sourceforge.plantuml.command.regex.IRegex;
import net.sourceforge.plantuml.command.regex.RegexConcat;
import net.sourceforge.plantuml.command.regex.RegexLeaf;
2022-12-17 11:01:10 +00:00
import net.sourceforge.plantuml.style.parser.StyleParser;
2023-01-09 19:13:37 +00:00
import net.sourceforge.plantuml.style.parser.StyleParsingException;
2022-12-17 11:01:10 +00:00
import net.sourceforge.plantuml.utils.BlocLines;
2019-08-26 17:07:21 +00:00
2020-08-25 17:24:17 +00:00
public class CommandStyleMultilinesCSS extends CommandMultilines2<TitledDiagram> {
2019-08-26 17:07:21 +00:00
2022-12-16 16:20:14 +00:00
public static final CommandStyleMultilinesCSS ME = new CommandStyleMultilinesCSS();
private CommandStyleMultilinesCSS() {
2022-09-23 16:53:33 +00:00
super(getRegexConcat(), MultilinesStrategy.REMOVE_STARTING_QUOTE, Trim.BOTH);
2019-08-26 17:07:21 +00:00
}
@Override
public String getPatternEnd() {
2023-01-09 19:13:37 +00:00
return "^[%s]*\\</?style\\>[%s]*$";
2019-08-26 17:07:21 +00:00
}
private static IRegex getRegexConcat() {
return RegexConcat.build(CommandStyleMultilinesCSS.class.getName(), RegexLeaf.start(), //
new RegexLeaf("\\<style\\>"), //
RegexLeaf.end() //
2020-08-25 17:24:17 +00:00
);
2019-08-26 17:07:21 +00:00
}
2020-08-25 17:24:17 +00:00
protected CommandExecutionResult executeNow(TitledDiagram diagram, BlocLines lines) {
2020-12-01 21:39:27 +00:00
try {
final StyleBuilder styleBuilder = diagram.getSkinParam().getCurrentStyleBuilder();
2022-12-17 11:01:10 +00:00
for (Style modifiedStyle : StyleParser.parse(lines.subExtract(1, 1), styleBuilder))
2020-12-01 21:39:27 +00:00
diagram.getSkinParam().muteStyle(modifiedStyle);
2022-04-10 19:24:55 +00:00
((SkinParam) diagram.getSkinParam()).applyPendingStyleMigration();
2020-12-01 21:39:27 +00:00
return CommandExecutionResult.ok();
2023-01-09 19:13:37 +00:00
} catch (StyleParsingException e) {
return CommandExecutionResult.error("Error in style definition: " + e.getMessage());
2020-12-01 21:39:27 +00:00
} catch (NoStyleAvailableException e) {
2022-08-17 17:34:24 +00:00
// Logme.error(e);
2020-12-01 21:39:27 +00:00
return CommandExecutionResult.error("General failure: no style available.");
2019-08-26 17:07:21 +00:00
}
}
}