예제 #1
0
파일: Static.java 프로젝트: jzuijlek/Lucee
  private String getFullname(Tag tag, String defaultValue) {
    if (tag != null) {
      String fn = tag.getFullname();
      if (StringUtil.isEmpty(fn)) fn = tag.getTagLibTag().getFullName();
      if (!StringUtil.isEmpty(fn)) return fn;
    }

    return defaultValue;
  }
예제 #2
0
파일: ASMUtil.java 프로젝트: denuno/Lucee4
  /**
   * Prueft ob das angegebene Tag innerhalb seiner Ebene einmalig ist oder nicht.
   *
   * @param tag Ausgangspunkt, nach diesem tag darf das angegebene nicht vorkommen.
   * @return kommt das Tag vor.
   */
  public static boolean hasSisterTagWithSameName(Tag tag) {

    Body body = (Body) tag.getParent();
    List<Statement> stats = body.getStatements();
    Iterator<Statement> it = stats.iterator();
    Statement other;
    String name = tag.getTagLibTag().getName();

    while (it.hasNext()) {
      other = it.next();
      if (other != tag
          && other instanceof Tag
          && ((Tag) other).getTagLibTag().getName().equals(name)) return true;
    }
    return false;
  }
예제 #3
0
파일: ASMUtil.java 프로젝트: denuno/Lucee4
 /**
  * Gibt das uebergeordnete CFXD Tag Element zurueck, falls dies nicht existiert wird null
  * zurueckgegeben.
  *
  * @param el Element von dem das parent Element zurueckgegeben werden soll.
  * @return uebergeordnete CFXD Tag Element
  */
 public static Tag getParentTag(Tag tag) {
   Statement p = tag.getParent();
   if (p == null) return null;
   p = p.getParent();
   if (p instanceof Tag) return (Tag) p;
   return null;
 }
예제 #4
0
파일: ASMUtil.java 프로젝트: denuno/Lucee4
  /**
   * replace src with trg
   *
   * @param src
   * @param trg
   */
  public static void replace(Tag src, Tag trg, boolean moveBody) {
    trg.setParent(src.getParent());

    Body p = (Body) src.getParent();
    List<Statement> stats = p.getStatements();
    Iterator<Statement> it = stats.iterator();
    Statement stat;
    int count = 0;

    while (it.hasNext()) {
      stat = it.next();
      if (stat == src) {
        if (moveBody && src.getBody() != null) src.getBody().setParent(trg);
        stats.set(count, trg);
        break;
      }
      count++;
    }
  }
예제 #5
0
파일: ASMUtil.java 프로젝트: denuno/Lucee4
  public static boolean isLiteralAttribute(
      Tag tag, Attribute attr, short type, boolean required, boolean throwWhenNot)
      throws EvaluatorException {
    String strType = "/constant";
    if (attr != null && !isNull(attr.getValue())) {

      switch (type) {
        case TYPE_ALL:
          if (attr.getValue() instanceof Literal) return true;
          break;
        case TYPE_BOOLEAN:
          if (CastBoolean.toExprBoolean(attr.getValue()) instanceof LitBoolean) return true;
          strType = " boolean";
          break;
        case TYPE_NUMERIC:
          if (CastDouble.toExprDouble(attr.getValue()) instanceof LitDouble) return true;
          strType = " numeric";
          break;
        case TYPE_STRING:
          if (CastString.toExprString(attr.getValue()) instanceof LitString) return true;
          strType = " string";
          break;
      }
      if (!throwWhenNot) return false;
      throw new EvaluatorException(
          "Attribute ["
              + attr.getName()
              + "] of the Tag ["
              + tag.getFullname()
              + "] must be a literal"
              + strType
              + " value. "
              + "attributes java class type "
              + attr.getValue().getClass().getName());
    }
    if (required) {
      if (!throwWhenNot) return false;
      throw new EvaluatorException(
          "Attribute [" + attr.getName() + "] of the Tag [" + tag.getFullname() + "] is required");
    }
    return false;
  }
예제 #6
0
파일: ASMUtil.java 프로젝트: denuno/Lucee4
 /**
  * Gibt ein uebergeordnetes Tag mit dem uebergebenen Full-Name (Namespace und Name) zurueck, falls
  * ein solches existiert, andernfalls wird null zurueckgegeben.
  *
  * @param el Startelement, von wo aus gesucht werden soll.
  * @param fullName Name des gesuchten Tags.
  * @return uebergeornetes Element oder null.
  */
 public static Tag getAncestorTag(Tag tag, String fullName) {
   Statement parent = tag;
   while (true) {
     parent = parent.getParent();
     if (parent == null) return null;
     if (parent instanceof Tag) {
       tag = (Tag) parent;
       if (tag.getFullname().equalsIgnoreCase(fullName)) return tag;
     }
   }
 }
