com.blade.kit.StringKit.isBlank() - java examples

Here are the examples of the java api com.blade.kit.StringKit.isBlank() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

19 Examples 7

19 View Complete Implementation : PathRegexBuilder.java
Copyright Apache License 2.0
Author : lets-blade
private PathBuilderMeta rowToPath(String row) {
    if (!row.contains(":")) {
        return PathBuilderMeta.builder().name(row).type(PathBuilderMeta.PathTypeEnum.COMMON).build();
    }
    String[] itemPath = row.split(":");
    if (StringKit.isBlank(itemPath[0])) {
        return PathBuilderMeta.builder().name(itemPath[1]).regex(PATH_VARIABLE_REPLACE).type(PathBuilderMeta.PathTypeEnum.PARAM).build();
    } else {
        return PathBuilderMeta.builder().name(itemPath[0]).regex("(" + itemPath[1] + ")").type(PathBuilderMeta.PathTypeEnum.REGEX).build();
    }
}

19 View Complete Implementation : Theme.java
Copyright MIT License
Author : tfssweb
/**
 * 返回主题设置选项
 *
 * @param key
 * @return
 */
public static String theme_option(String key, String defaultValue) {
    String option = theme_option(key);
    if (StringKit.isBlank(option)) {
        return defaultValue;
    }
    return option;
}

18 View Complete Implementation : PathRegexBuilder.java
Copyright Apache License 2.0
Author : lets-blade
public String parsePath(String path) {
    if (StringKit.isBlank(path))
        return path;
    String[] pathModule = path.split("/");
    Arrays.stream(pathModule).filter(row -> !row.isEmpty()).map(this::rowToPath).forEach(this::join);
    pathBuilder.deleteCharAt(pathBuilder.length() - 1);
    return build(true);
}

17 View Complete Implementation : RouteActionArguments.java
Copyright Apache License 2.0
Author : lets-blade
private static Object getHeader(ParamStruct paramStruct) throws BladeException {
    Type argType = paramStruct.argType;
    HeaderParam headerParam = paramStruct.headerParam;
    String paramName = paramStruct.paramName;
    Request request = paramStruct.request;
    String key = StringKit.isEmpty(headerParam.value()) ? paramName : headerParam.value();
    String val = request.header(key);
    if (StringKit.isBlank(val)) {
        val = headerParam.defaultValue();
    }
    return ReflectKit.convert(argType, val);
}

17 View Complete Implementation : RouteActionArguments.java
Copyright Apache License 2.0
Author : lets-blade
private static Object getPathParam(ParamStruct paramStruct) {
    Type argType = paramStruct.argType;
    PathParam pathParam = paramStruct.pathParam;
    String paramName = paramStruct.paramName;
    Request request = paramStruct.request;
    String name = StringKit.isEmpty(pathParam.name()) ? paramName : pathParam.name();
    String val = request.pathString(name);
    if (StringKit.isBlank(val)) {
        val = pathParam.defaultValue();
    }
    return ReflectKit.convert(argType, val);
}

16 View Complete Implementation : DynamicContext.java
Copyright Apache License 2.0
Author : lets-blade
public static boolean isJarPackage(String packageName) {
    if (StringKit.isBlank(packageName)) {
        return false;
    }
    try {
        packageName = packageName.replace(".", "/");
        Enumeration<URL> dirs = DynamicContext.clreplaced.getClreplacedLoader().getResources(packageName);
        if (dirs.hasMoreElements()) {
            String url = dirs.nextElement().toString();
            return url.indexOf(".jar!") != -1 || url.indexOf(".zip!") != -1;
        }
    } catch (Exception e) {
        log.error("", e);
    }
    return false;
}

16 View Complete Implementation : IndexController.java
Copyright MIT License
Author : tfssweb
/**
 * 系统备份
 *
 * @return
 */
