KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > apache > xml > serialize > Encodings


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  *
5  * Copyright (c) 1999 The Apache Software Foundation. All rights
6  * reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * Apache Software Foundation (http://www.apache.org/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "Xerces" and "Apache Software Foundation" must
28  * not be used to endorse or promote products derived from this
29  * software without prior written permission. For written
30  * permission, please contact apache@apache.org.
31  *
32  * 5. Products derived from this software may not be called "Apache",
33  * nor may "Apache" appear in their name, without prior written
34  * permission of the Apache Software Foundation.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
40  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47  * SUCH DAMAGE.
48  * ====================================================================
49  *
50  * This software consists of voluntary contributions made by many
51  * individuals on behalf of the Apache Software Foundation and was
52  * originally based on software copyright (c) 1999, International
53  * Business Machines, Inc., http://www.apache.org. For more
54  * information on the Apache Software Foundation, please see
55  * <http://www.apache.org/>.
56  */

57
58
59 package org.enhydra.apache.xml.serialize;
60
61
62
63
64 /**
65  * Provides information about encodings. Depends on the Java runtime
66  * to provides writers for the different encodings, but can be used
67  * to override encoding names and provide the last printable character
68  * for each encoding.
69  *
70  * @version $Id: Encodings.java,v 1.2 2005/01/26 08:28:45 jkjome Exp $
71  * @author <a HREF="mailto:arkin@intalio.com">Assaf Arkin</a>
72  */

73 public class Encodings
74 {
75
76
77     /**
78      * The last printable character for unknown encodings.
79      */

80     static final int DefaultLastPrintable = 0x7F;
81
82     /**
83      * @param encoding a MIME charset name, or null.
84      */

85     static EncodingInfo getEncodingInfo(String JavaDoc encoding) {
86         if (encoding == null)
87             return new EncodingInfo(null, DefaultLastPrintable);
88         for (int i = 0; i < _encodings.length; i++) {
89             if (_encodings[i].name.equalsIgnoreCase(encoding))
90                 return _encodings[i];
91         }
92         return new SieveEncodingInfo(encoding, DefaultLastPrintable);
93     }
94
95     static final String JavaDoc JIS_DANGER_CHARS
96     = "\\\u007e\u007f\u00a2\u00a3\u00a5\u00ac"
97     +"\u2014\u2015\u2016\u2026\u203e\u203e\u2225\u222f\u301c"
98     +"\uff3c\uff5e\uffe0\uffe1\uffe2\uffe3";
99
100     /**
101      * Constructs a list of all the supported encodings.
102      */

103     private static final EncodingInfo[] _encodings = new EncodingInfo[] {
104         new EncodingInfo("ASCII", 0x7F),
105         new EncodingInfo("US-ASCII", 0x7F),
106         new EncodingInfo("ISO-8859-1", 0xFF),
107         new EncodingInfo("ISO-8859-2", 0xFF),
108         new EncodingInfo("ISO-8859-3", 0xFF),
109         new EncodingInfo("ISO-8859-4", 0xFF),
110         new EncodingInfo("ISO-8859-5", 0xFF),
111         new EncodingInfo("ISO-8859-6", 0xFF),
112         new EncodingInfo("ISO-8859-7", 0xFF),
113         new EncodingInfo("ISO-8859-8", 0xFF),
114         new EncodingInfo("ISO-8859-9", 0xFF),
115         /**
116          * Does JDK's converter supprt surrogates?
117          * A Java encoding name "UTF-8" is suppoted by JDK 1.2 or later.
118          */

119         new EncodingInfo("UTF-8", "UTF8", 0x10FFFF),
120         /**
121          * JDK 1.1 supports "Shift_JIS" as an alias of "SJIS".
122          * But JDK 1.2 treats "Shift_JIS" as an alias of "MS932".
123          * The JDK 1.2's behavior is invalid against IANA registrations.
124          */

125         new SieveEncodingInfo("Shift_JIS", "SJIS", 0x7F, JIS_DANGER_CHARS),
126         /**
127          * "MS932" is supported by JDK 1.2 or later.
128          */

129         new SieveEncodingInfo("Windows-31J", "MS932", 0x7F, JIS_DANGER_CHARS),
130         new SieveEncodingInfo("EUC-JP", null, 0x7F, JIS_DANGER_CHARS),
131         new SieveEncodingInfo("ISO-2022-JP", null, 0x7F, JIS_DANGER_CHARS),
132     };
133 }
134
Popular Tags