public static String makeHTMLNameSafe(String name){
  if (name == null || name.isEmpty()) {
    return name;
  }
  char[] chrs=name.toCharArray();
  if (name.indexOf(percentInt) != -1 || name.indexOf(spaceInt) != -1 || name.indexOf(fullStopInt) != -1 || name.indexOf(plusInt) != -1 || name.indexOf(colonInt) != -1 || name.indexOf(equalsInt) != -1 || name.indexOf(forwardSlashInt) != -1 || name.indexOf(backSlashInt) != -1) {
    for (int i=0; i < chrs.length; i++) {
switch (chrs[i]) {
case ampersand:
        chrs[i]=ampersandInt;
      break;
case spaceInt:
    chrs[i]=underScoreInt;
  break;
case fullStopInt:
chrs[i]=minusInt;
break;
case percentInt:
chrs[i]=underScoreInt;
break;
case plusInt:
chrs[i]=pInt;
break;
case colonInt:
chrs[i]=cInt;
break;
case equalsInt:
chrs[i]=qInt;
break;
case forwardSlashInt:
chrs[i]=underScoreInt;
break;
case backSlashInt:
chrs[i]=underScoreInt;
break;
}
}
}
final char[] testchrs={openSquareBracketInt,closeSquareBracketInt,hashInt,divideInt,openCurlyBracket,closeCurlyBracket};
int count=0;
for (final char chr1 : chrs) {
for (final char testchr : testchrs) {
if (chr1 == testchr) {
count++;
}
}
}
if (count > 0) {
int c=0;
final char[] tmp=new char[chrs.length - count];
MAINLOOP: for (final char chr : chrs) {
for (final char testchr : testchrs) {
if (chr == testchr) {
continue MAINLOOP;
}
}
tmp[c++]=chr;
}
chrs=tmp;
}
if (chrs[0] >= zeroInt && chrs[0] <= nineInt) {
final char[] tmp=new char[chrs.length + 1];
System.arraycopy(chrs,0,tmp,1,chrs.length);
tmp[0]=aInt;
chrs=tmp;
}
name=new String(chrs);
return name;
}

public static String makeHTMLNameSafe ( String name ) { if ( name == null || name . isEmpty ( ) ) { return name ; } char [ ] chrs = name . toCharArray ( ) ; if ( name . indexOf ( percentInt ) != - 1 || name . indexOf ( spaceInt ) != - 1 || name . indexOf ( fullStopInt ) != - 1 || name . indexOf ( plusInt ) != - 1 || name . indexOf ( colonInt ) != - 1 || name . indexOf ( equalsInt ) != - 1 || name . indexOf ( forwardSlashInt ) != - 1 || name . indexOf ( backSlashInt ) != - 1 ) { for ( int i = 0 ; i < chrs . length ; i ++ ) { switch ( chrs [ i ] ) { case ampersand : chrs [ i ] = ampersandInt ; break ; case spaceInt : chrs [ i ] = underScoreInt ; break ; case fullStopInt : chrs [ i ] = minusInt ; break ; case percentInt : chrs [ i ] = underScoreInt ; break ; case plusInt : chrs [ i ] = pInt ; break ; case colonInt : chrs [ i ] = cInt ; break ; case equalsInt : chrs [ i ] = qInt ; break ; case forwardSlashInt : chrs [ i ] = underScoreInt ; break ; case backSlashInt : chrs [ i ] = underScoreInt ; break ; } } } final char [ ] testchrs = { openSquareBracketInt , closeSquareBracketInt , hashInt , divideInt , openCurlyBracket , closeCurlyBracket } ; int count = 0 ; for ( final char chr1 : chrs ) { for ( final char testchr : testchrs ) { if ( chr1 == testchr ) { count ++ ; } } } if ( count > 0 ) { int c = 0 ; final char [ ] tmp = new char [ chrs . length - count ] ; MAINLOOP : for ( final char chr : chrs ) { for ( final char testchr : testchrs ) { if ( chr == testchr ) { continue MAINLOOP ; } } tmp [ c ++ ] = chr ; } chrs = tmp ; } if ( chrs [ 0 ] >= zeroInt && chrs [ 0 ] <= nineInt ) { final char [ ] tmp = new char [ chrs . length + 1 ] ; System . arraycopy ( chrs , 0 , tmp , 1 , chrs . length ) ; tmp [ 0 ] = aInt ; chrs = tmp ; } name = new String ( chrs ) ; return name ; }
replaces all spaces ' ' with underscores ' _ ' to allow the whole name to be used in html
