Source Code Cross Referenced for RBTMXImporter.java in  » Internationalization-Localization » RBManager » com » ibm » rbm » 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 » RBManager » com.ibm.rbm 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *****************************************************************************
003:         * Copyright (C) 2000-2004, International Business Machines Corporation and  *
004:         * others. All Rights Reserved.                                              *
005:         *****************************************************************************
006:         */
007:        package com.ibm.rbm;
008:
009:        import java.io.*;
010:        import java.util.*;
011:
012:        import javax.xml.parsers.*;
013:
014:        import org.w3c.dom.*;
015:        import org.xml.sax.*;
016:
017:        import com.ibm.rbm.gui.RBManagerGUI;
018:
019:        /**
020:         * This is the super class for all importer plug-in classes. This class defines the methods
021:         * and functionality common to all importers. This includes setting up the options dialog and
022:         * displaying it to the user, performing the actual insertions into the resource bundle manager,
023:         * and managing any import conflicts.
024:         * 
025:         * @author Jared Jackson
026:         * @see com.ibm.rbm.RBManager
027:         */
028:        public class RBTMXImporter extends RBImporter {
029:
030:            Document tmx_xml = null;
031:
032:            /**
033:             * Basic constructor for the TMX importer from the parent RBManager data and a Dialog title.
034:             */
035:
036:            public RBTMXImporter(String title, RBManager rbm, RBManagerGUI gui) {
037:                super (title, rbm, gui);
038:            }
039:
040:            protected void setupFileChooser() {
041:                chooser.setFileFilter(new javax.swing.filechooser.FileFilter() {
042:                    public boolean accept(File f) {
043:                        if (f.isDirectory())
044:                            return true;
045:                        if (f.getName().endsWith(".tmx"))
046:                            return true;
047:                        return false;
048:                    }
049:
050:                    public String getDescription() {
051:                        return Resources
052:                                .getTranslation("import_TMX_file_description");
053:                    }
054:                });
055:            }
056:
057:            protected void beginImport() throws IOException {
058:                super .beginImport();
059:                File tmx_file = getChosenFile();
060:
061:                try {
062:                    FileInputStream fis = new FileInputStream(tmx_file);
063:                    InputSource is = new InputSource(fis);
064:                    DocumentBuilder builder = DocumentBuilderFactory
065:                            .newInstance().newDocumentBuilder();
066:                    tmx_xml = builder.parse(is);
067:                    fis.close();
068:                } catch (Exception e) {
069:                    e.printStackTrace(System.err);
070:                    throw new IOException(e.getMessage());
071:                }
072:                if (tmx_xml == null)
073:                    return;
074:
075:                importDoc();
076:            }
077:
078:            private void importDoc() {
079:                if (tmx_xml == null)
080:                    return;
081:                Element root = tmx_xml.getDocumentElement();
082:                Node node = root.getFirstChild();
083:                while (node != null
084:                        && (node.getNodeType() != Node.ELEMENT_NODE || !(node
085:                                .getNodeName().equalsIgnoreCase("header")))) {
086:                    node = node.getNextSibling();
087:                }
088:                //ElementImpl header = (ElementImpl)node;
089:                node = root.getFirstChild();
090:                while (node != null
091:                        && (node.getNodeType() != Node.ELEMENT_NODE || !(node
092:                                .getNodeName().equalsIgnoreCase("body")))) {
093:                    node = node.getNextSibling();
094:                }
095:                Element body = (Element) node;
096:                resolveEncodings(getEncodingsVector(body));
097:
098:                // Now do the actual import resource by resource
099:                NodeList tu_list = body.getElementsByTagName("tu");
100:                for (int i = 0; i < tu_list.getLength(); i++) {
101:                    Element tu_elem = (Element) tu_list.item(i);
102:                    // Get the key value
103:                    String name = tu_elem.getAttribute("tuid");
104:                    if (name == null || name.length() < 1)
105:                        continue;
106:                    // Get the group if it exists
107:                    String group = null;
108:                    NodeList prop_list = tu_elem.getElementsByTagName("prop");
109:                    for (int j = 0; j < prop_list.getLength(); j++) {
110:                        Element prop_elem = (Element) prop_list.item(j);
111:                        String type = prop_elem.getAttribute("type");
112:                        if (type != null && type.equals("x-Group")) {
113:                            prop_elem.normalize();
114:                            NodeList text_list = prop_elem.getChildNodes();
115:                            if (text_list.getLength() < 1)
116:                                continue;
117:                            Text text_elem = (Text) text_list.item(0);
118:                            group = text_elem.getNodeValue();
119:                        }
120:                    }
121:                    if (group == null || group.length() < 1)
122:                        group = getDefaultGroup();
123:
124:                    NodeList tuv_list = tu_elem.getElementsByTagName("tuv");
125:                    // For each tuv element
126:                    for (int j = 0; j < tuv_list.getLength(); j++) {
127:                        Element tuv_elem = (Element) tuv_list.item(j);
128:                        String encoding = tuv_elem.getAttribute("lang");
129:                        // Get the current encoding
130:                        if (encoding == null)
131:                            continue;
132:                        char array[] = encoding.toCharArray();
133:                        for (int k = 0; k < array.length; k++) {
134:                            if (array[k] == '-')
135:                                array[k] = '_';
136:                        }
137:                        encoding = String.valueOf(array);
138:                        // Get the translation value
139:                        NodeList seg_list = tuv_elem
140:                                .getElementsByTagName("seg");
141:                        if (seg_list.getLength() < 1)
142:                            continue;
143:                        Element seg_elem = (Element) seg_list.item(0);
144:                        seg_elem.normalize();
145:                        NodeList text_list = seg_elem.getChildNodes();
146:                        if (text_list.getLength() < 1)
147:                            continue;
148:                        Text text_elem = (Text) text_list.item(0);
149:                        String value = text_elem.getNodeValue();
150:                        if (value == null || value.length() < 1)
151:                            continue;
152:                        // Create the bundle item
153:                        BundleItem item = new BundleItem(null, name, value);
154:                        // Get creation, modification values
155:                        item.setCreatedDate(tuv_elem
156:                                .getAttribute("creationdate"));
157:                        item.setModifiedDate(tuv_elem
158:                                .getAttribute("changedate"));
159:                        if (tuv_elem.getAttribute("changeid") != null)
160:                            item.setModifier(tuv_elem.getAttribute("changeid"));
161:                        if (tuv_elem.getAttribute("creationid") != null)
162:                            item
163:                                    .setCreator(tuv_elem
164:                                            .getAttribute("creationid"));
165:                        // Get properties specified
166:                        prop_list = tuv_elem.getElementsByTagName("prop");
167:                        Hashtable lookups = null;
168:                        for (int k = 0; k < prop_list.getLength(); k++) {
169:                            Element prop_elem = (Element) prop_list.item(k);
170:                            String type = prop_elem.getAttribute("type");
171:                            if (type != null && type.equals("x-Comment")) {
172:                                // Get the comment
173:                                prop_elem.normalize();
174:                                text_list = prop_elem.getChildNodes();
175:                                if (text_list.getLength() < 1)
176:                                    continue;
177:                                text_elem = (Text) text_list.item(0);
178:                                String comment = text_elem.getNodeValue();
179:                                if (comment != null && comment.length() > 0)
180:                                    item.setComment(comment);
181:                            } else if (type != null
182:                                    && type.equals("x-Translated")) {
183:                                // Get the translated flag value
184:                                prop_elem.normalize();
185:                                text_list = prop_elem.getChildNodes();
186:                                if (text_list.getLength() < 1)
187:                                    continue;
188:                                text_elem = (Text) text_list.item(0);
189:                                if (text_elem.getNodeValue() != null) {
190:                                    if (text_elem.getNodeValue()
191:                                            .equalsIgnoreCase("true"))
192:                                        item.setTranslated(true);
193:                                    else if (text_elem.getNodeValue()
194:                                            .equalsIgnoreCase("false"))
195:                                        item.setTranslated(false);
196:                                    else
197:                                        item
198:                                                .setTranslated(getDefaultTranslated());
199:                                } else
200:                                    item.setTranslated(getDefaultTranslated());
201:                            } else if (type != null && type.equals("x-Lookup")) {
202:                                // Get a lookup value
203:                                prop_elem.normalize();
204:                                text_list = prop_elem.getChildNodes();
205:                                if (text_list.getLength() < 1)
206:                                    continue;
207:                                text_elem = (Text) text_list.item(0);
208:                                if (text_elem.getNodeValue() != null) {
209:                                    String text = text_elem.getNodeValue();
210:                                    if (text.indexOf("=") > 0) {
211:                                        try {
212:                                            if (lookups == null)
213:                                                lookups = new Hashtable();
214:                                            String lkey = text.substring(0,
215:                                                    text.indexOf("="));
216:                                            String lvalue = text.substring(text
217:                                                    .indexOf("=") + 1, text
218:                                                    .length());
219:                                            lookups.put(lkey, lvalue);
220:                                        } catch (Exception ex) { /* String out of bounds - Ignore and go on */
221:                                        }
222:                                    }
223:                                } else
224:                                    item.setTranslated(getDefaultTranslated());
225:                            }
226:                        }
227:                        if (lookups != null)
228:                            item.setLookups(lookups);
229:                        importResource(item, encoding, group);
230:                    }
231:                }
232:            }
233:
234:            private Vector getEncodingsVector(Element body) {
235:        String empty = "";
236:        if (body == null)
237:        	return null;
238:        Hashtable hash = new Hashtable();
239:        NodeList tu_list = body.getElementsByTagName("tu");
240:        for (int i=0; i < tu_list.getLength(); i++) {
241:            Element tu_elem = (Element)tu_list.item(i);
242:            NodeList tuv_list = tu_elem.getElementsByTagName("tuv");
243:            for (int j=0; j < tuv_list.getLength(); j++) {
244:                Element tuv_elem = (Element)tuv_list.item(j);
245:                String encoding = tuv_elem.getAttribute("lang");
246:                if (encoding == null)
247:                	continue;
248:                char array[] = encoding.toCharArray();
249:                for (int k=0; k < array.length; k++) {
250:                    if (array[k] == '-')
251:                    	array[k] = '_';
252:                }
253:                encoding = String.valueOf(array);
254:                if (!(hash.containsKey(encoding)))
255:                	hash.put(encoding,empty);
256:            }
257:        }
258:        Vector v = new Vector();
259:        Enumeration enum = hash.keys();
260:        while (enum.hasMoreElements()) {
261:        	v.addElement(enum.nextElement());
262:        }
263:        return v;
264:    }
265:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.