Example #1
0
 @Override
 @SuppressWarnings({"unchecked", "rawtypes"})
 public void execute(
     Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
     throws TemplateException, IOException {
   Site site = FrontUtils.getSite(env);
   List<Content> list = getList(params, env);
   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);
 }
 /** 保存添加和修改,对象的id不为空时,为修改,否则为添加 */
 @PageType(EnumPageType.JSONPAGE)
 @RequestMapping(value = "/save/json", method = RequestMethod.POST)
 @ResponseBody
 public DwzJson settlementSave(
     UserAgent userAgent,
     @RequestParam(required = false) String dwzId,
     @ModelAttribute("settlement") Settlement settlement,
     @RequestParam(required = false) String dwzId,
     ModelMap model) {
   DwzJson dwzJson;
   if (settlement == null) {
     dwzJson =
         new DwzJson(
             "300", this.messageSource.getMessage("operation.failed", null, this.getThisLocale()));
     return dwzJson;
   }
   if (settlement.getId() != null && settlement.getId() >= 0) {
     // 保存修改
     ServiceResult<Integer> result =
         settlementService.update(new ServiceRequest(settlement, userAgent));
     if (result.getErrorNO() != null) {
       dwzJson =
           new DwzJson(
               "300",
               this.messageSource.getMessage(
                   result.getErrorInfo(), result.getMsgArgs(), this.getThisLocale()));
     } else {
       dwzJson =
           new DwzJson(
               "200",
               this.messageSource.getMessage(
                   "operation.success", result.getMsgArgs(), this.getThisLocale()),
               StringUtils.isBlank(dwzId) ? "dwz_tab_settlement" : dwzId,
               "closeCurrent");
     }
   } else {
     // 保存新增
     ServiceResult<Settlement> result =
         settlementService.save(new ServiceRequest(settlement, userAgent));
     if (result.getErrorNO() != null) {
       dwzJson =
           new DwzJson(
               "300",
               this.messageSource.getMessage(
                   result.getErrorInfo(), result.getMsgArgs(), this.getThisLocale()));
     } else {
       dwzJson =
           new DwzJson(
               "200",
               this.messageSource.getMessage(
                   "operation.success", result.getMsgArgs(), this.getThisLocale()),
               StringUtils.isBlank(dwzId) ? "dwz_tab_settlement" : dwzId,
               "closeCurrent");
     }
   }
   return dwzJson;
 }
  /** 进入添加页面 */
  @PageType(EnumPageType.AJAXPAGE)
  @RequestMapping(value = "/addAjax")
  public String settlementAddAjax(
      UserAgent userAgent, @RequestParam(required = false) String dwzId, ModelMap model) {
    Settlement settlement = new Settlement();
    model.put("settlement", settlement);
    model.put("operType", "add");

    model.put("dwzId", StringUtils.isBlank(dwzId) ? "dwz_tab_settlement" : dwzId);
    return "settlement/objAjax";
  }
  /** 根据查询条件,批量删除 */
  @PageType(EnumPageType.JSONPAGE)
  @RequestMapping(value = "/delJson", method = RequestMethod.POST)
  public @ResponseBody DwzJson settlementDelBatch(
      @ModelAttribute("query") SettlementQuery query,
      @RequestParam(required = false) String dwzId,
      UserAgent userAgent,
      ModelMap model) {
    DwzJson dwzJson;
    // 将query.ids的条件合并到query.id_in中
    if (query != null && StringUtils.isNotBlank(query.getIds())) {
      List<Long> id_in = query.getIdsList();
      if (query.getId_in() == null) {
        query.setId_in(id_in);
      } else {
        query.getId_in().addAll(id_in);
      }
    }
    // 如果没有条件,就拒绝删除操作,以免所有数据被删掉.
    if (query == null || (query.getId_in() == null || query.getId_in().size() <= 0)) {
      dwzJson =
          new DwzJson(
              "300",
              this.getMessageSource()
                  .getMessage("delete.error.parameter.ids.null", null, this.getThisLocale()));
      return dwzJson;
    }

    ServiceResult<Integer> result = settlementService.remove(new ServiceRequest(query, userAgent));
    if (result.getErrorNO() != null) {
      dwzJson =
          new DwzJson(
              "300",
              this.messageSource.getMessage(
                  result.getErrorInfo(), result.getMsgArgs(), this.getThisLocale()));
    } else {
      if (result.getDataObj() > 0) {
        dwzJson =
            new DwzJson(
                "200",
                this.messageSource.getMessage(
                    "operation.success", result.getMsgArgs(), this.getThisLocale()),
                StringUtils.isBlank(dwzId) ? "dwz_tab_settlement" : dwzId);
      } else {
        dwzJson =
            new DwzJson(
                "300",
                this.getMessageSource()
                    .getMessage("delete.error", result.getMsgArgs(), this.getThisLocale()));
      }
    }

    return dwzJson;
  }
  /** 删除一个数据 */
  @PageType(EnumPageType.JSONPAGE)
  @RequestMapping(value = "/delJson/{id}")
  public @ResponseBody DwzJson settlementDel(
      @PathVariable("id") Long id,
      @RequestParam(required = false) String dwzId,
      UserAgent userAgent,
      ModelMap model) {
    DwzJson dwzJson;
    if (id == null || id < 0) {
      dwzJson =
          new DwzJson(
              "300",
              this.getMessageSource()
                  .getMessage("delete.error.parameter.ids.null", null, this.getThisLocale()));
      return dwzJson;
    }
    SettlementQuery query = new SettlementQuery();
    query.setId(id);
    ServiceResult<Integer> result = settlementService.remove(new ServiceRequest(query, userAgent));
    if (result.getErrorNO() != null) {
      dwzJson =
          new DwzJson(
              "300",
              this.messageSource.getMessage(
                  result.getErrorInfo(), result.getMsgArgs(), this.getThisLocale()));
    } else {
      if (result.getDataObj() > 0) {
        dwzJson =
            new DwzJson(
                "200",
                this.messageSource.getMessage(
                    "operation.success", result.getMsgArgs(), this.getThisLocale()),
                StringUtils.isBlank(dwzId) ? "dwz_tab_settlement" : dwzId);
      } else {
        dwzJson =
            new DwzJson(
                "300",
                this.getMessageSource()
                    .getMessage("delete.error", result.getMsgArgs(), this.getThisLocale()));
      }
    }

    return dwzJson;
  }
  /** 查询 数据 */
  @PageType(EnumPageType.AJAXPAGE)
  @RequestMapping(value = "/indexAjax")
  public String settlementIndexAjax(
      @ModelAttribute("query") SettlementQuery query,
      @RequestParam(required = false) String dwzId,
      UserAgent userAgent,
      ModelMap model) {
    ServiceResult<DwzPage<Settlement>> result =
        settlementService.pageQuery(new ServiceRequest(query, userAgent));
    model.addAttribute("page", result.getDataObj());
    model.addAttribute("srs", result);
    model.addAttribute("query", query);

    model.addAttribute("dwzId", StringUtils.isBlank(dwzId) ? "dwz_tab_settlement" : dwzId);
    if (query != null && "lookup".equals(query.getDwzId())) {
      return "settlement/lookupAjax";
    }
    return "settlement/indexAjax";
  }
 /** 进入单条记录的修改页面 */
 @PageType(EnumPageType.AJAXPAGE)
 @RequestMapping(value = "/editAjax/{id}")
 public String settlementEdit(
     @PathVariable("id") Long id,
     UserAgent userAgent,
     @RequestParam(required = false) String dwzId,
     ModelMap model) {
   Settlement settlement =
       settlementService.queryOne(new ServiceRequest(id, userAgent)).getDataObj();
   if (settlement == null) {
     DwzJson dwzJson = new DwzJson();
     dwzJson.setStatusCode("300");
     dwzJson.setMessage("要修改的数据不存在.");
     model.put("msgJson", dwzJson);
     return "errorPage/msg" + EnumPageType.AJAXPAGE.getCode();
   }
   model.put("settlement", settlement);
   model.put("operType", "edit");
   model.put("dwzId", StringUtils.isBlank(dwzId) ? "dwz_tab_settlement" : dwzId);
   return "settlement/objAjax";
 }
