1 16 package org.apache.cocoon.webapps.session.xml; 17 18 19 20 26 public final class XMLUtil { 27 28 31 public static String encode(String value) { 32 StringBuffer buffer = new StringBuffer (value); 33 for(int i = 0; i < buffer.length(); i++) { 34 if (buffer.charAt(i) > 127) { 35 buffer.replace(i, i+1, "__"+((int)buffer.charAt(i))+";"); 36 } 37 } 38 return buffer.toString(); 39 } 40 41 44 public static String decode(String value) { 45 StringBuffer buffer = new StringBuffer (value); 46 int pos; 47 boolean found; 48 for(int i = 0; i < buffer.length(); i++) { 49 if (buffer.charAt(i) == '_' && 50 buffer.charAt(i+1) == '_') { 51 pos = i + 2; 52 found = false; 53 while (buffer.charAt(pos) >= '0' 54 && buffer.charAt(pos) <= '9') { 55 found = true; 56 pos++; 57 } 58 if (found == true 59 && pos > i + 2 60 && buffer.charAt(pos) == ';') { 61 int ent = new Integer (buffer.substring(i+2, pos)).intValue(); 62 buffer.replace(i, pos+1, ""+ (char)ent); 63 } 64 } 65 } 66 return buffer.toString(); 67 } 68 69 } 70 | Popular Tags |