Source Code Cross Referenced for NeutralToJ1Converter.java in  » Internationalization-Localization » icu4j » com » ibm » icu » dev » tool » localeconverter » 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 » Internationalization Localization » icu4j » com.ibm.icu.dev.tool.localeconverter 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *******************************************************************************
003:         * Copyright (C) 2002-2004, International Business Machines Corporation and    *
004:         * others. All Rights Reserved.                                                *
005:         *******************************************************************************
006:         */
007:        package com.ibm.icu.dev.tool.localeconverter;
008:
009:        import java.util.*;
010:
011:        public class NeutralToJ1Converter extends LocaleConverter {
012:            private static class Conversion {
013:                private String propName;
014:                private int ndx;
015:
016:                protected Conversion() {
017:                }
018:
019:                public Conversion(String propName) {
020:                    this .propName = propName;
021:                    this .ndx = -1;
022:                }
023:
024:                public Conversion(String propName, int ndx) {
025:                    this .propName = propName;
026:                    this .ndx = ndx;
027:                }
028:
029:                public String getPropName() {
030:                    return propName;
031:                }
032:
033:                public String convert(Hashtable source) throws ConversionError {
034:                    Object sourceData = source.get(propName);
035:                    if (sourceData == null) {
036:                        return null;
037:                    }
038:                    if (ndx >= 0) {
039:                        if (sourceData instanceof  String[]) {
040:                            sourceData = ((String[]) sourceData)[ndx];
041:                        } else if (sourceData instanceof  String[][]) {
042:                            sourceData = ((String[][]) sourceData)[ndx];
043:                        }
044:                    }
045:                    if (sourceData instanceof  String) {
046:                        return (String) sourceData;
047:                    } else if (sourceData instanceof  String[]) {
048:                        String[] data = (String[]) sourceData;
049:                        StringBuffer result = new StringBuffer();
050:                        for (int i = 0; i < data.length; i++) {
051:                            if (i > 0)
052:                                result.append(';');
053:                            result.append(data[i]);
054:                        }
055:                        return result.toString();
056:                    } else {
057:                        throw new ConversionError("could not convert tag: "
058:                                + propName);
059:                    }
060:                }
061:            }
062:
063:            private static class CollationConversion extends Conversion {
064:                public String convert(Hashtable source) throws ConversionError {
065:                    Object[][] elements = (Object[][]) source.get("collations");
066:                    CollationItem[] items = (CollationItem[]) elements[2][1];
067:                    if (items == null) {
068:                        return "";
069:                    } else {
070:                        StringBuffer result = new StringBuffer();
071:                        for (int i = 0; i < items.length; i++) {
072:                            if (items[i] != null) {
073:                                result.append(items[i].toString());
074:                            }
075:                        }
076:                        return result.toString();
077:                    }
078:                }
079:            }
080:
081:            private static final Conversion[] conversions = {
082:                    new Conversion("LocaleString"), /*locale id based on iso codes*/
083:                    new Conversion("LocaleID"), /*Windows id*/
084:                    new Conversion("ShortLanguage"), /*iso-3 abbrev lang name*/
085:                    new Conversion("ShortCountry"), /*iso-3 abbrev country name*/
086:                    new Conversion("Languages"), /*language names*/
087:                    new Conversion("Countries"), /*country names*/
088:                    new Conversion("MonthNames", 0), /*january*/
089:                    new Conversion("MonthNames", 1), /*february*/
090:                    new Conversion("MonthNames", 2), /*march*/
091:                    new Conversion("MonthNames", 3), /*april*/
092:                    new Conversion("MonthNames", 4), /*may*/
093:                    new Conversion("MonthNames", 5), /*june*/
094:                    new Conversion("MonthNames", 6), /*july*/
095:                    new Conversion("MonthNames", 7), /*august*/
096:                    new Conversion("MonthNames", 8), /*september*/
097:                    new Conversion("MonthNames", 9), /*october*/
098:                    new Conversion("MonthNames", 10), /*november*/
099:                    new Conversion("MonthNames", 11), /*december*/
100:                    new Conversion("MonthNames", 12), /*month 13 if applicable*/
101:                    new Conversion("MonthAbbreviations", 0), /*abb january*/
102:                    new Conversion("MonthAbbreviations", 1), /*abb february*/
103:                    new Conversion("MonthAbbreviations", 2), /*abb march*/
104:                    new Conversion("MonthAbbreviations", 3), /*abb april*/
105:                    new Conversion("MonthAbbreviations", 4), /*abb may*/
106:                    new Conversion("MonthAbbreviations", 5), /*abb june*/
107:                    new Conversion("MonthAbbreviations", 6), /*abb july*/
108:                    new Conversion("MonthAbbreviations", 7), /*abb august*/
109:                    new Conversion("MonthAbbreviations", 8), /*abb september*/
110:                    new Conversion("MonthAbbreviations", 9), /*abb october*/
111:                    new Conversion("MonthAbbreviations", 10), /*abb november*/
112:                    new Conversion("MonthAbbreviations", 11), /*abb december*/
113:                    new Conversion("MonthAbbreviations", 12), /*abb month 13 if applicable*/
114:                    new Conversion("DayNames", 0), /*Monday*/
115:                    new Conversion("DayNames", 1), /*Tuesday*/
116:                    new Conversion("DayNames", 2), /*Wednesday*/
117:                    new Conversion("DayNames", 3), /*Thursday*/
118:                    new Conversion("DayNames", 4), /*Friday*/
119:                    new Conversion("DayNames", 5), /*Saturday*/
120:                    new Conversion("DayNames", 6), /*Sunday*/
121:                    new Conversion("DayAbbreviations", 0), /*abb Monday*/
122:                    new Conversion("DayAbbreviations", 1), /*abb Tuesday*/
123:                    new Conversion("DayAbbreviations", 2), /*abb Wednesday*/
124:                    new Conversion("DayAbbreviations", 3), /*abb Thursday*/
125:                    new Conversion("DayAbbreviations", 4), /*abb Friday*/
126:                    new Conversion("DayAbbreviations", 5), /*abb Saturday*/
127:                    new Conversion("DayAbbreviations", 6), /*abb Sunday*/
128:                    new Conversion("AmPmMarkers", 0), /*am marker*/
129:                    new Conversion("AmPmMarkers", 1), /*pm marker*/
130:                    new Conversion("Eras"),/*era strings*/
131:                    new Conversion("NumberPatterns", 0), /*decimal pattern*/
132:                    new Conversion("NumberPatterns", 1), /*currency pattern*/
133:                    new Conversion("NumberPatterns", 2), /*percent pattern*/
134:                    new Conversion("NumberElements", 0), /*decimal separator*/
135:                    new Conversion("NumberElements", 1), /*group (thousands) separator*/
136:                    new Conversion("NumberElements", 2), /*list separator*/
137:                    new Conversion("NumberElements", 3), /*percent sign*/
138:                    new Conversion("NumberElements", 4), /*native 0 digit*/
139:                    new Conversion("NumberElements", 5), /*pattern digit*/
140:                    new Conversion("NumberElements", 6), /*minus sign*/
141:                    new Conversion("NumberElements", 7), /*exponential*/
142:                    new Conversion("CurrencyElements", 0), /*local currency symbol*/
143:                    new Conversion("CurrencyElements", 1), /*intl currency symbol*/
144:                    new Conversion("CurrencyElements", 2), /*monetary decimal separator*/
145:                    new Conversion("DateTimePatterns", 0), /*full time pattern*/
146:                    new Conversion("DateTimePatterns", 1), /*long time pattern*/
147:                    new Conversion("DateTimePatterns", 2), /*medium time pattern*/
148:                    new Conversion("DateTimePatterns", 3), /*short time pattern*/
149:                    new Conversion("DateTimePatterns", 4), /*full date pattern*/
150:                    new Conversion("DateTimePatterns", 5), /*long date pattern*/
151:                    new Conversion("DateTimePatterns", 6), /*medium date pattern*/
152:                    new Conversion("DateTimePatterns", 7), /*short date pattern*/
153:                    new Conversion("DateTimePatterns", 8), /*date-time pattern*/
154:                    new Conversion("DateTimeElements", 9), /*first day of week*/
155:                    new Conversion("DateTimeElements", 10), /*min days in first week*/
156:                    new CollationConversion(), /*collation order*/
157:            };
158:            private Locale locale;
159:            private Locale parentLocale;
160:            private ResourceBundle defaultData;
161:
162:            public NeutralToJ1Converter(Locale locale) {
163:                this .locale = locale;
164:                String language = locale.toString();
165:                String country = "";
166:                String variant = "";
167:
168:                int ndx = language.indexOf('_');
169:                if (ndx >= 0) {
170:                    country = language.substring(ndx + 1);
171:                    language = language.substring(0, ndx);
172:                }
173:                ndx = country.indexOf('_');
174:                if (ndx >= 0) {
175:                    variant = country.substring(ndx);
176:                    country = country.substring(0, ndx);
177:                }
178:
179:                if ("".equals(country)) {
180:                    language = "";
181:                    variant = "";
182:                } else if ("".equals(variant)) {
183:                    country = "";
184:                }
185:
186:                parentLocale = new Locale(language, country, variant);
187:                defaultData = ResourceBundle
188:                        .getBundle(
189:                                "com.ibm.icu.dev.tool.localeconverter.myLocaleElements",
190:                                parentLocale);
191:                //{{INIT_CONTROLS
192:                //}}
193:            }
194:
195:            /** convert the source table to the result */
196:            protected void convert(Hashtable result, Hashtable source)
197:                    throws ConversionError {
198:                Vector localeElements = new Vector();
199:                for (int i = 0; i < conversions.length; i++) {
200:                    final Conversion conv = conversions[i];
201:                    final String newValue = conv.convert(source);
202:                    if (newValue != null) {
203:                        localeElements.addElement(newValue);
204:                    } else {
205:                        localeElements.addElement(defaultData.getObject(conv
206:                                .getPropName()));
207:                    }
208:                }
209:                result.put("LocaleElements", localeElements);
210:            }
211:            //{{DECLARE_CONTROLS
212:            //}}
213:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.