Java Code Examples for com.blade.kit.StringKit#isBlank()

The following examples show how to use com.blade.kit.StringKit#isBlank() . These examples are extracted from open source projects. 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 Project: tale   File: TaleUtils.java    License: MIT License 6 votes vote down vote up
/**
 * 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            document   = parser.parse(markdown);
    HtmlRenderer    renderer   = HtmlRenderer.builder().extensions(extensions).build();
    String          content    = renderer.render(document);
    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("&lt;script src=\"https://gist.github.com/(\\w+)/(\\w+)\\.js\">&lt;/script>", "<script src=\"https://gist.github.com/$1/$2\\.js\"></script>");
    }

    return content;
}
 
Example 2
Source Project: blade   File: PathRegexBuilder.java    License: Apache License 2.0 6 votes vote down vote up
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();
    }
}
 
Example 3
Source Project: tale   File: ArticleController.java    License: MIT License 6 votes vote down vote up
/**
 * 发布文章操作
 *
 * @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);
    }
}
 
Example 4
Source Project: tale   File: IndexController.java    License: MIT License 6 votes vote down vote up
/**
 * 系统备份
 *
 * @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);
    }
}
 
Example 5
Source Project: blade   File: DynamicContext.java    License: Apache License 2.0 6 votes vote down vote up
public static boolean isJarPackage(String packageName) {
    if (StringKit.isBlank(packageName)) {
        return false;
    }
    try {
        packageName = packageName.replace(".", "/");
        Enumeration<URL> dirs = DynamicContext.class.getClassLoader().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;
}
 
Example 6
Source Project: blade   File: PathRegexBuilder.java    License: Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 7
Source Project: squirrelAI   File: WechatApp.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 微信状态通知
 */
public boolean wxStatusNotify() {

    String Url = this.BASE_URL + WechatInterface.WXSTATUS_CODE + this.PASS_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;
}
 
Example 8
Source Project: blade   File: RouteActionArguments.java    License: Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 9
Source Project: tale   File: Theme.java    License: MIT License 5 votes vote down vote up
/**
 * 返回主题设置选项
 *
 * @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;
}
 
Example 10
Source Project: tale   File: IndexController.java    License: MIT License 5 votes vote down vote up
/**
 * 修改密码
 */
@Route(value = "password", method = HttpMethod.POST)
@JSON
public RestResponse upPwd(@Param String old_password, @Param String password, Request request) {
    Users users = this.user();
    if (StringKit.isBlank(old_password) || StringKit.isBlank(password)) {
        return RestResponse.fail("请确认信息输入完整");
    }

    if (!users.getPassword().equals(EncryptKit.md5(users.getUsername() + old_password))) {
        return RestResponse.fail("旧密码错误");
    }
    if (password.length() < 6 || password.length() > 14) {
        return RestResponse.fail("请输入6-14位密码");
    }

    try {
        Users  temp = new Users();
        String pwd  = EncryptKit.md5(users.getUsername() + password);
        temp.setPassword(pwd);
        temp.update(users.getUid());
        new Logs(LogActions.UP_PWD, null, request.address(), this.getUid()).save();
        return RestResponse.ok();
    } catch (Exception e) {
        String msg = "密码修改失败";
        if (e instanceof TipException) {
            msg = e.getMessage();
        } else {
            log.error(msg, e);
        }
        return RestResponse.fail(msg);
    }
}
 
Example 11
Source Project: blade   File: RouteActionArguments.java    License: Apache License 2.0 5 votes vote down vote up
private static Object getAnnotationParam(Parameter parameter, String paramName, Request request) {
    Type  argType = parameter.getParameterizedType();
    Param param   = parameter.getAnnotation(Param.class);

    ParamStruct.ParamStructBuilder structBuilder = ParamStruct.builder().argType(argType).request(request);

    if (null != param) {
        ParamStruct paramStruct = structBuilder.param(param).paramName(paramName).build();
        return getQueryParam(paramStruct);
    }
    BodyParam bodyParam = parameter.getAnnotation(BodyParam.class);
    if (null != bodyParam) {
        return getBodyParam(structBuilder.build());
    }
    PathParam pathParam = parameter.getAnnotation(PathParam.class);
    if (null != pathParam) {
        return getPathParam(structBuilder.pathParam(pathParam).paramName(paramName).build());
    }
    HeaderParam headerParam = parameter.getAnnotation(HeaderParam.class);
    if (null != headerParam) {
        return getHeader(structBuilder.headerParam(headerParam).paramName(paramName).build());
    }
    // cookie param
    CookieParam cookieParam = parameter.getAnnotation(CookieParam.class);
    if (null != cookieParam) {
        return getCookie(structBuilder.cookieParam(cookieParam).paramName(paramName).build());
    }
    // form multipart
    MultipartParam multipartParam = parameter.getAnnotation(MultipartParam.class);
    if (null != multipartParam && argType == FileItem.class) {
        String name = StringKit.isBlank(multipartParam.value()) ? paramName : multipartParam.value();
        return request.fileItem(name).orElse(null);
    }
    return null;
}
 
