Example #1
0
  /**
   * @see
   *     railo.transformer.cfml.evaluator.EvaluatorSupport#evaluate(railo.transformer.bytecode.statement.tag.Tag,
   *     railo.transformer.library.tag.TagLibTag, railo.transformer.library.function.FunctionLib[])
   */
  public void evaluate(Tag tag, TagLibTag tagLibTag, FunctionLib[] flibs)
      throws EvaluatorException {
    String id = "sprite_" + IDGenerator.intId();
    try {
      Page page = ASMUtil.getAncestorPage(tag);
      String key = Md5.getDigestAsString(Thread.currentThread().getId() + ":" + page.getSource());
      Expression src = tag.getAttribute("src").getValue();

      // get data from previous sprites
      Previous previous = sprites.get(key);
      if (previous != null) {
        previous.tag.removeAttribute("_ids");
        previous.tag.removeAttribute("_srcs");
        previous.tag = tag;
      } else {
        sprites.put(key, previous = new Previous(tag));
      }

      previous.ids.add(id);
      if (previous.src == null) previous.src = src;
      else {
        previous.src = OpString.toExprString(previous.src, DELIMITER);
        previous.src = OpString.toExprString(previous.src, src);
      }

      tag.addAttribute(new Attribute(false, "_id", LitString.toExprString(id), "string"));
      tag.addAttribute(
          new Attribute(
              false,
              "_ids",
              LitString.toExprString(
                  railo.runtime.type.util.ListUtil.listToList(previous.ids, ",")),
              "string"));

      tag.addAttribute(new Attribute(false, "_srcs", previous.src, "string"));

    } catch (Throwable e) { // TODO handle Excpetion much more precise
      throw new PageRuntimeException(Caster.toPageException(e));
    }
  }