1 6 7 package com.quikj.application.communicator.applications.webtalk.controller; 8 9 13 public class Utilities 14 { 15 16 17 private static String ESCAPE_EQUAL = "&eq;"; 18 private static String ESCAPE_ESCAPE = "&"; 19 20 public static String escapeEqual(String input) 21 { 22 25 StringBuffer buf = new StringBuffer (input); 26 27 int index = 0; 28 while (index < buf.length()) 29 { 30 int replace_at = buf.toString().indexOf('&', index); 31 32 if (replace_at == -1) 33 { 34 break; 35 } 36 37 buf = buf.replace(replace_at, replace_at + 1, ESCAPE_ESCAPE); 38 39 index = replace_at + ESCAPE_ESCAPE.length(); 40 } 41 42 index = 0; 43 while (index < buf.length()) 44 { 45 int replace_at = buf.toString().indexOf('=', index); 46 47 if (replace_at == -1) 48 { 49 break; 50 } 51 52 buf = buf.replace(replace_at, replace_at + 1, ESCAPE_EQUAL); 53 54 index = replace_at + ESCAPE_EQUAL.length(); 55 } 56 57 return buf.toString(); 58 } 59 60 public static String deEscapeEqual(String input) 61 { 62 65 StringBuffer buf = new StringBuffer (input); 66 67 int index = 0; 68 while (index < buf.length()) 69 { 70 int replace_at = buf.toString().indexOf(ESCAPE_EQUAL, index); 71 72 if (replace_at == -1) 73 { 74 break; 75 } 76 77 buf = buf.replace(replace_at, replace_at + ESCAPE_EQUAL.length(), 78 "="); 79 80 index = replace_at + 1; 81 } 82 83 index = 0; 84 while (index < buf.length()) 85 { 86 int replace_at = buf.toString().indexOf(ESCAPE_ESCAPE, index); 87 88 if (replace_at == -1) 89 { 90 break; 91 } 92 93 buf = buf.replace(replace_at, replace_at + ESCAPE_ESCAPE.length(), 94 "&"); 95 96 index = replace_at + 1; 97 } 98 99 return buf.toString(); 100 } 101 102 103 104 } 105 | Popular Tags |