@Route(value = "backup", method = HttpMethod.POST)
@JSON
public RestResponse backup(@Param String bk_type, @Param String bk_path, Request request) {
    if (StringKit.isBlank(bk_type)) {
        return RestResponse.fail("请确认信息输入完整");
    }
    try {
        BackResponse backResponse = siteService.backup(bk_type, bk_path, "yyyyMMddHHmm");
        new Logs(LogActions.SYS_BACKUP, null, request.address(), this.getUid()).save();
        return RestResponse.ok(backResponse);
    } catch (Exception e) {
        String msg = "备份失败";
        if (e instanceof TipException) {
            msg = e.getMessage();
        } else {
            log.error(msg, e);
        }
        return RestResponse.fail(msg);
    }
}

16 View Complete Implementation : TaleUtils.java
Copyright MIT License
Author : tfssweb
/**
 * markdown转换为html
 *
 * @param markdown
 * @return
 */
public static String mdToHtml(String markdown) {
    if (StringKit.isBlank(markdown)) {
        return "";
    }
    List<Extension> extensions = Arrays.asList(TablesExtension.create());
    Parser parser = Parser.builder().extensions(extensions).build();
    Node doreplacedent = parser.parse(markdown);
    HtmlRenderer renderer = HtmlRenderer.builder().extensions(extensions).build();
    String content = renderer.render(doreplacedent);
    content = Commons.emoji(content);
    // 支持网易云音乐输出
    if (TaleConst.BCONF.getBoolean("app.support_163_music", true) && content.contains("[mp3:")) {
        content = content.replaceAll("\\[mp3:(\\d+)\\]", "<iframe frameborder=\"no\" border=\"0\" marginwidth=\"0\" marginheight=\"0\" width=350 height=106 src=\"//music.163.com/outchain/player?type=2&id=$1&auto=0&height=88\"></iframe>");
    }
    // 支持gist代码输出
    if (TaleConst.BCONF.getBoolean("app.support_gist", true) && content.contains("https://gist.github.com/")) {
        content = content.replaceAll("<script src=\"https://gist.github.com/(\\w+)/(\\w+)\\.js\"></script>", "<script src=\"https://gist.github.com/$1/$2\\.js\"></script>");
    }
    return content;
}

15 View Complete Implementation : SiteService.java
Copyright MIT License
Author : tfssweb
/**
 * 系统备份
 *
 * @param bkType
 * @param bkPath
 * @param fmt
 */
public BackResponse backup(String bkType, String bkPath, String fmt) throws Exception {
    BackResponse backResponse = new BackResponse();
    if ("attach".equals(bkType)) {
        if (StringKit.isBlank(bkPath)) {
            throw new TipException("请输入备份文件存储路径");
        }
        if (!Files.isDirectory(Paths.get(bkPath))) {
            throw new TipException("请输入一个存在的目录");
        }
        String bkAttachDir = AttachController.CLreplacedPATH + "upload";
        String bkThemesDir = AttachController.CLreplacedPATH + "templates/themes";
        String fname = DateKit.toString(new Date(), fmt) + "_" + StringKit.rand(5) + ".zip";
        String attachPath = bkPath + "/" + "attachs_" + fname;
        String themesPath = bkPath + "/" + "themes_" + fname;
        ZipUtils.zipFolder(bkAttachDir, attachPath);
        ZipUtils.zipFolder(bkThemesDir, themesPath);
        backResponse.setAttach_path(attachPath);
        backResponse.setTheme_path(themesPath);
    }
    // 备份数据库
    if ("db".equals(bkType)) {
        String filePath = "upload/" + DateKit.toString(new Date(), "yyyyMMddHHmmss") + "_" + StringKit.rand(8) + ".db";
        String cp = AttachController.CLreplacedPATH + filePath;
        Files.createDirectory(Paths.get(cp));
        Files.copy(Paths.get(SqliteJdbc.DB_PATH), Paths.get(cp));
        backResponse.setSql_path("/" + filePath);
        // 10秒后删除备份文件
        new Timer().schedule(new TimerTask() {

            @Override
            public void run() {
                new File(cp).delete();
            }
        }, 10 * 1000);
    }
    return backResponse;
}

14 View Complete Implementation : WechatApp.java
Copyright Apache License 2.0
Author : Zhyblx
/**
 * 消息检查
 */
