示例#1
0
 /**
  * 设置变量
  *
  * @param name 名称
  * @param value 变量值
  * @param env Environment
  */
 public static void setVariable(String name, Object value, Environment env)
     throws TemplateException {
   Assert.hasText(name);
   Assert.notNull(env);
   if (value instanceof TemplateModel) {
     env.setVariable(name, (TemplateModel) value);
   } else {
     env.setVariable(name, ObjectWrapper.BEANS_WRAPPER.wrap(value));
   }
 }
 @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);
   }
 }
示例#3
0
 /**
  * 设置变量
  *
  * @param variables 变量
  * @param env Environment
  */
 public static void setVariables(Map<String, Object> variables, Environment env)
     throws TemplateException {
   Assert.notNull(variables);
   Assert.notNull(env);
   for (Entry<String, Object> entry : variables.entrySet()) {
     String name = entry.getKey();
     Object value = entry.getValue();
     if (value instanceof TemplateModel) {
       env.setVariable(name, (TemplateModel) value);
     } else {
       env.setVariable(name, ObjectWrapper.BEANS_WRAPPER.wrap(value));
     }
   }
 }
示例#4
0
  @Override
  public void execute(
      Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
      throws TemplateException, IOException {

    Integer folderId = Integer.parseInt(params.get("folderId").toString());

    try {
      Folder folder = folderService.getFolderById(folderId);
      env.setVariable("tag_folder", DEFAULT_WRAPPER.wrap(folder));
    } catch (FolderNotFoundException e) {
      env.setVariable("tag_folder", DEFAULT_WRAPPER.wrap(new Folder()));
    }
    body.render(env.getOut());
  }
示例#5
0
  @Override
  public void execute(Environment e, Map map, TemplateModel[] tms, TemplateDirectiveBody tdb)
      throws TemplateException, IOException {
    HttpServletRequest request = (HttpServletRequest) e.getCustomAttribute("request");
    URLQueryHandler urlSetter = (URLQueryHandler) e.getCustomAttribute("urlSetter");

    String controllerName = map.get("provider").toString();
    String actionName = map.get("method").toString();
    String dataname = map.get("name").toString();

    HashMap<String, Object> ct = (HashMap<String, Object>) map;

    try {
      String className = JpageController.get().getClassName(controllerName);
      if (className != null && className.length() > 0) {
        Object x = Class.forName(className).newInstance();
        HashMap<String, Object> mapx = new HashMap<String, Object>();
        mapx.put("out", e.getOut());
        mapx.put("request", request);
        mapx.put("parameters", ct);
        mapx.put("urlSetter", urlSetter);

        ObjectSnooper obj = ObjectSnooper.snoop(x);
        obj.sett(mapx);
        obj.set(this._get(request));
        Object result = obj.trigger(actionName);
        obj.triggerr("close");

        HashMap<String, Object> xxtmap = new HashMap<String, Object>();
        Object xtt = obj.gett("local");
        if (xtt != null) {
          xxtmap = (HashMap<String, Object>) xtt;
        }
        e.setVariable(dataname, ObjectWrapper.DEFAULT_WRAPPER.wrap(result));
        e.setVariable(dataname + "_local", ObjectWrapper.DEFAULT_WRAPPER.wrap(xxtmap));
      }
    } catch (Exception ex) {
      ex.printStackTrace();
    }
    if (tdb != null) {
      tdb.render(e.getOut());
    }
  }
 /**
  * 移出先前放入env的variable中,TemplateModel
  *
  * @param env
  * @param variables
  * @param origVariables
  */
 public void removeVariables(
     Environment env,
     Map<String, TemplateModel> variables,
     Map<String, TemplateModel> origVariables)
     throws TemplateException {
   if (variables.size() <= 0) {
     return;
   }
   //
   for (String key : variables.keySet()) {
     env.setVariable(key, origVariables.get(key));
   }
 }
示例#7
0
 /*    */ public void execute(
     Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
     /*    */ throws TemplateException, IOException
       /*    */ {
   /* 32 */ Site site = ViewTools.getSite(env);
   /* 33 */ Integer parentId = TagModelTools.getInt("parentId", params);
   /* 34 */ List industryList = new ArrayList();
   /* 35 */ if (parentId != null)
     /* 36 */ industryList = this.industryService.getIndustryChild(parentId);
   /*    */ else {
     /* 38 */ industryList = this.industryService.getIndustryList(null);
     /*    */ }
   /* 40 */ env.setVariable("list", ObjectWrapper.DEFAULT_WRAPPER.wrap(industryList));
   /* 41 */ body.render(env.getOut());
   /* 42 */ ViewTools.includePagination(site, params, env);
   /*    */ }
 /**
  * 將要輸出的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;
 }
  @Override
  public void execute(Environment e, Map map, TemplateModel[] tms, TemplateDirectiveBody tdb)
      throws TemplateException, IOException {
    tagParameter = map;
    request = (HttpServletRequest) e.getCustomAttribute("request");
    urlSetter = (URLQueryHandler) e.getCustomAttribute("urlSetter");
    out = e.getOut();

    HashMap<String, Object> mapx = this.doService();
    if (mapx != null) {
      for (Entry<String, Object> c : mapx.entrySet()) {
        e.setVariable(c.getKey(), ObjectWrapper.DEFAULT_WRAPPER.wrap(c.getValue()));
      }
    }

    if (tdb != null) {
      tdb.render(e.getOut());
    }
  }
示例#10
0
  @Override
  public void execute(
      Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
      throws TemplateException, IOException {

    String sql = params.get("sql").toString();
    System.out.println(loopVars.length);
    System.out.println(sql);
    Channel r = new Channel();
    r.setName("dsadsadasd");
    List a = new ArrayList();
    a.add(r);
    a.add(r);
    a.add(r);
    a.add(r);
    a.add(r);
    env.setVariable("userlist", ObjectWrapper.DEFAULT_WRAPPER.wrap(a));

    env.getOut().write("3424234234");
    body.render(env.getOut());
  }