ICU-3501 Reduce dependency on xerces
X-SVN-Rev: 15993
This commit is contained in:
parent
a7ee6681cf
commit
b0198b2198
@ -185,24 +185,24 @@ public class RBReporter extends JFrame {
|
||||
}
|
||||
if (htmlCheck.isSelected()) {
|
||||
File htmlFile = new File(directory, htmlField.getText());
|
||||
DocumentImpl htmlReport = getHTMLReportz(htmlCombo.getSelectedIndex() == 0);
|
||||
Document htmlReport = getHTMLReportz(htmlCombo.getSelectedIndex() == 0);
|
||||
if (scanCheck.isSelected()) {
|
||||
// Add file scan information
|
||||
ElementImpl html_elem = (ElementImpl)htmlReport.getDocumentElement();
|
||||
Element html_elem = htmlReport.getDocumentElement();
|
||||
NodeList nl = html_elem.getElementsByTagName("BODY");
|
||||
ElementImpl body_elem = (ElementImpl)nl.item(0);
|
||||
ElementImpl h2_elem = (ElementImpl)htmlReport.createElement("H2");
|
||||
TextImpl h2_text = (TextImpl)htmlReport.createTextNode("Code Scan Results");
|
||||
ElementImpl block_elem = (ElementImpl)htmlReport.createElement("BLOCKQUOTE");
|
||||
ElementImpl p1_elem = (ElementImpl)htmlReport.createElement("P");
|
||||
ElementImpl p2_elem = (ElementImpl)htmlReport.createElement("P");
|
||||
ElementImpl p3_elem = (ElementImpl)htmlReport.createElement("P");
|
||||
TextImpl p1_text = (TextImpl)htmlReport.createTextNode("Number of unique resources found: " +
|
||||
scanner.getNumberMissingResources());
|
||||
TextImpl p2_text = (TextImpl)htmlReport.createTextNode("Number of resources missing from bundle: " +
|
||||
scanner.getNumberMissingResources());
|
||||
TextImpl p3_text = (TextImpl)htmlReport.createTextNode("Number of potentially unused resources in bundle: " +
|
||||
scanner.getNumberUnusedResources());
|
||||
Element body_elem = (Element)nl.item(0);
|
||||
Element h2_elem = htmlReport.createElement("H2");
|
||||
Text h2_text = htmlReport.createTextNode("Code Scan Results");
|
||||
Element block_elem = htmlReport.createElement("BLOCKQUOTE");
|
||||
Element p1_elem = htmlReport.createElement("P");
|
||||
Element p2_elem = htmlReport.createElement("P");
|
||||
Element p3_elem = htmlReport.createElement("P");
|
||||
Text p1_text = htmlReport.createTextNode("Number of unique resources found: " +
|
||||
scanner.getNumberMissingResources());
|
||||
Text p2_text = htmlReport.createTextNode("Number of resources missing from bundle: " +
|
||||
scanner.getNumberMissingResources());
|
||||
Text p3_text = htmlReport.createTextNode("Number of potentially unused resources in bundle: " +
|
||||
scanner.getNumberUnusedResources());
|
||||
|
||||
h2_elem.appendChild(h2_text);
|
||||
p1_elem.appendChild(p1_text);
|
||||
@ -215,19 +215,19 @@ public class RBReporter extends JFrame {
|
||||
body_elem.appendChild(block_elem);
|
||||
|
||||
// Missing resources from the bundle
|
||||
TextImpl missing_text = null;
|
||||
Text missing_text = null;
|
||||
Vector v = scanner.getMissingResources();
|
||||
if (htmlCombo.getSelectedIndex() == 0) {
|
||||
ElementImpl ul_elem = (ElementImpl)htmlReport.createElement("UL");
|
||||
missing_text = (TextImpl)htmlReport.createTextNode("Missing Resources:");
|
||||
Element ul_elem = htmlReport.createElement("UL");
|
||||
missing_text = htmlReport.createTextNode("Missing Resources:");
|
||||
ul_elem.appendChild(missing_text);
|
||||
for (int i=0; i < v.size(); i++) {
|
||||
ScanResult result = (ScanResult)v.elementAt(i);
|
||||
ElementImpl li_elem = (ElementImpl)htmlReport.createElement("LI");
|
||||
ElementImpl br_elem = (ElementImpl)htmlReport.createElement("BR");
|
||||
TextImpl t1_text = (TextImpl)htmlReport.createTextNode(result.getName() + " (" +
|
||||
Element li_elem = htmlReport.createElement("LI");
|
||||
Element br_elem = htmlReport.createElement("BR");
|
||||
Text t1_text = htmlReport.createTextNode(result.getName() + " (" +
|
||||
result.getOccurances().size() + " Occurances)");
|
||||
TextImpl t2_text = (TextImpl)htmlReport.createTextNode(result.getOccurances().toString());
|
||||
Text t2_text = htmlReport.createTextNode(result.getOccurances().toString());
|
||||
li_elem.appendChild(t1_text);
|
||||
li_elem.appendChild(br_elem);
|
||||
li_elem.appendChild(t2_text);
|
||||
@ -241,22 +241,22 @@ public class RBReporter extends JFrame {
|
||||
ScanResult result = (ScanResult)v.elementAt(i);
|
||||
buffer.append((i==0 ? "" : ", ") + result.getName() + " (" + result.getOccurances().size() + " Occurances)");
|
||||
}
|
||||
missing_text = (TextImpl)htmlReport.createTextNode(buffer.toString());
|
||||
ElementImpl br_elem = (ElementImpl)htmlReport.createElement("BR");
|
||||
missing_text = htmlReport.createTextNode(buffer.toString());
|
||||
Element br_elem = htmlReport.createElement("BR");
|
||||
p2_elem.appendChild(br_elem);
|
||||
p2_elem.appendChild(missing_text);
|
||||
}
|
||||
// Bundle resources not found in the code
|
||||
TextImpl unused_text = null;
|
||||
Text unused_text = null;
|
||||
v = scanner.getUnusedResources();
|
||||
if (htmlCombo.getSelectedIndex() == 0) {
|
||||
ElementImpl ul_elem = (ElementImpl)htmlReport.createElement("UL");
|
||||
unused_text = (TextImpl)htmlReport.createTextNode("Unused Resources:");
|
||||
Element ul_elem = htmlReport.createElement("UL");
|
||||
unused_text = htmlReport.createTextNode("Unused Resources:");
|
||||
ul_elem.appendChild(unused_text);
|
||||
for (int i=0; i < v.size(); i++) {
|
||||
ScanResult result = (ScanResult)v.elementAt(i);
|
||||
ElementImpl li_elem = (ElementImpl)htmlReport.createElement("LI");
|
||||
TextImpl t1_text = (TextImpl)htmlReport.createTextNode(result.getName() + " (Group: " +
|
||||
Element li_elem = htmlReport.createElement("LI");
|
||||
Text t1_text = htmlReport.createTextNode(result.getName() + " (Group: " +
|
||||
result.getGroupName() + ")");
|
||||
li_elem.appendChild(t1_text);
|
||||
ul_elem.appendChild(li_elem);
|
||||
@ -269,8 +269,8 @@ public class RBReporter extends JFrame {
|
||||
ScanResult result = (ScanResult)v.elementAt(i);
|
||||
buffer.append((i==0 ? "" : ", ") + result.getName());
|
||||
}
|
||||
unused_text = (TextImpl)htmlReport.createTextNode(buffer.toString());
|
||||
ElementImpl br_elem = (ElementImpl)htmlReport.createElement("BR");
|
||||
unused_text = htmlReport.createTextNode(buffer.toString());
|
||||
Element br_elem = htmlReport.createElement("BR");
|
||||
p3_elem.appendChild(br_elem);
|
||||
p3_elem.appendChild(unused_text);
|
||||
}
|
||||
@ -284,20 +284,20 @@ public class RBReporter extends JFrame {
|
||||
}
|
||||
if (xmlCheck.isSelected()) {
|
||||
File xmlFile = new File(directory, xmlField.getText());
|
||||
DocumentImpl xmlReport = getXMLReportz(xmlCombo.getSelectedIndex() == 0);
|
||||
Document xmlReport = getXMLReportz(xmlCombo.getSelectedIndex() == 0);
|
||||
if (scanCheck.isSelected()) {
|
||||
// Add file scan information
|
||||
ElementImpl root = (ElementImpl)xmlReport.getDocumentElement();
|
||||
ElementImpl code_scan_elem = (ElementImpl)xmlReport.createElement("CODE_SCAN");
|
||||
ElementImpl unique_elem = (ElementImpl)xmlReport.createElement("UNIQUE_RESOURCES");
|
||||
ElementImpl missing_elem = (ElementImpl)xmlReport.createElement("MISSING_RESOURCES");
|
||||
ElementImpl unused_elem = (ElementImpl)xmlReport.createElement("UNUSED_RESOURCES");
|
||||
ElementImpl unique_total_elem = (ElementImpl)xmlReport.createElement("TOTAL");
|
||||
ElementImpl missing_total_elem = (ElementImpl)xmlReport.createElement("TOTAL");
|
||||
ElementImpl unused_total_elem = (ElementImpl)xmlReport.createElement("TOTAL");
|
||||
TextImpl unique_total_text = (TextImpl)xmlReport.createTextNode(String.valueOf(scanner.getNumberMissingResources()));
|
||||
TextImpl missing_total_text = (TextImpl)xmlReport.createTextNode(String.valueOf(scanner.getNumberMissingResources()));
|
||||
TextImpl unused_total_text = (TextImpl)xmlReport.createTextNode(String.valueOf(scanner.getNumberUnusedResources()));
|
||||
Element root = xmlReport.getDocumentElement();
|
||||
Element code_scan_elem = xmlReport.createElement("CODE_SCAN");
|
||||
Element unique_elem = xmlReport.createElement("UNIQUE_RESOURCES");
|
||||
Element missing_elem = xmlReport.createElement("MISSING_RESOURCES");
|
||||
Element unused_elem = xmlReport.createElement("UNUSED_RESOURCES");
|
||||
Element unique_total_elem = xmlReport.createElement("TOTAL");
|
||||
Element missing_total_elem = xmlReport.createElement("TOTAL");
|
||||
Element unused_total_elem = xmlReport.createElement("TOTAL");
|
||||
Text unique_total_text = xmlReport.createTextNode(String.valueOf(scanner.getNumberMissingResources()));
|
||||
Text missing_total_text = xmlReport.createTextNode(String.valueOf(scanner.getNumberMissingResources()));
|
||||
Text unused_total_text = xmlReport.createTextNode(String.valueOf(scanner.getNumberUnusedResources()));
|
||||
|
||||
unique_total_elem.appendChild(unique_total_text);
|
||||
missing_total_elem.appendChild(missing_total_text);
|
||||
@ -313,13 +313,13 @@ public class RBReporter extends JFrame {
|
||||
Vector v = scanner.getMissingResources();
|
||||
for (int i=0; i < v.size(); i++) {
|
||||
ScanResult result = (ScanResult)v.elementAt(i);
|
||||
ElementImpl item_elem = (ElementImpl)xmlReport.createElement("RESOURCE");
|
||||
Element item_elem = xmlReport.createElement("RESOURCE");
|
||||
item_elem.setAttribute("NAME",result.getName());
|
||||
if (xmlCombo.getSelectedIndex() == 0) {
|
||||
Vector occ_v = result.getOccurances();
|
||||
for (int j=0; j < occ_v.size(); j++) {
|
||||
Occurance occ = (Occurance)occ_v.elementAt(j);
|
||||
ElementImpl occ_elem = (ElementImpl)xmlReport.createElement("OCCURANCE");
|
||||
Element occ_elem = xmlReport.createElement("OCCURANCE");
|
||||
occ_elem.setAttribute("FILE_NAME", occ.getFileName());
|
||||
occ_elem.setAttribute("FILE_PATH", occ.getFilePath());
|
||||
occ_elem.setAttribute("LINE_NUMBER", String.valueOf(occ.getLineNumber()));
|
||||
@ -332,7 +332,7 @@ public class RBReporter extends JFrame {
|
||||
v = scanner.getUnusedResources();
|
||||
for (int i=0; i < v.size(); i++) {
|
||||
ScanResult result = (ScanResult)v.elementAt(i);
|
||||
ElementImpl item_elem = (ElementImpl)xmlReport.createElement("RESOURCE");
|
||||
Element item_elem = xmlReport.createElement("RESOURCE");
|
||||
item_elem.setAttribute("NAME",result.getName());
|
||||
item_elem.setAttribute("GROUP",result.getGroupName());
|
||||
unused_elem.appendChild(item_elem);
|
||||
@ -440,20 +440,20 @@ public class RBReporter extends JFrame {
|
||||
/**
|
||||
* Returns an XHTML formatted report on the status of the currently opened resource bundle
|
||||
*/
|
||||
public DocumentImpl getHTMLReportz(boolean detailed) {
|
||||
DocumentImpl html = new DocumentImpl();
|
||||
ElementImpl root = (ElementImpl)html.createElement("HTML");
|
||||
public Document getHTMLReportz(boolean detailed) {
|
||||
Document html = new DocumentImpl();
|
||||
Element root = html.createElement("HTML");
|
||||
html.appendChild(root);
|
||||
ElementImpl head_elem = (ElementImpl)html.createElement("HEAD");
|
||||
ElementImpl title_elem = (ElementImpl)html.createElement("TITLE");
|
||||
TextImpl title_text = (TextImpl)html.createTextNode("Resource Bundle Report - " + rbm.getBaseClass());
|
||||
ElementImpl body_elem = (ElementImpl)html.createElement("BODY");
|
||||
ElementImpl center1_elem = (ElementImpl)html.createElement("CENTER");
|
||||
ElementImpl h1_elem = (ElementImpl)html.createElement("H1");
|
||||
ElementImpl center2_elem = (ElementImpl)html.createElement("CENTER");
|
||||
ElementImpl h3_elem = (ElementImpl)html.createElement("H1");
|
||||
TextImpl title1_text = (TextImpl)html.createTextNode("Resource Bundle Report: " + rbm.getBaseClass());
|
||||
TextImpl title2_text = (TextImpl)html.createTextNode("Report Generated: " + (new Date()).toString());
|
||||
Element head_elem = html.createElement("HEAD");
|
||||
Element title_elem = html.createElement("TITLE");
|
||||
Text title_text = html.createTextNode("Resource Bundle Report - " + rbm.getBaseClass());
|
||||
Element body_elem = html.createElement("BODY");
|
||||
Element center1_elem = html.createElement("CENTER");
|
||||
Element h1_elem = html.createElement("H1");
|
||||
Element center2_elem = html.createElement("CENTER");
|
||||
Element h3_elem = html.createElement("H1");
|
||||
Text title1_text = html.createTextNode("Resource Bundle Report: " + rbm.getBaseClass());
|
||||
Text title2_text = html.createTextNode("Report Generated: " + (new Date()).toString());
|
||||
Vector bundles = rbm.getBundles();
|
||||
|
||||
title_elem.appendChild(title_text);
|
||||
@ -492,17 +492,17 @@ public class RBReporter extends JFrame {
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
private void getHTMLLanguageReportz(DocumentImpl html, ElementImpl body_elem, boolean detailed, Bundle dict) {
|
||||
ElementImpl h2_elem = (ElementImpl)html.createElement("H2");
|
||||
TextImpl h2_text = (TextImpl)html.createTextNode("Language: " + (dict.language == null ? dict.encoding : dict.language) +
|
||||
(dict.country == null ? "" : " - Country: " + dict.country) +
|
||||
(dict.variant == null ? "" : " - Variant: " + dict.variant));
|
||||
ElementImpl block_elem = (ElementImpl)html.createElement("BLOCKQUOTE");
|
||||
ElementImpl p_elem = (ElementImpl)html.createElement("P");
|
||||
TextImpl p_text = (TextImpl)html.createTextNode("Number of NLS items in the file: " +
|
||||
String.valueOf(dict.allItems.size()));
|
||||
ElementImpl ul_elem = (ElementImpl)html.createElement("UL");
|
||||
TextImpl ul_text = (TextImpl)html.createTextNode("Untranslated NLS keys:");
|
||||
private void getHTMLLanguageReportz(Document html, Element body_elem, boolean detailed, Bundle dict) {
|
||||
Element h2_elem = html.createElement("H2");
|
||||
Text h2_text = html.createTextNode("Language: " + (dict.language == null ? dict.encoding : dict.language) +
|
||||
(dict.country == null ? "" : " - Country: " + dict.country) +
|
||||
(dict.variant == null ? "" : " - Variant: " + dict.variant));
|
||||
Element block_elem = html.createElement("BLOCKQUOTE");
|
||||
Element p_elem = html.createElement("P");
|
||||
Text p_text = html.createTextNode("Number of NLS items in the file: " +
|
||||
String.valueOf(dict.allItems.size()));
|
||||
Element ul_elem = html.createElement("UL");
|
||||
Text ul_text = html.createTextNode("Untranslated NLS keys:");
|
||||
|
||||
h2_elem.appendChild(h2_text);
|
||||
p_elem.appendChild(p_text);
|
||||
@ -518,15 +518,15 @@ public class RBReporter extends JFrame {
|
||||
if (tempItem.isTranslated()) continue;
|
||||
untranslated++;
|
||||
if (detailed) {
|
||||
ElementImpl li_elem = (ElementImpl)html.createElement("LI");
|
||||
TextImpl li_text = (TextImpl)html.createTextNode(tempItem.getKey());
|
||||
Element li_elem = html.createElement("LI");
|
||||
Text li_text = html.createTextNode(tempItem.getKey());
|
||||
li_elem.appendChild(li_text);
|
||||
ul_elem.appendChild(li_elem);
|
||||
}
|
||||
}
|
||||
ElementImpl p2_elem = (ElementImpl)html.createElement("P");
|
||||
TextImpl p2_text = (TextImpl)html.createTextNode("Number of NLS items not translated: " +
|
||||
String.valueOf(untranslated));
|
||||
Element p2_elem = html.createElement("P");
|
||||
Text p2_text = html.createTextNode("Number of NLS items not translated: " +
|
||||
String.valueOf(untranslated));
|
||||
p2_elem.appendChild(p2_text);
|
||||
block_elem.appendChild(p2_elem);
|
||||
if (detailed) block_elem.appendChild(ul_elem);
|
||||
@ -565,7 +565,7 @@ public class RBReporter extends JFrame {
|
||||
* Returns an XML formatted report on the status of the currently open resource bundle
|
||||
*/
|
||||
|
||||
public DocumentImpl getXMLReportz(boolean detailed) {
|
||||
public Document getXMLReportz(boolean detailed) {
|
||||
DocumentImpl xml = new DocumentImpl();
|
||||
Element root = xml.createElement("REPORT");
|
||||
root.setAttribute("BASECLASS", rbm.getBaseClass());
|
||||
@ -596,16 +596,16 @@ public class RBReporter extends JFrame {
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
private ElementImpl getXMLLanguageReportz(DocumentImpl xml, boolean detailed, Bundle dict) {
|
||||
ElementImpl lang_report_elem = (ElementImpl)xml.createElement("LANGUAGE_REPORT");
|
||||
ElementImpl locale_elem = (ElementImpl)xml.createElement("LOCALE");
|
||||
private Element getXMLLanguageReportz(Document xml, boolean detailed, Bundle dict) {
|
||||
Element lang_report_elem = xml.createElement("LANGUAGE_REPORT");
|
||||
Element locale_elem = xml.createElement("LOCALE");
|
||||
locale_elem.setAttribute("LANGUAGE", (dict.language == null ? dict.encoding : dict.language));
|
||||
locale_elem.setAttribute("COUNTRY", (dict.country == null ? "" : dict.country));
|
||||
locale_elem.setAttribute("VARIANT", (dict.variant == null ? "" : dict.variant));
|
||||
ElementImpl nls_total_elem = (ElementImpl)xml.createElement("NLS_TOTAL");
|
||||
TextImpl nls_total_text = (TextImpl)xml.createTextNode(String.valueOf(dict.allItems.size()));
|
||||
ElementImpl untranslated_total_elem = (ElementImpl)xml.createElement("UNTRANSLATED_TOTAL");
|
||||
ElementImpl untranslated_elem = (ElementImpl)xml.createElement("UNTRANSLATED");
|
||||
Element nls_total_elem = xml.createElement("NLS_TOTAL");
|
||||
Text nls_total_text = xml.createTextNode(String.valueOf(dict.allItems.size()));
|
||||
Element untranslated_total_elem = xml.createElement("UNTRANSLATED_TOTAL");
|
||||
Element untranslated_elem = xml.createElement("UNTRANSLATED");
|
||||
|
||||
nls_total_elem.appendChild(nls_total_text);
|
||||
lang_report_elem.appendChild(locale_elem);
|
||||
@ -619,12 +619,12 @@ public class RBReporter extends JFrame {
|
||||
BundleItem tempItem = (BundleItem)enum.nextElement();
|
||||
if (tempItem.isTranslated()) continue;
|
||||
untranslated++;
|
||||
ElementImpl resource_elem = (ElementImpl)xml.createElement("RESOURCEKEY");
|
||||
TextImpl resource_text = (TextImpl)xml.createTextNode(tempItem.getKey());
|
||||
Element resource_elem = xml.createElement("RESOURCEKEY");
|
||||
Text resource_text = xml.createTextNode(tempItem.getKey());
|
||||
resource_elem.appendChild(resource_text);
|
||||
untranslated_elem.appendChild(resource_elem);
|
||||
}
|
||||
TextImpl untranslated_total_text = (TextImpl)xml.createTextNode(String.valueOf(untranslated));
|
||||
Text untranslated_total_text = xml.createTextNode(String.valueOf(untranslated));
|
||||
untranslated_total_elem.appendChild(untranslated_total_text);
|
||||
|
||||
return lang_report_elem;
|
||||
|
@ -10,8 +10,7 @@ package com.ibm.rbm;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
import org.apache.xerces.parsers.*;
|
||||
import org.apache.xerces.dom.*;
|
||||
import org.apache.xerces.parsers.DOMParser;
|
||||
import org.w3c.dom.*;
|
||||
import org.xml.sax.*;
|
||||
|
||||
@ -24,7 +23,7 @@ import org.xml.sax.*;
|
||||
*/
|
||||
public class RBReporterScanner {
|
||||
private Bundle bundle;
|
||||
private DocumentImpl config;
|
||||
private Document config;
|
||||
private Hashtable fileRules;
|
||||
private Hashtable parseRules;
|
||||
private Hashtable results;
|
||||
@ -39,12 +38,12 @@ public class RBReporterScanner {
|
||||
InputSource is = new InputSource(new FileInputStream(configFile));
|
||||
DOMParser parser = new DOMParser();
|
||||
parser.parse(is);
|
||||
config = (DocumentImpl)parser.getDocument();
|
||||
config = parser.getDocument();
|
||||
} catch (SAXException saxe) {
|
||||
throw new IOException("Illegal XML Document: " + saxe.getMessage());
|
||||
}
|
||||
|
||||
ElementImpl root = (ElementImpl)config.getDocumentElement();
|
||||
Element root = config.getDocumentElement();
|
||||
fileRules = getFileRules(root);
|
||||
parseRules = getParseRules(root);
|
||||
|
||||
@ -99,29 +98,29 @@ public class RBReporterScanner {
|
||||
protected boolean performScan() throws IOException {
|
||||
resultsFound = false;
|
||||
|
||||
ElementImpl root = (ElementImpl)config.getDocumentElement();
|
||||
Element root = config.getDocumentElement();
|
||||
NodeList nl = root.getElementsByTagName("Scan");
|
||||
if (nl.getLength() < 1) return resultsFound;
|
||||
ElementImpl scan_elem = (ElementImpl)nl.item(0);
|
||||
Element scan_elem = (Element)nl.item(0);
|
||||
nl = scan_elem.getElementsByTagName("Directory");
|
||||
for (int i=0; i < nl.getLength(); i++) {
|
||||
ElementImpl dir_elem = (ElementImpl)nl.item(i);
|
||||
Element dir_elem = (Element)nl.item(i);
|
||||
File directory = new File(dir_elem.getAttribute("location"));
|
||||
boolean recurse = dir_elem.getAttribute("recurse_directories").equalsIgnoreCase("true");
|
||||
NodeList rules_list = dir_elem.getElementsByTagName("Rules");
|
||||
if (rules_list.getLength() < 1) continue;
|
||||
ElementImpl rules_elem = (ElementImpl)rules_list.item(0);
|
||||
Element rules_elem = (Element)rules_list.item(0);
|
||||
NodeList frules_list = rules_elem.getElementsByTagName("ApplyFileRule");
|
||||
// For each file rule
|
||||
for (int j=0; j < frules_list.getLength(); j++) {
|
||||
ElementImpl frule_elem = (ElementImpl)frules_list.item(j);
|
||||
Element frule_elem = (Element)frules_list.item(j);
|
||||
FileRule frule = (FileRule)fileRules.get(frule_elem.getAttribute("name"));
|
||||
if (frule == null) continue;
|
||||
NodeList prules_list = frule_elem.getElementsByTagName("ApplyParseRule");
|
||||
Vector prules_v = new Vector();
|
||||
// For each parse rule
|
||||
for (int k=0; k < prules_list.getLength(); k++) {
|
||||
ElementImpl prule_elem = (ElementImpl)prules_list.item(k);
|
||||
Element prule_elem = (Element)prules_list.item(k);
|
||||
ParseRule prule = (ParseRule)parseRules.get(prule_elem.getAttribute("name"));
|
||||
if (prule == null) continue;
|
||||
prules_v.addElement(prule);
|
||||
@ -192,15 +191,15 @@ public class RBReporterScanner {
|
||||
}
|
||||
}
|
||||
|
||||
private Hashtable getFileRules(ElementImpl root) {
|
||||
private Hashtable getFileRules(Element root) {
|
||||
Hashtable result = new Hashtable();
|
||||
NodeList frules_list = root.getElementsByTagName("FileRules");
|
||||
ElementImpl frules_elem = null;
|
||||
if (frules_list.getLength() > 0) frules_elem = (ElementImpl)frules_list.item(0);
|
||||
Element frules_elem = null;
|
||||
if (frules_list.getLength() > 0) frules_elem = (Element)frules_list.item(0);
|
||||
if (frules_elem == null) return result;
|
||||
frules_list = frules_elem.getElementsByTagName("FileRule");
|
||||
for (int i=0; i < frules_list.getLength(); i++) {
|
||||
ElementImpl elem = (ElementImpl)frules_list.item(i);
|
||||
Element elem = (Element)frules_list.item(i);
|
||||
FileRule frule = new FileRule(elem.getAttribute("name"), elem.getAttribute("starts_with"),
|
||||
elem.getAttribute("ends_with"), elem.getAttribute("contains"));
|
||||
result.put(elem.getAttribute("name"), frule);
|
||||
@ -208,15 +207,17 @@ public class RBReporterScanner {
|
||||
return result;
|
||||
}
|
||||
|
||||
private Hashtable getParseRules(ElementImpl root) {
|
||||
private Hashtable getParseRules(Element root) {
|
||||
Hashtable result = new Hashtable();
|
||||
NodeList prules_list = root.getElementsByTagName("ParseRules");
|
||||
ElementImpl prules_elem = null;
|
||||
if (prules_list.getLength() > 0) prules_elem = (ElementImpl)prules_list.item(0);
|
||||
if (prules_elem == null) return result;
|
||||
Element prules_elem = null;
|
||||
if (prules_list.getLength() > 0)
|
||||
prules_elem = (Element)prules_list.item(0);
|
||||
if (prules_elem == null)
|
||||
return result;
|
||||
prules_list = prules_elem.getElementsByTagName("ParseRule");
|
||||
for (int i=0; i < prules_list.getLength(); i++) {
|
||||
ElementImpl elem = (ElementImpl)prules_list.item(i);
|
||||
Element elem = (Element)prules_list.item(i);
|
||||
ParseRule prule = new ParseRule(elem.getAttribute("name"), elem.getAttribute("follows"),
|
||||
elem.getAttribute("precedes"));
|
||||
result.put(elem.getAttribute("name"), prule);
|
||||
|
@ -9,8 +9,7 @@ package com.ibm.rbm;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
import org.apache.xerces.parsers.*;
|
||||
import org.apache.xerces.dom.*;
|
||||
import org.apache.xerces.parsers.DOMParser;
|
||||
import org.w3c.dom.*;
|
||||
import org.xml.sax.*;
|
||||
|
||||
@ -28,7 +27,7 @@ import com.ibm.rbm.gui.RBManagerGUI;
|
||||
*/
|
||||
public class RBTMXImporter extends RBImporter {
|
||||
|
||||
DocumentImpl tmx_xml = null;
|
||||
Document tmx_xml = null;
|
||||
|
||||
/**
|
||||
* Basic constructor for the TMX importer from the parent RBManager data and a Dialog title.
|
||||
@ -61,7 +60,7 @@ public class RBTMXImporter extends RBImporter {
|
||||
//is.setEncoding("UTF-8");
|
||||
DOMParser parser = new DOMParser();
|
||||
parser.parse(is);
|
||||
tmx_xml = (DocumentImpl)parser.getDocument();
|
||||
tmx_xml = parser.getDocument();
|
||||
} catch (Exception e) {
|
||||
RBManagerGUI.debugMsg(e.getMessage());
|
||||
e.printStackTrace(System.err);
|
||||
@ -72,8 +71,9 @@ public class RBTMXImporter extends RBImporter {
|
||||
}
|
||||
|
||||
private void importDoc() {
|
||||
if (tmx_xml == null) return;
|
||||
ElementImpl root = (ElementImpl)tmx_xml.getDocumentElement();
|
||||
if (tmx_xml == null)
|
||||
return;
|
||||
Element root = tmx_xml.getDocumentElement();
|
||||
Node node = root.getFirstChild();
|
||||
while (node != null && (node.getNodeType() != Node.ELEMENT_NODE || !(node.getNodeName().equalsIgnoreCase("header")))) {
|
||||
node = node.getNextSibling();
|
||||
@ -83,27 +83,29 @@ public class RBTMXImporter extends RBImporter {
|
||||
while (node != null && (node.getNodeType() != Node.ELEMENT_NODE || !(node.getNodeName().equalsIgnoreCase("body")))) {
|
||||
node = node.getNextSibling();
|
||||
}
|
||||
ElementImpl body = (ElementImpl)node;
|
||||
Element body = (Element)node;
|
||||
resolveEncodings(getEncodingsVector(body));
|
||||
|
||||
// Now do the actual import resource by resource
|
||||
NodeList tu_list = body.getElementsByTagName("tu");
|
||||
for (int i=0; i < tu_list.getLength(); i++) {
|
||||
ElementImpl tu_elem = (ElementImpl)tu_list.item(i);
|
||||
Element tu_elem = (Element)tu_list.item(i);
|
||||
// Get the key value
|
||||
String name = tu_elem.getAttribute("tuid");
|
||||
if (name == null || name.length() < 1) continue;
|
||||
if (name == null || name.length() < 1)
|
||||
continue;
|
||||
// Get the group if it exists
|
||||
String group = null;
|
||||
NodeList prop_list = tu_elem.getElementsByTagName("prop");
|
||||
for (int j=0; j < prop_list.getLength(); j++) {
|
||||
ElementImpl prop_elem = (ElementImpl)prop_list.item(j);
|
||||
Element prop_elem = (Element)prop_list.item(j);
|
||||
String type = prop_elem.getAttribute("type");
|
||||
if (type != null && type.equals("x-Group")) {
|
||||
prop_elem.normalize();
|
||||
NodeList text_list = prop_elem.getChildNodes();
|
||||
if (text_list.getLength() < 1) continue;
|
||||
TextImpl text_elem = (TextImpl)text_list.item(0);
|
||||
if (text_list.getLength() < 1)
|
||||
continue;
|
||||
Text text_elem = (Text)text_list.item(0);
|
||||
group = text_elem.getNodeValue();
|
||||
}
|
||||
}
|
||||
@ -112,63 +114,76 @@ public class RBTMXImporter extends RBImporter {
|
||||
NodeList tuv_list = tu_elem.getElementsByTagName("tuv");
|
||||
// For each tuv element
|
||||
for (int j=0; j < tuv_list.getLength(); j++) {
|
||||
ElementImpl tuv_elem = (ElementImpl)tuv_list.item(j);
|
||||
Element tuv_elem = (Element)tuv_list.item(j);
|
||||
String encoding = tuv_elem.getAttribute("lang");
|
||||
// Get the current encoding
|
||||
if (encoding == null) continue;
|
||||
char array[] = encoding.toCharArray();
|
||||
for (int k=0; k < array.length; k++) {
|
||||
if (array[k] == '-') array[k] = '_';
|
||||
if (array[k] == '-')
|
||||
array[k] = '_';
|
||||
}
|
||||
encoding = String.valueOf(array);
|
||||
// Get the translation value
|
||||
NodeList seg_list = tuv_elem.getElementsByTagName("seg");
|
||||
if (seg_list.getLength() < 1) continue;
|
||||
ElementImpl seg_elem = (ElementImpl)seg_list.item(0);
|
||||
if (seg_list.getLength() < 1)
|
||||
continue;
|
||||
Element seg_elem = (Element)seg_list.item(0);
|
||||
seg_elem.normalize();
|
||||
NodeList text_list = seg_elem.getChildNodes();
|
||||
if (text_list.getLength() < 1) continue;
|
||||
TextImpl text_elem = (TextImpl)text_list.item(0);
|
||||
if (text_list.getLength() < 1)
|
||||
continue;
|
||||
Text text_elem = (Text)text_list.item(0);
|
||||
String value = text_elem.getNodeValue();
|
||||
if (value == null || value.length() < 1) continue;
|
||||
if (value == null || value.length() < 1)
|
||||
continue;
|
||||
// Create the bundle item
|
||||
BundleItem item = new BundleItem(null, name, value);
|
||||
// Get creation, modification values
|
||||
item.setCreatedDate(tuv_elem.getAttribute("creationdate"));
|
||||
item.setModifiedDate(tuv_elem.getAttribute("changedate"));
|
||||
if (tuv_elem.getAttribute("changeid") != null) item.setModifier(tuv_elem.getAttribute("changeid"));
|
||||
if (tuv_elem.getAttribute("creationid") != null) item.setCreator(tuv_elem.getAttribute("creationid"));
|
||||
if (tuv_elem.getAttribute("changeid") != null)
|
||||
item.setModifier(tuv_elem.getAttribute("changeid"));
|
||||
if (tuv_elem.getAttribute("creationid") != null)
|
||||
item.setCreator(tuv_elem.getAttribute("creationid"));
|
||||
// Get properties specified
|
||||
prop_list = tuv_elem.getElementsByTagName("prop");
|
||||
Hashtable lookups = null;
|
||||
for (int k=0; k < prop_list.getLength(); k++) {
|
||||
ElementImpl prop_elem = (ElementImpl)prop_list.item(k);
|
||||
Element prop_elem = (Element)prop_list.item(k);
|
||||
String type = prop_elem.getAttribute("type");
|
||||
if (type != null && type.equals("x-Comment")) {
|
||||
// Get the comment
|
||||
prop_elem.normalize();
|
||||
text_list = prop_elem.getChildNodes();
|
||||
if (text_list.getLength() < 1) continue;
|
||||
text_elem = (TextImpl)text_list.item(0);
|
||||
text_elem = (Text)text_list.item(0);
|
||||
String comment = text_elem.getNodeValue();
|
||||
if (comment != null && comment.length() > 0) item.setComment(comment);
|
||||
if (comment != null && comment.length() > 0)
|
||||
item.setComment(comment);
|
||||
} else if (type != null && type.equals("x-Translated")) {
|
||||
// Get the translated flag value
|
||||
prop_elem.normalize();
|
||||
text_list = prop_elem.getChildNodes();
|
||||
if (text_list.getLength() < 1) continue;
|
||||
text_elem = (TextImpl)text_list.item(0);
|
||||
text_elem = (Text)text_list.item(0);
|
||||
if (text_elem.getNodeValue() != null) {
|
||||
if (text_elem.getNodeValue().equalsIgnoreCase("true")) item.setTranslated(true);
|
||||
else if (text_elem.getNodeValue().equalsIgnoreCase("false")) item.setTranslated(false);
|
||||
else item.setTranslated(getDefaultTranslated());
|
||||
} else item.setTranslated(getDefaultTranslated());
|
||||
if (text_elem.getNodeValue().equalsIgnoreCase("true"))
|
||||
item.setTranslated(true);
|
||||
else if (text_elem.getNodeValue().equalsIgnoreCase("false"))
|
||||
item.setTranslated(false);
|
||||
else
|
||||
item.setTranslated(getDefaultTranslated());
|
||||
}
|
||||
else
|
||||
item.setTranslated(getDefaultTranslated());
|
||||
} else if (type != null && type.equals("x-Lookup")) {
|
||||
// Get a lookup value
|
||||
prop_elem.normalize();
|
||||
text_list = prop_elem.getChildNodes();
|
||||
if (text_list.getLength() < 1) continue;
|
||||
text_elem = (TextImpl)text_list.item(0);
|
||||
if (text_list.getLength() < 1)
|
||||
continue;
|
||||
text_elem = (Text)text_list.item(0);
|
||||
if (text_elem.getNodeValue() != null) {
|
||||
String text = text_elem.getNodeValue();
|
||||
if (text.indexOf("=") > 0) {
|
||||
@ -179,7 +194,9 @@ public class RBTMXImporter extends RBImporter {
|
||||
lookups.put(lkey, lvalue);
|
||||
} catch (Exception ex) { /* String out of bounds - Ignore and go on */ }
|
||||
}
|
||||
} else item.setTranslated(getDefaultTranslated());
|
||||
}
|
||||
else
|
||||
item.setTranslated(getDefaultTranslated());
|
||||
}
|
||||
}
|
||||
if (lookups != null) item.setLookups(lookups);
|
||||
@ -188,29 +205,35 @@ public class RBTMXImporter extends RBImporter {
|
||||
}
|
||||
}
|
||||
|
||||
private Vector getEncodingsVector(ElementImpl body) {
|
||||
private Vector getEncodingsVector(Element body) {
|
||||
String empty = "";
|
||||
if (body == null) return null;
|
||||
if (body == null)
|
||||
return null;
|
||||
Hashtable hash = new Hashtable();
|
||||
NodeList tu_list = body.getElementsByTagName("tu");
|
||||
for (int i=0; i < tu_list.getLength(); i++) {
|
||||
ElementImpl tu_elem = (ElementImpl)tu_list.item(i);
|
||||
Element tu_elem = (Element)tu_list.item(i);
|
||||
NodeList tuv_list = tu_elem.getElementsByTagName("tuv");
|
||||
for (int j=0; j < tuv_list.getLength(); j++) {
|
||||
ElementImpl tuv_elem = (ElementImpl)tuv_list.item(j);
|
||||
Element tuv_elem = (Element)tuv_list.item(j);
|
||||
String encoding = tuv_elem.getAttribute("lang");
|
||||
if (encoding == null) continue;
|
||||
if (encoding == null)
|
||||
continue;
|
||||
char array[] = encoding.toCharArray();
|
||||
for (int k=0; k < array.length; k++) {
|
||||
if (array[k] == '-') array[k] = '_';
|
||||
if (array[k] == '-')
|
||||
array[k] = '_';
|
||||
}
|
||||
encoding = String.valueOf(array);
|
||||
if (!(hash.containsKey(encoding))) hash.put(encoding,empty);
|
||||
if (!(hash.containsKey(encoding)))
|
||||
hash.put(encoding,empty);
|
||||
}
|
||||
}
|
||||
Vector v = new Vector();
|
||||
Enumeration enum = hash.keys();
|
||||
while (enum.hasMoreElements()) { v.addElement(enum.nextElement()); }
|
||||
while (enum.hasMoreElements()) {
|
||||
v.addElement(enum.nextElement());
|
||||
}
|
||||
return v;
|
||||
}
|
||||
}
|
@ -13,9 +13,7 @@ import com.ibm.rbm.gui.RBManagerGUI;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import org.apache.xerces.dom.DocumentImpl;
|
||||
import org.apache.xerces.dom.ElementImpl;
|
||||
import org.apache.xerces.dom.TextImpl;
|
||||
import org.apache.xerces.parsers.DOMParser;
|
||||
import org.w3c.dom.*;
|
||||
import org.xml.sax.*;
|
||||
@ -30,7 +28,7 @@ import org.xml.sax.*;
|
||||
*/
|
||||
public class RBxliffImporter extends RBImporter {
|
||||
|
||||
DocumentImpl xlf_xml = null;
|
||||
Document xlf_xml = null;
|
||||
|
||||
/**
|
||||
* Basic constructor for the XLIFF importer from the parent RBManager data and a Dialog title.
|
||||
@ -62,7 +60,7 @@ public class RBxliffImporter extends RBImporter {
|
||||
//is.setEncoding("UTF-8");
|
||||
DOMParser parser = new DOMParser();
|
||||
parser.parse(is);
|
||||
xlf_xml = (DocumentImpl)parser.getDocument();
|
||||
xlf_xml = parser.getDocument();
|
||||
fis.close();
|
||||
} catch (SAXException e) {
|
||||
RBManagerGUI.debugMsg(e.getMessage());
|
||||
@ -81,7 +79,7 @@ public class RBxliffImporter extends RBImporter {
|
||||
return;
|
||||
String language = "";
|
||||
String bundleNote = null;
|
||||
ElementImpl root = (ElementImpl)xlf_xml.getDocumentElement();
|
||||
Element root = xlf_xml.getDocumentElement();
|
||||
Node fileNode = root.getFirstChild();
|
||||
Node header = null;
|
||||
Node node = null;
|
||||
@ -97,9 +95,9 @@ public class RBxliffImporter extends RBImporter {
|
||||
}
|
||||
if (header.getNodeName().equalsIgnoreCase("header")) {
|
||||
// Get the notes if from the header if they exist.
|
||||
NodeList header_note_list = ((ElementImpl)header).getElementsByTagName("note");
|
||||
NodeList header_note_list = ((Element)header).getElementsByTagName("note");
|
||||
if (header_note_list.getLength() > 0) {
|
||||
TextImpl text_elem = (TextImpl)header_note_list.item(0).getChildNodes().item(0);
|
||||
Text text_elem = (Text)header_note_list.item(0).getChildNodes().item(0);
|
||||
if (text_elem != null) {
|
||||
String value = text_elem.getNodeValue();
|
||||
if (value != null && value.length() > 0) {
|
||||
@ -113,11 +111,11 @@ public class RBxliffImporter extends RBImporter {
|
||||
node = node.getNextSibling();
|
||||
}
|
||||
|
||||
ElementImpl body = (ElementImpl)node;
|
||||
Element body = (Element)node;
|
||||
//resolveEncodings(getEncodingsVector(body));
|
||||
|
||||
String sourceLocale = ((ElementImpl)fileNode).getAttribute("source-language");
|
||||
String targetLocale = ((ElementImpl)fileNode).getAttribute("target-language");
|
||||
String sourceLocale = ((Element)fileNode).getAttribute("source-language");
|
||||
String targetLocale = ((Element)fileNode).getAttribute("target-language");
|
||||
if (!sourceLocale.equals("")) {
|
||||
language = sourceLocale;
|
||||
}
|
||||
@ -145,7 +143,7 @@ public class RBxliffImporter extends RBImporter {
|
||||
}
|
||||
if (elementCount == 1 && groupCount == 1) {
|
||||
// ICU style group where the top group is just the locale.
|
||||
ElementImpl localeNode = (ElementImpl)last_group_node;
|
||||
Element localeNode = (Element)last_group_node;
|
||||
tu_list = last_group_node.getChildNodes();
|
||||
String rootGroupName = localeNode.getAttribute("id");
|
||||
if (rootGroupName != null && rootGroupName.equals("root")) {
|
||||
@ -169,10 +167,10 @@ public class RBxliffImporter extends RBImporter {
|
||||
rbm.getBundle(language).comment = bundleNote;
|
||||
|
||||
for (int i=0; i < tu_list.getLength(); i++) {
|
||||
if (!(tu_list.item(i) instanceof ElementImpl)) {
|
||||
if (!(tu_list.item(i) instanceof Element)) {
|
||||
continue;
|
||||
}
|
||||
ElementImpl tu_elem = (ElementImpl)tu_list.item(i);
|
||||
Element tu_elem = (Element)tu_list.item(i);
|
||||
|
||||
// Get the key value
|
||||
String name = tu_elem.getAttribute("id");
|
||||
@ -185,7 +183,7 @@ public class RBxliffImporter extends RBImporter {
|
||||
String groupComment = "";
|
||||
NodeList notes_list = tu_elem.getElementsByTagName("note");
|
||||
if (notes_list.getLength() > 0) {
|
||||
TextImpl text_elem = (TextImpl)notes_list.item(0).getChildNodes().item(0);
|
||||
Text text_elem = (Text)notes_list.item(0).getChildNodes().item(0);
|
||||
String value = text_elem.getNodeValue();
|
||||
if (value != null && value.length() > 0) {
|
||||
groupComment = value;
|
||||
@ -203,14 +201,14 @@ public class RBxliffImporter extends RBImporter {
|
||||
NodeList trans_unit_list = tu_elem.getElementsByTagName("trans-unit");
|
||||
// For each trans-unit element
|
||||
for (int j=0; j < trans_unit_list.getLength(); j++) {
|
||||
parseTranslationUnit(language, group, (ElementImpl)trans_unit_list.item(j));
|
||||
parseTranslationUnit(language, group, (Element)trans_unit_list.item(j));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void parseTranslationUnit(String language, String group, ElementImpl trans_unit_elem) {
|
||||
private void parseTranslationUnit(String language, String group, Element trans_unit_elem) {
|
||||
// Get the translation value
|
||||
ElementImpl target_elem = (ElementImpl)trans_unit_elem.getElementsByTagName("target").item(0);
|
||||
ElementImpl target_elem = (ElementImpl)trans_unit_elem.getElementsByTagName("target").item(0);
|
||||
if (target_elem == null) {
|
||||
// This is a template, or a skeleton
|
||||
target_elem = (ElementImpl)trans_unit_elem.getElementsByTagName("source").item(0);
|
||||
@ -221,7 +219,7 @@ public class RBxliffImporter extends RBImporter {
|
||||
NodeList text_list = target_elem.getChildNodes();
|
||||
if (text_list.getLength() < 1)
|
||||
return;
|
||||
TextImpl text_elem = (TextImpl)text_list.item(0);
|
||||
Text text_elem = (Text)text_list.item(0);
|
||||
String transValue = text_elem.getNodeValue();
|
||||
if (transValue == null || transValue.length() < 1)
|
||||
return;
|
||||
@ -247,11 +245,11 @@ public class RBxliffImporter extends RBImporter {
|
||||
item.setModifiedDate(date);
|
||||
}
|
||||
|
||||
ElementImpl note_elem = (ElementImpl)trans_unit_elem.getElementsByTagName("note").item(0);
|
||||
Element note_elem = (Element)trans_unit_elem.getElementsByTagName("note").item(0);
|
||||
if (note_elem != null) {
|
||||
NodeList note_list = note_elem.getChildNodes();
|
||||
if (note_list.getLength() > 0) {
|
||||
TextImpl note_text_elem = (TextImpl)note_list.item(0);
|
||||
Text note_text_elem = (Text)note_list.item(0);
|
||||
String comment = note_text_elem.getNodeValue();
|
||||
if (comment != null && comment.length() > 0) {
|
||||
item.setComment(comment);
|
||||
@ -259,13 +257,13 @@ public class RBxliffImporter extends RBImporter {
|
||||
}
|
||||
}
|
||||
|
||||
ElementImpl prop_group_elem = (ElementImpl)trans_unit_elem.getElementsByTagName("prop-group").item(0);
|
||||
Element prop_group_elem = (Element)trans_unit_elem.getElementsByTagName("prop-group").item(0);
|
||||
if (prop_group_elem != null) {
|
||||
NodeList prop_list = prop_group_elem.getChildNodes();
|
||||
int propertyLen = prop_list.getLength();
|
||||
for (int prop = 0; prop < propertyLen; prop++) {
|
||||
if (prop_list.item(prop) instanceof ElementImpl) {
|
||||
ElementImpl property_elem = (ElementImpl)prop_list.item(prop);
|
||||
if (prop_list.item(prop) instanceof Element) {
|
||||
Element property_elem = (Element)prop_list.item(prop);
|
||||
String propertyType = property_elem.getAttribute("prop-type");
|
||||
if (propertyType != null) {
|
||||
String value = property_elem.getChildNodes().item(0).getNodeValue();
|
||||
|
Loading…
Reference in New Issue
Block a user