public int[] syncCheck() {
    int[] arr = new int[2];
    String Url = this.WEBPUSH_URL + "/synccheck";
    JSONObject body = new JSONObject();
    body.put("BaseRequest", BaseRequest);
    HttpRequest request = null;
    String res = null;
    request = HttpRequest.get(Url, true, "r", DateKit.getCurrentUnixTime() + StringKit.getRandomNumber(5), "skey", this.SKEY, "uin", this.WXUIN, "sid", this.WXSID, "deviceid", this.DEVICEID, "synckey", this.SYNCKEY, "_", System.currentTimeMillis()).header("Cookie", this.Cookie);
    LOGGER.info("[*] " + request);
    // 当res为空的时候,程序就开始报错了
    // res = request.body();
    /**
     *   循环的作用是排错
     *   原理:当res 为空的情况下,会一直循环获取内容,直到有内容的才跳出循环
     */
    int i = 1;
    while (i > 0) {
        // 当 res 出错的时候,异常不处理,res 字符串为空;然后继续执行循环提,直到拿到内容。
        try {
            res = request.body();
        } catch (Exception e) {
            res = "";
        }
        if (res != null || "".equals(res) || res.length() != 0) {
            break;
        }
    }
    request.disconnect();
    if (StringKit.isBlank(res)) {
        return arr;
    }
    String retcode = Matchers.match("retcode:\"(\\d+)\",", res);
    String selector = Matchers.match("selector:\"(\\d+)\"}", res);
    if (null != retcode && null != selector) {
        arr[0] = Integer.parseInt(retcode);
        arr[1] = Integer.parseInt(selector);
        return arr;
    }
    return arr;
}

14 View Complete Implementation : WechatApp.java
Copyright Apache License 2.0
Author : Zhyblx
/**
 * 登陆微信
 */
public boolean login() {
    HttpRequest request = HttpRequest.get(this.REDIRECT_URL);
    LOGGER.info("[*] " + request);
    String res = request.body();
    this.Cookie = CookieUtil.getCookie(request);
    request.disconnect();
    if (StringKit.isBlank(res)) {
        return false;
    }
    this.SKEY = Matchers.match("<skey>(\\S+)</skey>", res);
    this.WXSID = Matchers.match("<wxsid>(\\S+)</wxsid>", res);
    this.WXUIN = Matchers.match("<wxuin>(\\S+)</wxuin>", res);
    this.Preplaced_TICKET = Matchers.match("<preplaced_ticket>(\\S+)</preplaced_ticket>", res);
    LOGGER.info("[*] skey[%s]" + this.SKEY);
    LOGGER.info("[*] wxsid[%s]" + this.WXSID);
    LOGGER.info("[*] wxuin[%s]" + this.WXUIN);
    LOGGER.info("[*] preplaced_ticket[%s]" + this.Preplaced_TICKET);
    this.BaseRequest = new JSONObject();
    BaseRequest.put("Uin", this.WXUIN);
    BaseRequest.put("Sid", this.WXSID);
    BaseRequest.put("Skey", this.SKEY);
    BaseRequest.put("DeviceID", this.DEVICEID);
    return true;
}

13 View Complete Implementation : ArticleController.java
Copyright MIT License
Author : tfssweb
/**
 * 发布文章操作
 *
 * @return
 */
@PostRoute(value = "publish")
@JSON
public RestResponse publishArticle(@Valid Contents contents) {
    Users users = this.user();
    contents.setType(Types.ARTICLE);
    contents.setAuthorId(users.getUid());
    if (StringKit.isBlank(contents.getCategories())) {
        contents.setCategories("默认");
    }
    try {
        Integer cid = contentsService.publish(contents);
        siteService.cleanCache(Types.C_STATISTICS);
        return RestResponse.ok(cid);
    } catch (Exception e) {
        String msg = "文章发布失败";
        if (e instanceof TipException) {
            msg = e.getMessage();
        } else {
            log.error(msg, e);
        }
        return RestResponse.fail(msg);
    }
}

