Ejemplo n.º 1
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());
  }
 /**
  * @param env
  * @param body
  * @param variables
  * @throws TemplateException
  * @throws IOException
  */
 public void render(
     Environment env, TemplateDirectiveBody body, Map<String, TemplateModel> variables)
     throws TemplateException, IOException {
   Map<String, TemplateModel> origVariables = addVariables(env, variables);
   body.render(env.getOut());
   removeVariables(env, variables, origVariables);
 }
 @SuppressWarnings("unchecked")
 public void execute(
     Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
     throws TemplateException, IOException {
   CmsSite site = FrontUtils.getSite(env);
   InvokeType type = DirectiveUtils.getInvokeType(params);
   Pagination page =
       bbsTopicMng.getMemberTopic(
           site.getId(),
           getCreaterId(params),
           FrontUtils.getPageNo(env),
           FrontUtils.getCount(params));
   Map<String, TemplateModel> paramWrap = new HashMap<String, TemplateModel>(params);
   paramWrap.put(OUT_PAGINATION, DEFAULT_WRAPPER.wrap(page));
   Map<String, TemplateModel> origMap = DirectiveUtils.addParamsToVariable(env, paramWrap);
   if (InvokeType.custom == type) {
     FrontUtils.includeTpl(TPL_MY_TOPIC, site, params, env);
     FrontUtils.includePagination(site, params, env);
   } else if (InvokeType.body == type) {
     body.render(env.getOut());
     FrontUtils.includePagination(site, params, env);
   } else {
     throw new RuntimeException("invoke type not handled: " + type);
   }
   DirectiveUtils.removeParamsFromVariable(env, paramWrap, origMap);
 }
  @SuppressWarnings("unchecked")
  public void execute(
      Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
      throws TemplateException, IOException {
    CmsSite site = FrontUtils.getSite(env);
    List<ContentTag> list = contentTagMng.getListForTag(FrontUtils.getCount(params));

    Map<String, TemplateModel> paramWrap = new HashMap<String, TemplateModel>(params);
    paramWrap.put(OUT_LIST, DEFAULT_WRAPPER.wrap(list));
    Map<String, TemplateModel> origMap = DirectiveUtils.addParamsToVariable(env, paramWrap);
    InvokeType type = DirectiveUtils.getInvokeType(params);
    String listStyle = DirectiveUtils.getString(PARAM_STYLE_LIST, params);
    if (InvokeType.sysDefined == type) {
      if (StringUtils.isBlank(listStyle)) {
        throw new ParamsRequiredException(PARAM_STYLE_LIST);
      }
      env.include(TPL_STYLE_LIST + listStyle + TPL_SUFFIX, UTF8, true);
    } else if (InvokeType.userDefined == type) {
      if (StringUtils.isBlank(listStyle)) {
        throw new ParamsRequiredException(PARAM_STYLE_LIST);
      }
      FrontUtils.includeTpl(TPL_STYLE_LIST, site, env);
    } else if (InvokeType.custom == type) {
      FrontUtils.includeTpl(TPL_NAME, site, params, env);
    } else if (InvokeType.body == type) {
      body.render(env.getOut());
    } else {
      throw new RuntimeException("invoke type not handled: " + type);
    }
    DirectiveUtils.removeParamsFromVariable(env, paramWrap, origMap);
  }
Ejemplo n.º 5
0
 @Override
 public void execute(
     Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
     throws TemplateException, IOException {
   Integer count = Integer.valueOf(params.get("count").toString());
   for (int i = 0; i < count.intValue(); i++) {
     body.render(env.getOut());
   }
 }
 /** {@inheritDoc} */
 public void render(Writer writer) {
   if (body != null) {
     try {
       body.render(writer);
     } catch (Exception e) {
       throw new PrimeException(e);
     }
   }
 }
  @Override
  public void execute(
      Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
      throws TemplateException, IOException {

    String siteLanguage = LocaleContextHolder.getLocale().getLanguage();
    String langValue = ((TemplateScalarModel) params.get("lang")).getAsString();

    if (langValue.equals(siteLanguage)) {
      body.render(env.getOut());
    }
  }
 @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.º 9
0
  @Override
  public void execute(
      Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
      throws TemplateException, IOException {
    long beginTime = System.currentTimeMillis();

    Map<String, TemplateModel> paramsWrap = putRes(env, params, loopVars, body);
    Map<String, TemplateModel> origMap = DirectiveUtils.addParamsToVariable(env, paramsWrap);
    body.render(env.getOut());
    DirectiveUtils.removeParamsFromVariable(env, paramsWrap, origMap);
    long endTime = System.currentTimeMillis();
    log.debug(this.getClass().getName() + ":共耗时" + String.valueOf(endTime - beginTime) + "微秒");
  }
Ejemplo n.º 10
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());
  }
  @SuppressWarnings("unchecked")
  public void execute(
      Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
      throws TemplateException, IOException {
    Integer siteId = getSiteId(params);
    if (siteId == null) {
      siteId = FrontUtils.getSite(env).getId();
    }
    List<CmsFriendlinkCtg> list = cmsFriendlinkCtgMng.getList(siteId);

    Map<String, TemplateModel> paramWrap = new HashMap<String, TemplateModel>(params);
    paramWrap.put(OUT_LIST, DEFAULT_WRAPPER.wrap(list));
    Map<String, TemplateModel> origMap = DirectiveUtils.addParamsToVariable(env, paramWrap);
    body.render(env.getOut());
    DirectiveUtils.removeParamsFromVariable(env, paramWrap, origMap);
  }
Ejemplo n.º 12
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);
   /*    */ }
Ejemplo n.º 13
0
  @SuppressWarnings("unchecked")
  public void execute(
      Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
      throws TemplateException, IOException {
    CmsSite site = FrontUtils.getSite(env);
    Integer parentId = DirectiveUtils.getInt(PARAM_PARENT_ID, params);
    Integer siteId = DirectiveUtils.getInt(PARAM_SITE_ID, params);
    boolean hasContentOnly = getHasContentOnly(params);

    Pagination page;
    if (parentId != null) {
      page =
          channelMng.getChildPageForTag(
              parentId, hasContentOnly, FrontUtils.getPageNo(env), FrontUtils.getCount(params));
    } else {
      if (siteId == null) {
        siteId = site.getId();
      }
      page =
          channelMng.getTopPageForTag(
              siteId, hasContentOnly, FrontUtils.getPageNo(env), FrontUtils.getCount(params));
    }

    Map<String, TemplateModel> paramWrap = new HashMap<String, TemplateModel>(params);
    paramWrap.put(OUT_PAGINATION, DEFAULT_WRAPPER.wrap(page));
    Map<String, TemplateModel> origMap = DirectiveUtils.addParamsToVariable(env, paramWrap);
    InvokeType type = DirectiveUtils.getInvokeType(params);
    String listStyle = DirectiveUtils.getString(PARAM_STYLE_LIST, params);
    if (InvokeType.sysDefined == type) {
      if (StringUtils.isBlank(listStyle)) {
        throw new ParamsRequiredException(PARAM_STYLE_LIST);
      }
      env.include(TPL_STYLE_LIST + listStyle + TPL_SUFFIX, UTF8, true);
    } else if (InvokeType.userDefined == type) {
      if (StringUtils.isBlank(listStyle)) {
        throw new ParamsRequiredException(PARAM_STYLE_LIST);
      }
      FrontUtils.includeTpl(TPL_STYLE_LIST, site, env);
    } else if (InvokeType.custom == type) {
      FrontUtils.includeTpl(TPL_NAME, site, params, env);
    } else if (InvokeType.body == type) {
      body.render(env.getOut());
    } else {
      throw new RuntimeException("invoke type not handled: " + type);
    }
    DirectiveUtils.removeParamsFromVariable(env, paramWrap, origMap);
  }
Ejemplo n.º 14
0
  public void execute(
      Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
      throws TemplateException, IOException {

    // 获取参数
    // 站点id
    String siteid = getParam(params, "siteid");
    // 类型
    String type = getParam(params, "type");

    if (body != null) {
      // 设置循环变量
      if (loopVars != null && loopVars.length > 0) {

        java.text.SimpleDateFormat df = new java.text.SimpleDateFormat("yyyy-MM-dd");
        java.util.Calendar calendar = java.util.Calendar.getInstance();
        String today = df.format(calendar.getTime());
        calendar.roll(java.util.Calendar.DAY_OF_YEAR, -1);
        String yesterday = df.format(calendar.getTime());
        calendar.roll(java.util.Calendar.DAY_OF_YEAR, 1);
        if (calendar.get(java.util.Calendar.MONTH) == 0) {
          calendar.roll(java.util.Calendar.YEAR, -1);
        }
        calendar.roll(java.util.Calendar.MONTH, -1);
        String month = df.format(calendar.getTime());

        Visit visit = new Visit();
        visit.setSiteid(siteid);
        if ("today".equals(type)) {
          // 今天
          visit.setStarttime(DateUtil.parse(today, "yyyy-MM-dd"));
        } else if ("yesterday".equals(type)) {
          // 昨天
          visit.setStarttime(DateUtil.parse(yesterday, "yyyy-MM-dd"));
          visit.setEndtime(DateUtil.parse(today, "yyyy-MM-dd"));
        } else if ("month".equals(type)) {
          // 本月
          visit.setStarttime(DateUtil.parse(month, "yyyy-MM-dd"));
        }

        loopVars[0] =
            new SimpleNumber(
                visitService.count(visit, "true".equals(getParam(params, "cache")) ? true : false));
        body.render(env.getOut());
      }
    }
  }
Ejemplo n.º 15
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());
    }
  }
Ejemplo n.º 16
0
  @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());
    }
  }
