@Override
 public void render(Writer out) throws TemplateException, IOException {
   if (body == null) return;
   TemplateDirectiveBodyOverrideWraper preOverridy =
       (TemplateDirectiveBodyOverrideWraper) env.getVariable(DirectiveKit.OVERRIDE_CURRENT_NODE);
   try {
     env.setVariable(DirectiveKit.OVERRIDE_CURRENT_NODE, this);
     body.render(out);
   } finally {
     env.setVariable(DirectiveKit.OVERRIDE_CURRENT_NODE, preOverridy);
   }
 }
Ejemplo n.º 2
0
  public void execute(
      Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
      throws TemplateException, IOException {

    TemplateDirectiveBodyOverrideWraper current =
        (TemplateDirectiveBodyOverrideWraper) env.getVariable(DirectiveUtils.OVERRIDE_CURRENT_NODE);
    if (current == null) {
      throw new TemplateException("<@super/> direction must be child of override", env);
    }
    TemplateDirectiveBody parent = current.parentBody;
    if (parent == null) {
      throw new TemplateException("not found parent for <@super/>", env);
    }
    parent.render(env.getOut());
  }
 /**
  * 將要輸出的TemplateModel放到env的variable中
  *
  * @param env
  * @param variables
  * @return
  * @throws TemplateException
  */
 public Map<String, TemplateModel> addVariables(
     Environment env, Map<String, TemplateModel> variables) throws TemplateException {
   Map<String, TemplateModel> origVariables = new HashMap<String, TemplateModel>();
   if (variables.size() <= 0) {
     return origVariables;
   }
   //
   for (Map.Entry<String, TemplateModel> entry : variables.entrySet()) {
     String key = entry.getKey();
     TemplateModel value = env.getVariable(key);
     if (value != null) {
       origVariables.put(key, value);
     }
     env.setVariable(key, entry.getValue());
   }
   return origVariables;
 }
Ejemplo n.º 4
0
 /**
  * 获取变量
  *
  * @param name 名称
  * @param env Environment
  * @return 变量
  */
 public static TemplateModel getVariable(String name, Environment env)
     throws TemplateModelException {
   Assert.hasText(name);
   Assert.notNull(env);
   return env.getVariable(name);
 }