Java Code Examples for com.vdurmont.emoji.EmojiParser#parseToAliases()

The following examples show how to use com.vdurmont.emoji.EmojiParser#parseToAliases() . 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: NewTopicPresenter.java    From guanggoo-android with Apache License 2.0 6 votes vote down vote up
@Override
public void newTopic(String title, String content) {
    mView.startLoading();

    title = EmojiParser.parseToAliases(title);
    content = EmojiParser.parseToAliases(content);

    NetworkTaskScheduler.getInstance().execute(new NewTopicTask(mView.getUrl(),
            title,
            content,
            new OnResponseListener<String>() {
                @Override
                public void onSucceed(String data) {
                    mView.stopLoading();
                    mView.onNewTopicSucceed();
                }

                @Override
                public void onFailed(String msg) {
                    mView.stopLoading();
                    mView.onNewTopicFailed(msg);
                }
    }));
}
 
Example 2
Source File: TopicDetailPresenter.java    From guanggoo-android with Apache License 2.0 6 votes vote down vote up
@Override
public void comment(String content) {
    mView.startLoading();
    content = EmojiParser.parseToAliases(content);
    NetworkTaskScheduler.getInstance().execute(new CommentTask(getUrl(), content, new OnResponseListener<String>() {
        @Override
        public void onSucceed(String data) {
            mView.stopLoading();
            mView.onCommentSucceed();
        }

        @Override
        public void onFailed(String msg) {
            mView.stopLoading();
            mView.onCommentFailed(msg);
        }
    }));
}
 
Example 3
Source File: CommentController.java    From Jantent with MIT License 5 votes vote down vote up
@PostMapping(value = "")
@ResponseBody
@Transactional(rollbackFor = TipException.class)
public RestResponseBo reply(@RequestParam Integer coid, @RequestParam String content, HttpServletRequest request) {
    if (null == coid || StringUtils.isBlank(content)) {
        return RestResponseBo.fail("请输入完整后评论");
    }

    if (content.length() > 2000) {
        return RestResponseBo.fail("请输入2000个字符以内的回复");
    }

    CommentVo temp = commentServcie.getCommentById(coid);
    if (null == temp) {
        return RestResponseBo.fail("不存在该评论");
    }

    UserVo users = this.user(request);
    content = MyUtils.cleanXSS(content);
    content = EmojiParser.parseToAliases(content);

    CommentVo comments = new CommentVo();
    comments.setAuthor(users.getUsername());
    comments.setAuthorId(users.getUid());
    comments.setCid(temp.getCid());
    comments.setIp(request.getRemoteAddr());
    comments.setUrl(users.getHomeUrl());
    comments.setContent(content);
    comments.setMail(users.getEmail());
    comments.setParent(coid);
    try {
        commentServcie.insertComment(comments);
        return RestResponseBo.ok();
    } catch (Exception e) {
        String msg = "回复失败";
        return ExceptionHelper.handlerException(logger, msg, e);
    }
}
 
Example 4
Source File: HomeController.java    From my-site with Apache License 2.0 4 votes vote down vote up
/**
 * 评论操作
 */
