* @param text Input parameter containing HTML tags (eg. <b>cat</b>)
* @return String without HTML tags (eg. cat)
*/
public static String removeHtml(String text) {
//#ifdef DLOGGING
Logger logger = Logger.getLogger("StringUtil");
boolean finerLoggable = logger.isLoggable(Level.FINER);
//#endif
try{
int idx = text.indexOf('<');
if (idx == -1) return text;
StringBuffer plainText = new StringBuffer();
String htmlText = text;
int htmlStartIndex = htmlText.indexOf('<');
if(htmlStartIndex == -1) {
return text;
}
while (htmlStartIndex>=0) {
plainText.append(htmlText.substring(0,htmlStartIndex));
int htmlEndIndex = htmlText.indexOf('>', htmlStartIndex);
// If we have unmatched '<' without '>' stop or we
// get into infinate loop.
if (htmlEndIndex < 0) {
//#ifdef DLOGGING
if (finerLoggable) {logger.finer("No end > for htmlStartIndex,htmlText=" + htmlStartIndex + "," + htmlText);}
if (finerLoggable) {logger.finer("plainText=" + plainText);}
//#endif
break;
}
htmlText = htmlText.substring(htmlEndIndex+1);
htmlStartIndex = htmlText.indexOf('<');