Source Code Cross Referenced for Encodings.java in  » Portal » uPortal_rel-2-6-1-GA » org » jasig » portal » serialize » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Portal » uPortal_rel 2 6 1 GA » org.jasig.portal.serialize 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 1999-2002,2004 The Apache Software Foundation.
003:         * 
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         * 
008:         *      http://www.apache.org/licenses/LICENSE-2.0
009:         * 
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:
017:        package org.jasig.portal.serialize;
018:
019:        import java.io.UnsupportedEncodingException;
020:        import java.util.Hashtable;
021:        import java.util.Locale;
022:
023:        import org.apache.xerces.util.EncodingMap;
024:
025:        /**
026:         * Provides information about encodings. Depends on the Java runtime
027:         * to provides writers for the different encodings, but can be used
028:         * to override encoding names and provide the last printable character
029:         * for each encoding.
030:         *
031:         * @version $Id: Encodings.java 36559 2006-04-28 18:38:13Z bjohnson $
032:         * @author <a href="mailto:arkin@intalio.com">Assaf Arkin</a>
033:         */
034:        public class Encodings {
035:
036:            /**
037:             * The last printable character for unknown encodings.
038:             */
039:            static final int DEFAULT_LAST_PRINTABLE = 0x7F;
040:
041:            // last printable character for Unicode-compatible encodings
042:            static final int LAST_PRINTABLE_UNICODE = 0xffff;
043:            // unicode-compliant encodings; can express plane 0
044:            static final String[] UNICODE_ENCODINGS = { "Unicode",
045:                    "UnicodeBig", "UnicodeLittle", "GB2312", "UTF8", "UTF-16", };
046:            // default (Java) encoding if none supplied:
047:            static final String DEFAULT_ENCODING = "UTF8";
048:
049:            // note that the size of this Hashtable
050:            // is bounded by the number of encodings recognized by EncodingMap;
051:            // therefore it poses no static mutability risk.
052:            static Hashtable _encodings = new Hashtable();
053:
054:            /**
055:             * @param encoding a MIME charset name, or null.
056:             */
057:            static EncodingInfo getEncodingInfo(String encoding,
058:                    boolean allowJavaNames) throws UnsupportedEncodingException {
059:                EncodingInfo eInfo = null;
060:                if (encoding == null) {
061:                    if ((eInfo = (EncodingInfo) _encodings
062:                            .get(DEFAULT_ENCODING)) != null)
063:                        return eInfo;
064:                    eInfo = new EncodingInfo(EncodingMap
065:                            .getJava2IANAMapping(DEFAULT_ENCODING),
066:                            DEFAULT_ENCODING, LAST_PRINTABLE_UNICODE);
067:                    _encodings.put(DEFAULT_ENCODING, eInfo);
068:                    return eInfo;
069:                }
070:                // need to convert it to upper case:
071:                encoding = encoding.toUpperCase(Locale.ENGLISH);
072:                String jName = EncodingMap.getIANA2JavaMapping(encoding);
073:                if (jName == null) {
074:                    // see if the encoding passed in is a Java encoding name.
075:                    if (allowJavaNames) {
076:                        EncodingInfo.testJavaEncodingName(encoding);
077:                        if ((eInfo = (EncodingInfo) _encodings.get(encoding)) != null)
078:                            return eInfo;
079:                        // is it known to be unicode-compliant?
080:                        int i = 0;
081:                        for (; i < UNICODE_ENCODINGS.length; i++) {
082:                            if (UNICODE_ENCODINGS[i].equalsIgnoreCase(encoding)) {
083:                                eInfo = new EncodingInfo(EncodingMap
084:                                        .getJava2IANAMapping(encoding),
085:                                        encoding, LAST_PRINTABLE_UNICODE);
086:                                break;
087:                            }
088:                        }
089:                        if (i == UNICODE_ENCODINGS.length) {
090:                            eInfo = new EncodingInfo(EncodingMap
091:                                    .getJava2IANAMapping(encoding), encoding,
092:                                    DEFAULT_LAST_PRINTABLE);
093:                        }
094:                        _encodings.put(encoding, eInfo);
095:                        return eInfo;
096:                    } else {
097:                        throw new UnsupportedEncodingException(encoding);
098:                    }
099:                }
100:                if ((eInfo = (EncodingInfo) _encodings.get(jName)) != null)
101:                    return eInfo;
102:                // have to create one...
103:                // is it known to be unicode-compliant?
104:                int i = 0;
105:                for (; i < UNICODE_ENCODINGS.length; i++) {
106:                    if (UNICODE_ENCODINGS[i].equalsIgnoreCase(jName)) {
107:                        eInfo = new EncodingInfo(encoding, jName,
108:                                LAST_PRINTABLE_UNICODE);
109:                        break;
110:                    }
111:                }
112:                if (i == UNICODE_ENCODINGS.length) {
113:                    eInfo = new EncodingInfo(encoding, jName,
114:                            DEFAULT_LAST_PRINTABLE);
115:                }
116:                _encodings.put(jName, eInfo);
117:                return eInfo;
118:            }
119:
120:            static final String JIS_DANGER_CHARS = "\\\u007e\u007f\u00a2\u00a3\u00a5\u00ac"
121:                    + "\u2014\u2015\u2016\u2026\u203e\u203e\u2225\u222f\u301c"
122:                    + "\uff3c\uff5e\uffe0\uffe1\uffe2\uffe3";
123:
124:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.