0

I want to add custom logic/class to my custom Jackson JsonSerialize implementation such that it parses out html based on certain rules. For example, if html is inclosed in single quotes '<b>'text'</b>' then the custom logic should accept the string as is. If its not in single quotes, like <b>text</b> then I want the custom logic/class to return just text. Additionally, if I have a block of html enclosed in three single quotes '''<html><head><title>example</title></head></html>''' it should accepted as is but if its not then only the example text should be returned and everything else parsed out. What is the best Java library to accomplish this? I thought about using AnitSamy but that leaves me open to an XSS attack since I need to accept anything inside quotes.

Examples:

input:<b>text</b>
output:text

input:'<b>'text'</b>'
output:'<b>'text'</b>'

input:<html><head><title>text</title></head></html>
output:text

input:'''<html><head><title>text</title></head></html>'''
output:'''<html><head><title>text</title></head></html>'''
4

1 回答 1

1

您可以使用 Java 正则表达式引擎来查找模式。前任:

p = Pattern.compile("'''[\\w*]'''");
m = p.matcher(input);
if(m.find()){
    //Do some logic
}

这是 Java 正则表达式网站的链接: http ://www.regular-expressions.info/java.html

于 2013-09-11T21:35:53.553 回答