Java Code Examples for org.springframework.web.util.HtmlUtils#htmlUnescape()

The following examples show how to use org.springframework.web.util.HtmlUtils#htmlUnescape() . 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: ArticleController.java    From feiqu-opensource with Apache License 2.0 6 votes vote down vote up
@GetMapping("caiji")
public void caiji(){
    String result = HttpUtil.get("http://hd.zt.raiyi.com/v9/private/682265b8574104c64c262c1b3f7a3eb771f01e126687b1a14b048025a9b639918ae7d834f2c3158c646add7a52ab8e78/weibo/theme/list?appCode=other_browser&tag=hot");
    AllDataRes allDataRes = JSON.parseObject(result, AllDataRes.class);
    List<SingleData> data = allDataRes.getData();
    for(SingleData singleData : data){
        String content = singleData.getContent();
        String html = singleData.getHtml();
        String htmlUn = HtmlUtils.htmlUnescape(html);
        Article article = new Article();
        article.setArticleTitle(content);
        article.setCreateTime(new Date());
        article.setArticleContent(htmlUn);
        article.setUserId(22);
        articleService.insert(article);
    }

}
 
Example 2
Source File: HTMLUtils.java    From jeecg-cloud with Apache License 2.0 5 votes vote down vote up
/**
 * 获取HTML内的文本,不包含标签
 *
 * @param html HTML 代码
 */
public static String getInnerText(String html) {
    if (StringUtils.isNotBlank(html)) {
        //去掉 html 的标签
        String content = html.replaceAll("</?[^>]+>", "");
        // 将多个空格合并成一个空格
        content = content.replaceAll("(&nbsp;)+", "&nbsp;");
        // 反向转义字符
        content = HtmlUtils.htmlUnescape(content);
        return content.trim();
    }
    return "";
}
 
Example 3
Source File: HTMLUtils.java    From teaching with Apache License 2.0 5 votes vote down vote up
/**
 * 获取HTML内的文本,不包含标签
 *
 * @param html HTML 代码
 */
public static String getInnerText(String html) {
    if (StringUtils.isNotBlank(html)) {
        //去掉 html 的标签
        String content = html.replaceAll("</?[^>]+>", "");
        // 将多个空格合并成一个空格
        content = content.replaceAll("(&nbsp;)+", "&nbsp;");
        // 反向转义字符
        content = HtmlUtils.htmlUnescape(content);
        return content.trim();
    }
    return "";
}
 
Example 4
Source File: HTMLUtils.java    From jeecg-boot with Apache License 2.0 5 votes vote down vote up
/**
 * 获取HTML内的文本,不包含标签
 *
 * @param html HTML 代码
 */
public static String getInnerText(String html) {
    if (StringUtils.isNotBlank(html)) {
        //去掉 html 的标签
        String content = html.replaceAll("</?[^>]+>", "");
        // 将多个空格合并成一个空格
        content = content.replaceAll("(&nbsp;)+", "&nbsp;");
        // 反向转义字符
        content = HtmlUtils.htmlUnescape(content);
        return content.trim();
    }
    return "";
}
 
Example 5
Source File: MessageController.java    From MyCommunity with Apache License 2.0 4 votes vote down vote up
private Map<String, Object> assembleMessageVo(Message message, Map<String, Object> messageVo, EventType type, int userId) {

        if (message != null) {
            // 用户id 加密
            message.setToId(XORUtil.encryptId(message.getToId(), Const.getIdEncodeKeys.userIdKeys));
            messageVo.put("message", message);

            String content = HtmlUtils.htmlUnescape(message.getContent());
            Map<String, Object> data = JSONObject.parseObject(content, HashMap.class);

            // 事件触发者 actor
            messageVo.put("user", iUserService.findUserById((Integer) data.get("userId")));
            messageVo.put("entityType", data.get("entityType"));
            // 如果是帖子id,则加密  评论id不用
            int entityId = data.get("entityType").equals(Const.entityType.ENTITY_TYPE_POST) ?
            XORUtil.encryptId((Integer) data.get("entityId"), Const.getIdEncodeKeys.postIdKeys) : (Integer) data.get("entityId");
            messageVo.put("entityId", entityId);

            /**
             * 注意:关注、注册事件没有 postId
             */
            if (data.get("postId") != null) {
                // 帖子id加密
                messageVo.put("postId", XORUtil.encryptId((Integer) data.get("postId"), Const.getIdEncodeKeys.postIdKeys));
            }

            /**
             * 取出注册时写的msg
             */
            if (data.get("msg") != null) {
                messageVo.put("msg", data.get("msg"));
            }

            int count = iMessageService.findNoticeCount(userId, type.getValue());
            messageVo.put("count", count);

            int unread = iMessageService.findNoticeUnreadCount(userId, type.getValue());
            messageVo.put("unread", unread);
        }

        return messageVo;
    }
 
