1 5 6 package org.exoplatform.services.jcr.impl.util; 7 8 14 15 public class StringConverter { 16 17 20 public static String normalizeString(String s, boolean canonical) { 21 22 StringBuffer strBuf = new StringBuffer (); 23 int len = (s != null) ? s.length() : 0; 24 for (int i = 0; i < len; i++) { 25 char c = s.charAt(i); 26 strBuf.append(normalizeChar(c, canonical)); 27 } 28 return new String (strBuf); 29 30 } 32 35 public static String normalizeChar(char c, boolean canonical) { 36 37 switch (c) { 38 case '<': 39 return "<"; 40 case '>': 41 return ">"; 42 case '&': 43 return "&"; 44 case '"': 45 return """; 46 case '\r': 47 case '\n': 48 if (canonical) { 49 return "&#" + Integer.toString(c) + ";"; 50 } 51 default: 53 return "" + c; 54 } 55 56 } 57 58 59 } 60 | Popular Tags |