Java Code Examples for cn.hutool.core.util.StrUtil#EMPTY

The following examples show how to use cn.hutool.core.util.StrUtil#EMPTY . 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: SpelUtil.java    From mall4j with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 支持 #p0 参数索引的表达式解析
 * @param rootObject 根对象,method 所在的对象
 * @param spel 表达式
 * @param method ,目标方法
 * @param args 方法入参
 * @return 解析后的字符串
 */
public static String parse(Object rootObject,String spel, Method method, Object[] args) {
    if (StrUtil.isBlank(spel)) {
        return StrUtil.EMPTY;
    }
    //获取被拦截方法参数名列表(使用Spring支持类库)
    LocalVariableTableParameterNameDiscoverer u =
            new LocalVariableTableParameterNameDiscoverer();
    String[] paraNameArr = u.getParameterNames(method);
    if (ArrayUtil.isEmpty(paraNameArr)) {
        return spel;
    }
    //使用SPEL进行key的解析
    ExpressionParser parser = new SpelExpressionParser();
    //SPEL上下文
    StandardEvaluationContext context = new MethodBasedEvaluationContext(rootObject,method,args,u);
    //把方法参数放入SPEL上下文中
    for (int i = 0; i < paraNameArr.length; i++) {
        context.setVariable(paraNameArr[i], args[i]);
    }
    return parser.parseExpression(spel).getValue(context, String.class);
}
 
Example 2
Source File: UploadFileHeader.java    From yue-library with Apache License 2.0 5 votes vote down vote up
/**
 * 头信息中获得content type
 * 
 * @param dataHeader data header string
 * @return content type or an empty string if no content type defined
 */
private String getContentType(String dataHeader) {
	String token = "Content-Type:";
	int start = dataHeader.indexOf(token);
	if (start == -1) {
		return StrUtil.EMPTY;
	}
	start += token.length();
	return dataHeader.substring(start);
}
 
Example 3
Source File: UploadFileHeader.java    From yue-library with Apache License 2.0 5 votes vote down vote up
/**
 * 处理头字符串,使之转化为字段
 * @param dataHeader
 */
private void processHeaderString(String dataHeader) {
	isFile = dataHeader.indexOf("filename") > 0;
	formFieldName = getDataFieldValue(dataHeader, "name");
	if (isFile) {
		formFileName = getDataFieldValue(dataHeader, "filename");
		if (formFileName == null) {
			return;
		}
		if (formFileName.length() == 0) {
			path = StrUtil.EMPTY;
			fileName = StrUtil.EMPTY;
		}
		int ls = FileUtil.lastIndexOfSeparator(formFileName);
		if (ls == -1) {
			path = StrUtil.EMPTY;
			fileName = formFileName;
		} else {
			path = formFileName.substring(0, ls);
			fileName = formFileName.substring(ls);
		}
		if (fileName.length() > 0) {
			this.contentType = getContentType(dataHeader);
			mimeType = getMimeType(contentType);
			mimeSubtype = getMimeSubtype(contentType);
			contentDisposition = getContentDisposition(dataHeader);
		}
	}
}
 
Example 4
Source File: BaseController.java    From v-mock with MIT License 5 votes vote down vote up
/**
 * 设置请求分页数据
 */
protected void startPage() {
    PageVo pageVo = TableSupport.getPage();
    Integer pageNum = pageVo.getPageNum();
    Integer pageSize = pageVo.getPageSize();
    if (pageNum != null && pageSize != null) {
        String orderBy = pageVo.getOrderBy().matches(SQL_PATTERN) ? pageVo.getOrderBy() : StrUtil.EMPTY;
        PageHelper.startPage(pageNum, pageSize, orderBy);
    }
}
 
Example 5
Source File: NginxController.java    From Jpom with MIT License 5 votes vote down vote up
private String reloadNginx() {
    String serviceName = nginxService.getServiceName();
    try {
        String format = StrUtil.format("{} -s reload", serviceName);
        String msg = CommandUtil.execSystemCommand(format);
        if (StrUtil.isNotEmpty(msg)) {
            DefaultSystemLog.getLog().info(msg);
            return "(" + msg + ")";
        }
    } catch (Exception e) {
        DefaultSystemLog.getLog().error("reload nginx error", e);
    }
    return StrUtil.EMPTY;
}
 