Example 6
Source File: MessageController.java    From MyCommunity with Apache License 2.0 4 votes vote down vote up
@RequestMapping(path = "/notice/detail/{topic}", method = RequestMethod.GET)
public String getNoticeDetail(@PathVariable("topic") String topic, Page page, Model model) {
    UserVo user = hostHolder.getUser();
    // 解密
    int userId = XORUtil.encryptId(user.getId(), Const.getIdEncodeKeys.userIdKeys);

    page.setLimit(5);
    page.setPath("/notice/detail/" + topic);
    page.setRows(iMessageService.findNoticeCount(userId, topic));


    List<Message> noticeList = iMessageService.findNotices(userId, topic, page.getOffset(), page.getLimit());
    List<Map<String, Object>> noticeVoList = new ArrayList<>();
    if (noticeList != null) {
        for (Message notice : noticeList) {
            Map<String, Object> map = new HashMap<>();
            // 通知
            map.put("notice", notice);
            // 内容
            String content = HtmlUtils.htmlUnescape(notice.getContent());
            Map<String, Object> data = JSONObject.parseObject(content, HashMap.class);
            // 事件触发者 actor
            map.put("user", iUserService.findUserById((Integer) data.get("userId")));
            map.put("entityType", data.get("entityType"));
            // 如果是帖子id,则加密  评论id不用
            int entityId = data.get("entityType").equals(Const.entityType.ENTITY_TYPE_POST) ?
                    XORUtil.encryptId((Integer) data.get("entityId"), Const.getIdEncodeKeys.postIdKeys) : (Integer) data.get("entityId");
            map.put("entityId", entityId);
            /**
             * 注意:关注、注册等系统事件没有 postId
             */
            if (!topic.equals(EventType.FOLLOW.getValue()) && !topic.equals(EventType.SYSTEM.getValue())) {
                // 帖子id加密
                map.put("postId", XORUtil.encryptId((Integer) data.get("postId"), Const.getIdEncodeKeys.postIdKeys));
            }

            /**
             * 类似注册事件还有 msg
             */
            if (data.get("msg") != null) {
                map.put("msg", data.get("msg"));
            }
            // 通知作者
            map.put("fromUser", iUserService.findUserById(notice.getFromId()));

            noticeVoList.add(map);
        }
    }
    model.addAttribute("notices", noticeVoList);

    // 先加密  再传进 getLetterIds 中
    for (Message message : noticeList) {
        message.setToId(XORUtil.encryptId(message.getToId(), Const.getIdEncodeKeys.userIdKeys));
    }
    // 设置已读
    List<Integer> ids = getLetterIds(noticeList);
    if (!ids.isEmpty()) {
        iMessageService.readMessage(ids);
    }

    return "/site/notice-detail";
}
 
Example 7
Source File: DemoController.java    From jeewx with Apache License 2.0 4 votes vote down vote up
@RequestMapping(params = "demoTurn")
@ResponseBody
public String demoTurn(String id){
	String code = systemService.get(TSDemo.class, id).getDemocode();
	return HtmlUtils.htmlUnescape(code);
}
 
Example 8
Source File: XssUtils.java    From onetwo with Apache License 2.0 4 votes vote down vote up
public static String unescape(String content){
	return HtmlUtils.htmlUnescape(content);
}
 
Example 9
Source File: FormatHelper.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
public static String htmlUnescape(String input){
	return HtmlUtils.htmlUnescape(input);
}
 
Example 10
Source File: Html.java    From conference-app with MIT License 4 votes vote down vote up
public static String unEscapeHtml(String html) {
    return HtmlUtils.htmlUnescape(html);
}
 
Example 11
Source File: FormatHelper.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
public static String htmlUnescape(String input){
	return HtmlUtils.htmlUnescape(input);
}