// unHTML.java
// ---------------------------
// part of YaCy
// (C) by Marc Nause; marc.nause@gmx.de.
// Braunschweig, Germany, 2005
// last major change: 27.06.
/**Some code to avoid people being able to mess with the message system
*by using HTML.
*@author Marc Nause
extended for bbCode by Alexander Schier
*/
package de.anomic.tools;
public class bbCode {
String text;
/**init - no Code yet*/
public bbCode()
{
}
/**Replaces all < and > with < and > in a string.
*@author Marc Nause
*@return String
*/
public String escapeHtml(String input){
String output = "";
int iter = 0;
while(iter < input.length()){
String temp = input.substring(iter,iter+1);
iter++;
if(temp.equals("<")) {temp = "<";}
else if (temp.equals(">")) {temp = ">";}
output = output + temp;
}
return output;
}
/**Parses parts of bbCode (TODO: [Img],[URL],[List],[List=]).
*@author Alexander Schier
*@author Roland Ramthun
*@return String
*/
public String bb(String input){
String output = escapeHtml(input);
//Parse bold
output = output.replaceAll("\\[b\\]", "<b>");
output = output.replaceAll("\\[/b\\]", "</b>");
//Parse italic
output = output.replaceAll("\\[i\\]", "<i>");
output = output.replaceAll("\\[/i\\]", "</i>");
//Parse underlined
output = output.replaceAll("\\[u\\]", "<u>");
output = output.replaceAll("\\[/u\\]", "</u>");
return output;
}
}