Java Code Examples for cn.hutool.core.util.StrUtil#emptyToDefault()

The following examples show how to use cn.hutool.core.util.StrUtil#emptyToDefault() . 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: SshService.java    From Jpom with MIT License 6 votes vote down vote up
public static Session getSession(SshModel sshModel) {
    if (sshModel.getConnectType() == SshModel.ConnectType.PASS) {
        return JschUtil.openSession(sshModel.getHost(), sshModel.getPort(), sshModel.getUser(), sshModel.getPassword());
    }
    if (sshModel.getConnectType() == SshModel.ConnectType.PUBKEY) {
        File tempPath = ServerConfigBean.getInstance().getTempPath();
        String sshFile = StrUtil.emptyToDefault(sshModel.getId(), IdUtil.fastSimpleUUID());
        File ssh = FileUtil.file(tempPath, "ssh", sshFile);
        FileUtil.writeString(sshModel.getPrivateKey(), ssh, CharsetUtil.UTF_8);
        byte[] pas = null;
        if (StrUtil.isNotEmpty(sshModel.getPassword())) {
            pas = sshModel.getPassword().getBytes();
        }
        return JschUtil.openSession(sshModel.getHost(), sshModel.getPort(), sshModel.getUser(), FileUtil.getAbsolutePath(ssh), pas);
    }
    throw new IllegalArgumentException("不支持的模式");
}
 
Example 2
Source File: BaseAgentController.java    From Jpom with MIT License 5 votes vote down vote up
/**
 * 获取server 端操作人
 *
 * @param request req
 * @return name
 */
private static String getUserName(HttpServletRequest request) {
    String name = ServletUtil.getHeaderIgnoreCase(request, ConfigBean.JPOM_SERVER_USER_NAME);
    name = CharsetUtil.convert(name, CharsetUtil.CHARSET_ISO_8859_1, CharsetUtil.CHARSET_UTF_8);
    name = StrUtil.emptyToDefault(name, StrUtil.DASHED);
    return URLUtil.decode(name, CharsetUtil.CHARSET_UTF_8);
}
 
Example 3
Source File: ServerExtConfigBean.java    From Jpom with MIT License 5 votes vote down vote up
public long getIpErrorLockTime() {
    if (this.ipErrorLockTimeValue == -1) {
        String str = StrUtil.emptyToDefault(this.ipErrorLockTime, "60*60*5*1000");
        this.ipErrorLockTimeValue = Convert.toLong(ScriptUtil.eval(str), TimeUnit.HOURS.toMillis(5));
    }
    return this.ipErrorLockTimeValue;
}
 
Example 4
Source File: AutoBackLog.java    From Jpom with MIT License 5 votes vote down vote up
@PreLoadMethod
private static void startAutoBackLog() {
    if (projectInfoService == null) {
        projectInfoService = SpringUtil.getBean(ProjectInfoService.class);
    }
    // 获取cron 表达式
    String cron = StrUtil.emptyToDefault(AgentExtConfigBean.getInstance().autoBackConsoleCron, "none");
    if ("none".equalsIgnoreCase(cron.trim())) {
        DefaultSystemLog.getLog().info("没有配置自动备份控制台日志表达式");
        return;
    }
    String size = StrUtil.emptyToDefault(AgentExtConfigBean.getInstance().autoBackSize, "50MB");
    MAX_SIZE = FileSize.valueOf(size.trim());
    //
    CronUtil.schedule(ID, cron, () -> {
        try {
            List<ProjectInfoModel> list = projectInfoService.list();
            if (list == null) {
                return;
            }
            list.forEach(projectInfoModel -> {
                checkProject(projectInfoModel, null);
                //
                List<ProjectInfoModel.JavaCopyItem> javaCopyItemList = projectInfoModel.getJavaCopyItemList();
                if (javaCopyItemList == null) {
                    return;
                }
                javaCopyItemList.forEach(javaCopyItem -> checkProject(projectInfoModel, javaCopyItem));
            });
        } catch (Exception e) {
            DefaultSystemLog.getLog().error("定时备份日志失败", e);
        }
    });
    CronUtils.start();
}
 
Example 5
Source File: ProjectInfoModel.java    From Jpom with MIT License 5 votes vote down vote up
/**
 * 默认
 *
 * @return url token
 */
