当前位置: 首页>>代码示例>>Java>>正文


Java Lexer.nextNode方法代码示例

本文整理汇总了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);
	}
}
 
开发者ID:huanzhou,项目名称:jeecms6,代码行数:19,代码来源:StrUtils.java

示例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();
}
 
开发者ID:8090boy,项目名称:gomall.la,代码行数:33,代码来源:SafeHtml.java

示例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);
	}
}
 
开发者ID:huanzhou,项目名称:jeecms6,代码行数:36,代码来源:CmsKeywordMngImpl.java

示例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();
}
 
开发者ID:eclipse123,项目名称:JForum,代码行数:33,代码来源:SafeHtml.java


注:本文中的org.htmlparser.lexer.Lexer.nextNode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。