示例#1
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();
  }
  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();
  }