Example 6
Source File: ProjectInfoModel.java    From Jpom with MIT License 5 votes vote down vote up
/**
 * 拼接java 执行的jar路径
 *
 * @param projectInfoModel 项目
 * @return classpath 或者 jar
 */
public static String getClassPathLib(ProjectInfoModel projectInfoModel) {
    List<File> files = listJars(projectInfoModel);
    if (files.size() <= 0) {
        return "";
    }
    // 获取lib下面的所有jar包
    StringBuilder classPath = new StringBuilder();
    RunMode runMode = projectInfoModel.getRunMode();
    int len = files.size();
    if (runMode == RunMode.ClassPath) {
        classPath.append("-classpath ");
    } else if (runMode == RunMode.Jar || runMode == RunMode.JarWar) {
        classPath.append("-jar ");
        // 只取一个jar文件
        len = 1;
    } else if (runMode == RunMode.JavaExtDirsCp) {
        classPath.append("-Djava.ext.dirs=");
        String javaExtDirsCp = projectInfoModel.getJavaExtDirsCp();
        String[] split = StrUtil.split(javaExtDirsCp, StrUtil.COLON);
        if (ArrayUtil.isEmpty(split)) {
            classPath.append(". -cp ");
        } else {
            classPath.append(split[0]).append(" -cp ");
            if (split.length > 1) {
                classPath.append(split[1]).append(FileUtils.getJarSeparator());
            }
        }
    } else {
        return StrUtil.EMPTY;
    }
    for (int i = 0; i < len; i++) {
        File file = files.get(i);
        classPath.append(file.getAbsolutePath());
        if (i != len - 1) {
            classPath.append(FileUtils.getJarSeparator());
        }
    }
    return classPath.toString();
}
 
Example 7
Source File: BaseJpomInterceptor.java    From Jpom with MIT License 5 votes vote down vote up
static String getHeaderProxyPath(HttpServletRequest request) {
    String proxyPath = ServletUtil.getHeaderIgnoreCase(request, PROXY_PATH);
    if (StrUtil.isEmpty(proxyPath)) {
        return StrUtil.EMPTY;
    }
    if (proxyPath.endsWith(StrUtil.SLASH)) {
        proxyPath = proxyPath.substring(0, proxyPath.length() - 1);
    }
    return proxyPath;
}
 
Example 8
Source File: AccessFilter.java    From zuihou-admin-cloud with Apache License 2.0 5 votes vote down vote up
protected String getHeader(String headerName, ServerHttpRequest request) {
    HttpHeaders headers = request.getHeaders();
    String token = StrUtil.EMPTY;
    if (headers == null || headers.isEmpty()) {
        return token;
    }

    token = headers.getFirst(headerName);

    if (StringUtils.isNotBlank(token)) {
        return token;
    }

    return request.getQueryParams().getFirst(headerName);
}
 
Example 9
Source File: SqlUtil.java    From RuoYi with Apache License 2.0 5 votes vote down vote up
/**
 * 检查字符,防止注入绕过
 */
public static String escapeOrderBySql(String value){
    if (StrUtil.isNotEmpty(value) && !isValidOrderBySql(value))
    {
        return StrUtil.EMPTY;
    }
    return value;
}
 
Example 10
Source File: TestUtil.java    From albedo with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static String toParams(Map<String, ?> paramMap) {
	if (CollectionUtil.isEmpty(paramMap)) {
		return StrUtil.EMPTY;
	}
	Charset charset = CharsetUtil.CHARSET_UTF_8;

	final StringBuilder sb = new StringBuilder();
	boolean isFirst = true, isFristTwo = true;
	String key;
	Object value;
	for (Map.Entry<String, ?> item : paramMap.entrySet()) {
		if (isFirst) {
			isFirst = false;
		} else {
			sb.append("&");
		}
		key = item.getKey();
		if (StrUtil.isNotEmpty(key)) {
			value = item.getValue();
			if (value instanceof Collection) {
				for (Object obj : (Collection) value) {
					if (isFristTwo) {
						isFristTwo = false;
					} else {
						sb.append("&");
					}
					appendUrl(sb, obj, key, charset);
				}
			} else {
				appendUrl(sb, value, key, charset);
			}

		}
	}
	return sb.toString();
}
 
