Exemplo n.º 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));
    }
  }
Exemplo n.º 2
0
  /**
   * @see
   *     railo.transformer.cfml.attributes.AttributeEvaluator#evaluate(railo.transformer.library.tag.TagLibTag,
   *     org.w3c.dom.Element)
   */
  public TagLibTag evaluate(TagLibTag tagLibTag, Tag tag) throws AttributeEvaluatorException {
    tagLibTag.setParseBody(false);

    Attribute attrOutput = tag.getAttribute("output");
    if (attrOutput == null) return tagLibTag;

    Expression expr = CastBoolean.toExprBoolean(attrOutput.getValue());

    if (!(expr instanceof LitBoolean))
      throw new AttributeEvaluatorException(
          "Attribute output of the Tag Function, must be a literal boolean value (true or false)");
    boolean output = ((LitBoolean) expr).getBooleanValue();
    if (output) tagLibTag.setParseBody(true);

    return tagLibTag;
  }
Exemplo n.º 3
0
  @Override
  public void evaluate(Tag tag, TagLibTag libTag) throws EvaluatorException {
    String ns = libTag.getTagLib().getNameSpaceAndSeparator();
    String loopName = ns + "loop";
    String whileName = ns + "while";

    // label
    String label = null;

    Attribute attrLabel = tag.getAttribute("label");
    if (attrLabel != null) {
      TagBreak tb = (TagBreak) tag;
      label = variableToString(tag, attrLabel, null);
      if (label != null) {
        tb.setLabel(label = label.trim());
        tag.removeAttribute("label");
      } else if (ASMUtil.isLiteralAttribute(tag, attrLabel, ASMUtil.TYPE_STRING, false, true)) {
        LitString ls = (LitString) CastString.toExprString(tag.getAttribute("label").getValue());
        label = ls.getString();
        if (!StringUtil.isEmpty(label, true)) {
          tb.setLabel(label = label.trim());
          tag.removeAttribute("label");
        } else label = null;
      }
    }

    // no base tag found
    if (!ASMUtil.hasAncestorBreakFCStatement(tag, label)) {
      if (tag.isScriptBase()) {
        if (StringUtil.isEmpty(label))
          throw new EvaluatorException(
              "Wrong Context, " + libTag.getName() + " must be inside a looping statement or tag");
        throw new EvaluatorException(
            "Wrong Context, "
                + libTag.getName()
                + " must be inside a looping statement or tag with the label ["
                + label
                + "]");
      }

      if (StringUtil.isEmpty(label))
        throw new EvaluatorException(
            "Wrong Context, tag "
                + libTag.getFullName()
                + " must be inside a "
                + loopName
                + " or "
                + whileName
                + " tag");
      throw new EvaluatorException(
          "Wrong Context, tag "
              + libTag.getFullName()
              + " must be inside a "
              + loopName
              + " or "
              + whileName
              + " tag with the label ["
              + label
              + "]");
    }
  }