com.aliyuncs.utils.StringUtils Java Examples

The following examples show how to use com.aliyuncs.utils.StringUtils. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SensitiveWordUtil.java    From pybbs with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 替换敏感字字符
 *
 * @param txt        文本
 * @param replaceStr 替换的字符串,匹配的敏感词以字符逐个替换,如 语句:我爱中国人 敏感词:中国人,替换字符串:[屏蔽],替换结果:我爱[屏蔽]
 * @param matchType  敏感词匹配规则
 * @return
 */
public static String replaceSensitiveWord(String txt, String replaceStr, int matchType) {
    if (StringUtils.isEmpty(txt)) return null;
    String resultTxt = txt;
    //获取所有的敏感词
    Set<String> set = getSensitiveWord(txt, matchType);
    Iterator<String> iterator = set.iterator();
    String word;
    while (iterator.hasNext()) {
        word = iterator.next();
        resultTxt = resultTxt.replaceAll(word, replaceStr);
    }

    return resultTxt;
}
 
Example #2
Source File: MachineCmdResultListener.java    From MicroCommunity with Apache License 2.0 4 votes vote down vote up
@Override
protected void doSoService(ServiceDataFlowEvent event, DataFlowContext context, JSONObject reqJson) {

    ResponseEntity<String> responseEntity = null;
    ResultVo resultVo = null;

    Map<String, String> reqHeader = context.getRequestHeaders();

    HttpHeaders headers = new HttpHeaders();
    String communityId = reqJson.containsKey("communityId") ? reqJson.getString("communityId") : reqHeader.get("communityId");
    if (StringUtil.isEmpty(communityId)) {
        resultVo = new ResultVo(ResultVo.CODE_MACHINE_ERROR, "请求地址中未包含小区信息");
        responseEntity = new ResponseEntity<>(resultVo.toString(), headers, HttpStatus.OK);
        context.setResponseEntity(responseEntity);
        return;
    }
    if (!reqHeader.containsKey("machinecode") || StringUtils.isEmpty(reqHeader.get("machinecode"))) {
        resultVo = new ResultVo(ResultVo.CODE_MACHINE_ERROR, "请求头中未包含设备编码");
        responseEntity = new ResponseEntity<>(resultVo.toString(), headers, HttpStatus.OK);
        context.setResponseEntity(responseEntity);
        return;
    }
    for (String key : reqHeader.keySet()) {
        if (key.toLowerCase().equals("content-length")) {
            continue;
        }
        headers.add(key, reqHeader.get(key));
    }

    //String communityId = reqJson.containsKey("communityId") ? reqJson.getString("communityId") : reqHeader.get("communityId");

    //检查设备是否合法
    MachineDto machineDto = new MachineDto();
    machineDto.setMachineCode(reqHeader.get("machinecode"));
    machineDto.setCommunityId(communityId);
    int machineCount = machineInnerServiceSMOImpl.queryMachinesCount(machineDto);
    if (machineCount < 1) {
        resultVo = new ResultVo(ResultVo.CODE_MACHINE_ERROR, "该设备【" + reqJson.getString("machinecode") + "】未在该小区【" + communityId + "】注册");
        responseEntity = new ResponseEntity<>(resultVo.toString(), headers, HttpStatus.OK);
        context.setResponseEntity(responseEntity);
        return;
    }

    //outParam.put("data", outParam);

    if (!reqJson.containsKey("code")) {
        resultVo = new ResultVo(ResultVo.CODE_MACHINE_ERROR, "请求报文格式错误 未包含code");
        responseEntity = new ResponseEntity<>(resultVo.toString(), headers, HttpStatus.OK);
        context.setResponseEntity(responseEntity);
        return;
    }

    //这里根据 code 修改命令执行结果
    int code = reqJson.getIntValue("code");
    MachineTranslateDto tmpMtDto = new MachineTranslateDto();
    tmpMtDto.setMachineTranslateId(reqJson.getString("taskid"));
    tmpMtDto.setCommunityId(communityId);
    ResultVo frontResultVo = null;
    if (ResultVo.CODE_MACHINE_OK != code) {
        tmpMtDto.setState(MachineGetTaskInfoListener.STATE_CMD_ERROR);
        tmpMtDto.setRemark(reqJson.getString("msg"));
        frontResultVo = new ResultVo(ResultVo.CODE_ERROR, reqJson.getString("msg"));
    } else {
        tmpMtDto.setState(MachineGetTaskInfoListener.STATE_CMD_SUCCESS);
        frontResultVo = new ResultVo(ResultVo.CODE_OK, reqJson.getString("msg"));

    }
    machineTranslateInnerServiceSMOImpl.updateMachineTranslateState(tmpMtDto);
    //写kafka消息
    try {
        KafkaFactory.sendKafkaMessage(FRONT_KAFKA_TOPIC, frontResultVo.toString());
    } catch (Exception e) {
        logger.error("通知 front失败", e);
    }
    resultVo = new ResultVo(ResultVo.CODE_MACHINE_OK, ResultVo.MSG_OK);
    responseEntity = new ResponseEntity<>(resultVo.toString(), headers, HttpStatus.OK);
    context.setResponseEntity(responseEntity);
}
 
