private String concat(final List<? extends CharSequence> strings) {
   final StringBuilder sb = new StringBuilder();
   for (CharSequence s : strings) {
     sb.append(StringUtils.trin(s));
   }
   return sb.toString();
 }
示例#2
0
 public Url initUrl() {
   if (this.size() == 0) {
     return null;
   }
   final UrlBuilder urlBuilder = new UrlBuilder(null, ModeUrl.AT_START);
   return urlBuilder.getUrl(StringUtils.trin(this.get(0).toString()));
 }
示例#3
0
  public void draw(
      UShape ushape, double x, double y, ColorMapper mapper, UParam param, SvgGraphics svg) {

    final UClip clip = clipContainer.getClip();
    if (clip != null && clip.isInside(x, y) == false) {
      return;
    }

    final UText shape = (UText) ushape;
    final FontConfiguration fontConfiguration = shape.getFontConfiguration();
    final UFont font = fontConfiguration.getFont();
    String fontWeight = null;
    if (fontConfiguration.containsStyle(FontStyle.BOLD) || font.isBold()) {
      fontWeight = "bold";
    }
    String fontStyle = null;
    if (fontConfiguration.containsStyle(FontStyle.ITALIC) || font.isItalic()) {
      fontStyle = "italic";
    }
    String textDecoration = null;
    if (fontConfiguration.containsStyle(FontStyle.UNDERLINE)) {
      textDecoration = "underline";
    } else if (fontConfiguration.containsStyle(FontStyle.STRIKE)) {
      textDecoration = "line-through";
    }

    String backColor = null;
    if (fontConfiguration.containsStyle(FontStyle.BACKCOLOR)) {
      backColor =
          StringUtils.getAsHtml(mapper.getMappedColor(fontConfiguration.getExtendedColor()));
    }

    svg.setFillColor(StringUtils.getAsHtml(mapper.getMappedColor(fontConfiguration.getColor())));
    String text = shape.getText();
    if (text.startsWith(" ")) {
      final double space = stringBounder.calculateDimension(font, " ").getWidth();
      while (text.startsWith(" ")) {
        x += space;
        text = text.substring(1);
      }
    }
    text = StringUtils.trin(text);
    final Dimension2D dim = stringBounder.calculateDimension(font, text);
    svg.text(
        text,
        x,
        y,
        font.getFamily(UFontContext.SVG),
        font.getSize(),
        fontWeight,
        fontStyle,
        textDecoration,
        dim.getWidth(),
        fontConfiguration.getAttributes(),
        backColor);
  }
示例#4
0
 private static List<CharSequence> manageEmbededDiagrams2(
     final Collection<? extends CharSequence> strings) {
   final List<CharSequence> result = new ArrayList<CharSequence>();
   final Iterator<? extends CharSequence> it = strings.iterator();
   while (it.hasNext()) {
     CharSequence s = it.next();
     if (s != null && StringUtils.trin(s.toString()).equals("{{")) {
       final List<CharSequence> other = new ArrayList<CharSequence>();
       other.add("@startuml");
       while (it.hasNext()) {
         final CharSequence s2 = it.next();
         if (s2 != null && StringUtils.trin(s2.toString()).equals("}}")) {
           break;
         }
         other.add(s2);
       }
       other.add("@enduml");
       s = new EmbededDiagram(Display.create(other));
     }
     result.add(s);
   }
   return result;
 }
示例#5
0
 @Override
 public PSystemJcckit executeLine(PSystemJcckit system, String line) {
   if (system == null && line.startsWith("jcckit")) {
     data = new StringBuilder();
     extractDimension(line);
     return createSystem();
   }
   if (data == null) {
     return null;
   }
   data.append(StringUtils.trin(line));
   data.append("\n");
   return createSystem();
 }
示例#6
0
 public final CommandControl isValid(BlocLines lines) {
   if (lines.size() != 1) {
     return CommandControl.NOT_OK;
   }
   lines = lines.removeInnerComments();
   if (isCommandForbidden()) {
     return CommandControl.NOT_OK;
   }
   final String line = StringUtils.trin(lines.getFirst499());
   final boolean result = pattern.match(line);
   if (result) {
     actionIfCommandValid();
   }
   return result ? CommandControl.OK : CommandControl.NOT_OK;
 }
