summaryrefslogtreecommitdiff
path: root/src/net/sourceforge/plantuml/creole/CreoleParser.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/net/sourceforge/plantuml/creole/CreoleParser.java')
-rw-r--r--src/net/sourceforge/plantuml/creole/CreoleParser.java95
1 files changed, 95 insertions, 0 deletions
diff --git a/src/net/sourceforge/plantuml/creole/CreoleParser.java b/src/net/sourceforge/plantuml/creole/CreoleParser.java
new file mode 100644
index 0000000..0e19af8
--- /dev/null
+++ b/src/net/sourceforge/plantuml/creole/CreoleParser.java
@@ -0,0 +1,95 @@
+/* ========================================================================
+ * PlantUML : a free UML diagram generator
+ * ========================================================================
+ *
+ * (C) Copyright 2009-2014, Arnaud Roques
+ *
+ * Project Info: http://plantuml.sourceforge.net
+ *
+ * This file is part of PlantUML.
+ *
+ * Licensed under The MIT License (Massachusetts Institute of Technology License)
+ *
+ * See http://opensource.org/licenses/MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
+ * IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ *
+ * Original Author: Arnaud Roques
+ */
+package net.sourceforge.plantuml.creole;
+
+import java.util.Arrays;
+import java.util.List;
+
+import net.sourceforge.plantuml.EmbededDiagram;
+import net.sourceforge.plantuml.ISkinSimple;
+import net.sourceforge.plantuml.cucadiagram.Display;
+import net.sourceforge.plantuml.graphic.FontConfiguration;
+import net.sourceforge.plantuml.graphic.HorizontalAlignment;
+
+public class CreoleParser {
+
+ private final FontConfiguration fontConfiguration;
+ private final ISkinSimple skinParam;
+ private final HorizontalAlignment horizontalAlignment;
+ private final boolean modeSimpleLine;
+
+ public CreoleParser(FontConfiguration fontConfiguration, HorizontalAlignment horizontalAlignment,
+ ISkinSimple skinParam, boolean modeSimpleLine) {
+ this.modeSimpleLine = modeSimpleLine;
+ this.fontConfiguration = fontConfiguration;
+ this.skinParam = skinParam;
+ this.horizontalAlignment = horizontalAlignment;
+ }
+
+ private Stripe createStripe(String line, CreoleContext context, Stripe lastStripe) {
+ if (lastStripe instanceof StripeTable && line.startsWith("|") && line.endsWith("|")) {
+ final StripeTable table = (StripeTable) lastStripe;
+ table.analyzeAndAddNormal(line);
+ return null;
+ } else if (line.startsWith("|=") && line.endsWith("|")) {
+ return new StripeTable(fontConfiguration, skinParam, line);
+ }
+ return new CreoleStripeSimpleParser(line, context, fontConfiguration, skinParam, modeSimpleLine).createStripe(context);
+ }
+
+ public Sheet createSheet(Display display) {
+ final Sheet sheet = new Sheet(horizontalAlignment);
+ if (display != null) {
+ final CreoleContext context = new CreoleContext();
+ for (CharSequence cs : display) {
+ final Stripe stripe;
+ if (cs instanceof EmbededDiagram) {
+ final Atom atom = new AtomEmbededSystem((EmbededDiagram) cs);
+ stripe = new Stripe() {
+ public List<Atom> getAtoms() {
+ return Arrays.asList(atom);
+ }
+ };
+ } else {
+ stripe = createStripe(cs.toString(), context, sheet.getLastStripe());
+ }
+ if (stripe != null) {
+ sheet.add(stripe);
+ }
+ }
+ }
+ return sheet;
+ }
+}