Source Code Cross Referenced for GenerateLocalizedPropertiesFiles.java in  » IDE-Netbeans » jmx » org » netbeans » modules » jmx » i18n » 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 » IDE Netbeans » jmx » org.netbeans.modules.jmx.i18n 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * GenerateLocalizedPropertiesFiles.java
003:         *
004:         * Created on January 9, 2006, 9:53 AM
005:         *
006:         * To change this template, choose Tools | Options and locate the template under
007:         * the Source Creation and Management node. Right-click the template and choose
008:         * Open. You can then make changes to the template in the Source Editor.
009:         */
010:
011:        package org.netbeans.modules.jmx.i18n;
012:
013:        import java.io.File;
014:        import java.io.FileInputStream;
015:        import java.io.FileOutputStream;
016:        import java.text.ParseException;
017:        import java.util.Map.Entry;
018:        import java.util.Properties;
019:        import java.util.Set;
020:        import java.util.StringTokenizer;
021:
022:        /**
023:         *
024:         * @author jfdenise
025:         */
026:        public class GenerateLocalizedPropertiesFiles {
027:
028:            /** Creates a new instance of Main */
029:            public GenerateLocalizedPropertiesFiles() {
030:            }
031:
032:            /**
033:             * @param args the command line arguments
034:             */
035:            public static void main(String[] args) throws Exception {
036:
037:                String dirs = System.getProperty("jmx.i18n.properties.dirs");// NOI18N
038:                StringTokenizer tokenizer = new StringTokenizer(dirs, ",");// NOI18N
039:                String prefix = System.getProperty("jmx.i18n.prefix");// NOI18N
040:                String locale = System.getProperty("jmx.i18n.locale");// NOI18N
041:                while (tokenizer.hasMoreElements()) {
042:                    generateFile(locale, prefix, tokenizer.nextToken());
043:                }
044:            }
045:
046:            private static void generateFile(String locale, String prefix,
047:                    String dir) throws Exception {
048:                File file = new File("." + File.separator + "src"
049:                        + // NOI18N
050:                        File.separator + dir + File.separator
051:                        + "Bundle.properties");// NOI18N
052:                System.out.println("Reading file : " + file.getAbsolutePath());// NOI18N
053:                String newDir = "." + File.separator + "build" + // NOI18N
054:                        File.separator + "locale" + File.separator + dir;// NOI18N
055:                String newFileName = newDir + File.separator + "Bundle_"
056:                        + locale + // NOI18N
057:                        ".properties";// NOI18N
058:                File dirs = new File(newDir);
059:                dirs.mkdirs();
060:                File f = new File(newFileName);
061:                f.createNewFile();
062:                FileOutputStream output = new FileOutputStream(f);
063:
064:                //Load properties file
065:                Properties properties = new Properties();
066:                properties.load(new FileInputStream(file));
067:                Properties newProperties = new Properties();
068:                Set<Entry<Object, Object>> entries = properties.entrySet();
069:                for (Entry entry : entries) {
070:                    String key = (String) entry.getKey();
071:
072:                    String value = (String) entry.getValue();
073:                    if (!key.endsWith("Template")) {// NOI18N
074:                        //We are not translating Numbers
075:                        try {
076:                            Integer.valueOf(value);
077:                        } catch (Exception e) {
078:                            if (!("localhost".equals(value)))// NOI18N
079:                                value = parseEscapes(prefix) + entry.getValue();
080:                        }
081:                    }
082:                    newProperties.setProperty(key, value);
083:                }
084:                System.out.println("Localized file : " + newFileName);// NOI18N
085:                newProperties.store(output, "Localized in " + locale);// NOI18N
086:                output.close();
087:            }
088:
089:            public static String parseEscapes(CharSequence text)
090:                    throws ParseException {
091:                // For each character...
092:                int length = text.length();
093:                StringBuffer sb = new StringBuffer(length);
094:                for (int iChar = 0; iChar < length;) {
095:                    char ch = text.charAt(iChar++);
096:
097:                    // Handle escapes.
098:                    if (ch == '\\') {
099:                        if (iChar >= length) {
100:                            throw new ParseException(
101:                                    "Orphaned escape character.", iChar);// NOI18N
102:                        }
103:                        ch = text.charAt(iChar++);
104:                        if (ch == 'u') {
105:                            // A Unicode escape sequence.
106:                            if (iChar > length - 4) {
107:                                throw new ParseException(
108:                                        "Malformed Unicode escape.", iChar);// NOI18N
109:                            }
110:                            int value = 0;
111:                            for (int iDigit = 4; iDigit > 0; iDigit--) {
112:                                int digitValue = Character.digit(text
113:                                        .charAt(iChar++), 16);
114:                                if (digitValue < 0) {
115:                                    throw new ParseException(
116:                                            "Malformed Unicode escape.", iChar);// NOI18N
117:                                }
118:                                value = (value << 4) + digitValue;
119:                            }
120:                            sb.append((char) value);
121:                        } else {
122:                            // A standard escape sequence.
123:                            switch (ch) {
124:                            case 't':
125:                                ch = '\t';
126:                                break;// NOI18N
127:                            case 'r':
128:                                ch = '\r';
129:                                break;// NOI18N
130:                            case 'n':
131:                                ch = '\n';
132:                                break;// NOI18N
133:                            case 'f':
134:                                ch = '\f';
135:                                break;// NOI18N
136:                            }
137:                            sb.append(ch);
138:                        }
139:
140:                        continue;
141:                    }
142:
143:                    // An unescaped character.
144:                    sb.append(ch);
145:                }
146:
147:                return sb.toString();
148:            }
149:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.