Example 11
Source File: CodeGenServiceImpl.java    From spring-boot-demo with MIT License 5 votes vote down vote up
@SneakyThrows
private Entity queryTable(TableRequest request) {
    HikariDataSource dataSource = DbUtil.buildFromTableRequest(request);
    Db db = new Db(dataSource);

    String paramSql = StrUtil.EMPTY;
    if (StrUtil.isNotBlank(request.getTableName())) {
        paramSql = "and table_name = ?";
    }
    String sql = String.format(TABLE_SQL_TEMPLATE, paramSql);
    Entity entity = db.queryOne(sql, request.getTableName());

    dataSource.close();
    return entity;
}
 
Example 12
Source File: Monitor.java    From Jpom with MIT License 4 votes vote down vote up
/**
 * 检查状态
 *
 * @param monitorModel 监控信息
 * @param nodeModel    节点信息
 * @param id           项目id
 * @param copyId       副本id
 * @param runStatus    当前运行状态
 */
private void checkNotify(MonitorModel monitorModel, NodeModel nodeModel, String id, String copyId, boolean runStatus) {
    // 获取上次状态
    String projectCopyId = id;
    String copyMsg = StrUtil.EMPTY;
    if (StrUtil.isNotEmpty(copyId)) {
        projectCopyId = StrUtil.format("{}:{}", id, copyId);
        copyMsg = StrUtil.format("副本:{}、", copyId);
    }
    boolean pre = getPreStatus(monitorModel.getId(), nodeModel.getId(), projectCopyId);
    String title = null;
    String context = null;
    //查询项目运行状态
    if (runStatus) {
        if (!pre) {
            // 上次是异常状态
            title = StrUtil.format("【{}】节点的【{}】项目{}已经恢复正常运行", nodeModel.getName(), id, copyMsg);
            context = "";
        }
    } else {
        //
        if (monitorModel.isAutoRestart()) {
            // 执行重启
            try {
                JsonMessage<String> reJson = NodeForward.requestBySys(nodeModel, NodeUrl.Manage_Restart, "id", id, "copyId", copyId);
                if (reJson.getCode() == HttpStatus.HTTP_OK) {
                    // 重启成功
                    runStatus = true;
                    title = StrUtil.format("【{}】节点的【{}】项目{}已经停止,已经执行重启操作,结果成功", nodeModel.getName(), id, copyMsg);
                } else {
                    title = StrUtil.format("【{}】节点的【{}】项目{}已经停止,已经执行重启操作,结果失败", nodeModel.getName(), id, copyMsg);
                }
                context = "重启结果:" + reJson.toString();
            } catch (Exception e) {
                DefaultSystemLog.getLog().error("执行重启操作", e);
                title = StrUtil.format("【{}】节点的【{}】项目{}已经停止,重启操作异常", nodeModel.getName(), id, copyMsg);
                context = ExceptionUtil.stacktraceToString(e);
            }
        } else {
            title = StrUtil.format("【{}】节点的【{}】项目{}已经没有运行", nodeModel.getName(), id, copyMsg);
            context = "请及时检查";
        }
    }
    if (!pre && !runStatus) {
        // 上一次也是异常,并且当前也是异常
        return;
    }
    MonitorNotifyLog monitorNotifyLog = new MonitorNotifyLog();
    monitorNotifyLog.setStatus(runStatus);
    monitorNotifyLog.setTitle(title);
    monitorNotifyLog.setContent(context);
    monitorNotifyLog.setCreateTime(System.currentTimeMillis());
    monitorNotifyLog.setNodeId(nodeModel.getId());
    monitorNotifyLog.setProjectId(projectCopyId);
    monitorNotifyLog.setMonitorId(monitorModel.getId());
    //
    List<String> notify = monitorModel.getNotifyUser();
    this.notifyMsg(notify, monitorNotifyLog);
}