@PostMapping(value = "/blog/comment")
@ResponseBody
public APIResponse comment(HttpServletRequest request, HttpServletResponse response,
                           @RequestParam(name = "cid", required = true) Integer cid,
                           @RequestParam(name = "coid", required = false) Integer coid,
                           @RequestParam(name = "author", required = false) String author,
                           @RequestParam(name = "mail", required = false) String mail,
                           @RequestParam(name = "url", required = false) String url,
                           @RequestParam(name = "text", required = true) String text,
                           @RequestParam(name = "_csrf_token", required = true) String _csrf_token) {

    String ref = request.getHeader("Referer");
    if (StringUtils.isBlank(ref) || StringUtils.isBlank(_csrf_token)) {
        return APIResponse.fail("访问失败");
    }

    String token = cache.hget(Types.CSRF_TOKEN.getType(), _csrf_token);
    if (StringUtils.isBlank(token)) {
        return APIResponse.fail("访问失败");
    }

    if (null == cid || StringUtils.isBlank(text)) {
        return APIResponse.fail("请输入完整后评论");
    }

    if (StringUtils.isNotBlank(author) && author.length() > 50) {
        return APIResponse.fail("姓名过长");
    }

    if (StringUtils.isNotBlank(mail) && !TaleUtils.isEmail(mail)) {
        return APIResponse.fail("请输入正确的邮箱格式");
    }

    if (StringUtils.isNotBlank(url) && !PatternKit.isURL(url)) {
        return APIResponse.fail("请输入正确的URL格式");
    }

    if (text.length() > 200) {
        return APIResponse.fail("请输入200个字符以内的评论");
    }

    String val = IPKit.getIpAddrByRequest(request) + ":" + cid;
    Integer count = cache.hget(Types.COMMENTS_FREQUENCY.getType(), val);
    if (null != count && count > 0) {
        return APIResponse.fail("您发表评论太快了,请过会再试");
    }

    author = TaleUtils.cleanXSS(author);
    text = TaleUtils.cleanXSS(text);

    author = EmojiParser.parseToAliases(author);
    text = EmojiParser.parseToAliases(text);

    CommentDomain comments = new CommentDomain();
    comments.setAuthor(author);
    comments.setCid(cid);
    comments.setIp(request.getRemoteAddr());
    comments.setUrl(url);
    comments.setContent(text);
    comments.setMail(mail);
    comments.setParent(coid);
    try {
        commentService.addComment(comments);
        cookie("tale_remember_author", URLEncoder.encode(author, "UTF-8"), 7 * 24 * 60 * 60, response);
        cookie("tale_remember_mail", URLEncoder.encode(mail, "UTF-8"), 7 * 24 * 60 * 60, response);
        if (StringUtils.isNotBlank(url)) {
            cookie("tale_remember_url", URLEncoder.encode(url, "UTF-8"), 7 * 24 * 60 * 60, response);
        }
        // 设置对每个文章1分钟可以评论一次
        cache.hset(Types.COMMENTS_FREQUENCY.getType(), val, 1, 60);

        return APIResponse.success();
    } catch (Exception e) {
        throw BusinessException.withErrorCode(ErrorConstant.Comment.ADD_NEW_COMMENT_FAIL);
    }
}
 
Example 5
Source File: IndexController.java    From Jantent with MIT License 4 votes vote down vote up
/**
 * 评论操作
 *
 * @param request
 * @param response
 * @param cid
 * @param coid
 * @param author
 * @param mail
 * @param url
 * @param text
 * @param _csrf_token
 * @return
 */
