Beispiel #1
0
 // TODO: Long term we need a markdown engine :)
 public static void markup(Element e, String text, String linkCssClass) {
   e.setInnerHTML("");
   List<String> paragraphs = StringUtils.split(text, "\n\n");
   for (String paragraph : paragraphs) {
     markupParagraph(e, paragraph, linkCssClass);
   }
 }
Beispiel #2
0
 public static void addClassesToElement(Element e, String... classNames) {
   for (String className : classNames) {
     if (!StringUtils.isNullOrEmpty(className)) {
       addClassName(className, e);
     }
   }
 }
Beispiel #3
0
 public static void setCollideTitle(String subtitle) {
   if (StringUtils.isNullOrEmpty(subtitle)) {
     getDocument().setTitle("Collide");
   } else {
     getDocument().setTitle(subtitle + " - Collide");
   }
 }
Beispiel #4
0
 /** {@inheritDoc} */
 @NotNull
 @Override
 public String getActiveTime() {
   return isAlive()
       ? StringUtils.timeSecToHumanReadable(
           (System.currentTimeMillis() - creationTime) / ONE_SEC.getValue())
       : TIMER_STUB;
 }
Beispiel #5
0
  @NotNull
  private String getLifeTime(@NotNull RunnerMetric lifeTimeMetric) {
    String lifeTimeValue = lifeTimeMetric.getValue();

    if (RunnerMetric.ALWAYS_ON.equals(lifeTimeValue)) {
      return lifeTimeValue;
    }

    if (lifeTimeValue == null) {
      return TIMER_STUB;
    }
    double lifeTime = NUMBER_FORMAT.parse(lifeTimeValue);

    return StringUtils.timeMlsToHumanReadable((long) lifeTime);
  }
Beispiel #6
0
  @NotNull
  private String getTimeOut(@NotNull RunnerMetric timeoutMetric) {
    String timeout = timeoutMetric.getValue();

    if (RunnerMetric.ALWAYS_ON.equals(timeout)) {
      return timeout;
    }

    if (timeout == null) {
      return TIMER_STUB;
    }

    double terminationTime = NUMBER_FORMAT.parse(timeout);
    double terminationTimeout = terminationTime - System.currentTimeMillis();

    if (terminationTimeout <= 0) {
      return TIMER_STUB;
    }

    return StringUtils.timeMlsToHumanReadable((long) terminationTimeout);
  }
Beispiel #7
0
  /** Creates a paragraph tag and fills it with spans and anchor tags internally. */
  private static void markupParagraph(Element parent, String text, String linkCssClass) {
    if (StringUtils.isNullOrWhitespace(text)) {
      // don't add any dom here
      return;
    }

    ParagraphElement myParagraph = createParagraphElement();
    int index = 0;
    REGEXP_MARKUP.setLastIndex(0);

    SpanElement current = createSpanElement();
    for (MatchResult match = REGEXP_MARKUP.exec(text);
        match != null;
        match = REGEXP_MARKUP.exec(text)) {
      current.setTextContent(text.substring(index, match.getIndex()));
      myParagraph.appendChild(current);
      current = createSpanElement();

      /*
       * If our match is a \n we need to create a <br/> element to force a line break, otherwise we
       * matched an http/www link so let's make an anchor tag out of it.
       */
      if (match.getGroup(0).equals("\n")) {
        myParagraph.appendChild(createBRElement());
      } else {
        AnchorElement anchor = createAnchorElement(linkCssClass);
        anchor.setHref(match.getGroup(0));
        anchor.setTarget("_blank");
        anchor.setTextContent(match.getGroup(0));
        myParagraph.appendChild(anchor);
      }

      index = match.getIndex() + match.getGroup(0).length();
    }
    current.setTextContent(text.substring(index));
    myParagraph.appendChild(current);
    parent.appendChild(myParagraph);
  }