Java 类org.apache.velocity.runtime.parser.node.ASTBlock 实例源码

项目:sundrio    文件:ClassDirective.java   
@Override
public boolean render(InternalContextAdapter context, Writer writer, Node node) throws IOException {
    String block = "";
    TypeDef clazz = null;
    for (int i = 0; i < node.jjtGetNumChildren(); i++) {
        if (node.jjtGetChild(i) != null) {
            if (!(node.jjtGetChild(i) instanceof ASTBlock)) {
                //reading and casting inline parameters
                if (i == 0) {
                    clazz = (TypeDef) node.jjtGetChild(i).value(context);
                } else {
                    break;
                }
            } else {
                //reading block content and rendering it
                StringWriter blockContent = new StringWriter();
                node.jjtGetChild(i).render(context, blockContent);

                block = blockContent.toString();
                break;
            }
        }
    }
    writeClazz(writer, clazz, block);
    return true;
}
项目:velocity-scripting    文件:WhereDirective.java   
@Override
protected Params getParams(InternalContextAdapter context, Node node) throws IOException {
  final Params params = new Params();
  params.setPrefix("WHERE");
  params.setPrefixOverrides("AND |OR |AND\n|OR\n|AND\r|OR\r");
  if (node.jjtGetNumChildren() == 1) {
    final Node child = node.jjtGetChild(0);
    if (child instanceof ASTBlock) {
      StringWriter blockContent = new StringWriter();
      child.render(context, blockContent);
      params.setBody(blockContent.toString().trim());
      return params;
    }
  }
  return null;
}
项目:velocity-scripting    文件:SetDirective.java   
@Override
protected Params getParams(InternalContextAdapter context, Node node) throws IOException {
  final Params params = new Params();
  params.setPrefix("SET");
  params.setSuffixOverrides(",");
  if (node.jjtGetNumChildren() == 1) {
    final Node child = node.jjtGetChild(0);
    if (child instanceof ASTBlock) {
      StringWriter blockContent = new StringWriter();
      child.render(context, blockContent);
      params.setBody(blockContent.toString().trim());
      return params;
    }
  }
  return null;
}
项目:sundrio    文件:MethodDirective.java   
@Override
public boolean render(InternalContextAdapter context, Writer writer, Node node) throws IOException {
    String block = "";
    Method method = null;
    Boolean isInterface = false;
    for (int i = 0; i < node.jjtGetNumChildren(); i++) {
        if (node.jjtGetChild(i) != null) {
            if (!(node.jjtGetChild(i) instanceof ASTBlock)) {
                //reading and casting inline parameters
                if (i == 0) {
                    method = (Method) node.jjtGetChild(i).value(context);
                } else if (i == 1) {
                    isInterface = (Boolean) node.jjtGetChild(i).value(context);
                } else {
                    break;
                }
            } else {
                //reading block content and rendering it
                StringWriter blockContent = new StringWriter();
                node.jjtGetChild(i).render(context, blockContent);

                block = blockContent.toString();
                break;
            }
        }
    }
    writeMethod(writer, method, block, isInterface);
    return true;
}
项目:mycollab    文件:TrimExtDirective.java   
protected Params getParams(final InternalContextAdapter context, final Node node) throws IOException,
        ResourceNotFoundException, ParseErrorException, MethodInvocationException {
    final Params params = new Params();
    final int nodes = node.jjtGetNumChildren();
    for (int i = 0; i < nodes; i++) {
        Node child = node.jjtGetChild(i);
        if (child != null) {
            if (!(child instanceof ASTBlock)) {
                if (i == 0) {
                    params.setPrefix(String.valueOf(child.value(context)));
                } else if (i == 1) {
                    params.setPrefixOverrides(String.valueOf(child.value(context)).toUpperCase(Locale.ENGLISH));
                } else if (i == 2) {
                    params.setSuffix(String.valueOf(child.value(context)));
                } else if (i == 3) {
                    params.setSuffixOverrides(String.valueOf(child.value(context)).toUpperCase(Locale.ENGLISH));
                } else {
                    break;
                }
            } else {
                StringWriter blockContent = new StringWriter();
                child.render(context, blockContent);
                if ("".equals(blockContent.toString().trim())) {
                    return null;
                }
                params.setBody(blockContent.toString().trim());
                break;
            }
        }
    }
    return params;
}
项目:velocity-scripting    文件:TrimDirective.java   
protected Params getParams(final InternalContextAdapter context, final Node node) throws IOException {
  final Params params = new Params();
  final int nodes = node.jjtGetNumChildren();
  for (int i = 0; i < nodes; i++) {
    Node child = node.jjtGetChild(i);
    if (child != null) {
      if (!(child instanceof ASTBlock)) {
        if (i == 0) {
          params.setPrefix(String.valueOf(child.value(context)));
        }
        else if (i == 1) {
          params.setPrefixOverrides(String.valueOf(child.value(context)).toUpperCase(Locale.ENGLISH));
        }
        else if (i == 2) {
          params.setSuffix(String.valueOf(child.value(context)));
        }
        else if (i == 3) {
          params.setSuffixOverrides(String.valueOf(child.value(context)).toUpperCase(Locale.ENGLISH));
        }
        else {
          break;
        }
      }
      else {
        StringWriter blockContent = new StringWriter();
        child.render(context, blockContent);
        params.setBody(blockContent.toString().trim());
        break;
      }
    }
  }
  return params;
}
项目:velocity-edit    文件:NodeVisitor.java   
/**
 * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTBlock,
 *      java.lang.Object)
 */
public Object visit(ASTBlock aNode, Object aData)
{
    return aNode.childrenAccept(this, aData);
}