本文整理汇总了Java中org.apache.commons.text.StringEscapeUtils.unescapeHtml4方法的典型用法代码示例。如果您正苦于以下问题:Java StringEscapeUtils.unescapeHtml4方法的具体用法?Java StringEscapeUtils.unescapeHtml4怎么用?Java StringEscapeUtils.unescapeHtml4使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.text.StringEscapeUtils
的用法示例。
在下文中一共展示了StringEscapeUtils.unescapeHtml4方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getUrl
import org.apache.commons.text.StringEscapeUtils; //导入方法依赖的package包/类
/**
* Gets a URL from a wiki page value.
* @param htmlLink link as present on wiki page.
* @return address the link points to (if it is an 'a'), the original link otherwise.
*/
public String getUrl(String htmlLink) {
String result = htmlLink;
if (htmlLink != null) {
Matcher linkMatcher = LINKPATTERN.matcher(htmlLink);
Matcher imgMatcher = IMAGEPATTERN.matcher(htmlLink);
if (linkMatcher.matches()) {
String href = linkMatcher.group(1);
href = StringEscapeUtils.unescapeHtml4(href);
result = href + linkMatcher.group(3);
} else if (imgMatcher.matches()) {
String src = imgMatcher.group(1);
result = StringEscapeUtils.unescapeHtml4(src);
}
}
return result;
}
示例2: getTitle
import org.apache.commons.text.StringEscapeUtils; //导入方法依赖的package包/类
final public String getTitle() {
if (titleCache != null)
return titleCache;
if (rootNode == null)
return null;
String[] p1 = { "html", "head", "title" };
String title = rootNode.getFirstTextNode(p1);
if (title == null) {
String[] p2 = { "html", "title" };
title = rootNode.getFirstTextNode(p2);
}
if (title == null)
return null;
titleCache = StringEscapeUtils.unescapeHtml4(title);
return titleCache;
}
示例3: cleanupPreFormatted
import org.apache.commons.text.StringEscapeUtils; //导入方法依赖的package包/类
/**
* Removes HTML preformatting (if any).
* @param value value (possibly pre-formatted)
* @return value without HTML preformatting.
*/
public String cleanupPreFormatted(String value) {
String result = value;
if (value != null) {
Matcher matcher = PRE_FORMATTED_PATTERN.matcher(value);
if (matcher.matches()) {
String escapedBody = matcher.group(1);
result = StringEscapeUtils.unescapeHtml4(escapedBody);
}
}
return result;
}
示例4: printText
import org.apache.commons.text.StringEscapeUtils; //导入方法依赖的package包/类
/**
* Write a {@link String} value into XML output.
*
* @param value
* XML string
*
* @param minLength
* minimal length
*
* @param maxLength
* maximal length
*
* @return
* XML string
*
* @throws IllegalArgumentException
* if a validation error occured
*/
private static String printText( String value, Integer minLength, Integer maxLength )
{
String val = StringUtils.trimToNull( value );
if (val==null)
{
throw new IllegalArgumentException(
"The provided text '" + value + "' is invalid!" );
}
if (minLength!=null && val.length()<minLength)
{
throw new IllegalArgumentException(
"The provided text " + value + " is too short (minimum is " + minLength + ")!" );
}
val = StringEscapeUtils.unescapeHtml4( value );
// replace <br> with line breaks
Matcher m = BR_TAG_PATTERN.matcher( val );
val = StringUtils.trimToEmpty( m.replaceAll( SystemUtils.LINE_SEPARATOR ) );
// strip any other html code
m = ANY_TAG_PATTERN.matcher( val );
val = StringUtils.trimToEmpty( m.replaceAll( "" ) );
val = StringUtils.replace( val, "<", "«" );
val = StringUtils.replace( val, ">", "»" );
return (maxLength!=null)?
StringUtils.abbreviate( val, maxLength ): val;
}
示例5: mapFieldTarget
import org.apache.commons.text.StringEscapeUtils; //导入方法依赖的package包/类
final public String mapFieldTarget(CommonFieldTarget dfTarget, String content) {
if (StringUtils.isBlank(content))
return null;
if (dfTarget.isConvertHtmlEntities())
content = StringEscapeUtils.unescapeHtml4(content);
if (dfTarget.isRemoveTag())
content = StringUtils.removeTag(content);
if (dfTarget.hasRegexpPattern())
content = dfTarget.applyRegexPattern(content);
return content;
}
示例6: getAudio
import org.apache.commons.text.StringEscapeUtils; //导入方法依赖的package包/类
@SneakyThrows
@Override
public List<Audio> getAudio(Long ownerId) {
VkAudioDto audioDto;
List<Audio> list = new ArrayList<>();
int offset = 0;
do {
Connection.Response response = Jsoup.connect(PATH_BASE + "/al_audio.php")
.userAgent(USER_AGENT).cookies(cookies).method(Connection.Method.POST)
.data("access_hash", "")
.data("act", "load_section")
.data("al", "1")
.data("claim", "0")
.data("offset", String.valueOf(offset))
.data("owner_id", ownerId.toString())
.data("playlist_id", "-1")
.data("type", "playlist")
.execute();
String body = response.body();
String json = body.substring(body.indexOf(JSON_DELIMITER) + JSON_DELIMITER.length());
json = json.substring(0, json.indexOf("<!>"));
audioDto = JsonUtils.fromString(json, VkAudioDto.class);
for (List values : audioDto.getList()) {
Audio audio = new Audio(
((Number) values.get(0)).longValue(),
((Number) values.get(1)).longValue(),
StringEscapeUtils.unescapeHtml4((String) values.get(4)),
StringEscapeUtils.unescapeHtml4((String) values.get(3)),
(Integer) values.get(5)
);
list.add(audio);
}
offset = audioDto.getNextOffset();
} while (audioDto.hasMore());
log.debug("Total count: {}", audioDto.getTotalCount());
log.debug("Fetched audio collection: {}", list.size());
return list;
}
示例7: testHTMLDecode
import org.apache.commons.text.StringEscapeUtils; //导入方法依赖的package包/类
public void testHTMLDecode(String f) throws IOException {
String out = StringEscapeUtils.unescapeHtml4(FileUtility.readFile(f));
FileUtility.writeFile(out, f + ".out");
}
示例8: getBodyTextContent
import org.apache.commons.text.StringEscapeUtils; //导入方法依赖的package包/类
private void getBodyTextContent(ParserResultItem result, StringBuilder sb, HtmlNodeAbstract<Object> node,
boolean bAddBlock, String[] directFields, int recursion, Set<Object> nodeExclusionsSet) {
if (recursion == 0) {
Logging.warn("Max recursion reached (getBodyTextContent)");
return;
}
if (nodeExclusionsSet != null)
if (nodeExclusionsSet.contains(node.node))
return;
recursion--;
if (node.isComment())
return;
String nodeName = node.getNodeName();
if ("script".equalsIgnoreCase(nodeName))
return;
if ("style".equalsIgnoreCase(nodeName))
return;
if ("object".equalsIgnoreCase(nodeName))
return;
if ("title".equalsIgnoreCase(nodeName))
return;
if ("oss".equalsIgnoreCase(nodeName)) {
if ("yes".equalsIgnoreCase(node.getAttribute("ignore")))
return;
}
boolean bEnterDirectField = false;
String classNameAttribute = node.getAttribute("class");
if (classNameAttribute != null) {
String[] classNames = org.apache.commons.lang3.StringUtils.split(classNameAttribute);
if (classNames != null) {
for (String className : classNames) {
if (OPENSEARCHSERVER_IGNORE.equalsIgnoreCase(className))
return;
if (className.startsWith(OPENSEARCHSERVER_FIELD)) {
String directField = classNameAttribute.substring(OPENSEARCHSERVER_FIELD_LENGTH);
if (directField.length() > 0) {
directFields = directField.split("\\.");
bEnterDirectField = directFields.length > 0;
}
}
}
}
}
if (node.isTextNode()) {
String text = node.getText();
text = text.replaceAll("\\r", " ");
text = text.replaceAll("\\n", " ");
text = StringUtils.replaceConsecutiveSpaces(text, " ");
text = text.trim();
if (text.length() > 0) {
text = StringEscapeUtils.unescapeHtml4(text);
if (sb.length() > 0)
sb.append(' ');
sb.append(text);
}
}
final List<HtmlNodeAbstract<Object>> children = node.getChildNodes();
if (children != null)
for (HtmlNodeAbstract<Object> htmlNode : children)
getBodyTextContent(result, sb, htmlNode, bAddBlock, directFields, recursion, nodeExclusionsSet);
if (bAddBlock && nodeName != null && sb.length() > 0) {
String currentTag = nodeName.toLowerCase();
boolean bForSentence = sb.charAt(sb.length() - 1) != '.' && sentenceTagSet.contains(currentTag);
if (bForSentence || bEnterDirectField) {
if (directFields != null)
result.addDirectFields(directFields, sb.toString());
else
addFieldBody(result, currentTag, sb.toString());
sb.setLength(0);
}
}
}
示例9: getMetaContent
import org.apache.commons.text.StringEscapeUtils; //导入方法依赖的package包/类
final public static String getMetaContent(final HtmlNodeAbstract<?> node) {
String content = node.getAttributeText("content");
if (content == null)
return null;
return StringEscapeUtils.unescapeHtml4(content);
}
示例10: IndexDocument
import org.apache.commons.text.StringEscapeUtils; //导入方法依赖的package包/类
/**
* Create a new instance of IndexDocument from an XML structure <br>
* <field name="FIELDNAME"><br>
* <value>VALUE1</value><br>
* <value>VALUE2</value><br>
* </field>
*
* @param client
* @param parserSelector
* @param documentNode
* @param urlDefaultCredential
* @param httpDownloader
* @throws XPathExpressionException
* @throws SearchLibException
* @throws ClassNotFoundException
* @throws IllegalAccessException
* @throws InstantiationException
* @throws DOMException
* @throws IOException
* @throws URISyntaxException
*/
public IndexDocument(Client client, ParserSelector parserSelector, Node documentNode,
CredentialItem urlDefaultCredential, HttpDownloader httpDownloader)
throws XPathExpressionException, SearchLibException, InstantiationException, IllegalAccessException,
ClassNotFoundException, IOException, URISyntaxException {
this(LanguageEnum.findByCode(XPathParser.getAttributeString(documentNode, "lang")));
List<Node> fieldNodes = DomUtils.getNodes(documentNode, "field");
for (Node fieldNode : fieldNodes) {
List<String> copyFieldList = getCopyFieldList(fieldNode);
String fieldName = XPathParser.getAttributeString(fieldNode, "name");
List<Node> valueNodes = DomUtils.getNodes(fieldNode, "value");
for (Node valueNode : valueNodes) {
boolean removeTag = "yes".equalsIgnoreCase(XPathParser.getAttributeString(valueNode, "removeTag"));
boolean convertHtmlEntities = "yes".equalsIgnoreCase(
XPathParser.getAttributeString(valueNode, "convertHtmlEntities"));
String textContent = valueNode.getTextContent();
if (convertHtmlEntities)
textContent = StringEscapeUtils.unescapeHtml4(textContent);
if (removeTag)
textContent = StringUtils.removeTag(textContent);
Float boost = XPathParser.getAttributeFloat(valueNode, "boost");
add(fieldName, textContent, boost);
if (copyFieldList != null)
for (String f : copyFieldList)
add(f, textContent, boost);
}
}
List<Node> binaryNodes = DomUtils.getNodes(documentNode, "binary");
for (Node node : binaryNodes) {
boolean bFaultTolerant = "yes".equalsIgnoreCase(XPathParser.getAttributeString(node, "faultTolerant"));
String filename = XPathParser.getAttributeString(node, "fileName");
if (filename == null || filename.length() == 0)
filename = XPathParser.getAttributeString(node, "filename");
String filePath = XPathParser.getAttributeString(node, "filePath");
if (filePath == null || filePath.length() == 0)
filePath = XPathParser.getAttributeString(node, "filepath");
String contentType = XPathParser.getAttributeString(node, "contentType");
if (contentType == null || contentType.length() == 0)
contentType = XPathParser.getAttributeString(node, "contenttype");
String content = node.getTextContent();
String url = XPathParser.getAttributeString(node, "url");
Parser parser = doBinary(url, content, filePath, filename, client, parserSelector, contentType,
urlDefaultCredential, httpDownloader, bFaultTolerant);
if (parser != null)
parser.popupateResult(0, this);
}
}
示例11: html
import org.apache.commons.text.StringEscapeUtils; //导入方法依赖的package包/类
/**
* Unescapes supplied HTML content so it can be rendered inside a wiki page.
* @param htmlSource HTML code to display (possibly surrounded by <pre></pre> tags).
* @return unescaped content, enclosed in <div></div> so wiki will not escape it.
*/
public String html(String htmlSource) {
String cleanSource = htmlCleaner.cleanupPreFormatted(htmlSource);
return "<div>" + StringEscapeUtils.unescapeHtml4(cleanSource) + "</div>";
}