Source Code Cross Referenced for I18n.java in  » Portal » Open-Portal » com » sun » portal » desktop » util » 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 » Open Portal » com.sun.portal.desktop.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // Copyright 03/16/00 Sun Microsystems, Inc. All Rights Reserved.
002:        // "@(#)I18n.java	1.5 00/03/16 Sun Microsystems"
003:
004:        package com.sun.portal.desktop.util;
005:
006:        import java.lang.*;
007:        import java.util.*;
008:        import java.text.*;
009:        import java.io.*;
010:        import javax.servlet.*;
011:        import javax.servlet.http.*;
012:
013:        public class I18n {
014:            public static final String DEFAULT_CHARSET = "UTF-8";
015:            public static final String ASCII_CHARSET = "ISO-8859-1";
016:
017:            static public String print(String s) {
018:                if (s == null) {
019:                    return null;
020:                }
021:
022:                StringBuffer buf = new StringBuffer();
023:                for (int i = 0; i < s.length(); i++) {
024:                    int c = (int) s.charAt(i);
025:                    if (c >= 32 && c < 127)
026:                        buf.append(s.charAt(i));
027:                    else {
028:                        buf.append("\\u");
029:                        String n = "";
030:                        for (int j = 0; j < 4; j++) {
031:                            n = "" + Character.forDigit(c & 0xf, 16) + n;
032:                            c = c >> 4;
033:                        }
034:                        buf.append(n);
035:                    }
036:                }
037:                return buf.toString();
038:            }
039:
040:            static public String decodeCharset(String s, String charset) {
041:                if (s == null) {
042:                    return null;
043:                }
044:
045:                try {
046:                    byte buf[] = s.getBytes(ASCII_CHARSET);
047:                    return new String(buf, 0, buf.length, charset);
048:                } catch (UnsupportedEncodingException uee) {
049:                    return s;
050:                }
051:            }
052:
053:            static public String encodeCharset(String s, String charset) {
054:                if (s == null) {
055:                    return null;
056:                }
057:
058:                try {
059:                    byte buf[] = s.getBytes(charset);
060:                    return new String(buf, 0, buf.length, ASCII_CHARSET);
061:                } catch (UnsupportedEncodingException uee) {
062:                    return s;
063:                }
064:            }
065:
066:            static public boolean isAscii(String s) {
067:                // perform i18n check - the equals test returns false if there are
068:                // any chars with value > 256, i.e., multi-byte characters.
069:
070:                if (s == null) {
071:                    return true;
072:                }
073:
074:                try {
075:                    if (!s.equals(new String(s.getBytes(ASCII_CHARSET),
076:                            ASCII_CHARSET))) {
077:                        // the name does contain non-latin chars
078:                        return false;
079:                    }
080:                } catch (java.io.UnsupportedEncodingException uee) {
081:                    // we should never reach this.
082:                    return false;
083:                }
084:
085:                return true;
086:            }
087:
088:            static private String format(MessageFormat mf, Object o) {
089:                String msg = mf.format(new Object[] { o }, new StringBuffer(),
090:                        null).toString();
091:
092:                return msg;
093:            }
094:
095:            static private String format(MessageFormat mf, Object[] array) {
096:                String msg = mf.format(array, new StringBuffer(), null)
097:                        .toString();
098:
099:                return msg;
100:            }
101:
102:            static public String format(String pattern, Long j, Locale l) {
103:
104:                MessageFormat mf = new MessageFormat("");
105:                mf.setLocale(l);
106:                mf.applyPattern(pattern);
107:                String msg = format(mf, j);
108:
109:                return msg;
110:            }
111:
112:            static public String format(String pattern, Integer i, Locale l) {
113:
114:                MessageFormat mf = new MessageFormat("");
115:                mf.setLocale(l);
116:                mf.applyPattern(pattern);
117:                String msg = format(mf, i);
118:
119:                return msg;
120:            }
121:
122:            static public String format(String pattern, Date d, TimeZone tz,
123:                    Locale l) {
124:
125:                MessageFormat mf = new MessageFormat("");
126:                mf.setLocale(l);
127:                mf.applyPattern(pattern);
128:                ((DateFormat) mf.getFormats()[0]).setTimeZone(tz);
129:
130:                //
131:                // possibly two formats, one for date and one for time
132:                // depends on pattern, which is in the 
133:                //
134:                DateFormat df1 = ((DateFormat) mf.getFormats()[0]);
135:                if (df1 != null) {
136:                    df1.setTimeZone(tz);
137:                }
138:
139:                DateFormat df2 = ((DateFormat) mf.getFormats()[1]);
140:                if (df2 != null) {
141:                    df2.setTimeZone(tz);
142:                }
143:
144:                return format(mf, d);
145:            }
146:
147:            static public String format(String pattern, TimeZone tz, Locale l) {
148:
149:                MessageFormat mf = new MessageFormat("");
150:                mf.setLocale(l);
151:                mf.applyPattern(pattern);
152:
153:                Object[] arguments = {
154:                        new String(tz.getID()),
155:                        new String(tz.getDisplayName(false, TimeZone.SHORT, l)),
156:                        new String(tz.getDisplayName(false, TimeZone.LONG, l)) };
157:
158:                return format(mf, arguments);
159:            }
160:
161:            /**
162:             * Replacement URLEncoder.encode() method for i18n purposes
163:             * Uses our replacement IURLEncoder class due to bug in java URLEncoder class
164:             * encodes twice because the PAPI decodes once automatically (via the Servlet API) 
165:             * and then automatically does charset decoding with possibly the wrong charset 
166:             * so we need to hide behind an extra layer of URLEncoding
167:             * @param enc string to encode, converts to UTF8 first
168:             **/
169:            static public String IURLEncode(String enc) {
170:                try {
171:                    return IURLEncoder.encode(IURLEncoder.encode(new String(enc
172:                            .getBytes(DEFAULT_CHARSET), ASCII_CHARSET)));
173:                } catch (Exception e) {
174:                    return enc;
175:                }
176:            }
177:
178:            /**
179:             * Replacement URLDecoder.decode() method for i18n purposes
180:             * Uses our replacement IURLDecoder class due to bug in java URLDecoder class
181:             * @param enc string to decode, converts from UTF8 first
182:             **/
183:            static public String IURLDecode(String enc) {
184:                try {
185:                    String dc = new String(IURLDecoder.decode(enc));
186:                    return new String(dc.getBytes(ASCII_CHARSET),
187:                            DEFAULT_CHARSET);
188:                } catch (Exception e) {
189:                    return enc;
190:                }
191:            }
192:
193:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.