KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > saxon > event > UnicodeNormalizer


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 /**
7  * UnicodeNormalizer: This ProxyReceiver performs unicode normalization on the contents
8  * of attribute and text nodes.
9  *
10  * @author Michael Kay
11 */

12
13
14 public class UnicodeNormalizer extends ProxyReceiver {
15
16     private Normalizer normalizer;
17
18     public UnicodeNormalizer(String JavaDoc 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     /**
38      * Output an attribute
39      */

40
41     public void attribute(int nameCode, int typeCode, CharSequence JavaDoc value, int locationId, int properties)
42             throws XPathException {
43         super.attribute(nameCode, typeCode, normalizer.normalize(value.toString()), locationId, properties);
44     }
45
46     /**
47     * Output character data
48     */

49
50     public void characters(CharSequence JavaDoc chars, int locationId, int properties) throws XPathException {
51         super.characters(normalizer.normalize(chars.toString()), locationId, properties);
52     }
53
54 };
55
56 //
57
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
58
// you may not use this file except in compliance with the License. You may obtain a copy of the
59
// License at http://www.mozilla.org/MPL/
60
//
61
// Software distributed under the License is distributed on an "AS IS" basis,
62
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
63
// See the License for the specific language governing rights and limitations under the License.
64
//
65
// The Original Code is: all this file.
66
//
67
// The Initial Developer of the Original Code is Michael H. Kay
68
//
69
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
70
//
71
// Contributor(s): none.
72
//
73

74
Popular Tags