01: package net.sf.saxon.event;
02:
03: import net.sf.saxon.codenorm.Normalizer;
04: import net.sf.saxon.trans.XPathException;
05: import net.sf.saxon.trans.DynamicError;
06:
07: /**
08: * UnicodeNormalizer: This ProxyReceiver performs unicode normalization on the contents
09: * of attribute and text nodes.
10: *
11: * @author Michael Kay
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(
30: "Unknown normalization form " + form);
31: err.setErrorCode("SESU0011");
32: throw err;
33: }
34:
35: normalizer = new Normalizer(fb);
36: }
37:
38: /**
39: * Output an attribute
40: */
41:
42: public void attribute(int nameCode, int typeCode,
43: CharSequence value, int locationId, int properties)
44: throws XPathException {
45: super .attribute(nameCode, typeCode,
46: normalizer.normalize(value), locationId, properties);
47: }
48:
49: /**
50: * Output character data
51: */
52:
53: public void characters(CharSequence chars, int locationId,
54: int properties) throws XPathException {
55: super .characters(normalizer.normalize(chars), locationId,
56: properties);
57: }
58:
59: };
60:
61: //
62: // The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
63: // you may not use this file except in compliance with the License. You may obtain a copy of the
64: // License at http://www.mozilla.org/MPL/
65: //
66: // Software distributed under the License is distributed on an "AS IS" basis,
67: // WITHOUT WARRANTY OF ANY KIND, either express or implied.
68: // See the License for the specific language governing rights and limitations under the License.
69: //
70: // The Original Code is: all this file.
71: //
72: // The Initial Developer of the Original Code is Michael H. Kay
73: //
74: // Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
75: //
76: // Contributor(s): none.
77: //
|