private boolean isStandalone(IEntity ent) {
   for (final Link link : classDiagram.getLinks()) {
     if (link.getEntity1() == ent || link.getEntity2() == ent) {
       return false;
     }
   }
   return true;
 }
Exemple #2
0
 public static boolean onlyOneLink(IEntity ent, Collection<Link> links) {
   int nb = 0;
   for (Link link : links) {
     if (link.contains(ent)) {
       nb++;
     }
     if (nb > 1) {
       return false;
     }
   }
   return nb == 1;
 }
  @Override
  protected CommandExecutionResult executeArg(RegexResult arg) {
    final Code g1 = Code.of(arg.get("G1", 0));
    final Code g2 = Code.of(arg.get("G2", 0));

    if (getSystem().isGroup(g1) && getSystem().isGroup(g2)) {
      return executePackageLink(arg);
    }
    if (getSystem().isGroup(g1) || getSystem().isGroup(g2)) {
      return CommandExecutionResult.error("Package can be only linked to other package");
    }

    final IEntity cl1 = getSystem().getOrCreateClass(g1);
    final IEntity cl2 = getSystem().getOrCreateClass(g2);

    if (arg.get("G1", 1) != null) {
      cl1.setStereotype(new Stereotype(arg.get("G1", 1)));
    }
    if (arg.get("G2", 1) != null) {
      cl2.setStereotype(new Stereotype(arg.get("G2", 1)));
    }

    final LinkType linkType;
    String queue;
    if (arg.get("AR_TO_RIGHT", 0) == null) {
      queue = arg.get("AR_TO_LEFT", 2) + arg.get("AR_TO_LEFT", 4);
      linkType = getLinkTypeNormal(queue, arg.get("AR_TO_LEFT", 1)).getInversed();
    } else {
      queue = arg.get("AR_TO_RIGHT", 1) + arg.get("AR_TO_RIGHT", 3);
      linkType = getLinkTypeNormal(queue, arg.get("AR_TO_RIGHT", 4));
    }
    final Direction dir = getDirection(arg);

    if (dir == Direction.LEFT || dir == Direction.RIGHT) {
      queue = "-";
    }

    Link link = new Link(cl1, cl2, linkType, arg.get("END", 0), queue.length());

    if (dir == Direction.LEFT || dir == Direction.UP) {
      link = link.getInv();
    }

    getSystem().addLink(link);
    return CommandExecutionResult.ok();
  }
 private void addLinkNew(List<Link> result, Link link) {
   for (int i = 0; i < result.size(); i++) {
     final Link other = result.get(i);
     if (other.sameConnections(link)) {
       while (i < result.size() && result.get(i).sameConnections(link)) {
         i++;
       }
       if (i == result.size()) {
         result.add(link);
       } else {
         result.add(i, link);
       }
       return;
     }
   }
   result.add(link);
 }