Example #3
Source File: BaseMachineListener.java    From MicroCommunity with Apache License 2.0 4 votes vote down vote up
/**
 * 校验报文内容
 *
 * @param event
 * @param context
 * @param reqJson
 */
protected boolean validateMachineBody(ServiceDataFlowEvent event, DataFlowContext context, JSONObject reqJson,
                                      IMachineInnerServiceSMO machineInnerServiceSMOImpl) {

    ResponseEntity<String> responseEntity = null;
    ResultVo resultVo = null;
    Map<String, String> reqHeader = context.getRequestHeaders();
    HttpHeaders headers = new HttpHeaders();
    String communityId = reqJson.containsKey("communityId") ? reqJson.getString("communityId") : reqHeader.get("communityId");
    if (StringUtil.isEmpty(communityId)) {
        resultVo = new ResultVo(ResultVo.CODE_MACHINE_ERROR, "请求头中未包含小区编码");
        responseEntity = new ResponseEntity<>(resultVo.toString(), headers, HttpStatus.OK);
        context.setResponseEntity(responseEntity);
        return false;
    }
    for (String key : reqHeader.keySet()) {
        if (key.toLowerCase().equals("content-length")) {
            continue;
        }
        headers.add(key, reqHeader.get(key));
    }

    if (!reqHeader.containsKey("machinecode") || StringUtils.isEmpty(reqHeader.get("machinecode"))) {
        resultVo = new ResultVo(ResultVo.CODE_MACHINE_ERROR, "请求头中未包含设备编码");
        responseEntity = new ResponseEntity<>(resultVo.toString(), headers, HttpStatus.OK);
        context.setResponseEntity(responseEntity);
        return false;
    }
    //检查设备是否合法
    //检查设备是否合法
    MachineDto machineDto = new MachineDto();
    machineDto.setMachineCode(reqHeader.get("machinecode"));
    machineDto.setCommunityId(communityId);
    List<MachineDto> machineDtos = machineInnerServiceSMOImpl.queryMachines(machineDto);
    if (machineDtos == null || machineDtos.size() < 1) {
        resultVo = new ResultVo(ResultVo.CODE_MACHINE_ERROR, "该设备【" + reqHeader.get("machinecode") + "】未在该小区【" + communityId + "】注册");
        responseEntity = new ResponseEntity<>(resultVo.toString(), headers, HttpStatus.OK);
        context.setResponseEntity(responseEntity);
        return false;
    }

    if ("1600".equals(machineDtos.get(0).getState())) { //设备禁用状态
        resultVo = new ResultVo(ResultVo.CODE_MACHINE_ERROR, "该设备【" + reqHeader.get("machinecode") + "】禁用状态");
        responseEntity = new ResponseEntity<>(resultVo.toString(), headers, HttpStatus.OK);
        context.setResponseEntity(responseEntity);
        return false;
    }
    reqJson.put("machineCode", machineDtos.get(0).getMachineCode());
    reqJson.put("machineId", machineDtos.get(0).getMachineId());
    reqJson.put("communityId", communityId);
    return true;
}