com.vdurmont.emoji.EmojiParser Java Examples
The following examples show how to use
com.vdurmont.emoji.EmojiParser.
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: ContentServcieImpl.java From Jantent with MIT License | 7 votes |
@Override public void updateArticle(ContentVo contents) { // 检查文章输入 checkContent(contents); if (StringUtils.isBlank(contents.getSlug())) { contents.setSlug(null); } int time = DateKit.getCurrentUnixTime(); contents.setModified(time); Integer cid = contents.getCid(); contents.setContent(EmojiParser.parseToAliases(contents.getContent())); contentDao.updateByPrimaryKeySelective(contents); // 更新缓存 String contentKey = RedisKeyUtil.getKey(ContentKey.TABLE_NAME, ContentKey.MAJOR_KEY, contents.getSlug()); redisService.deleteKey(contentKey); relationshipService.deleteById(cid, null); metasService.saveMetas(cid, contents.getTags(), Types.TAG.getType()); metasService.saveMetas(cid, contents.getCategories(), Types.CATEGORY.getType()); }
Example #2
Source File: ContentsService.java From tale with MIT License | 6 votes |
/** * 编辑文章 * * @param contents 文章对象 */ public void updateArticle(Contents contents) { contents.setModified(DateKit.nowUnix()); contents.setContent(EmojiParser.parseToAliases(contents.getContent())); contents.setTags(contents.getTags() != null ? contents.getTags() : ""); contents.setCategories(contents.getCategories() != null ? contents.getCategories() : ""); String tags = contents.getTags(); String categories = contents.getCategories(); Integer cid = contents.getCid(); contents.update(cid); if (null != contents.getType() && !contents.getType().equals(Types.PAGE)) { new Relationships().delete("cid", cid); } metasService.saveMetas(cid, tags, Types.TAG); metasService.saveMetas(cid, categories, Types.CATEGORY); }
Example #3
Source File: NewTopicPresenter.java From guanggoo-android with Apache License 2.0 | 6 votes |
@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 #4
Source File: TopicDetailPresenter.java From guanggoo-android with Apache License 2.0 | 6 votes |
@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 #5
Source File: CommonTools.java From xiaoV with GNU General Public License v3.0 | 5 votes |
/** * 处理emoji表情 * * @param d * @param k * @author https://github.com/yaphone * @date 2017年4月23日 下午2:39:04 */ public static void emojiFormatter(JSONObject d, String k) { Matcher matcher = getMatcher( "<span class=\"emoji emoji(.{1,10})\"></span>", d.getString(k)); StringBuilder sb = new StringBuilder(); String content = d.getString(k); int lastStart = 0; while (matcher.find()) { String str = matcher.group(1); if (str.length() == 6) { } else if (str.length() == 10) { } else { str = "&#x" + str + ";"; String tmp = content.substring(lastStart, matcher.start()); sb.append(tmp + str); lastStart = matcher.end(); } } if (lastStart < content.length()) { sb.append(content.substring(lastStart)); } if (sb.length() != 0) { d.put(k, EmojiParser.parseToUnicode(sb.toString())); } else { d.put(k, content); } }
Example #6
Source File: MessageAPI.java From DiscordMC with GNU General Public License v2.0 | 5 votes |
/** * Send a chat message to the Minecraft server * * @param origin {@link IChannel} the message came from * @param username player who sent the message * @param message the actual message which gets sent */ public static void sendToMinecraft(IChannel origin, String username, String message) { String formattedMessage = getFormattedMessage(origin, username); DiscordMC.getSubscribedPlayers().forEach(uuid -> Bukkit.getPlayer(uuid).sendMessage( EmojiParser.parseToAliases(formattedMessage .replaceAll("%message", ChatColor.stripColor(message))))); }
Example #7
Source File: CommentController.java From Jantent with MIT License | 5 votes |
@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 #8
Source File: ContentServcieImpl.java From Jantent with MIT License | 5 votes |
@Override public void publish(ContentVo contents) { checkContent(contents); if (StringUtils.isNotBlank(contents.getSlug())) { if (contents.getSlug().length() < 5) { throw new TipException("路径太短了"); } if (!MyUtils.isPath(contents.getSlug())) { throw new TipException("您输入的路径不合法"); } ContentVoExample contentVoExample = new ContentVoExample(); contentVoExample.createCriteria().andTypeEqualTo(contents.getType()).andSlugEqualTo(contents.getSlug()); long count = contentDao.countByExample(contentVoExample); if (count > 0) { throw new TipException("该路径已经存在,请重新输入"); } } else { contents.setSlug(null); } // 去除表情 contents.setContent(EmojiParser.parseToAliases(contents.getContent())); int time = DateKit.getCurrentUnixTime(); contents.setCreated(time); contents.setModified(time); contents.setHits(0); contents.setCommentsNum(0); contentDao.insert(contents); String tags = contents.getTags(); String categories = contents.getCategories(); Integer cid = contents.getCid(); metasService.saveMetas(cid, tags, Types.TAG.getType()); metasService.saveMetas(cid, categories, Types.CATEGORY.getType()); }
Example #9
Source File: RemovingEmojiFromStringUnitTest.java From tutorials with MIT License | 4 votes |
@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 #10
Source File: RemovingEmojiFromStringUnitTest.java From tutorials with MIT License | 4 votes |
@Test public void whenRemoveEmojiUsingLibrary_thenSuccess() { String result = EmojiParser.removeAllEmojis(text); System.out.println(result); assertEquals(result, "la conférence, commencera à 10 heures "); }
Example #11
Source File: PostHelper.java From hipda with GNU General Public License v2.0 | 4 votes |
public PostBean post() { PostBean postBean = mPostArg; String replyText = postBean.getContent(); String tid = postBean.getTid(); String pid = postBean.getPid(); int fid = postBean.getFid(); int floor = postBean.getFloor(); String subject = postBean.getSubject(); String typeid = postBean.getTypeid(); int count = 0; while (mInfo == null && count < 3) { count++; mInfo = new PrePostAsyncTask(mCtx, null, mMode).doInBackground(postBean); } mFloor = floor; replyText = replaceToTags(replyText); replyText = EmojiParser.parseToHtmlDecimal(replyText); if (!TextUtils.isEmpty(subject)) subject = EmojiParser.parseToHtmlDecimal(subject); if (mMode != MODE_EDIT_POST) { String tailStr = HiSettingsHelper.getInstance().getTailStr(); if (!TextUtils.isEmpty(tailStr) && HiSettingsHelper.getInstance().isAddTail()) { if (!replyText.trim().endsWith(tailStr)) replyText += " " + tailStr; } } String url = HiUtils.ReplyUrl + tid + "&replysubmit=yes"; // do send switch (mMode) { case MODE_REPLY_THREAD: case MODE_QUICK_REPLY: doPost(url, replyText, null, null, false); break; case MODE_REPLY_POST: case MODE_QUOTE_POST: doPost(url, EmojiParser.parseToHtmlDecimal(mInfo.getQuoteText()) + "\n\n " + replyText, null, null, false); break; case MODE_NEW_THREAD: url = HiUtils.NewThreadUrl + fid + "&typeid=" + typeid + "&topicsubmit=yes"; doPost(url, replyText, subject, null, false); break; case MODE_EDIT_POST: url = HiUtils.EditUrl + "&extra=&editsubmit=yes&mod=&editsubmit=yes" + "&fid=" + fid + "&tid=" + tid + "&pid=" + pid + "&page=1"; doPost(url, replyText, subject, typeid, postBean.isDelete()); break; } postBean.setSubject(mTitle); postBean.setFloor(mFloor); postBean.setTid(mTid); postBean.setMessage(mResult); postBean.setStatus(mStatus); postBean.setDetailListBean(mDetailListBean); return postBean; }
Example #12
Source File: StopList.java From TweetwallFX with MIT License | 4 votes |
public static String removeEmojis(final String s) { return EmojiParser.removeAllEmojis(s); }
Example #13
Source File: ContentsService.java From tale with MIT License | 4 votes |
/** * 发布文章 * * @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; }
Example #14
Source File: IndexController.java From tale with MIT License | 4 votes |
/** * 评论操作 */ @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 #15
Source File: CommentController.java From tale with MIT License | 4 votes |
@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 #16
Source File: IndexController.java From Jantent with MIT License | 4 votes |
/** * 评论操作 * * @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 #17
Source File: OutgoingMessageViewHolder.java From weMessage with GNU Affero General Public License v3.0 | 4 votes |
private boolean isStringEmojis(String text){ return !StringUtils.isEmpty(text.trim()) && StringUtils.isEmpty(EmojiParser.removeAllEmojis(text).trim()); }
Example #18
Source File: IncomingMessageViewHolder.java From weMessage with GNU Affero General Public License v3.0 | 4 votes |
private boolean isStringEmojis(String text){ return !StringUtils.isEmpty(text.trim()) && StringUtils.isEmpty(EmojiParser.removeAllEmojis(text).trim()); }
Example #19
Source File: HomeController.java From my-site with Apache License 2.0 | 4 votes |
/** * 评论操作 */ @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 #20
Source File: MessageAPI.java From DiscordMC with GNU General Public License v2.0 | 3 votes |
/** * Send a chat message to the Minecraft server console * * @param origin {@link IChannel} the message came from * @param username player who sent the message * @param message the actual message which gets sent */ public static void sendToMinecraftConsole(IChannel origin, String username, String message) { String formattedMessage = getFormattedMessage(origin, username); Bukkit.getConsoleSender().sendMessage( EmojiParser.parseToAliases(formattedMessage.replaceAll("%message", ChatColor.stripColor(message)))); }
Example #21
Source File: Commons.java From tale with MIT License | 2 votes |
/** * An :grinning:awesome :smiley:string 😄with a few :wink:emojis! * <p> * 这种格式的字符转换为emoji表情 * * @param value * @return */ public static String emoji(String value) { return EmojiParser.parseToUnicode(value); }
Example #22
Source File: Commons.java From Jantent with MIT License | 2 votes |
/** * An :grinning:awesome :smiley:string 😄with a few :wink:emojis! * <p> * 这种格式的字符转换为emoji表情 * * @param value * @return */ public static String emoji(String value) { return EmojiParser.parseToUnicode(value); }
Example #23
Source File: MessageAPI.java From DiscordMC with GNU General Public License v2.0 | 2 votes |
/** * Send a raw message to the Minecraft server * * @param message raw message which gets sent */ public static void sendRawToMinecraft(String message) { Bukkit.broadcastMessage(EmojiParser.parseToAliases(message)); }
Example #24
Source File: Commons.java From my-site with Apache License 2.0 | 2 votes |
/** * An :grinning:awesome :smiley:string 😄with a few :wink:emojis! * <p> * 这种格式的字符转换为emoji表情 * * @param value * @return */ public static String emoji(String value) { return EmojiParser.parseToUnicode(value); }
Example #25
Source File: EmojiUtils.java From feiqu-opensource with Apache License 2.0 | 2 votes |
/** * Replaces the emoji's aliases (between 2 ':') occurrences and the html * representations by their unicode. * * @param input the string to parse * * @return the string with the emojis replaced by their alias. */ public static String toUnicode(String input) { return EmojiParser.parseToUnicode(input); }
Example #26
Source File: EmojiUtils.java From feiqu-opensource with Apache License 2.0 | 2 votes |
/** * 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); }