示例#7
0
  public final CommandExecutionResult execute(S system, BlocLines lines) {
    if (lines.size() != 1) {
      throw new IllegalArgumentException();
    }
    lines = lines.removeInnerComments();
    final String line = StringUtils.trin(lines.getFirst499());
    if (isForbidden(line)) {
      return CommandExecutionResult.error("Forbidden line " + line);
    }

    final RegexResult arg = pattern.matcher(line);
    if (arg == null) {
      return CommandExecutionResult.error("Cannot parse line " + line);
    }
    if (system instanceof PSystemError) {
      return CommandExecutionResult.error("PSystemError cannot be cast");
    }
    // System.err.println("lines="+lines);
    // System.err.println("pattern="+pattern.getPattern());
    return executeArg(system, arg);
  }
  @Override
  public CommandExecutionResult executeNow(ActivityDiagram3 diagram, BlocLines lines) {
    lines = lines.trim(false);
    final RegexResult line0 = getStartingPattern().matcher(StringUtils.trin(lines.getFirst499()));
    final RegexResult lineLast = getPatternEnd2().matcher(lines.getLast499().toString());

    // System.err.println("line0=" + line0);
    // System.err.println("linesLast=" + lineLast);

    //
    // final HtmlColor color =
    // diagram.getSkinParam().getIHtmlColorSet().getColorIfValid(line0.get("COLOR", 0));

    final String test = line0.get("TEST1", 0);
    Display testDisplay = Display.getWithNewlines(test);
    for (CharSequence s : lines.subExtract(1, 1)) {
      testDisplay = testDisplay.add(s);
    }
    final String trailTest = lineLast.get("TEST1", 0);
    if (StringUtils.isEmpty(trailTest) == false) {
      testDisplay = testDisplay.add(trailTest);
    }

    Display yes = Display.NULL; // Display.getWithNewlines("arg.getLazzy(\"WHEN\", 0)");
    final Display out = Display.NULL; // Display.getWithNewlines("arg.getLazzy(\"OUT\", 0)");
    final HtmlColor linkColor =
        null; // diagram.getSkinParam().getIHtmlColorSet().getColorIfValid(arg.get("COLOR",
    // 0));
    final Display linkLabel = Display.NULL; // Display.getWithNewlines("arg.get(\"LABEL\", 0)");
    final List<Display> splitted =
        testDisplay.splitMultiline(
            MyPattern.cmpile("\\)[%s]*(is|equals?)[%s]*\\(", Pattern.CASE_INSENSITIVE));
    if (splitted.size() == 2) {
      testDisplay = splitted.get(0);
      yes = splitted.get(1);
    }

    return diagram.repeatWhile(testDisplay, yes, out, linkLabel, linkColor);
  }
  public CreoleStripeSimpleParser(
      String line,
      CreoleContext creoleContext,
      FontConfiguration fontConfiguration,
      ISkinSimple skinParam,
      CreoleMode modeSimpleLine) {
    this.fontConfiguration = fontConfiguration;
    this.modeSimpleLine = modeSimpleLine;
    this.skinParam = skinParam;
    if (skinParam == null) {
      throw new IllegalArgumentException();
    }

    final Pattern p4 = MyPattern.cmpile("^--([^-]*)--$");
    final Matcher m4 = p4.matcher(line);
    if (m4.find()) {
      this.line = m4.group(1);
      this.style = new StripeStyle(StripeStyleType.HORIZONTAL_LINE, 0, '-');
      return;
    }

    final Pattern p5 = MyPattern.cmpile("^==([^=]*)==$");
    final Matcher m5 = p5.matcher(line);
    if (m5.find()) {
      this.line = m5.group(1);
      this.style = new StripeStyle(StripeStyleType.HORIZONTAL_LINE, 0, '=');
      return;
    }
    final Pattern p5b = MyPattern.cmpile("^===*==$");
    final Matcher m5b = p5b.matcher(line);
    if (m5b.find()) {
      this.line = "";
      this.style = new StripeStyle(StripeStyleType.HORIZONTAL_LINE, 0, '=');
      return;
    }

    // if (modeSimpleLine == CreoleMode.FULL) {
    // final Pattern p6 = MyPattern.cmpile("^__([^_]*)__$");
    // final Matcher m6 = p6.matcher(line);
    // if (m6.find()) {
    // this.line = m6.group(1);
    // this.style = new StripeStyle(StripeStyleType.HORIZONTAL_LINE, 0, '_');
    // return;
    // }
    // }

    final Pattern p7 = MyPattern.cmpile("^\\.\\.([^\\.]*)\\.\\.$");
    final Matcher m7 = p7.matcher(line);
    if (m7.find()) {
      this.line = m7.group(1);
      this.style = new StripeStyle(StripeStyleType.HORIZONTAL_LINE, 0, '.');
      return;
    }

    if (modeSimpleLine == CreoleMode.FULL) {
      final Pattern p1 = MyPattern.cmpile("^(\\*+)([^*]+(?:[^*]|\\*\\*[^*]+\\*\\*)*)$");
      final Matcher m1 = p1.matcher(line);
      if (m1.find()) {
        this.line = StringUtils.trin(m1.group(2));
        final int order = m1.group(1).length() - 1;
        this.style = new StripeStyle(StripeStyleType.LIST_WITHOUT_NUMBER, order, '\0');
        return;
      }
    }

    if (modeSimpleLine == CreoleMode.FULL) {
      final Pattern p2 = MyPattern.cmpile("^(#+)(.+)$");
      final Matcher m2 = p2.matcher(CharHidder.hide(line));
      if (m2.find()) {
        this.line = StringUtils.trin(CharHidder.unhide(m2.group(2)));
        final int order = CharHidder.unhide(m2.group(1)).length() - 1;
        this.style = new StripeStyle(StripeStyleType.LIST_WITH_NUMBER, order, '\0');
        return;
      }
    }

    final Pattern p3 = MyPattern.cmpile("^(=+)(.+)$");
    final Matcher m3 = p3.matcher(line);
    if (m3.find()) {
      this.line = StringUtils.trin(m3.group(2));
      final int order = m3.group(1).length() - 1;
      this.style = new StripeStyle(StripeStyleType.HEADING, order, '\0');
      return;
    }

    this.line = line;
    this.style = new StripeStyle(StripeStyleType.NORMAL, 0, '\0');
  }