Example 12
Source Project: blade   File: RouteActionArguments.java    License: Apache License 2.0 5 votes vote down vote up
private static Object getQueryParam(ParamStruct paramStruct) {
    Param   param     = paramStruct.param;
    String  paramName = paramStruct.paramName;
    Type    argType   = paramStruct.argType;
    Request request   = paramStruct.request;
    if (null == param) {
        return null;
    }

    String name = StringKit.isBlank(param.name()) ? paramName : param.name();

    if (ReflectKit.isBasicType(argType) || argType.equals(Date.class)
            || argType.equals(BigDecimal.class) || argType.equals(LocalDate.class)
            || argType.equals(LocalDateTime.class) || (argType instanceof Class && ((Class) argType).isEnum())) {

        String value = request.query(name).orElseGet(() -> getDefaultValue(param.defaultValue(), argType));

        return ReflectKit.convert(argType, value);
    } else {
        if (ParameterizedType.class.isInstance(argType)) {

            List<String> values = request.parameters().get(param.name());
            return getParameterizedTypeValues(values, argType);
        }
        return parseModel(ReflectKit.typeToClass(argType), request, param.name());
    }
}
 
Example 13
Source Project: blade   File: RouteActionArguments.java    License: Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 14
Source Project: squirrelAI   File: WechatApp.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * 微信初始化
 */
public boolean wxInit() {

    String url = this.BASE_URL + "/webwxinit?r=" + DateKit.getCurrentUnixTime() + "&pass_ticket=" + this.PASS_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;
}
 
Example 15
Source Project: squirrelAI   File: WechatApp.java    License: Apache License 2.0 4 votes vote down vote up
/**
     * 获取联系人
     */
    public boolean getContact() {

        String url = this.BASE_URL + "/webwxgetcontact?pass_ticket=" + this.PASS_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;
    }
 
Example 16
Source Project: squirrelAI   File: WechatApp.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * 消息检查
 */
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;
}
 
Example 17
Source Project: tale   File: IndexController.java    License: MIT License 4 votes vote down vote up
/**
 * 评论操作
 */
@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);
    }
}
 
Example 18
Source Project: tale   File: InstallController.java    License: MIT License 4 votes vote down vote up
@Route(value = "/", method = HttpMethod.POST)
@JSON
public RestResponse doInstall(@Param String site_title, @Param String site_url,
                              @Param String admin_user, @Param String admin_email,
                              @Param String admin_pwd) {
    if (Files.exists(Paths.get(AttachController.CLASSPATH + "install.lock"))
            && TaleConst.OPTIONS.getInt("allow_install", 0) != 1) {
        return RestResponse.fail("请勿重复安装");
    }
    try {
        if (StringKit.isBlank(site_title) ||
                StringKit.isBlank(site_url) ||
                StringKit.isBlank(admin_user) ||
                StringKit.isBlank(admin_pwd)) {
            return RestResponse.fail("请确认网站信息输入完整");
        }

        if (admin_pwd.length() < 6 || admin_pwd.length() > 14) {
            return RestResponse.fail("请输入6-14位密码");
        }

        if (StringKit.isNotBlank(admin_email) && !TaleUtils.isEmail(admin_email)) {
            return RestResponse.fail("邮箱格式不正确");
        }

        Users temp = new Users();
        temp.setUsername(admin_user);
        temp.setPassword(admin_pwd);
        temp.setEmail(admin_email);

        siteService.initSite(temp);

        if (site_url.endsWith("/")) {
            site_url = site_url.substring(0, site_url.length() - 1);
        }
        if (!site_url.startsWith("http")) {
            site_url = "http://".concat(site_url);
        }
        optionsService.saveOption("site_title", site_title);
        optionsService.saveOption("site_url", site_url);

        TaleConst.OPTIONS = Environment.of(optionsService.getOptions());
    } catch (Exception e) {
        String msg = "安装失败";
        if (e instanceof TipException) {
            msg = e.getMessage();
        } else {
            log.error(msg, e);
        }
        return RestResponse.fail(msg);
    }
    return RestResponse.ok();
}
 
Example 19
Source Project: tale   File: SiteService.java    License: MIT License 4 votes vote down vote up
/**
 * 系统备份
 *
 * @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.CLASSPATH + "upload";
        String bkThemesDir = AttachController.CLASSPATH + "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.CLASSPATH + 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;
}
 
Example 20
Source Project: tale   File: ContentsService.java    License: MIT License 4 votes vote down vote up
/**
 * 发布文章
 *
 * @param contents 文章对象
 */
public Integer publish(Contents contents) {
    if (null == contents) {
        throw new TipException("文章对象为空");
    }
    if (StringKit.isBlank(contents.getTitle())) {
        throw new TipException("文章标题不能为空");
    }
    if (contents.getTitle().length() > TaleConst.MAX_TITLE_COUNT) {
        throw new TipException("文章标题最多可以输入" + TaleConst.MAX_TITLE_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();

    metasService.saveMetas(cid, tags, Types.TAG);
    metasService.saveMetas(cid, categories, Types.CATEGORY);

    return cid;
}