本文整理汇总了Java中org.htmlparser.lexer.Lexer.nextNode方法的典型用法代码示例。如果您正苦于以下问题:Java Lexer.nextNode方法的具体用法?Java Lexer.nextNode怎么用?Java Lexer.nextNode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.htmlparser.lexer.Lexer
的用法示例。
在下文中一共展示了Lexer.nextNode方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: html2Text
import org.htmlparser.lexer.Lexer; //导入方法依赖的package包/类
public static String html2Text(String html, int len) {
try {
Lexer lexer = new Lexer(html);
Node node;
StringBuilder sb = new StringBuilder(html.length());
while ((node = lexer.nextNode()) != null) {
if (node instanceof TextNode) {
sb.append(node.toHtml());
}
if (sb.length() > len) {
break;
}
}
return sb.toString();
} catch (ParserException e) {
throw new RuntimeException(e);
}
}
示例2: ensureAllAttributesAreSafe
import org.htmlparser.lexer.Lexer; //导入方法依赖的package包/类
/**
* Given an input, analyze each HTML tag and remove unsecure attributes from
* them.
*
* @param contents
* The content to verify
* @return the content, secure.
*/
public String ensureAllAttributesAreSafe(String contents) {
StringBuffer sb = new StringBuffer(contents.length());
try {
Lexer lexer = new Lexer(contents);
Node node;
while ((node = lexer.nextNode()) != null) {
if (node instanceof Tag) {
Tag tag = (Tag) node;
this.checkAndValidateAttributes(tag, false);
sb.append(tag.toHtml());
} else {
sb.append(node.toHtml());
}
}
} catch (Exception e) {
throw new RuntimeException("Problems while parsing HTML", e);
}
return sb.toString();
}
示例3: attachKeyword
import org.htmlparser.lexer.Lexer; //导入方法依赖的package包/类
@Transactional(readOnly = true)
public String attachKeyword(Integer siteId, String txt) {
if (StringUtils.isBlank(txt)) {
return txt;
}
List<CmsKeyword> list = getListBySiteId(siteId, true, true);
int len = list.size();
if (len <= 0) {
return txt;
}
String[] searchArr = new String[len];
String[] replacementArr = new String[len];
int i = 0;
for (CmsKeyword k : list) {
searchArr[i] = k.getName();
replacementArr[i] = k.getUrl();
i++;
}
try {
Lexer lexer = new Lexer(txt);
Node node;
StringBuilder sb = new StringBuilder((int) (txt.length() * 1.2));
while ((node = lexer.nextNode()) != null) {
if (node instanceof TextNode) {
sb.append(StringUtils.replaceEach(node.toHtml(), searchArr,
replacementArr));
} else {
sb.append(node.toHtml());
}
}
return sb.toString();
} catch (ParserException e) {
throw new RuntimeException(e);
}
}
示例4: ensureAllAttributesAreSafe
import org.htmlparser.lexer.Lexer; //导入方法依赖的package包/类
/**
* Given an input, analyze each HTML tag and remove unsecure attributes from them.
*
* @param contents The content to verify
* @return the content, secure.
*/
public String ensureAllAttributesAreSafe(String contents) {
StringBuilder sb = new StringBuilder(contents.length());
try {
Lexer lexer = new Lexer(contents);
Node node;
while ((node = lexer.nextNode()) != null) {
if (node instanceof Tag) {
Tag tag = (Tag) node;
this.checkAndValidateAttributes(tag, false);
sb.append(tag.toHtml());
}
else {
sb.append(node.toHtml());
}
}
}
catch (Exception e) {
throw new ForumException("Problems while parsing HTML: " + e, e);
}
return sb.toString();
}