Package anvil.script.statements.taglib

Examples of anvil.script.statements.taglib.Attribute


  public void parse(TemplateParser parser, anvil.parser.Tag tag)
  {
    ArrayList nodes = new ArrayList();
    Enumeration e = _tagdef.getAttributes();
    while(e.hasMoreElements()) {
      Attribute attr = (Attribute)e.nextElement();
      String name = attr.getName();
      String value = tag.getValue(attr.getName());
      if (value == null) {
        if (attr.isRequired()) {
          parser.error(parser.getLocation(), "Required attribute '"+name+"' missing");
        } else {
          value = attr.getDefault();
        }
      }
      if (value != null) {
        Node node = ConstantNode.UNDEFINED;
        switch(attr.getType()) {
        case Attribute.TYPE_STRING:
          node = new ConstantNode(Any.create(value));
          break;

        case Attribute.TYPE_DOUBLE:
          try {
            node = new ConstantNode(Any.create(Double.parseDouble(value)));
          } catch (NumberFormatException nfe) {
            parser.error(parser.getLocation(), "Value of attribute '"+name+"' is not a floating point number");
          }
          break;

        case Attribute.TYPE_INT:
          try {
            node = new ConstantNode(Any.create(anvil.util.Conversions.parseNumberUnsafe(value)));
          } catch (NumberFormatException nfe) {
            parser.error(parser.getLocation(), "Value of attribute '"+name+"' is not an integer");
          }
          break;
         
        case Attribute.TYPE_BOOLEAN:
          node = new ConstantNode(Any.create(Any.IS_BOOLEAN, value));
          break;
           
        case Attribute.TYPE_EXPR:
          value = value.trim();
          if (value.length() > 0) {
            ExpressionParser p = new ExpressionParser(parser, parser.getLocation(), value);
            node = p.parseExpression(p.TYPE_VALUE).getChild();
          } else {
            node = ConstantNode.UNDEFINED;
          }
          break;
        }
        nodes.add(new MappingNode(new ConstantNode(name), node));
      }
    }
    if (_tagdef.allowAnyAttributes()) {
      Iterator iter = _tag.getAttributes();
      while(iter.hasNext()) {
        anvil.parser.Attribute attr = (anvil.parser.Attribute)iter.next();
        String name = attr.getName();
        if (!_tagdef.hasAttribute(name)) {
          nodes.add(new MappingNode(
            new ConstantNode(name),
            new ConstantNode(attr.getValue())));
        }
      }
    }

    int n = nodes.size();
View Full Code Here

TOP

Related Classes of anvil.script.statements.taglib.Attribute

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.