KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > xml > io > ShiftJisCharacterSet


1
2 /*
3  * Enhydra Java Application Server Project
4  *
5  * The contents of this file are subject to the Enhydra Public License
6  * Version 1.1 (the "License"); you may not use this file except in
7  * compliance with the License. You may obtain a copy of the License on
8  * the Enhydra web site ( http://www.enhydra.org/ ).
9  *
10  * Software distributed under the License is distributed on an "AS IS"
11  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
12  * the License for the specific terms governing rights and limitations
13  * under the License.
14  *
15  * The Initial Developer of the Enhydra Application Server is Lutris
16  * Technologies, Inc. The Enhydra Application Server and portions created
17  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
18  * All Rights Reserved.
19  *
20  * Contributor(s):
21  *
22  * $Id: ShiftJisCharacterSet.java,v 1.2 2003/06/29 05:58:48 jkjome Exp $
23  */

24 package org.enhydra.xml.io;
25
26 /**
27  * Class that implements special character handling for Shift_JIS.
28  * This detects invalid ranges so that they can be encoded by character
29  * entity references.
30  * <P>
31  * Required to support i-mode Emoji characters. These are character codes
32  * that represent symbols on i-mode phones. The characters codes are invalid
33  * Shift-JIS character and must be encoded in HTML pages as numeric character
34  * entity references. Special handling is required on formatting to detect
35  * these characters.
36  * <P>
37  * See http://www.nttdocomo.com/i/tag/emoji/ for details.
38  */

39 class ShiftJisCharacterSet extends CharacterSet {
40     /** Constructor */
41     public ShiftJisCharacterSet(String JavaDoc name,
42                                 int charSize,
43                                 String JavaDoc mimePreferred,
44                                 String JavaDoc[] aliases) {
45         super(name, charSize, mimePreferred, aliases);
46     }
47     
48     /**
49      * @see CharacterSet#isValid
50      */

51     public boolean isValid(char ch) {
52         int byte1 = ((ch >> 8) & 0xFF);
53         int byte2 = (ch & 0xFF);
54
55         // FIXME: Right now, we just exclude the user defined range,
56
// which will result them being encoded as char entity refs
57
// This partial solution was done for safety, due to limited
58
// time to develop tests.
59

60         if (((0xF0 <= byte1) && (byte1 <= 0xFC))
61             && (((0x40 <= byte2) && (byte2 <= 0x7e))
62                 || ((0x80 <= byte2) && (byte2 <= 0xFC)))) {
63             // User defined range
64
return false;
65         } else {
66             return true; // FIXME: see above
67
}
68     }
69
70     /**
71      * @see CharacterSet#sameValidCharRange
72      */

73     public boolean sameValidCharRange(CharacterSet otherSet) {
74         // Only valid if Shift_JIS (only one of these objects should
75
// exists, so we can compare pointers).
76
return (otherSet == this);
77     }
78 }
79
Popular Tags