13 View Complete Implementation : TemplateController.java
Copyright MIT License
Author : tfssweb
@Route(value = "save", method = HttpMethod.POST)
@JSON
public RestResponse saveTpl(@Param String fileName, @Param String content) {
    if (StringKit.isBlank(fileName)) {
        return RestResponse.fail("缺少参数,请重试");
    }
    String themePath = Const.CLreplacedPATH + File.separatorChar + "templates" + File.separatorChar + "themes" + File.separatorChar + Commons.site_theme();
    String filePath = themePath + File.separatorChar + fileName;
    try {
        if (Files.exists(Paths.get(filePath))) {
            byte[] rf_wiki_byte = content.getBytes("UTF-8");
            Files.write(Paths.get(filePath), rf_wiki_byte);
        } else {
            Files.createFile(Paths.get(filePath));
            byte[] rf_wiki_byte = content.getBytes("UTF-8");
            Files.write(Paths.get(filePath), rf_wiki_byte);
        }
        return RestResponse.ok();
    } catch (Exception e) {
        log.error("写入文件失败", e);
        return RestResponse.fail("写入文件失败: " + e.getMessage());
    }
}

13 View Complete Implementation : IndexController.java
Copyright MIT License
Author : tfssweb
/**
 * 评论操作
 */
@CsrfToken(valid = true)
@PostRoute(value = "comment")
@JSON
public RestResponse comment(Request request, Response response, @HeaderParam String Referer, @Valid Comments comments) {
    if (StringKit.isBlank(Referer)) {
        return RestResponse.fail(ErrorCode.BAD_REQUEST);
    }
    if (!Referer.startsWith(Commons.site_url())) {
        return RestResponse.fail("非法评论来源");
    }
    String val = request.address() + ":" + comments.getCid();
    Integer count = cache.hget(Types.COMMENTS_FREQUENCY, val);
    if (null != count && count > 0) {
        return RestResponse.fail("您发表评论太快了,请过会再试");
    }
    comments.setAuthor(TaleUtils.cleanXSS(comments.getAuthor()));
    comments.setContent(TaleUtils.cleanXSS(comments.getContent()));
    comments.setAuthor(EmojiParser.parseToAliases(comments.getAuthor()));
    comments.setContent(EmojiParser.parseToAliases(comments.getContent()));
    comments.setIp(request.address());
    comments.setParent(comments.getCoid());
    try {
        commentsService.saveComment(comments);
        response.cookie("tale_remember_author", URLEncoder.encode(comments.getAuthor(), "UTF-8"), 7 * 24 * 60 * 60);
        response.cookie("tale_remember_mail", URLEncoder.encode(comments.getMail(), "UTF-8"), 7 * 24 * 60 * 60);
        if (StringKit.isNotBlank(comments.getUrl())) {
            response.cookie("tale_remember_url", URLEncoder.encode(comments.getUrl(), "UTF-8"), 7 * 24 * 60 * 60);
        }
        // 设置对每个文章30秒可以评论一次
        cache.hset(Types.COMMENTS_FREQUENCY, val, 1, 30);
        siteService.cleanCache(Types.C_STATISTICS);
        return RestResponse.ok();
    } catch (Exception e) {
        String msg = "评论发布失败";
        if (e instanceof TipException) {
            msg = e.getMessage();
        } else {
            log.error(msg, e);
        }
        return RestResponse.fail(msg);
    }
}

12 View Complete Implementation : WechatApp.java
Copyright Apache License 2.0
Author : Zhyblx
/**
 * 微信状态通知
 */
public boolean wxStatusNotify() {
    String Url = this.BASE_URL + WechatInterface.WXSTATUS_CODE + this.Preplaced_TICKET;
    JSONObject body = new JSONObject();
    body.put("BaseRequest", BaseRequest);
    body.put("Code", 3);
    body.put("FromUserName", this.User.getString("UserName"));
    body.put("ToUserName", this.User.getString("UserName"));
    body.put("ClientMsgId", DateKit.getCurrentUnixTime());
    HttpRequest request = HttpRequest.post(Url).header("Content-Type", "application/json;charset=utf-8").header("Cookie", this.Cookie).send(body.toString());
    LOGGER.info("[*] " + request);
    String res = request.body();
    request.disconnect();
    if (StringKit.isBlank(res)) {
        return false;
    }
    try {
        JSONObject jsonObject = (JSONObject) JSON.parse(res);
        JSONObject BaseResponse = (JSONObject) jsonObject.get("BaseResponse");
        if (null != BaseResponse) {
            int ret = BaseResponse.getInt("Ret", -1);
            return ret == 0;
        }
    } catch (Exception e) {
    }
    return false;
}

