Hi Miroslav,
Again I was facing same problem to send " (double quotes) across to
client side using Rocket.
I have done some changes in Utilities in htmlEncode and htmlDecode
methods.Can you please check them and give me some suggestions on
this.
While encoding I replace ' & " with lower order ASCII characters and
when they are received at client side then again I replace ASCII
characters back with ' & ".
Changes are as follows
/**
* Accepts a plain string escaping various characters so that the
given
* string is html encoded.
*
* @param plainText
* @return
*/
static final char replaceCharFroQuote = 0x11;
static final char replaceCharForDoubleQuote = 0x12;
public static String htmlEncode(final String plainText) {
Checker.notNull("parameter:plainText", plainText);
final StringBuffer buf = new StringBuffer();
final int length = plainText.length();
for (int i = 0; i < length; i++) {
final char c = plainText.charAt(i);
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
start !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
if('\\'==c){
i++;
final char g = plainText.charAt(i);
if(g=='\"'){
buf.append(replaceCharForDoubleQuote);
}else{
buf.append(c);
}
continue;
}
if('\''==c){
buf.append(replaceCharFroQuote);
continue;
}
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
END!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
if ('<' == c) {
buf.append("<");
continue;
}
if ('>' == c) {
buf.append(">");
continue;
}
if ('&' == c) {
buf.append("&");
continue;
}
// if ('\'' == c) {
// buf.append("'");
// continue;
// }
if ('"' == c) {
buf.append(""");
continue;
}
buf.append(c);
}
return buf.toString();
}
/**
* Accepts a encoded string and returns the original decoded value.
*
* @param htmlEncodedText
* @return
*/
public static String htmlDecode(final String htmlEncodedText) {
Checker.notNull("parameter:htmlEncodedText", htmlEncodedText);
final StringBuffer buf = new StringBuffer();
final int length = htmlEncodedText.length();
for (int i = 0; i < length;) {
final char c = htmlEncodedText.charAt(i);
i++;
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
START!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
if('\\'==c){
buf.append('\\');
}
if(replaceCharFroQuote==c){
buf.append('\'');
continue;
}
if(replaceCharForDoubleQuote==c){
buf.append('\\');
buf.append('\"');
continue;
}
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
END !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
if ('&' == c) {
final int semiColon = htmlEncodedText.indexOf(';', i);
final String entity = htmlEncodedText.substring(i, semiColon);
i = semiColon + 1;
if (entity.equals("lt")) {
buf.append("<");
continue;
}
if (entity.equals("gt")) {
buf.append(">");
continue;
}
if (entity.equals("amp")) {
buf.append("&");
continue;
}
if (entity.equals("quot")) {
buf.append('"');
continue;
}
// if (entity.equals("#39")){
// buf.append('\'');
// continue;
//
// }
throw new RuntimeException("Unknown/unsupported html entity &" +
entity + ";");
}
buf.append(c);
}
return buf.toString();