- 浏览: 409067 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (325)
- 数据中台 (15)
- 设计模式 (7)
- 数据结构 (4)
- JavaScript (51)
- 网页设计与制作 (7)
- Flex (4)
- Fckeditor (7)
- Struts (12)
- Spring (19)
- Hibernate (14)
- EJB3.0 (19)
- Java EE 6 (2)
- JSP (22)
- 辅助框架 (9)
- WebService (1)
- XML (8)
- 正则表达式 (5)
- 并发(多线程) (2)
- Java网络 (10)
- 开发工具 (25)
- Oracle (15)
- MySQL (8)
- Git (4)
- SQL Server (2)
- C# (9)
- php (14)
- asp (2)
- ColdFusion (5)
- Tex (1)
- 云游戏 (1)
最新评论
-
CSDNBenbenChong:
...
SQL里desc和asc是什么意思 -
雪狐一号:
非常好 顶一个
SQL里desc和asc是什么意思 -
boyleichinasoft:
thinking...
该如何去使用设计模式呢? -
nforce_com:
写的很好,学习了!不过Student 一般情况下不会删除所有 ...
JPA多对多 -
TaoistWar:
那是FCKEditor的,详细信息只能查看官方文档,或者直接看 ...
1.fckeditor-java-2.5给上传图片添加水印
百度RSS新闻中的XML的
<
description
>
-
<![CDATA[
<a target=_blank href=http://news.beijingoffice.com.cn/35/2008111185936.html><img border=0 src=image/20/94/339730.jpg></a><br>刚刚过去的传统楼市"银十"风光不再,在月初的秋交会和下旬出台的中央"救市"新政合捧之下,10月深圳楼市的成交并没有出现显著放量。最新出炉的研究报告显示,上月深圳一手房成交量仅上涨10%,均价12979元/平方米 ... <br /> <a href=http://tech.qq.com/a/20081111/000109.htm target=_blank style="font-size:13px">大摩报告称:国内房市将进入数年熊市</a><nobr><span style="padding-left:10px;font-size:12px;color:#666666">QQ</font></nobr><br> <a href=http://sz.house.sina.com.cn/news/2008-11-11/082721998.html target=_blank style="font-size:13px">深圳上周新房成交量翻一番 均价同步涨近一成</a><nobr><span style="padding-left:10px;font-size:12px;color:#666666">新浪</font></nobr><br> - <a href=http://www.p5w.net/news/cjxw/200811/t2000687.htm target=_blank><font color="#008000">全景网</font></a> - <a href=http://www.house365.com/news/html/200811/79353_1.htm target=_blank><font color="#008000">365地产家居网</font></a> - <a href=http://cd.focus.cn/news/2008-11-11/562634.html target=_blank><font color="#008000">焦点房地产</font></a> - <a href=http://www.cq.xinhuanet.com/house/2008-11/11/content_14883026.htm target=_blank><font color="#008000">新华网重庆频道</font></a> - <a href=/n?cmd=2&page=%68%74%74%70%3a%2f%2f%77%77%77%2e%63%66%69%2e%6e%65%74%2e%63%6e%2f%70%32%30%30%38%31%31%31%31%30%30%30%34%39%35%2e%68%74%6d%6c&pn=1&clk=crel&cls=housenews&where=focuspage&class=housenews><font color="#008000">524条相关>></font></a><br>]]> <script type="text/javascript"><!----></script>
</
description
>
目标:
1.src=image/20/94/339730.jpg替换为http://news.baidu.com/image/20/94/339730.jpg 2.最后一个<a>标签为相关信息,删除
解决办法:用下则表达式为主解决了问题一,用到了HTML Parser解决问题二
public String doReplace(String content) { String content2 = content; try { Parser myParser; myParser = Parser.createParser(content2, "GBK"); NodeFilter filter = new TagNameFilter("A"); NodeList list = myParser.extractAllNodesThatMatch(filter); Node tempNode = list.remove(list.size()-1); int startNum = tempNode.getStartPosition(); content2 = content2.substring(0,startNum)+"<br/>"; } catch (ParserException e) { e.printStackTrace(); } Pattern p1 = Pattern.compile("<img(.*?)>", Pattern.CASE_INSENSITIVE); Matcher m1 = p1.matcher(content2); StringBuffer sb = new StringBuffer(); while (m1.find()) { String tempImg = m1.group(); int x = tempImg.indexOf(" src"); // 用图片的格式来定位src结束位置 int y = tempImg.indexOf(".jpg"); if (y == -1) { y = tempImg.indexOf(".jpeg"); if (y == -1) { y = tempImg.indexOf(".png"); if (y == -1) { y = tempImg.indexOf(".gif"); if (y == -1) { y = tempImg.indexOf(".bmp"); } else { y += 4; } } else { y += 4; } } else { y += 5; } } else { y += 4; } if (y != -1) { // 去掉src处空格 String tempSrc = tempImg.substring(x + 4, y).trim(); if (tempSrc.startsWith("=")) { tempSrc = tempSrc.substring(1, tempSrc.length()).trim(); } // 替换不是以http://开头的图片路径 if (!tempSrc.startsWith("http://")) { tempSrc = "=http://news.baidu.com/" + tempSrc; tempImg = tempImg.substring(0, x + 4) + tempSrc + tempImg.substring(y, tempImg.length()); } // 以上代码达到了把<img >标签的src属性替换 // ----------------------- m1.appendReplacement(sb, tempImg); } } m1.appendTail(sb); content2 = sb.toString(); return content2; }
发表评论
-
2.JSP的编码
2010-04-12 16:56 520使用统一编码UTF-8,JSP页面,JAVA类文件,数据库等 ... -
1.对Java编码的理解
2010-04-12 16:04 6421.原理 String username = req.get ... -
JSTL c:forEach map
2010-03-11 10:34 1802<c:forEach items="${map ... -
JSTL的EL表达式fn函数
2009-11-05 16:59 2155<%@ taglib prefix="fn&q ... -
汗啊!web.xml中可以配多个<url-patten>,居然现在才知道
2009-11-05 14:58 1162用了Struts2与FckEditor集成,发现Struts2 ... -
5.Servlet过滤器的使用
2009-08-11 18:12 6611.什么是Servlet过滤器? 我们日常生活中的 ... -
4.ServletContext(服务器全局变量)的使用
2009-07-28 00:40 2600在Sevlet中有时会用到服务器的全局变量,本节内 ... -
3.ServletConfig的使用
2009-07-28 00:34 935在2.Servlet的生命周期 中,我们重载了Se ... -
2.Servlet的生命周期
2009-07-28 00:24 6391.通过程序代码我们可以看出Serlet的生命周期。代码如下: ... -
1.Servlet的HelloWorld
2009-07-28 00:14 1047从今天开始,整理一下以前学习的J2EE知识。从JSP ... -
JavaSE的HTTP协议POST请求
2009-07-26 15:51 843package com.taoistwar.jsp.http; ... -
JavaSE的HTTP协议GET请求
2009-07-26 15:49 716package com.taoistwar.jsp.http; ... -
在action中获取项目所在的绝对路径
2009-02-14 09:40 1810String path = request.getSessio ... -
<jsp:include page="/xx.jsp"/>的使用
2009-01-18 23:14 1373<jsp:include/>的使用 包含相 ... -
JSP自定义EL函数实例教程
2009-01-18 21:43 915类: com.yx.news.view.action.Ta ... -
Java Reflection 反射机制
2009-01-16 22:12 631ClassLoad类的加载机制: * 并非一次性加载 * 需 ... -
myeclipse连接oracle出错
2009-01-11 13:25 990我用 myeclipse 连接 oracle的时候 ... -
JBPM的下载地址
2008-12-27 10:00 5539JBPM的下载地址: http://www.mirr ... -
用标签截取字符串长度
2008-12-16 08:57 631<c:out value="${fn:subs ... -
VeryCD资源
2008-11-21 17:45 689尚学堂: http://www.verycd.com/grou ...
评论