Ejemplo n.º 17
0
  @Override
  @SuppressWarnings("rawtypes")
  public void execute(
      Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
      throws TemplateException, IOException {

    Boolean active = getActiveValue(params);
    if (active == null) {
      super.execute(env, params, loopVars, body);
      return;
    }
    Object objectValue = getObjectValue(env, params);
    if (objectValue != null && objectValue instanceof PageOut) {
      PageOut page = (PageOut) objectValue;
      if (page.isActive().booleanValue() == active.booleanValue()) {
        body.render(env.getOut());
      }
    }
  }
Ejemplo n.º 18
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());
  }
Ejemplo n.º 19
0
  @SuppressWarnings("unchecked")
  public void execute(
      Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
      throws TemplateException, IOException {
    Integer id = getId(params);
    Boolean next = DirectiveUtils.getBool(PRAMA_NEXT, params);
    Content content;
    if (next == null) {
      content = contentMng.findById(id);
    } else {
      CmsSite site = FrontUtils.getSite(env);
      Integer channelId = DirectiveUtils.getInt(PARAM_CHANNEL_ID, params);
      content = contentMng.getSide(id, site.getId(), channelId, next);
    }

    Map<String, TemplateModel> paramWrap = new HashMap<String, TemplateModel>(params);
    paramWrap.put(OUT_BEAN, DEFAULT_WRAPPER.wrap(content));
    Map<String, TemplateModel> origMap = DirectiveUtils.addParamsToVariable(env, paramWrap);
    body.render(env.getOut());
    DirectiveUtils.removeParamsFromVariable(env, paramWrap, origMap);
  }
Ejemplo n.º 20
0
  public void execute(
      Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
      throws TemplateException, IOException {

    // 获取参数
    // 信息id
    String infoid = getParam(params, "infoid");
    Writer out = env.getOut();
    if (body != null) {
      // 设置循环变量
      if (loopVars != null && loopVars.length > 0 && infoid.trim().length() > 0) {
        // 查询信息图片集
        InfoImg infoImg = new InfoImg();
        infoImg.setInfoid(infoid);
        List<InfoImg> infoImgList = infoImgService.find(infoImg, " ordernum ");
        if (infoImgList != null && infoImgList.size() > 0) {
          loopVars[0] = new ArrayModel(infoImgList.toArray(), new BeansWrapper());
          body.render(env.getOut());
        }
      }
    }
  }
  public void execute(
      Environment env,
      @SuppressWarnings("rawtypes") Map params,
      TemplateModel[] loopVars,
      TemplateDirectiveBody body)
      throws TemplateException, IOException {
    // Check if no parameters were given:
    if (!params.isEmpty()) {
      throw new TemplateModelException("This directive doesn't allow parameters.");
    }
    if (loopVars.length != 0) {
      throw new TemplateModelException("This directive doesn't allow loop variables.");
    }

    // If there is non-empty nested content:
    if (body != null) {
      // Executes the nested body. Same as <#nested> in FTL, except
      // that we use our own writer instead of the current output writer.
      body.render(new UpperCaseFilterWriter(env.getOut()));
    } else {
      throw new RuntimeException("missing body");
    }
  }
  @SuppressWarnings("unchecked")
  public void execute(
      Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
      throws TemplateException, IOException {
    String instantMessagingTypeString =
        DirectiveUtil.getStringParameter(INSTANT_MESSAGING_TYPE_PARAMETER_NAME, params);
    Integer count = DirectiveUtil.getIntegerParameter(COUNT_PARAMETER_NAME, params);

    InstantMessagingType instantMessagingType = null;
    if (StringUtils.isNotEmpty(instantMessagingTypeString)) {
      instantMessagingType = InstantMessagingType.valueOf(instantMessagingTypeString);
    }

    List<InstantMessaging> instantMessagingList =
        instantMessagingService.getInstantMessagingList(instantMessagingType, count);

    if (body != null && instantMessagingList != null) {
      if (loopVars.length > 0) {
        loopVars[0] = ObjectWrapper.BEANS_WRAPPER.wrap(instantMessagingList);
      }
      body.render(env.getOut());
    }
  }
Ejemplo n.º 23
0
 protected void renderBody(Environment env, TemplateDirectiveBody body)
     throws IOException, TemplateException {
   if (body != null) {
     body.render(env.getOut());
   }
 }