1 package net.sf.saxon.event; 2 import net.sf.saxon.codenorm.Normalizer; 3 import net.sf.saxon.trans.XPathException; 4 import net.sf.saxon.trans.DynamicError; 5 6 12 13 14 public class UnicodeNormalizer extends ProxyReceiver { 15 16 private Normalizer normalizer; 17 18 public UnicodeNormalizer(String form) throws XPathException { 19 byte fb; 20 if (form.equals("NFC")) { 21 fb = Normalizer.C; 22 } else if (form.equals("NFD")) { 23 fb = Normalizer.D; 24 } else if (form.equals("NFKC")) { 25 fb = Normalizer.KC; 26 } else if (form.equals("NFKD")) { 27 fb = Normalizer.KD; 28 } else { 29 DynamicError err = new DynamicError("Unknown normalization form " + form); 30 err.setErrorCode("SESU0011"); 31 throw err; 32 } 33 34 normalizer = new Normalizer(fb); 35 } 36 37 40 41 public void attribute(int nameCode, int typeCode, CharSequence value, int locationId, int properties) 42 throws XPathException { 43 super.attribute(nameCode, typeCode, normalizer.normalize(value.toString()), locationId, properties); 44 } 45 46 49 50 public void characters(CharSequence chars, int locationId, int properties) throws XPathException { 51 super.characters(normalizer.normalize(chars.toString()), locationId, properties); 52 } 53 54 }; 55 56 74 | Popular Tags |