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


001:        /**
002:         *******************************************************************************
003:         * Copyright (C) 2001-2004, International Business Machines Corporation and    *
004:         * others. All Rights Reserved.                                                *
005:         *******************************************************************************
006:         */package com.ibm.icu.dev.tool.translit;
007:
008:        import com.ibm.icu.text.*;
009:        import java.io.*;
010:
011:        /**
012:         * A command-line interface to the ICU4J transliterators.
013:         * @author Alan Liu
014:         */
015:        public class Trans {
016:
017:            public static void main(String[] args) throws Exception {
018:                boolean isHTML = false;
019:                int pos = 0;
020:
021:                String transName = null; // first untagged string is this
022:                String inText = null; // all other untagged strings are this
023:                String inName = null;
024:                String outName = null;
025:
026:                while (pos < args.length) {
027:                    if (args[pos].equals("-html")) {
028:                        isHTML = true;
029:                    } else if (args[pos].equals("-i")) {
030:                        if (++pos == args.length)
031:                            usage();
032:                        inName = args[pos];
033:                    } else if (args[pos].equals("-o")) {
034:                        if (++pos == args.length)
035:                            usage();
036:                        outName = args[pos];
037:                    } else if (transName == null) {
038:                        transName = args[pos];
039:                    } else {
040:                        if (inText == null) {
041:                            inText = args[pos];
042:                        } else {
043:                            inText = inText + " " + args[pos];
044:                        }
045:                    }
046:                    ++pos;
047:                }
048:
049:                if (inText != null && inName != null) {
050:                    usage();
051:                }
052:
053:                Transliterator trans = Transliterator.getInstance(transName);
054:                BufferedReader in = null;
055:                if (inName != null) {
056:                    in = new BufferedReader(new InputStreamReader(
057:                            new FileInputStream(inName), "UTF8"));
058:                }
059:                PrintWriter out = null;
060:                if (outName != null) {
061:                    out = new PrintWriter(new OutputStreamWriter(
062:                            new FileOutputStream(outName), "UTF8"));
063:                } else {
064:                    out = new PrintWriter(System.out);
065:                }
066:                trans(trans, inText, in, out, isHTML);
067:                out.close();
068:            }
069:
070:            static void trans(Transliterator trans, String inText,
071:                    BufferedReader in, PrintWriter out, boolean isHTML)
072:                    throws IOException {
073:                boolean inTag = false; // If true, we are within a <tag>
074:                for (;;) {
075:                    String line = null;
076:                    if (inText != null) {
077:                        line = inText;
078:                        inText = null;
079:                    } else if (in != null) {
080:                        line = in.readLine();
081:                    }
082:                    if (line == null) {
083:                        break;
084:                    }
085:                    if (isHTML) {
086:                        // Pass tags between < and > unchanged
087:                        StringBuffer buf = new StringBuffer();
088:                        int right = -1;
089:                        if (inTag) {
090:                            right = line.indexOf('>');
091:                            if (right < 0) {
092:                                right = line.length() - 1;
093:                            }
094:                            buf.append(line.substring(0, right + 1));
095:                            if (DEBUG)
096:                                System.out.println("*S:"
097:                                        + line.substring(0, right + 1));
098:                            inTag = false;
099:                        }
100:                        for (;;) {
101:                            int left = line.indexOf('<', right + 1);
102:                            if (left < 0) {
103:                                if (right < line.length() - 1) {
104:                                    buf.append(trans.transliterate(line
105:                                            .substring(right + 1)));
106:                                    if (DEBUG)
107:                                        System.out.println("T:"
108:                                                + line.substring(right + 1));
109:                                }
110:                                break;
111:                            }
112:                            // Append transliterated segment right+1..left-1
113:                            buf.append(trans.transliterate(line.substring(
114:                                    right + 1, left)));
115:                            if (DEBUG)
116:                                System.out.println("T:"
117:                                        + line.substring(right + 1, left));
118:                            right = line.indexOf('>', left + 1);
119:                            if (right < 0) {
120:                                inTag = true;
121:                                buf.append(line.substring(left));
122:                                if (DEBUG)
123:                                    System.out.println("S:"
124:                                            + line.substring(left));
125:                                break;
126:                            }
127:                            buf.append(line.substring(left, right + 1));
128:                            if (DEBUG)
129:                                System.out.println("S:"
130:                                        + line.substring(left, right + 1));
131:                        }
132:                        line = buf.toString();
133:                    } else {
134:                        line = trans.transliterate(line);
135:                    }
136:                    out.println(line);
137:                }
138:            }
139:
140:            static final boolean DEBUG = false;
141:
142:            /**
143:             * Emit usage and die.
144:             */
145:            static void usage() {
146:                System.out
147:                        .println("Usage: java com.ibm.icu.dev.tool.translit.Trans [-html] <trans> ( <input> | -i <infile>) [ -o <outfile> ]");
148:                System.out.println("<trans>   Name of transliterator");
149:                System.out.println("<input>   Text to transliterate");
150:                System.out.println("<infile>  Name of input file");
151:                System.out.println("<outfile> Name of output file");
152:                System.out
153:                        .println("-html     Only transliterate text outside of <tags>");
154:                System.out
155:                        .println("Input may come from the command line or a file.\n");
156:                System.out.println("Ouput may go to stdout or a file.\n");
157:                System.exit(0);
158:            }
159:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.