예제 #7
0
파일: Static.java 프로젝트: jzuijlek/Lucee
  @Override
  public void evaluate(Tag tag, TagLibTag libTag) throws EvaluatorException {

    // check parent
    Body body = null;

    String compName = Property.getComponentName(tag);

    boolean isCompChild = false;
    Tag p = ASMUtil.getParentTag(tag);

    if (p != null && (p instanceof TagComponent || getFullname(p, "").equalsIgnoreCase(compName))) {
      isCompChild = true;
      body = p.getBody();
    }

    Tag pp = p != null ? ASMUtil.getParentTag(p) : null;
    if (!isCompChild
        && pp != null
        && (p instanceof TagComponent || getFullname(pp, "").equalsIgnoreCase(compName))) {
      isCompChild = true;
      body = pp.getBody();
    }

    if (!isCompChild) {
      throw new EvaluatorException(
          "Wrong Context for the the static constructor, "
              + "a static constructor must inside a component body.");
    }

    // Body body=(Body) tag.getParent();
    List<Statement> children = tag.getBody().getStatements();

    // remove that tag from parent
    ASMUtil.remove(tag);

    StaticBody sb = getStaticBody(body);
    ASMUtil.addStatements(sb, children);
  }
예제 #8
0
파일: ASMUtil.java 프로젝트: denuno/Lucee4
 public static void removeLiterlChildren(Tag tag, boolean recursive) {
   Body body = tag.getBody();
   if (body != null) {
     List<Statement> list = body.getStatements();
     Statement[] stats = list.toArray(new Statement[list.size()]);
     PrintOut po;
     Tag t;
     for (int i = 0; i < stats.length; i++) {
       if (stats[i] instanceof PrintOut) {
         po = (PrintOut) stats[i];
         if (po.getExpr() instanceof Literal) {
           body.getStatements().remove(po);
         }
       } else if (recursive && stats[i] instanceof Tag) {
         t = (Tag) stats[i];
         if (t.getTagLibTag().isAllowRemovingLiteral()) {
           removeLiterlChildren(t, recursive);
         }
       }
     }
   }
 }
예제 #9
0
파일: ASMUtil.java 프로젝트: denuno/Lucee4
  /**
   * Prueft ob das das angegebene Tag in der gleichen Ebene nach dem angegebenen Tag vorkommt.
   *
   * @param tag Ausgangspunkt, nach diesem tag darf das angegebene nicht vorkommen.
   * @param nameToFind Tag Name der nicht vorkommen darf
   * @return kommt das Tag vor.
   */
  public static boolean hasSisterTagAfter(Tag tag, String nameToFind) {
    Body body = (Body) tag.getParent();
    List<Statement> stats = body.getStatements();
    Iterator<Statement> it = stats.iterator();
    Statement other;

    boolean isAfter = false;
    while (it.hasNext()) {
      other = it.next();

      if (other instanceof Tag) {
        if (isAfter) {
          if (((Tag) other).getTagLibTag().getName().equals(nameToFind)) return true;
        } else if (other == tag) isAfter = true;
      }
    }
    return false;
  }
예제 #10
0
파일: ASMUtil.java 프로젝트: denuno/Lucee4
 public static boolean isLiteralAttribute(
     Tag tag, String attrName, short type, boolean required, boolean throwWhenNot)
     throws EvaluatorException {
   return isLiteralAttribute(tag, tag.getAttribute(attrName), type, required, throwWhenNot);
 }
예제 #11
0
파일: ASMUtil.java 프로젝트: denuno/Lucee4
 /**
  * remove this tag from his parent body
  *
  * @param tag
  */
 public static void remove(Tag tag) {
   Body body = (Body) tag.getParent();
   body.getStatements().remove(tag);
 }
예제 #12
0
파일: ASMUtil.java 프로젝트: denuno/Lucee4
 /**
  * extract the content of a attribut
  *
  * @param cfxdTag
  * @param attrName
  * @return attribute value
  * @throws EvaluatorException
  */
 public static Literal getAttributeLiteral(Tag tag, String attrName, Literal defaultValue) {
   Attribute attr = tag.getAttribute(attrName);
   if (attr != null && attr.getValue() instanceof Literal) return ((Literal) attr.getValue());
   return defaultValue;
 }
예제 #13
0
파일: ASMUtil.java 프로젝트: denuno/Lucee4
 /**
  * extract the content of a attribut
  *
  * @param cfxdTag
  * @param attrName
  * @return attribute value
  * @throws EvaluatorException
  */
 public static Literal getAttributeLiteral(Tag tag, String attrName) throws EvaluatorException {
   Attribute attr = tag.getAttribute(attrName);
   if (attr != null && attr.getValue() instanceof Literal) return ((Literal) attr.getValue());
   throw new EvaluatorException("attribute [" + attrName + "] must be a constant value");
 }
예제 #14
0
파일: ASMUtil.java 프로젝트: denuno/Lucee4
 public static boolean isParentTag(Tag tag, Class clazz) {
   Tag p = getParentTag(tag);
   if (p == null) return false;
   return p.getClass() == clazz;
 }
예제 #15
0
파일: ASMUtil.java 프로젝트: denuno/Lucee4
 public static boolean isParentTag(Tag tag, String fullName) {
   Tag p = getParentTag(tag);
   if (p == null) return false;
   return p.getFullname().equalsIgnoreCase(fullName);
 }