public class BBCtoHTML_Parser {
Map<String,String> bbMap = new HashMap<String , String>();
public BBCtoHTML_Parser(){
fillHashmap();
}
public String parse(String html){
for (Map.Entry<String, String> entry: bbMap.entrySet()) {
html = html.replaceAll(entry.getKey().toString(), entry.getValue().toString());
}
return html;
}
public void fillHashmap(){
bbMap.put("<br />", "\r");
bbMap.put("<strong>(.+?)</strong>", "\\[b\\]$1\\[/b\\]");
bbMap.put("<b>(.+?)</b>", "\\[b\\]$1\\[/b\\]");
bbMap.put("<span style='font-style:italic;'>(.+?)</span>", "\\[i\\]$1\\[/i\\]");
bbMap.put("<span style='text-decoration:underline;'>(.+?)</span>", "\\[u\\]$1\\[/u\\]");
bbMap.put("<h1>(.+?)</h1>", "\\[h1\\]$1\\[/h1\\]");
bbMap.put("<h2>(.+?)</h2>", "\\[h2\\]$1\\[/h2\\]");
bbMap.put("<h3>(.+?)</h3>", "\\[h3\\]$1\\[/h3\\]");
bbMap.put("<h4>(.+?)</h4>", "\\[h4\\]$1\\[/h4\\]");
bbMap.put("<h5>(.+?)</h5>", "\\[h5\\]$1\\[/h5\\]");
bbMap.put("<h6>(.+?)</h6>", "\\[h6\\]$1\\[/h6\\]");
bbMap.put("<blockquote>(.+?)</blockquote>", "\\[quote\\]$1\\[/quote\\]");
bbMap.put("<p>(.+?)</p>", "\\[p\\]$1\\[/p\\]");
bbMap.put("<p style='text-indent:(.+?)px;line-height:$2%;'>$3</p>", "\\[p=$1,$1\\]$1\\[/p\\]");
bbMap.put("<div align='center'>(.+?)", "\\[center\\]$1\\[/center\\]");
bbMap.put("<div align='(.+?)'>$2", "\\[align=$1\\]$1\\[/align\\]");
bbMap.put("<span style='color:(.+?);'>$2</span>", "\\[color=$1\\]$1\\[/color\\]");
bbMap.put("<span style='font-size:(.+?);'>$2</span>", "\\[size=$1\\]$1\\[/size\\]");
bbMap.put("<img src='(.+?)' />", "\\[img\\]$1\\[/img\\]");
bbMap.put("<img width='(.+?)' height='$2' src='$3' />", "\\[img=$1,$1\\]$1\\[/img\\]");
bbMap.put("<a href='mailto:(.+?)'>(.+?)</a>", "\\[email\\]$1\\[/email\\]");
bbMap.put("<a href='mailto:(.+?)'>$2</a>", "\\[email=$1\\]$1\\[/email\\]");
bbMap.put("<a href='(.+?)'>(.+?)</a>", "\\[url\\]$1\\[/url\\]");
bbMap.put("<a href='(.+?)'>$2</a>", "\\[url=$1\\]$1\\[/url\\]");
bbMap.put("<object width='640' height='380'><param name='movie' value='http://www.youtube.com/v/(.+?)'></param><embed src='http://www.youtube.com/v/(.+?)' type='application/x-shockwave-flash' width='640' height='380'></embed></object>", "\\[youtube\\]$1\\[/youtube\\]");
bbMap.put("<video src='(.+?)' />", "\\[video\\]$1\\[/video\\]");
bbMap.put("<img(.+?)src=\"(.+?)\"(.+?)/>", "[img]$2[/Img]");
bbMap.put("<a(.+?)href=\"(.+?)\">(.+?)</a>", "[url=$2]$3[/url]");
bbMap.put("<i>(.+?)</i>", "[i]$1[/i]");
bbMap.put("<span class(.+?)>", "");
bbMap.put("img=\"(.+?)\"", "[img]$1[/img]");
}
}