@PostMapping(value = "comment")
@ResponseBody
@Transactional(rollbackFor = TipException.class)
public RestResponseBo comment(HttpServletRequest request, HttpServletResponse response,
                              @RequestParam Integer cid, @RequestParam Integer coid,
                              @RequestParam String author, @RequestParam String mail,
                              @RequestParam String url, @RequestParam String text, @RequestParam String _csrf_token) {
    String ref = request.getHeader("Referer");
    if (StringUtils.isBlank(ref) || StringUtils.isBlank(_csrf_token)) {
        return RestResponseBo.fail("Bad request");
    }

    String token = cache.hget(Types.CSRF_TOKEN.getType(), _csrf_token);
    if (StringUtils.isBlank(token)) {
        return RestResponseBo.fail("Bad request");
    }

    if (null == cid || StringUtils.isBlank(text)) {
        return RestResponseBo.fail("请输入完整后评论");
    }
    if (StringUtils.isNotBlank(author) && author.length() > 50) {
        return RestResponseBo.fail("姓名过长");
    }

    if (StringUtils.isNotBlank(mail) && !MyUtils.isEmail(mail)) {
        return RestResponseBo.fail("请输入正确的邮箱格式");
    }

    if (StringUtils.isNotBlank(url) && !PatternKit.isURL(url)) {
        return RestResponseBo.fail("请输入正确的URL格式");
    }

    if (text.length() > 200) {
        return RestResponseBo.fail("请输入200个字符以内的评论");
    }

    String val = IpUtil.getIpAddrByRequest(request) + ":" + cid;
    Integer count = cache.hget(Types.COMMENTS_FREQUENCY.getType(), val);
    if (null != count && count > 0) {
        return RestResponseBo.fail("您发表的评论太快了,请过会再试");
    }

    // 去除js脚本
    author = MyUtils.cleanXSS(author);
    text = MyUtils.cleanXSS(text);

    author = EmojiParser.parseToAliases(author);
    text = EmojiParser.parseToAliases(text);

    CommentVo comments = new CommentVo();
    comments.setAuthor(author);
    comments.setCid(cid);
    comments.setIp(request.getRemoteAddr());
    comments.setUrl(url);
    comments.setContent(text);
    comments.setMail(mail);
    comments.setParent(coid);
    try {
        commentService.insertComment(comments);
        cookie("tale_remember_author", URLEncoder.encode(author, "UTF-8"), 7 * 24 * 60 * 60, response);
        cookie("tale_remember_mail", URLDecoder.decode(mail, "UTF-8"), 7 * 24 * 60 * 60, response);
        if (StringUtils.isNotBlank(url)) {
            cookie("tale_remember_author", URLEncoder.encode(author, "UTF-8"), 7 * 24 * 60 * 60, response);
        }
        // 设置对每个文章1分钟评论一次
        cache.hset(Types.COMMENTS_FREQUENCY.getType(), val, 1, 60);
        return RestResponseBo.ok();
    } catch (Exception e) {
        String msg = "评论发布失败";
        return ExceptionHelper.handlerException(logger,msg,e);
    }
}
 
Example 6
Source File: CommentController.java    From tale with MIT License 4 votes vote down vote up
@PostRoute(value = "")
@JSON
public RestResponse reply(@Param Integer coid, @Param String content, Request request) {
    if (null == coid || StringKit.isBlank(content)) {
        return RestResponse.fail("请输入完整后评论");
    }

    if (content.length() > 2000) {
        return RestResponse.fail("请输入2000个字符以内的回复");
    }
    Comments c = commentsService.byId(coid);
    if (null == c) {
        return RestResponse.fail("不存在该评论");
    }
    Users users = this.user();
    content = TaleUtils.cleanXSS(content);
    content = EmojiParser.parseToAliases(content);

    Comments comments = new Comments();
    comments.setAuthor(users.getUsername());
    comments.setAuthor_id(users.getUid());
    comments.setCid(c.getCid());
    comments.setIp(request.address());
    comments.setUrl(users.getHome_url());
    comments.setContent(content);
    if (StringKit.isNotBlank(users.getEmail())) {
        comments.setMail(users.getEmail());
    } else {
        comments.setMail("[email protected]");
    }
    comments.setParent(coid);
    try {
        commentsService.saveComment(comments);
        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 7
Source File: RemovingEmojiFromStringUnitTest.java    From tutorials with MIT License 4 votes vote down vote up
@Test
public void whenReplaceEmojiUsingLibrary_thenSuccess() {
    String result = EmojiParser.parseToAliases(text);
    System.out.println(result);
    assertEquals(result, "la conférence, commencera à 10 heures :sweat_smile:");
}
 
Example 8
Source File: EmojiUtils.java    From feiqu-opensource with Apache License 2.0 2 votes vote down vote up
/**
 * Replaces the emoji's unicode occurrences by one of their alias
 * (between 2 ':').
 *
 * @param input the string to parse
 *
 * @return the string with the emojis replaced by their alias.
 */
public static String toAliases(String input) {
    return EmojiParser.parseToAliases(input);
}