Exemple #5
0
 public Link getInv() {
   // if (getLength() == 1) {
   // final int x = cl1.getXposition();
   // cl2.setXposition(x-1);
   // }
   final Link result =
       new Link(
           cl2,
           cl1,
           getType().getInversed(),
           label,
           length,
           qualifier2,
           qualifier1,
           labeldistance,
           labelangle,
           specificColor);
   result.inverted = true;
   return result;
 }
 public static void applyStyle(String arrowStyle, Link link) {
   if (arrowStyle == null) {
     return;
   }
   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();
     } else {
       link.setSpecificColor(s);
     }
   }
 }
  @Override
  protected CommandExecutionResult executeArg(Map<String, RegexPartialMatch> arg2) {
    final IEntity entity1 = getEntity(getSystem(), arg2, true);
    if (entity1 == null) {
      return CommandExecutionResult.error("No such activity");
    }
    if (arg2.get("STEREOTYPE").get(0) != null) {
      entity1.setStereotype(new Stereotype(arg2.get("STEREOTYPE").get(0)));
    }
    if (arg2.get("BACKCOLOR").get(0) != null) {
      entity1.setSpecificBackcolor(arg2.get("BACKCOLOR").get(0));
    }

    final IEntity entity2 = getEntity(getSystem(), arg2, false);
    if (entity2 == null) {
      return CommandExecutionResult.error("No such activity");
    }
    if (arg2.get("BACKCOLOR2").get(0) != null) {
      entity2.setSpecificBackcolor(arg2.get("BACKCOLOR2").get(0));
    }
    if (arg2.get("STEREOTYPE2").get(0) != null) {
      entity2.setStereotype(new Stereotype(arg2.get("STEREOTYPE2").get(0)));
    }

    final String linkLabel = arg2.get("BRACKET").get(0);

    final String arrow = StringUtils.manageArrowForCuca(arg2.get("ARROW").get(0));
    final int lenght = arrow.length() - 1;

    Link link =
        new Link(
            entity1, entity2, new LinkType(LinkDecor.ARROW, LinkDecor.NONE), linkLabel, lenght);
    final Direction direction = StringUtils.getArrowDirection(arg2.get("ARROW").get(0));
    if (direction == Direction.LEFT || direction == Direction.UP) {
      link = link.getInv();
    }

    getSystem().addLink(link);

    return CommandExecutionResult.ok();
  }
  public CommandExecutionResult execute(List<String> lines) {
    final List<String> strings = StringUtils.removeEmptyColumns(lines.subList(1, lines.size() - 1));
    if (strings.size() > 0) {
      final List<CharSequence> n = StringUtils.manageEmbededDiagrams(strings);

      final Link link = getSystem().getLastStateLink();
      if (link == null) {
        return CommandExecutionResult.error("No link defined");
      }
      Position position = Position.BOTTOM;
      final Matcher m = getStartingPattern().matcher(lines.get(0));
      if (m.find()) {
        final String pos = m.group(1);
        if (pos != null) {
          position = Position.valueOf(pos.toUpperCase());
        }
      }

      link.addNote(n, position);
      return CommandExecutionResult.ok();
    }
    return CommandExecutionResult.error("No note defined");
  }