12 View Complete Implementation : WechatApp.java
Copyright Apache License 2.0
Author : Zhyblx
/**
 * 微信初始化
 */
public boolean wxInit() {
    String url = this.BASE_URL + "/webwxinit?r=" + DateKit.getCurrentUnixTime() + "&preplaced_ticket=" + this.Preplaced_TICKET + "&skey=" + this.SKEY;
    JSONObject body = new JSONObject();
    body.put("BaseRequest", this.BaseRequest);
    HttpRequest request = HttpRequest.post(url).header("Content-Type", "application/json;charset=utf-8").header("Cookie", this.Cookie).send(body.toString());
    LOGGER.info("[*] " + request);
    String res = request.body();
    request.disconnect();
    if (StringKit.isBlank(res)) {
        return false;
    }
    try {
        JSONObject jsonObject = (JSONObject) JSON.parse(res);
        if (null != jsonObject) {
            JSONObject BaseResponse = (JSONObject) jsonObject.get("BaseResponse");
            if (null != BaseResponse) {
                int ret = BaseResponse.getInt("Ret", -1);
                if (ret == 0) {
                    this.SyncKey = (JSONObject) jsonObject.get("SyncKey");
                    this.User = (JSONObject) jsonObject.get("User");
                    StringBuffer synckey = new StringBuffer();
                    JSONArray list = (JSONArray) SyncKey.get("List");
                    for (int i = 0, len = list.size(); i < len; i++) {
                        JSONObject item = (JSONObject) list.get(i);
                        synckey.append("|" + item.getInt("Key", 0) + "_" + item.getInt("Val", 0));
                    }
                    this.SYNCKEY = synckey.substring(1);
                    return true;
                }
            }
        }
    } catch (Exception e) {
    }
    return false;
}

11 View Complete Implementation : ContentsService.java
Copyright MIT License
Author : tfssweb
/**
 * 发布文章
 *
 * @param contents 文章对象
 */
public Integer publish(Contents contents) {
    if (null == contents) {
        throw new TipException("文章对象为空");
    }
    if (StringKit.isBlank(contents.getreplacedle())) {
        throw new TipException("文章标题不能为空");
    }
    if (contents.getreplacedle().length() > TaleConst.MAX_replacedLE_COUNT) {
        throw new TipException("文章标题最多可以输入" + TaleConst.MAX_replacedLE_COUNT + "个字符");
    }
    if (StringKit.isBlank(contents.getContent())) {
        throw new TipException("文章内容不能为空");
    }
    // 最多可以输入5w个字
    int len = contents.getContent().length();
    if (len > TaleConst.MAX_TEXT_COUNT) {
        throw new TipException("文章内容最多可以输入" + TaleConst.MAX_TEXT_COUNT + "个字符");
    }
    if (null == contents.getAuthorId()) {
        throw new TipException("请登录后发布文章");
    }
    if (StringKit.isNotBlank(contents.getSlug())) {
        if (contents.getSlug().length() < 5) {
            throw new TipException("路径太短了");
        }
        if (!TaleUtils.isPath(contents.getSlug())) {
            throw new TipException("您输入的路径不合法");
        }
        long count = new Contents().where("type", contents.getType()).and("slug", contents.getSlug()).count();
        if (count > 0) {
            throw new TipException("该路径已经存在,请重新输入");
        }
    }
    contents.setContent(EmojiParser.parseToAliases(contents.getContent()));
    int time = DateKit.nowUnix();
    contents.setCreated(time);
    contents.setModified(time);
    String tags = contents.getTags();
    String categories = contents.getCategories();
    Integer cid = contents.save();
    metreplacedervice.saveMetas(cid, tags, Types.TAG);
    metreplacedervice.saveMetas(cid, categories, Types.CATEGORY);
    return cid;
}