Example #8
0
  public void init() throws MQClientException {
    nameServer = PropertyFileUtil.get("rocketmq.namesrv.domain");

    if (StringUtils.isBlank(nameServer)) {

      logger.warn("【MQ init】property rocketmq.namesrv.domain not found");

      return;
    }

    if ("localTest".equals(nameServer)) {

      logger.warn("【MQ init】localTest");

      return;
    }

    if (StringUtils.isBlank(System.getProperty("rocketmq.namesrv.domain"))) {
      System.setProperty("rocketmq.namesrv.domain", nameServer);
    }
    topicType = getTopic();
    topic = RocketMqUtils.getTopic(topicType);

    if (StringUtils.isBlank(group)) {
      group = "S_" + topic.getTopic() + "_" + topic.getTags();
    }
    consumer = new DefaultMQPushConsumer(group);
    consumer.setNamesrvAddr(nameServer);
    consumer.setMessageModel(getMessageModel());
    consumer.setConsumeThreadMin(minConsumeThread);
    consumer.setConsumeThreadMax(maxConsumeThread);
    // 可以不设置 设置后可以起多个 消费端
    try {
      consumer.setInstanceName("DEFAULT_CONSUMER-" + InetAddress.getLocalHost().getHostName());
    } catch (UnknownHostException e) {
      logger.error("getHostName error", e);
    }
    // 设置订阅的topic 设置订阅过滤表达式
    if (StringUtils.isBlank(subExpression)) {
      subExpression = topic.getTags();
      consumer.subscribe(topic.getTopic(), subExpression);
    } else {
      consumer.subscribe(topic.getTopic(), subExpression);
    }
    try {
      consumer.registerMessageListener(this);
      consumer.start();
    } catch (MQClientException e) {
      logger.error(
          "consumer start error!topic={},subExpression={},group={}",
          topic.getTopic(),
          subExpression,
          group,
          e);
    }
    logger.info(
        "consumer start! topic={},subExpression={},group={}",
        topic.getTopic(),
        subExpression,
        group);
  }