public String getToken() {
    // 兼容旧数据
    if ("no".equalsIgnoreCase(this.token)) {
        return "";
    }
    return StrUtil.emptyToDefault(token, StrUtil.EMPTY);
}
 
Example 6
Source File: ProjectInfoModel.java    From Jpom with MIT License 4 votes vote down vote up
public String getLog() {
    return StrUtil.emptyToDefault(log, StrUtil.EMPTY);
}
 
Example 7
Source File: ProjectInfoModel.java    From Jpom with MIT License 4 votes vote down vote up
public String getArgs() {
    return StrUtil.emptyToDefault(args, StrUtil.EMPTY);
}
 
Example 8
Source File: ScriptModel.java    From Jpom with MIT License 4 votes vote down vote up
public String getLastRunUser() {
    return StrUtil.emptyToDefault(lastRunUser, StrUtil.DASHED);
}
 
Example 9
Source File: BaseAgentWebSocketHandle.java    From Jpom with MIT License 4 votes vote down vote up
protected String getOptUserName(Session session) {
    String name = USER.get(session.getId());
    return StrUtil.emptyToDefault(name, StrUtil.DASHED);
}
 
Example 10
Source File: ProjectInfoModel.java    From Jpom with MIT License 4 votes vote down vote up
public String getMainClass() {
    return StrUtil.emptyToDefault(mainClass, StrUtil.EMPTY);
}
 
Example 11
Source File: OutGivingNodeProject.java    From Jpom with MIT License 4 votes vote down vote up
public String getLastOutGivingTime() {
    return StrUtil.emptyToDefault(lastOutGivingTime, StrUtil.DASHED);
}
 
Example 12
Source File: NodeModel.java    From Jpom with MIT License 4 votes vote down vote up
public String getGroup() {
    return StrUtil.emptyToDefault(group, "默认");
}
 
Example 13
Source File: UserOperateLogV1.java    From Jpom with MIT License 4 votes vote down vote up
public String getDataId() {
    return StrUtil.emptyToDefault(dataId, StrUtil.DASHED);
}
 
Example 14
Source File: UserOperateLogV1.java    From Jpom with MIT License 4 votes vote down vote up
public String getNodeId() {
    return StrUtil.emptyToDefault(nodeId, StrUtil.DASHED);
}
 
Example 15
Source File: ProjectInfoModel.java    From Jpom with MIT License 4 votes vote down vote up
public String getJvm() {
    return StrUtil.emptyToDefault(jvm, StrUtil.EMPTY);
}
 
Example 16
Source File: ProjectInfoModel.java    From Jpom with MIT License 4 votes vote down vote up
public String getJavaExtDirsCp() {
    return StrUtil.emptyToDefault(javaExtDirsCp, StrUtil.EMPTY);
}
 
Example 17
Source File: JSONObject.java    From RuoYi with Apache License 2.0 2 votes vote down vote up
/**
 * 返回字段字符串值。如果不存在,返回defaultValue。
 *
 * @param name         字段名。
 * @param defaultValue 字段不存在时,返回的值。
 * @return 返回指定字段字符串值。
 */
public String getStr(final String name, final String defaultValue) {
    return StrUtil.emptyToDefault(getStr(name), defaultValue);
}
 
Example 18
Source File: JSONObject.java    From RuoYi with Apache License 2.0 2 votes vote down vote up
/**
 * 获取指定字段的字符串值。如果字段不存在,返回defaultValue。
 *
 * @param name         字段名,支持多级。
 * @param defaultValue 查询失败时,返回的值。
 * @return 返回指定的字符串值,或者defaultValue。
 */
public String strValue(final String name, final String defaultValue) {
    return StrUtil.emptyToDefault(strValue(name), defaultValue);
}
 
Example 19
Source File: AgentExtConfigBean.java    From Jpom with MIT License 2 votes vote down vote up
/**
 * 是否开启日志备份
 *
 * @return 如果表达式配置为none 则不配置,重启业不备份
 */
public boolean openLogBack() {
    String cron = StrUtil.emptyToDefault(autoBackConsoleCron, "none");
    return !"none".equalsIgnoreCase(cron.trim());
}