11 View Complete Implementation : WechatApp.java
Copyright Apache License 2.0
Author : Zhyblx
/**
 * 获取最新消息
 */
public JSONObject webwxsync() {
    String url = this.BASE_URL + "/webwxsync?lang=zh_CN&preplaced_ticket=" + this.Preplaced_TICKET + "&skey=" + this.SKEY + "&sid=" + this.WXSID + "&r=" + DateKit.getCurrentUnixTime();
    JSONObject body = new JSONObject();
    body.put("BaseRequest", BaseRequest);
    body.put("SyncKey", this.SyncKey);
    body.put("rr", DateKit.getCurrentUnixTime());
    HttpRequest request = HttpRequest.post(url).header("Content-Type", "application/json;charset=utf-8").header("Cookie", this.Cookie).send(body.toString());
    LOGGER.info("[*] " + request);
    String res = request.body();
    request.disconnect();
    if (StringKit.isBlank(res)) {
        return null;
    }
    JSONObject jsonObject = (JSONObject) JSON.parse(res);
    JSONObject BaseResponse = (JSONObject) jsonObject.get("BaseResponse");
    if (null != BaseResponse) {
        int ret = BaseResponse.getInt("Ret", -1);
        if (ret == 0) {
            this.SyncKey = (JSONObject) jsonObject.get("SyncKey");
            StringBuffer synckey = new StringBuffer();
            JSONArray list = (JSONArray) SyncKey.get("List");
            for (int i = 0, len = list.size(); i < len; i++) {
                JSONObject item = (JSONObject) list.get(i);
                synckey.append("|" + item.getInt("Key", 0) + "_" + item.getInt("Val", 0));
            }
            this.SYNCKEY = synckey.substring(1);
        }
    }
    return jsonObject;
}

10 View Complete Implementation : WechatApp.java
Copyright Apache License 2.0
Author : Zhyblx
/**
 * 获取联系人
 */
public boolean getContact() {
    String url = this.BASE_URL + "/webwxgetcontact?preplaced_ticket=" + this.Preplaced_TICKET + "&skey=" + this.SKEY + "&r=" + DateKit.getCurrentUnixTime();
    JSONObject body = new JSONObject();
    body.put("BaseRequest", BaseRequest);
    HttpRequest request = HttpRequest.post(url).header("Content-Type", "application/json;charset=utf-8").header("Cookie", this.Cookie).send(body.toString());
    LOGGER.info("[*] " + request);
    String res = request.body();
    request.disconnect();
    if (StringKit.isBlank(res)) {
        return false;
    }
    try {
        JSONObject jsonObject = (JSONObject) JSON.parse(res);
        // AddressBook类的作用:
        // 1.导出好友列表
        // 2.判断好友是否在数据库中存在,如果是数据库中不存在的好友,那么会将最新的好友存储在数据库中
        AddressBook.getAddressBookList(jsonObject);
        JSONObject BaseResponse = (JSONObject) jsonObject.get("BaseResponse");
        if (null != BaseResponse) {
            int ret = BaseResponse.getInt("Ret", -1);
            if (ret == 0) {
                this.MemberList = (JSONArray) jsonObject.get("MemberList");
                this.ContactList = new JSONArray();
                if (null != MemberList) {
                    for (int i = 0, len = MemberList.size(); i < len; i++) {
                        JSONObject contact = (JSONObject) this.MemberList.get(i);
                        // 公众号/服务号
                        if (contact.getInt("VerifyFlag", 0) == 8) {
                            continue;
                        }
                        // 特殊联系人
                        // if (SpecialUsers.contains(contact.getString("UserName"))) {
                        // continue;
                        // }
                        // 群聊
                        if (contact.getString("UserName").indexOf("@@") != -1) {
                            continue;
                        }
                        // 自己
                        if (contact.getString("UserName").equals(this.User.getString("UserName"))) {
                            continue;
                        }
                        ContactList.add(contact);
                    }
                    return true;
                }
            }
        }
    } catch (Exception e) {
    }
    return false;
}