ICU-3501 Fix various importation issues
X-SVN-Rev: 15978
This commit is contained in:
parent
48276604e2
commit
ba5c47a577
@ -85,7 +85,8 @@ public class Bundle {
|
||||
public boolean equals(Object o) { return false; }
|
||||
|
||||
public int compare(Object o1, Object o2) {
|
||||
if (!(o1 instanceof BundleGroup) || !(o2 instanceof BundleGroup)) return 0;
|
||||
if (!(o1 instanceof BundleGroup) || !(o2 instanceof BundleGroup))
|
||||
return 0;
|
||||
BundleGroup g1 = (BundleGroup)o1;
|
||||
BundleGroup g2 = (BundleGroup)o2;
|
||||
return g1.getName().compareTo(g2.getName());
|
||||
@ -141,10 +142,12 @@ public class Bundle {
|
||||
*/
|
||||
|
||||
public String getVariantEncoding() {
|
||||
if (encoding == null || encoding.indexOf("_") < 0) return null;
|
||||
if (encoding == null || encoding.indexOf("_") < 0)
|
||||
return null;
|
||||
// Strip off the language
|
||||
String workStr = encoding.substring(encoding.indexOf("_")+1,encoding.length());
|
||||
if (workStr == null || workStr.length() < 1 || workStr.indexOf("_") < 0) return null;
|
||||
if (workStr == null || workStr.length() < 1 || workStr.indexOf("_") < 0)
|
||||
return null;
|
||||
// Strip off the country
|
||||
workStr = workStr.substring(encoding.indexOf("_")+1, workStr.length());
|
||||
return workStr.trim();
|
||||
@ -157,7 +160,8 @@ public class Bundle {
|
||||
public Vector getUntranslatedItemsAsVector() {
|
||||
Iterator iter = untranslatedItems.iterator();
|
||||
Vector v = new Vector();
|
||||
while (iter.hasNext()) v.addElement(iter.next());
|
||||
while (iter.hasNext())
|
||||
v.addElement(iter.next());
|
||||
return v;
|
||||
}
|
||||
|
||||
@ -205,7 +209,8 @@ public class Bundle {
|
||||
Iterator iter = groups.iterator();
|
||||
while (iter.hasNext()) {
|
||||
BundleGroup group = (BundleGroup)iter.next();
|
||||
if (group.getName().equals(groupName)) return true;
|
||||
if (group.getName().equals(groupName))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -274,18 +279,13 @@ public class Bundle {
|
||||
*/
|
||||
|
||||
public void addUntranslatedItem(BundleItem item) {
|
||||
if (item.getParentGroup().getParentBundle() != this) return;
|
||||
// First check to see if it is all ready there
|
||||
boolean found = false;
|
||||
Iterator iter = untranslatedItems.iterator();
|
||||
while (iter.hasNext()) {
|
||||
BundleItem oldItem = (BundleItem)iter.next();
|
||||
if (oldItem == item) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
if (item.getParentGroup().getParentBundle() != this)
|
||||
return;
|
||||
// Remove it if it exists.
|
||||
if (untranslatedItems.contains(item)) {
|
||||
untranslatedItems.remove(item);
|
||||
}
|
||||
if (!found) untranslatedItems.add(item);
|
||||
untranslatedItems.add(item);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -301,9 +301,11 @@ public class Bundle {
|
||||
*/
|
||||
|
||||
public BundleItem getUntranslatedItem(int index) {
|
||||
if (index >= untranslatedItems.size()) return null;
|
||||
if (index >= untranslatedItems.size())
|
||||
return null;
|
||||
Iterator iter = untranslatedItems.iterator();
|
||||
for (int i=0; i < index; i++) iter.next();
|
||||
for (int i=0; i < index; i++)
|
||||
iter.next();
|
||||
return (BundleItem)iter.next();
|
||||
}
|
||||
|
||||
@ -334,9 +336,11 @@ public class Bundle {
|
||||
*/
|
||||
|
||||
public BundleGroup getBundleGroup(int index) {
|
||||
if (index >= getGroupCount()) return null;
|
||||
if (index >= getGroupCount())
|
||||
return null;
|
||||
Iterator iter = groups.iterator();
|
||||
for (int i=0; i < index; i++) iter.next();
|
||||
for (int i=0; i < index; i++)
|
||||
iter.next();
|
||||
return (BundleGroup)iter.next();
|
||||
}
|
||||
|
||||
@ -349,7 +353,8 @@ public class Bundle {
|
||||
Iterator iter = groups.iterator();
|
||||
while(iter.hasNext()) {
|
||||
BundleGroup group = (BundleGroup)iter.next();
|
||||
if (group.getName().equals(groupName)) return group;
|
||||
if (group.getName().equals(groupName))
|
||||
return group;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -390,10 +395,12 @@ public class Bundle {
|
||||
if (allItems.containsKey(item.getKey())) {
|
||||
duplicates.addElement(item);
|
||||
} else {
|
||||
if (!(groups.contains(item.getParentGroup()))) addBundleGroup(item.getParentGroup());
|
||||
if (!(groups.contains(item.getParentGroup())))
|
||||
addBundleGroup(item.getParentGroup());
|
||||
item.getParentGroup().addBundleItem(item);
|
||||
allItems.put(item.getKey(), item);
|
||||
if (!item.isTranslated()) addUntranslatedItem(item);
|
||||
if (!item.isTranslated())
|
||||
addUntranslatedItem(item);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -162,7 +162,8 @@ public class RBImporter extends JDialog {
|
||||
}
|
||||
}
|
||||
// If all group identification efforts fail, we fail
|
||||
if (group == null) return;
|
||||
if (group == null)
|
||||
return;
|
||||
item.setParentGroup(group);
|
||||
// Check for and resolve conflicts
|
||||
if (bundle.allItems.containsKey(item.getKey())) {
|
||||
@ -179,13 +180,15 @@ public class RBImporter extends JDialog {
|
||||
*/
|
||||
|
||||
protected void resolveResource(Bundle bundle, BundleItem item) {
|
||||
if (this.getResourceConflictOption() == RESOURCE_OPTION_IGNORE) return;
|
||||
if (this.getResourceConflictOption() == RESOURCE_OPTION_IGNORE)
|
||||
return;
|
||||
else if (this.getResourceConflictOption() == RESOURCE_OPTION_OVERWRITE) {
|
||||
bundle.removeItem(item.getKey());
|
||||
bundle.addBundleItem(item);
|
||||
} else if (this.getResourceConflictOption() == RESOURCE_OPTION_PROMPT) {
|
||||
BundleItem original = (BundleItem)bundle.allItems.get(item.getKey());
|
||||
if (original == null) return;
|
||||
if (original == null)
|
||||
return;
|
||||
String trans = original.getTranslation();
|
||||
String options[] = { Resources.getTranslation("import_resource_conflict_overwrite"),
|
||||
Resources.getTranslation("import_resource_conflict_ignore")};
|
||||
@ -195,11 +198,13 @@ public class RBImporter extends JDialog {
|
||||
"\n" + Resources.getTranslation("import_resource_conflict_choose_target", trans),
|
||||
Resources.getTranslation("import_file_conflicts"), JOptionPane.QUESTION_MESSAGE,
|
||||
null, options, options[0]);
|
||||
if (result == null) return;
|
||||
if (result == null)
|
||||
return;
|
||||
if (result.equals(Resources.getTranslation("import_resource_conflict_overwrite"))) {
|
||||
bundle.removeItem(item.getKey());
|
||||
bundle.addBundleItem(item);
|
||||
} else if (result.equals(Resources.getTranslation("import_resource_conflict_ignore"))) return;
|
||||
} else if (result.equals(Resources.getTranslation("import_resource_conflict_ignore")))
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@ -362,10 +367,13 @@ public class RBImporter extends JDialog {
|
||||
public void actionPerformed(ActionEvent ev) {
|
||||
try {
|
||||
beginImport();
|
||||
gui.updateProjectTree();
|
||||
gui.updateDisplayTree();
|
||||
thisWindowClosing();
|
||||
} catch (IOException ioe) {
|
||||
ioe.printStackTrace(System.err);
|
||||
JOptionPane.showMessageDialog(null,
|
||||
Resources.getTranslation("error") + "\n" + Resources.getTranslation("error"),
|
||||
Resources.getTranslation("error") + "\n" + ioe.getLocalizedMessage(),
|
||||
Resources.getTranslation("error"), JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
@ -378,7 +386,18 @@ public class RBImporter extends JDialog {
|
||||
});
|
||||
|
||||
// Setup combo box
|
||||
groupComboBox = new JComboBox(((Bundle)rbm.getBundles().elementAt(0)).getGroupsAsVector());
|
||||
Bundle baseBundle = ((Bundle)rbm.getBundles().elementAt(0));
|
||||
BundleGroup ungroupedGroup = baseBundle.getUngroupedGroup();
|
||||
groupComboBox = new JComboBox(baseBundle.getGroupsAsVector());
|
||||
int groupComboBoxCount = groupComboBox.getItemCount();
|
||||
for (int selectedIndex = 0; selectedIndex < groupComboBoxCount; selectedIndex++) {
|
||||
BundleGroup bundGroup = ((BundleGroup)groupComboBox.getItemAt(selectedIndex));
|
||||
if (bundGroup.getName().equals(ungroupedGroup.getName())) {
|
||||
// By default, use the ungrouped group. Probably named 'Ungrouped Items'.
|
||||
groupComboBox.setSelectedIndex(selectedIndex);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Arange components
|
||||
groupBox.add(Box.createHorizontalGlue());
|
||||
|
@ -22,8 +22,10 @@ import org.xml.sax.*;
|
||||
|
||||
/**
|
||||
* This imports XLIFF files into RBManager.
|
||||
* For more information see <a href="http://www.oasis-open.org/committees/xliff/documents/xliff-specification.htm">
|
||||
* http://www.oasis-open.org/committees/xliff/documents/xliff-specification.htm</a>
|
||||
*
|
||||
* @author grhoten
|
||||
* @author George Rhoten
|
||||
* @see com.ibm.rbm.RBManager
|
||||
*/
|
||||
public class RBxliffImporter extends RBImporter {
|
||||
@ -72,17 +74,33 @@ public class RBxliffImporter extends RBImporter {
|
||||
if (xlf_xml == null)
|
||||
return;
|
||||
String language = null;
|
||||
String bundleNote = null;
|
||||
ElementImpl root = (ElementImpl)xlf_xml.getDocumentElement();
|
||||
Node fileNode = root.getFirstChild();
|
||||
Node header = null;
|
||||
Node node = null;
|
||||
while (fileNode != null && !(fileNode.getNodeType() == Node.ELEMENT_NODE && fileNode.getNodeName().equalsIgnoreCase("file"))) {
|
||||
fileNode = fileNode.getNextSibling();
|
||||
}
|
||||
node = fileNode.getFirstChild();
|
||||
/* while (node != null && !(node.getNodeType() == Node.ELEMENT_NODE && node.getNodeName().equalsIgnoreCase("header"))) {
|
||||
node = node.getNextSibling();
|
||||
header = fileNode.getFirstChild();
|
||||
while (header != null
|
||||
&& !(header.getNodeType() == Node.ELEMENT_NODE
|
||||
&& (header.getNodeName().equalsIgnoreCase("header")
|
||||
|| header.getNodeName().equalsIgnoreCase("body")))) {
|
||||
header = header.getNextSibling();
|
||||
}
|
||||
node = root.getFirstChild();*/
|
||||
if (header.getNodeName().equalsIgnoreCase("header")) {
|
||||
// Get the notes if from the header if they exist.
|
||||
NodeList header_not_list = ((ElementImpl)header).getElementsByTagName("note");
|
||||
if (header_not_list.getLength() > 0) {
|
||||
TextImpl text_elem = (TextImpl)header_not_list.item(0);
|
||||
String value = text_elem.getNodeValue();
|
||||
if (value != null && value.length() > 0) {
|
||||
bundleNote = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
node = header.getNextSibling();
|
||||
while (node != null && !(node.getNodeType() == Node.ELEMENT_NODE && node.getNodeName().equalsIgnoreCase("body"))) {
|
||||
node = node.getNextSibling();
|
||||
}
|
||||
@ -155,6 +173,16 @@ public class RBxliffImporter extends RBImporter {
|
||||
String group = null;
|
||||
if (tu_elem.getNodeName().equalsIgnoreCase("group")) {
|
||||
group = name;
|
||||
String groupComment = "";
|
||||
NodeList notes_list = tu_elem.getElementsByTagName("note");
|
||||
if (notes_list.getLength() > 0) {
|
||||
TextImpl text_elem = (TextImpl)notes_list.item(0);
|
||||
String value = text_elem.getNodeValue();
|
||||
if (value != null && value.length() > 0) {
|
||||
groupComment = value;
|
||||
}
|
||||
}
|
||||
rbm.createGroup(group, groupComment);
|
||||
//NodeList group_list = tu_elem.getElementsByTagName("group");
|
||||
}
|
||||
|
||||
@ -255,7 +283,7 @@ public class RBxliffImporter extends RBImporter {
|
||||
// item.setLookups(lookups);
|
||||
importResource(item, language, group);
|
||||
}
|
||||
private Vector getEncodingsVector(ElementImpl body) {
|
||||
/* private Vector getEncodingsVector(ElementImpl body) {
|
||||
String empty = "";
|
||||
if (body == null) return null;
|
||||
Hashtable hash = new Hashtable();
|
||||
@ -279,5 +307,5 @@ public class RBxliffImporter extends RBImporter {
|
||||
Enumeration enum = hash.keys();
|
||||
while (enum.hasMoreElements()) { v.addElement(enum.nextElement()); }
|
||||
return v;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
@ -466,8 +466,10 @@ public class RBManagerGUI extends JFrame implements ActionListener, MouseListene
|
||||
String user = JOptionPane.showInputDialog(this,
|
||||
Resources.getTranslation("dialog_user_name"), Resources.getTranslation("dialog_title_user_name"),
|
||||
JOptionPane.QUESTION_MESSAGE);
|
||||
if (user != null && !(user.equals(""))) setUser(user);
|
||||
} else rbm.setUser(oldUser);
|
||||
if (user != null && !(user.equals("")))
|
||||
setUser(user);
|
||||
} else
|
||||
rbm.setUser(oldUser);
|
||||
} else if (ev.getActionCommand().equals(Resources.getTranslation("menu_file_save"))) {
|
||||
// Menu -> File -> Save Resource Bundle
|
||||
saveResources();
|
||||
@ -484,7 +486,8 @@ public class RBManagerGUI extends JFrame implements ActionListener, MouseListene
|
||||
RBJavaImporter importer = new RBJavaImporter(Resources.getTranslation("import_java_title"), rbm, this);
|
||||
} else if (ev.getActionCommand().equals(Resources.getTranslation("menu_file_import_TMX"))) {
|
||||
// Menu -> File -> Import -> TMX
|
||||
if (rbm == null || rbm.getBundles() == null) return;
|
||||
if (rbm == null || rbm.getBundles() == null)
|
||||
return;
|
||||
RBTMXImporter importer = new RBTMXImporter(Resources.getTranslation("import_TMX_title"), rbm, this);
|
||||
} else if (ev.getActionCommand().equals(Resources.getTranslation("menu_file_import_XLF"))) {
|
||||
// Menu -> File -> Import -> XLIFF
|
||||
@ -495,7 +498,8 @@ public class RBManagerGUI extends JFrame implements ActionListener, MouseListene
|
||||
// Menu -> File -> Export -> Properties
|
||||
RBPropertiesExporter exp = new RBPropertiesExporter();
|
||||
try {
|
||||
if (rbm != null && rbm.getBundles() != null) exp.export(rbm);
|
||||
if (rbm != null && rbm.getBundles() != null)
|
||||
exp.export(rbm);
|
||||
} catch (IOException ioe) {
|
||||
JOptionPane.showMessageDialog(this, Resources.getTranslation("error_export"),
|
||||
Resources.getTranslation("error"), JOptionPane.ERROR_MESSAGE);
|
||||
@ -706,7 +710,8 @@ public class RBManagerGUI extends JFrame implements ActionListener, MouseListene
|
||||
Bundle bundle = null;
|
||||
if (activeNode == null) return;
|
||||
Object o = activeNode.getUserObject();
|
||||
if (o == null) return;
|
||||
if (o == null)
|
||||
return;
|
||||
if (o instanceof String) {
|
||||
// A node that is not a root was selected.... I need to do something here
|
||||
String str = (String)o;
|
||||
@ -724,13 +729,16 @@ public class RBManagerGUI extends JFrame implements ActionListener, MouseListene
|
||||
jPanelSearch.removeElements();
|
||||
}
|
||||
//return;
|
||||
} else if (o instanceof Bundle) {
|
||||
}
|
||||
else if (o instanceof Bundle) {
|
||||
bundle = (Bundle) activeNode.getUserObject();
|
||||
jPanelStats.setBundle(bundle);
|
||||
jPanelUntrans.setBundle(bundle);
|
||||
jPanelGroups.setBundle(bundle);
|
||||
jPanelSearch.setBundle(bundle);
|
||||
} else RBManagerGUI.debugMsg(o.toString());
|
||||
}
|
||||
else
|
||||
RBManagerGUI.debugMsg(o.toString());
|
||||
|
||||
jPanelStats.updateComponents();
|
||||
jPanelUntrans.updateComponents();
|
||||
@ -740,7 +748,7 @@ public class RBManagerGUI extends JFrame implements ActionListener, MouseListene
|
||||
validateTree();
|
||||
}
|
||||
|
||||
protected void updateProjectTree() {
|
||||
public void updateProjectTree() {
|
||||
debugMsg("Updating Project Trees");
|
||||
|
||||
DefaultMutableTreeNode root = null;
|
||||
|
Loading…
Reference in New Issue
Block a user