Exemple #9
0
  @Override
  protected CommandExecutionResult executeArg(Map<String, RegexPartialMatch> arg) {
    final IEntity entity1 = CommandLinkActivity.getEntity(getSystem(), arg, true);

    getSystem().startIf(arg.get("IF").get(1));

    int lenght = 2;

    if (arg.get("ARROW").get(0) != null) {
      final String arrow = StringUtils.manageArrowForCuca(arg.get("ARROW").get(0));
      lenght = arrow.length() - 1;
    }

    final IEntity branch = getSystem().getCurrentContext().getBranch();

    Link link =
        new Link(
            entity1,
            branch,
            new LinkType(LinkDecor.ARROW, LinkDecor.NONE),
            arg.get("BRACKET").get(0),
            lenght,
            null,
            arg.get("IF").get(0),
            getSystem().getLabeldistance(),
            getSystem().getLabelangle());
    if (arg.get("ARROW").get(0) != null) {
      final Direction direction = StringUtils.getArrowDirection(arg.get("ARROW").get(0));
      if (direction == Direction.LEFT || direction == Direction.UP) {
        link = link.getInv();
      }
    }

    getSystem().addLink(link);

    return CommandExecutionResult.ok();
  }
 private void addExtension(Link link, String assId) {
   final Element association = document.createElement("UML:Generalization");
   association.setAttribute("xmi.id", assId);
   association.setAttribute("namespace", "model1");
   if (link.getLabel() != null) {
     association.setAttribute("name", forXMI(link.getLabel()));
   }
   if (link.getType().getDecor1() == LinkDecor.EXTENDS) {
     association.setAttribute("child", link.getEntity1().getUid());
     association.setAttribute("parent", link.getEntity2().getUid());
   } else if (link.getType().getDecor2() == LinkDecor.EXTENDS) {
     association.setAttribute("child", link.getEntity2().getUid());
     association.setAttribute("parent", link.getEntity1().getUid());
   } else {
     throw new IllegalStateException();
   }
   ownedElement.appendChild(association);
 }
 private void addLink(Link link, String weight) {
   getSystem().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 void addLink(Link link) {
    final String assId = "ass" + UniqueSequence.getValue();
    if (link.getType().getDecor1() == LinkDecor.EXTENDS
        || link.getType().getDecor2() == LinkDecor.EXTENDS) {
      addExtension(link, assId);
      return;
    }
    final Element association = document.createElement("UML:Association");
    association.setAttribute("xmi.id", assId);
    association.setAttribute("namespace", "model1");
    if (link.getLabel() != null) {
      association.setAttribute("name", forXMI(link.getLabel()));
    }

    final Element connection = document.createElement("UML:Association.connection");
    final Element end1 = document.createElement("UML:AssociationEnd");
    end1.setAttribute("xmi.id", "end" + UniqueSequence.getValue());
    end1.setAttribute("association", assId);
    end1.setAttribute("type", link.getEntity1().getUid());
    if (link.getQualifier1() != null) {
      end1.setAttribute("name", forXMI(link.getQualifier1()));
    }
    final Element endparticipant1 = document.createElement("UML:AssociationEnd.participant");
    // if (fileFormat == FileFormat.XMI_ARGO) {
    // if (done.contains(link.getEntity1())) {
    // endparticipant1.appendChild(createEntityNodeRef(link.getEntity1()));
    // } else {
    // endparticipant1.appendChild(createEntityNode(link.getEntity1()));
    // done.add(link.getEntity1());
    // }
    // } else if (fileFormat == FileFormat.XMI_STAR) {
    if (link.getType().getDecor2() == LinkDecor.COMPOSITION) {
      end1.setAttribute("aggregation", "composite");
    }
    if (link.getType().getDecor2() == LinkDecor.AGREGATION) {
      end1.setAttribute("aggregation", "aggregate");
    }
    // }
    end1.appendChild(endparticipant1);
    connection.appendChild(end1);

    final Element end2 = document.createElement("UML:AssociationEnd");
    end2.setAttribute("xmi.id", "end" + UniqueSequence.getValue());
    end2.setAttribute("association", assId);
    end2.setAttribute("type", link.getEntity2().getUid());
    if (link.getQualifier2() != null) {
      end2.setAttribute("name", forXMI(link.getQualifier2()));
    }
    final Element endparticipant2 = document.createElement("UML:AssociationEnd.participant");
    // if (fileFormat == FileFormat.XMI_ARGO) {
    // if (done.contains(link.getEntity2())) {
    // endparticipant2.appendChild(createEntityNodeRef(link.getEntity2()));
    // } else {
    // endparticipant2.appendChild(createEntityNode(link.getEntity2()));
    // done.add(link.getEntity2());
    // }
    // } else if (fileFormat == FileFormat.XMI_STAR) {
    if (link.getType().getDecor1() == LinkDecor.COMPOSITION) {
      end2.setAttribute("aggregation", "composite");
    }
    if (link.getType().getDecor1() == LinkDecor.AGREGATION) {
      end2.setAttribute("aggregation", "aggregate");
    }
    // }
    end2.appendChild(endparticipant2);
    connection.appendChild(end2);

    association.appendChild(connection);

    ownedElement.appendChild(association);
  }
  @Override
  protected CommandExecutionResult executeArg(RegexResult arg) {
    String ent1 = arg.get("ENT1", 1);
    String ent2 = arg.get("ENT2", 1);
    if (ent1 == null) {
      return executeArgSpecial1(arg);
    }
    if (ent2 == null) {
      return executeArgSpecial2(arg);
    }
    ent1 = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(ent1);
    ent2 = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(ent2);
    if (getSystem().isGroup(ent1) && getSystem().isGroup(ent2)) {
      return executePackageLink(arg);
    }
    if (getSystem().isGroup(ent1) || getSystem().isGroup(ent2)) {
      return CommandExecutionResult.error("Package can be only linked to other package");
    }

    final ILeaf cl1 = (ILeaf) getSystem().getOrCreateClass(ent1);
    final ILeaf cl2 = (ILeaf) getSystem().getOrCreateClass(ent2);

    if (arg.get("ENT1", 0) != null) {
      final LeafType type = LeafType.getLeafType(arg.get("ENT1", 0));
      if (type != LeafType.OBJECT) {
        cl1.muteToType(type);
      }
    }
    if (arg.get("ENT2", 0) != null) {
      final LeafType type = LeafType.getLeafType(arg.get("ENT2", 0));
      if (type != LeafType.OBJECT) {
        cl2.muteToType(type);
      }
    }
    if (arg.get("ENT1", 2) != null) {
      cl1.setStereotype(
          new Stereotype(
              arg.get("ENT1", 2),
              getSystem().getSkinParam().getCircledCharacterRadius(),
              getSystem().getSkinParam().getFont(FontParam.CIRCLED_CHARACTER, null)));
    }
    if (arg.get("ENT2", 2) != null) {
      cl2.setStereotype(
          new Stereotype(
              arg.get("ENT2", 2),
              getSystem().getSkinParam().getCircledCharacterRadius(),
              getSystem().getSkinParam().getFont(FontParam.CIRCLED_CHARACTER, null)));
    }

    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);
    }
    // if (dir != null && linkType.isExtendsOrAgregationOrCompositionOrPlus()) {
    // dir = dir.getInv();
    // }

    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) {
        final Pattern p1 = Pattern.compile("^\"([^\"]+)\"([^\"]+)\"([^\"]+)\"$");
        final Matcher m1 = p1.matcher(labelLink);
        if (m1.matches()) {
          firstLabel = m1.group(1);
          labelLink =
              StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(m1.group(2).trim()).trim();
          secondLabel = m1.group(3);
        } else {
          final Pattern p2 = Pattern.compile("^\"([^\"]+)\"([^\"]+)$");
          final Matcher m2 = p2.matcher(labelLink);
          if (m2.matches()) {
            firstLabel = m2.group(1);
            labelLink =
                StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(m2.group(2).trim()).trim();
            secondLabel = null;
          } else {
            final Pattern p3 = Pattern.compile("^([^\"]+)\"([^\"]+)\"$");
            final Matcher m3 = p3.matcher(labelLink);
            if (m3.matches()) {
              firstLabel = null;
              labelLink =
                  StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(m3.group(1).trim())
                      .trim();
              secondLabel = m3.group(2);
            }
          }
        }
      }
      labelLink = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(labelLink);
    }

    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;
      labelLink = labelLink.substring(2).trim();
    } else if (labelLink != null && labelLink.startsWith("> ")) {
      linkArrow = LinkArrow.DIRECT_NORMAL;
      labelLink = labelLink.substring(2).trim();
    } else if (labelLink != null && labelLink.endsWith(" >")) {
      linkArrow = LinkArrow.DIRECT_NORMAL;
      labelLink = labelLink.substring(0, labelLink.length() - 2).trim();
    } else if (labelLink != null && labelLink.endsWith(" <")) {
      linkArrow = LinkArrow.BACKWARD;
      labelLink = labelLink.substring(0, labelLink.length() - 2).trim();
    }

    Link link =
        new Link(
            cl1,
            cl2,
            linkType,
            labelLink,
            queue,
            firstLabel,
            secondLabel,
            getSystem().getLabeldistance(),
            getSystem().getLabelangle());

    if (dir == Direction.LEFT || dir == Direction.UP) {
      link = link.getInv();
    }
    link.setLinkArrow(linkArrow);

    addLink(link, arg.get("HEADER", 0));

    return CommandExecutionResult.ok();
  }
  @Override
  protected CommandExecutionResult executeArg(
      AbstractClassOrObjectDiagram diagram, RegexResult arg) {
    Code ent1 = Code.of(arg.get("ENT1", 1));
    Code ent2 = Code.of(arg.get("ENT2", 1));
    if (ent1 == null) {
      return executeArgSpecial1(diagram, arg);
    }
    if (ent2 == null) {
      return executeArgSpecial2(diagram, arg);
    }
    ent1 = ent1.eventuallyRemoveStartingAndEndingDoubleQuote();
    ent2 = ent2.eventuallyRemoveStartingAndEndingDoubleQuote();
    if (diagram.isGroup(ent1) && diagram.isGroup(ent2)) {
      return executePackageLink(diagram, arg);
    }

    final IEntity cl1 =
        diagram.isGroup(ent1)
            ? diagram.getGroup(
                Code.of(
                    StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get("ENT1", 1))))
            : diagram.getOrCreateLeaf(ent1, null, null);
    final IEntity cl2 =
        diagram.isGroup(ent2)
            ? diagram.getGroup(
                Code.of(
                    StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get("ENT2", 1))))
            : diagram.getOrCreateLeaf(ent2, null, null);

    if (arg.get("ENT1", 0) != null) {
      final LeafType type = LeafType.getLeafType(arg.get("ENT1", 0));
      if (type != LeafType.OBJECT) {
        ((ILeaf) cl1).muteToType(type, null);
      }
    }
    if (arg.get("ENT2", 0) != null) {
      final LeafType type = LeafType.getLeafType(arg.get("ENT2", 0));
      if (type != LeafType.OBJECT) {
        ((ILeaf) cl2).muteToType(type, null);
      }
    }
    if (arg.get("ENT1", 2) != null) {
      cl1.setStereotype(
          new Stereotype(
              arg.get("ENT1", 2),
              diagram.getSkinParam().getCircledCharacterRadius(),
              diagram.getSkinParam().getFont(FontParam.CIRCLED_CHARACTER, null)));
    }
    if (arg.get("ENT2", 2) != null) {
      cl2.setStereotype(
          new Stereotype(
              arg.get("ENT2", 2),
              diagram.getSkinParam().getCircledCharacterRadius(),
              diagram.getSkinParam().getFont(FontParam.CIRCLED_CHARACTER, null)));
    }

    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) {
        final Pattern p1 = MyPattern.cmpile("^[%g]([^%g]+)[%g]([^%g]+)[%g]([^%g]+)[%g]$");
        final Matcher m1 = p1.matcher(labelLink);
        if (m1.matches()) {
          firstLabel = m1.group(1);
          labelLink =
              StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(m1.group(2).trim()).trim();
          secondLabel = m1.group(3);
        } else {
          final Pattern p2 = MyPattern.cmpile("^[%g]([^%g]+)[%g]([^%g]+)$");
          final Matcher m2 = p2.matcher(labelLink);
          if (m2.matches()) {
            firstLabel = m2.group(1);
            labelLink =
                StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(m2.group(2).trim()).trim();
            secondLabel = null;
          } else {
            final Pattern p3 = MyPattern.cmpile("^([^%g]+)[%g]([^%g]+)[%g]$");
            final Matcher m3 = p3.matcher(labelLink);
            if (m3.matches()) {
              firstLabel = null;
              labelLink =
                  StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(m3.group(1).trim())
                      .trim();
              secondLabel = m3.group(2);
            }
          }
        }
      }
      labelLink = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(labelLink);
    }

    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;
      labelLink = labelLink.substring(2).trim();
    } else if (labelLink != null && labelLink.startsWith("> ")) {
      linkArrow = LinkArrow.DIRECT_NORMAL;
      labelLink = labelLink.substring(2).trim();
    } else if (labelLink != null && labelLink.endsWith(" >")) {
      linkArrow = LinkArrow.DIRECT_NORMAL;
      labelLink = labelLink.substring(0, labelLink.length() - 2).trim();
    } else if (labelLink != null && labelLink.endsWith(" <")) {
      linkArrow = LinkArrow.BACKWARD;
      labelLink = labelLink.substring(0, labelLink.length() - 2).trim();
    }

    Link link =
        new Link(
            cl1,
            cl2,
            linkType,
            Display.getWithNewlines(labelLink),
            queue,
            firstLabel,
            secondLabel,
            diagram.getLabeldistance(),
            diagram.getLabelangle());

    if (dir == Direction.LEFT || dir == Direction.UP) {
      link = link.getInv();
    }
    link.setLinkArrow(linkArrow);
    applyStyle(arg.getLazzy("ARROW_STYLE", 0), link);

    addLink(diagram, link, arg.get("HEADER", 0));

    return CommandExecutionResult.ok();
  }
  public CommandExecutionResult execute(List<String> lines) {
    StringUtils.trim(lines, false);
    final RegexResult line0 = getStartingPattern().matcher(lines.get(0).trim());

    final IEntity entity1 = CommandLinkActivity.getEntity(getSystem(), line0, true);

    if (line0.get("STEREOTYPE", 0) != null) {
      entity1.setStereotype(new Stereotype(line0.get("STEREOTYPE", 0)));
    }
    if (line0.get("BACKCOLOR", 0) != null) {
      entity1.setSpecificBackcolor(HtmlColorUtils.getColorIfValid(line0.get("BACKCOLOR", 0)));
    }
    final StringBuilder sb = new StringBuilder();

    final String desc0 = line0.get("DESC", 0);
    Url urlActivity = null;
    if (StringUtils.isNotEmpty(desc0)) {
      final UrlBuilder urlBuilder =
          new UrlBuilder(getSystem().getSkinParam().getValue("topurl"), true);
      urlActivity = urlBuilder.getUrl(desc0);
      if (urlActivity == null) {
        sb.append(desc0);
        sb.append("\\n");
      }
    }
    for (int i = 1; i < lines.size() - 1; i++) {
      if (i == 1 && urlActivity == null) {
        final UrlBuilder urlBuilder =
            new UrlBuilder(getSystem().getSkinParam().getValue("topurl"), true);
        urlActivity = urlBuilder.getUrl(lines.get(i));
        if (urlActivity != null) {
          continue;
        }
      }
      sb.append(lines.get(i));
      if (i < lines.size() - 2) {
        sb.append("\\n");
      }
    }

    final List<String> lineLast =
        StringUtils.getSplit(Pattern.compile(getPatternEnd()), lines.get(lines.size() - 1));
    if (StringUtils.isNotEmpty(lineLast.get(0))) {
      if (sb.length() > 0 && sb.toString().endsWith("\\n") == false) {
        sb.append("\\n");
      }
      sb.append(lineLast.get(0));
    }

    final String display = sb.toString();
    final Code code = Code.of(lineLast.get(1) == null ? display : lineLast.get(1));

    String partition = null;
    if (lineLast.get(3) != null) {
      partition = lineLast.get(3);
      partition = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(partition);
    }
    if (partition != null) {
      getSystem()
          .getOrCreateGroup(
              Code.of(partition),
              StringUtils.getWithNewlines(partition),
              null,
              GroupType.PACKAGE,
              null);
    }
    final IEntity entity2 =
        getSystem().createLeaf(code, StringUtils.getWithNewlines(display), LeafType.ACTIVITY);
    if (partition != null) {
      getSystem().endGroup();
    }
    if (urlActivity != null) {
      entity2.addUrl(urlActivity);
    }

    if (lineLast.get(2) != null) {
      entity2.setStereotype(new Stereotype(lineLast.get(2)));
    }
    if (lineLast.get(4) != null) {
      entity2.setSpecificBackcolor(HtmlColorUtils.getColorIfValid(lineLast.get(4)));
    }

    if (entity1 == null || entity2 == null) {
      return CommandExecutionResult.error("No such entity");
    }

    final String arrow = StringUtils.manageArrowForCuca(line0.get("ARROW", 0));
    final int lenght = arrow.length() - 1;

    final String linkLabel = line0.get("BRACKET", 0);

    LinkType type = new LinkType(LinkDecor.ARROW, LinkDecor.NONE);
    if (line0.get("ARROW", 0).contains(".")) {
      type = type.getDotted();
    }
    Link link = new Link(entity1, entity2, type, linkLabel, lenght);
    final Direction direction = StringUtils.getArrowDirection(line0.get("ARROW", 0));
    if (direction == Direction.LEFT || direction == Direction.UP) {
      link = link.getInv();
    }

    if (line0.get("URL", 0) != null) {
      final UrlBuilder urlBuilder =
          new UrlBuilder(getSystem().getSkinParam().getValue("topurl"), true);
      final Url urlLink = urlBuilder.getUrl(line0.get("URL", 0));
      link.setUrl(urlLink);
    }

    getSystem().addLink(link);

    return CommandExecutionResult.ok();
  }
  @Override
  protected CommandExecutionResult executeArg(StateDiagram diagram, RegexResult arg) {
    final String ent1 = arg.get("ENT1", 0);
    final String ent2 = arg.get("ENT2", 0);

    final IEntity cl1 = getEntityStart(diagram, ent1);
    if (cl1 == null) {
      return CommandExecutionResult.error(
          "The state "
              + ent1
              + " has been created in a concurrent state : it cannot be used here.");
    }
    final IEntity cl2 = getEntityEnd(diagram, ent2);
    if (cl2 == null) {
      return CommandExecutionResult.error(
          "The state "
              + ent2
              + " has been created in a concurrent state : it cannot be used here.");
    }

    if (arg.get("ENT1", 1) != null) {
      cl1.setStereotype(new Stereotype(arg.get("ENT1", 1)));
    }
    if (arg.get("ENT1", 2) != null) {
      cl1.setSpecificColorTOBEREMOVED(
          ColorType.BACK,
          diagram.getSkinParam().getIHtmlColorSet().getColorIfValid(arg.get("ENT1", 2)));
    }
    if (arg.get("ENT2", 1) != null) {
      cl2.setStereotype(new Stereotype(arg.get("ENT2", 1)));
    }
    if (arg.get("ENT2", 2) != null) {
      cl2.setSpecificColorTOBEREMOVED(
          ColorType.BACK,
          diagram.getSkinParam().getIHtmlColorSet().getColorIfValid(arg.get("ENT2", 2)));
    }

    String queue = arg.get("ARROW_BODY1", 0) + arg.get("ARROW_BODY2", 0);
    final Direction dir = getDirection(arg);

    if (dir == Direction.LEFT || dir == Direction.RIGHT) {
      queue = "-";
    }

    final int lenght = queue.length();

    final boolean crossStart = arg.get("ARROW_CROSS_START", 0) != null;
    final boolean circleEnd = arg.get("ARROW_CIRCLE_END", 0) != null;
    final LinkType linkType =
        new LinkType(
            circleEnd ? LinkDecor.ARROW_AND_CIRCLE : LinkDecor.ARROW,
            crossStart ? LinkDecor.CIRCLE_CROSS : LinkDecor.NONE);

    Link link = new Link(cl1, cl2, linkType, Display.getWithNewlines(arg.get("LABEL", 0)), lenght);
    if (dir == Direction.LEFT || dir == Direction.UP) {
      link = link.getInv();
    }
    CommandLinkClass.applyStyle(arg.getLazzy("ARROW_STYLE", 0), link);
    diagram.addLink(link);

    return CommandExecutionResult.ok();
  }