Example #9
0
  public void initialiseWithLines(ArrayList<StringBuilder> lines, ProcessingOptions options)
      throws UnsupportedEncodingException {

    // remove blank rows at the bottom
    boolean done = false;
    int i;
    for (i = lines.size() - 1; i >= 0 && !done; i--) {
      StringBuilder row = lines.get(i);
      if (!StringUtils.isBlank(row.toString())) done = true;
    }
    rows = new ArrayList<StringBuilder>(lines.subList(0, i + 2));

    if (options != null) fixTabs(options.getTabSize());
    else fixTabs(ProcessingOptions.DEFAULT_TAB_SIZE);

    // make all lines of equal length
    // add blank outline around the buffer to prevent fill glitch
    // convert tabs to spaces (or remove them if setting is 0)

    int blankBorderSize = 2;

    int maxLength = 0;
    int index = 0;

    String encoding = null;
    if (options != null) encoding = options.getCharacterEncoding();

    Iterator<StringBuilder> it = rows.iterator();
    while (it.hasNext()) {
      String row = it.next().toString();
      if (encoding != null) {
        byte[] bytes = row.getBytes();
        row = new String(bytes, encoding);
      }
      if (row.length() > maxLength) maxLength = row.length();
      rows.set(index, new StringBuilder(row));
      index++;
    }

    it = rows.iterator();
    ArrayList<StringBuilder> newRows = new ArrayList<StringBuilder>();
    // TODO: make the following depend on blankBorderSize

    StringBuilder topBottomRow =
        new StringBuilder(StringUtils.repeatString(" ", maxLength + blankBorderSize * 2));

    newRows.add(topBottomRow);
    newRows.add(topBottomRow);
    while (it.hasNext()) {
      StringBuilder row = it.next();

      if (row.length() < maxLength) {
        String borderString = StringUtils.repeatString(" ", blankBorderSize);
        StringBuilder newRow = new StringBuilder();

        newRow.append(borderString);
        newRow.append(row);
        newRow.append(StringUtils.repeatString(" ", maxLength - row.length()));
        newRow.append(borderString);

        newRows.add(newRow);
      } else { // TODO: why is the following line like that?
        newRows.add(new StringBuilder("  ").append(row).append("  "));
      }
    }
    // TODO: make the following depend on blankBorderSize
    newRows.add(topBottomRow);
    newRows.add(topBottomRow);
    rows = newRows;

    replaceBullets();
    replaceHumanColorCodes();
  }