|
|
|
@ -109,131 +109,22 @@ public class wikiCode {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//The following method has been submitted by Kane (added and a few changes by MN)
|
|
|
|
|
/** Replaces special characters from a string. Otherwise they might cause ugly output on some systems.
|
|
|
|
|
* This code is also important to avoid XSS attacks.
|
|
|
|
|
*
|
|
|
|
|
* @param text a string that possibly contains special characters
|
|
|
|
|
* @return the string with all special characters encoded so they will look right on every system
|
|
|
|
|
*/
|
|
|
|
|
public static String replaceHTML(String text) {
|
|
|
|
|
if (text==null) { return null; }
|
|
|
|
|
for (int x=0;x<=htmlentities.length-1;x=x+2) {
|
|
|
|
|
int p=0;
|
|
|
|
|
while ((p=text.indexOf(htmlentities[x],p))>=0) {
|
|
|
|
|
text=text.substring(0,p)+htmlentities[x+1]+text.substring(p+htmlentities[x].length());
|
|
|
|
|
p+=htmlentities[x+1].length();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return text;
|
|
|
|
|
public static String replaceHTML(String result) {
|
|
|
|
|
if (result == null) return null;
|
|
|
|
|
int p0;
|
|
|
|
|
|
|
|
|
|
// Ampersands have to be replaced first. If they were replaced later,
|
|
|
|
|
// other replaced characters containing ampersands would get messed up.
|
|
|
|
|
p0 = 0; while ((p0 = result.indexOf("&", p0)) >= 0) {result = result.substring(0, p0) + "&" + result.substring(p0 + 1); p0++;}
|
|
|
|
|
p0 = 0; while ((p0 = result.indexOf('"', p0)) >= 0) result = result.substring(0, p0) + """ + result.substring(p0 + 1);
|
|
|
|
|
p0 = 0; while ((p0 = result.indexOf("<", p0)) >= 0) result = result.substring(0, p0) + "<" + result.substring(p0 + 1);
|
|
|
|
|
p0 = 0; while ((p0 = result.indexOf(">", p0)) >= 0) result = result.substring(0, p0) + ">" + result.substring(p0 + 1);
|
|
|
|
|
//p0 = 0; while ((p0 = result.indexOf("*", p0)) >= 0) result = result.substring(0, p0) + "•" + result.substring(p0 + 1);
|
|
|
|
|
p0 = 0; while ((p0 = result.indexOf("(C)", p0)) >= 0) result = result.substring(0, p0) + "©" + result.substring(p0 + 3);
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static String[] htmlentities={
|
|
|
|
|
"&","&", // Ampersands _have_ to be replaced first. If they were replaced later,
|
|
|
|
|
// other replaced characters containing ampersands would get messed up.
|
|
|
|
|
//" "," ",
|
|
|
|
|
"¡","¡",
|
|
|
|
|
"¢","¢",
|
|
|
|
|
"£","£",
|
|
|
|
|
//"?","¤",
|
|
|
|
|
"¥","¥",
|
|
|
|
|
//"?","¦",
|
|
|
|
|
"§","§",
|
|
|
|
|
//"?","¨",
|
|
|
|
|
"©","©",
|
|
|
|
|
"ª","ª",
|
|
|
|
|
"«","«",
|
|
|
|
|
"¬","¬",
|
|
|
|
|
//"","­",
|
|
|
|
|
"®","®",
|
|
|
|
|
"¯","¯",
|
|
|
|
|
"°","°",
|
|
|
|
|
"±","±",
|
|
|
|
|
"²","²",
|
|
|
|
|
"³","³",
|
|
|
|
|
//"?","´",
|
|
|
|
|
"µ","µ",
|
|
|
|
|
"¶","¶",
|
|
|
|
|
"·","·",
|
|
|
|
|
//"?","¸",
|
|
|
|
|
"¹","¹",
|
|
|
|
|
"º","º",
|
|
|
|
|
"»","»",
|
|
|
|
|
//"?","¼",
|
|
|
|
|
//"?","½",
|
|
|
|
|
//"?","¾",
|
|
|
|
|
"¿","¿",
|
|
|
|
|
"À","À",
|
|
|
|
|
"Á","Á",
|
|
|
|
|
"Â","Â",
|
|
|
|
|
"Ã","Ã",
|
|
|
|
|
"Ä","Ä",
|
|
|
|
|
"Å","Å",
|
|
|
|
|
"Æ","Æ",
|
|
|
|
|
"Ç","Ç",
|
|
|
|
|
"È","È",
|
|
|
|
|
"É","É",
|
|
|
|
|
"Ê","Ê",
|
|
|
|
|
"Ë","Ë",
|
|
|
|
|
"Ì","Ì",
|
|
|
|
|
"Í","Í",
|
|
|
|
|
"Î","Î",
|
|
|
|
|
"Ï","Ï",
|
|
|
|
|
"Ð","Ð",
|
|
|
|
|
"Ñ","Ñ",
|
|
|
|
|
"Ò","Ò",
|
|
|
|
|
"Ó","Ó",
|
|
|
|
|
"Ô","Ô",
|
|
|
|
|
"Õ","Õ",
|
|
|
|
|
"Ö","Ö",
|
|
|
|
|
"×","×",
|
|
|
|
|
"Ø","Ø",
|
|
|
|
|
"Ù","Ù",
|
|
|
|
|
"Ú","Ú",
|
|
|
|
|
"Û","Û",
|
|
|
|
|
"Ü","Ü",
|
|
|
|
|
"Ý","Ý",
|
|
|
|
|
"Þ","Þ",
|
|
|
|
|
"ß","ß",
|
|
|
|
|
"à","à",
|
|
|
|
|
"á","á",
|
|
|
|
|
"â","â",
|
|
|
|
|
"ã","ã",
|
|
|
|
|
"ä","ä",
|
|
|
|
|
"å","å",
|
|
|
|
|
"æ","æ",
|
|
|
|
|
"ç","ç",
|
|
|
|
|
"è","è",
|
|
|
|
|
"é","é",
|
|
|
|
|
"ê","ê",
|
|
|
|
|
"ë","ë",
|
|
|
|
|
"ì","ì",
|
|
|
|
|
"í","í",
|
|
|
|
|
"î","î",
|
|
|
|
|
"ï","ï",
|
|
|
|
|
"ð","ð",
|
|
|
|
|
"ñ","ñ",
|
|
|
|
|
"ò","ò",
|
|
|
|
|
"ó","ó",
|
|
|
|
|
"ô","ô",
|
|
|
|
|
"õ","õ",
|
|
|
|
|
"ö","ö",
|
|
|
|
|
"÷","÷",
|
|
|
|
|
"ø","ø",
|
|
|
|
|
"ù","ù",
|
|
|
|
|
"ú","ú",
|
|
|
|
|
"û","û",
|
|
|
|
|
"ü","ü",
|
|
|
|
|
"ý","ý",
|
|
|
|
|
"þ","þ",
|
|
|
|
|
"ÿ","ÿ",
|
|
|
|
|
"\"",""",
|
|
|
|
|
"<","<",
|
|
|
|
|
">",">",
|
|
|
|
|
"(C)","©"
|
|
|
|
|
};
|
|
|
|
|
//end of Kane's code
|
|
|
|
|
|
|
|
|
|
/** Replaces wiki tags with HTML tags.
|
|
|
|
|
*
|
|
|
|
|
* @param result a line of text
|
|
|
|
|