Package cn.org.rapid_framework.velocity.directive

Source Code of cn.org.rapid_framework.velocity.directive.SuperDirective

package cn.org.rapid_framework.velocity.directive;

import java.io.IOException;
import java.io.Writer;

import org.apache.velocity.context.InternalContextAdapter;
import org.apache.velocity.exception.MethodInvocationException;
import org.apache.velocity.exception.ParseErrorException;
import org.apache.velocity.exception.ResourceNotFoundException;
import org.apache.velocity.runtime.parser.node.Node;

import cn.org.rapid_framework.velocity.directive.OverrideDirective.OverrideNodeWrapper;

/**
* @author badqiu
*/
public class SuperDirective extends org.apache.velocity.runtime.directive.Directive{

  @Override
  public String getName() {
    return "super";
  }

  @Override
  public int getType() {
    return LINE;
  }

  @Override
  public boolean render(InternalContextAdapter context, Writer writer, Node node)
      throws IOException, ResourceNotFoundException, ParseErrorException,MethodInvocationException {
   
    OverrideNodeWrapper current = (OverrideNodeWrapper)context.get(Utils.OVERRIDE_CURRENT_NODE);
    if(current == null) {
      throw new ParseErrorException("#super direction must be child of override");
    }
    OverrideNodeWrapper parent = current.parentNode;
    if(parent == null) {
      throw new ParseErrorException("not found parent block for #super ");
    }
    return parent.render(context,writer);
  }



}
TOP

Related Classes of cn.org.rapid_framework.velocity.directive.SuperDirective

TOP
Copyright © 2018 www.massapi.com. 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.