ICU-1905 Initial version of the RBManager
X-SVN-Rev: 8644
This commit is contained in:
parent
1d7e598643
commit
416fc50421
460
tools/unicodetools/com/ibm/rbm/Bundle.java
Normal file
460
tools/unicodetools/com/ibm/rbm/Bundle.java
Normal file
@ -0,0 +1,460 @@
|
||||
/*
|
||||
*****************************************************************************
|
||||
* Copyright (C) 2000-2002, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*****************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/unicodetools/com/ibm/rbm/Bundle.java,v $
|
||||
* $Date: 2002/05/20 18:53:10 $
|
||||
* $Revision: 1.1 $
|
||||
*
|
||||
*****************************************************************************
|
||||
*/
|
||||
package com.ibm.rbm;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintStream;
|
||||
import java.io.Writer;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* A class representing the entire Bundle of Resources for a particular language, country, variant.
|
||||
*
|
||||
* @author Jared Jackson - Email: <a href="mailto:jjared@almaden.ibm.com">jjared@almaden.ibm.com</a>
|
||||
* @see com.ibm.rbm.RBManager
|
||||
*/
|
||||
public class Bundle {
|
||||
|
||||
// The following public class variables reflect the various properties that can be included as
|
||||
// meta-data in a resource bundle formatted by RBManager
|
||||
public String name;
|
||||
/**
|
||||
* The encoding of the bundle (e.g. 'en', 'en_US', 'de', etc.)
|
||||
*/
|
||||
public String encoding;
|
||||
/**
|
||||
* A descriptor of the language in the encoding (e.g. English, German, etc.)
|
||||
*/
|
||||
public String language;
|
||||
/**
|
||||
* A descriptor of the country in the encoding (e.g. US, Canada, Great Britain)
|
||||
*/
|
||||
public String country;
|
||||
/**
|
||||
* The descriptor of the variant in the encoding (e.g. Euro, Irish, etc.)
|
||||
*/
|
||||
public String variant;
|
||||
/**
|
||||
* A comment concerning the bundle
|
||||
*/
|
||||
public String comment;
|
||||
/**
|
||||
* The name of the person responsible for the managerment of this bundle
|
||||
*/
|
||||
public String manager;
|
||||
|
||||
private TreeSet groups; // A vector of groups of NLS items, the key is the group name
|
||||
|
||||
/**
|
||||
* A hashtable of all of the items in the bundle, hashed according to their
|
||||
* NLS key.
|
||||
*/
|
||||
|
||||
public Hashtable allItems; // A hashtable of all items in the file, the key is the NLS key
|
||||
|
||||
private TreeSet untranslatedItems; // A vector of all items which are untranslated
|
||||
|
||||
/**
|
||||
* A vector containing all of the items which are duplicates (based on the NLS keys)
|
||||
* of items previously declared in the bundle.
|
||||
*/
|
||||
|
||||
public Vector duplicates; // A vector of items which are duplicates (NLS Keys) of previous items
|
||||
|
||||
/**
|
||||
* Constructor for creating an empty bundle with a given encoding
|
||||
*/
|
||||
|
||||
public Bundle(String encoding) {
|
||||
this.encoding = encoding;
|
||||
language = null;
|
||||
country = null;
|
||||
variant = null;
|
||||
comment = null;
|
||||
manager = null;
|
||||
groups = new TreeSet(new Comparator() {
|
||||
public boolean equals(Object o) { return false; }
|
||||
|
||||
public int compare(Object o1, Object o2) {
|
||||
if (!(o1 instanceof BundleGroup) || !(o2 instanceof BundleGroup)) return 0;
|
||||
BundleGroup g1 = (BundleGroup)o1;
|
||||
BundleGroup g2 = (BundleGroup)o2;
|
||||
return g1.getName().compareTo(g2.getName());
|
||||
}
|
||||
});
|
||||
|
||||
untranslatedItems = new TreeSet(new Comparator() {
|
||||
public boolean equals(Object o) { return false; }
|
||||
|
||||
public int compare(Object o1, Object o2) {
|
||||
if (!(o1 instanceof BundleItem) || !(o2 instanceof BundleItem)) return 0;
|
||||
BundleItem i1 = (BundleItem)o1;
|
||||
BundleItem i2 = (BundleItem)o2;
|
||||
return i1.getKey().compareTo(i2.getKey());
|
||||
}
|
||||
});
|
||||
|
||||
duplicates = new Vector();
|
||||
allItems = new Hashtable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodings are of the form -> language_country_variant <- (e.g. en_us_southern)
|
||||
* This method returns the language encoding string, or null if it is not specified
|
||||
*/
|
||||
|
||||
public String getLanguageEncoding() {
|
||||
if (encoding == null) return null;
|
||||
if (encoding.indexOf("_") >= 0) return encoding.substring(0,encoding.indexOf("_"));
|
||||
else return encoding.trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodings are of the form -> language_country_variant <- (e.g. en_us_southern)
|
||||
* This method returns the country encoding string, or null if it is not specified
|
||||
*/
|
||||
|
||||
public String getCountryEncoding() {
|
||||
if (encoding == null || encoding.indexOf("_") < 0) return null;
|
||||
// Strip off the language
|
||||
String workStr = encoding.substring(encoding.indexOf("_")+1,encoding.length());
|
||||
if (workStr.indexOf("_") >= 0) return workStr.substring(0,encoding.indexOf("_"));
|
||||
else return workStr.trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodings are of the form -> language_country_variant <- (e.g. en_us_southern)
|
||||
* This method returns the variant encoding string, or null if it is not specified
|
||||
*/
|
||||
|
||||
public String getVariantEncoding() {
|
||||
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;
|
||||
// Strip off the country
|
||||
workStr = workStr.substring(encoding.indexOf("_")+1, workStr.length());
|
||||
return workStr.trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the UntranslatedItems as a vector. I should find where this happens and stop it.
|
||||
*/
|
||||
|
||||
public Vector getUntranslatedItemsAsVector() {
|
||||
Iterator iter = untranslatedItems.iterator();
|
||||
Vector v = new Vector();
|
||||
while (iter.hasNext()) v.addElement(iter.next());
|
||||
return v;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks all items in the untranslated items set. If they belong to a group whose name
|
||||
* matches the passed in name, then they are removed.
|
||||
*/
|
||||
|
||||
public void removeUntranslatedItemsByGroup(String groupName) {
|
||||
Iterator iter = untranslatedItems.iterator();
|
||||
try {
|
||||
while(iter.hasNext()) {
|
||||
BundleItem item = null;
|
||||
item = (BundleItem)iter.next();
|
||||
if (item != null && item.getParentGroup().getName().equals(groupName)) {
|
||||
removeUntranslatedItem(item.getKey());
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
RBManagerGUI.debugMsg(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see if an item of the given key name exists in the set of untranslated items. If
|
||||
* it does exist, then it is removed.
|
||||
*/
|
||||
|
||||
public void removeUntranslatedItem(String name) {
|
||||
Iterator iter = untranslatedItems.iterator();
|
||||
while (iter.hasNext()) {
|
||||
BundleItem item = (BundleItem)iter.next();
|
||||
if (item.getKey().equals(name)) {
|
||||
untranslatedItems.remove(item);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the boolean of wether a group of a given name exists in the bundle
|
||||
*/
|
||||
|
||||
public boolean hasGroup(String groupName) {
|
||||
Iterator iter = groups.iterator();
|
||||
while (iter.hasNext()) {
|
||||
BundleGroup group = (BundleGroup)iter.next();
|
||||
if (group.getName().equals(groupName)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a group of the given name and optionally associates a comment with
|
||||
* that group.
|
||||
*/
|
||||
|
||||
public void addBundleGroup(String groupName, String groupComment) {
|
||||
BundleGroup bg = new BundleGroup(this, groupName);
|
||||
bg.setComment(groupComment);
|
||||
addBundleGroup(bg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the group of the given name if it exists in the bundle
|
||||
*/
|
||||
|
||||
public void removeGroup(String groupName) {
|
||||
Iterator iter = groups.iterator();
|
||||
while (iter.hasNext()) {
|
||||
BundleGroup tempGroup = (BundleGroup)iter.next();
|
||||
if (tempGroup.getName().equals(groupName)) {
|
||||
groups.remove(tempGroup);
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Remove the items from the untanslated items
|
||||
removeUntranslatedItemsByGroup(groupName);
|
||||
|
||||
// Loop through all Items
|
||||
Enumeration enum = allItems.elements();
|
||||
while(enum.hasMoreElements()) {
|
||||
BundleItem item = (BundleItem)enum.nextElement();
|
||||
if (item.getParentGroup().getName().equals(groupName)) {
|
||||
allItems.remove(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a single resource item from the bundle
|
||||
*/
|
||||
|
||||
public void removeItem(String key) {
|
||||
Object o = allItems.get(key);
|
||||
if (o != null) {
|
||||
BundleItem item = (BundleItem)o;
|
||||
// Remove from allItems Hashtable
|
||||
allItems.remove(key);
|
||||
// Remove from item's group
|
||||
if (item.getParentGroup() != null) {
|
||||
BundleGroup group = item.getParentGroup();
|
||||
group.removeBundleItem(key);
|
||||
}
|
||||
// Remove from untranslatedItems Hashtable
|
||||
removeUntranslatedItem(key);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to add a BundleItem to the untranslatedItems. The addition will fail in two cases: One, if
|
||||
* the item does not all ready belong to this Bundle, and Two, if the item is all ready in the set of
|
||||
* untranslated items.
|
||||
*/
|
||||
|
||||
protected 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 (!found) untranslatedItems.add(item);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of items currently marked as untranslated
|
||||
*/
|
||||
|
||||
public int getUntranslatedItemsSize() {
|
||||
return untranslatedItems.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the indexth untranslated item
|
||||
*/
|
||||
|
||||
public BundleItem getUntranslatedItem(int index) {
|
||||
if (index >= untranslatedItems.size()) return null;
|
||||
Iterator iter = untranslatedItems.iterator();
|
||||
for (int i=0; i < index; i++) iter.next();
|
||||
return (BundleItem)iter.next();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the various resource bundle groups stored in a Vector collection.
|
||||
*/
|
||||
|
||||
public Vector getGroupsAsVector() {
|
||||
Vector v = new Vector();
|
||||
Iterator iter = groups.iterator();
|
||||
while (iter.hasNext()) {
|
||||
BundleGroup group = (BundleGroup)iter.next();
|
||||
v.addElement(group);
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of groups in the bundle.
|
||||
*/
|
||||
|
||||
public int getGroupCount() {
|
||||
return groups.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a bundle group given a certain index.
|
||||
*/
|
||||
|
||||
public BundleGroup getBundleGroup(int index) {
|
||||
if (index >= getGroupCount()) return null;
|
||||
Iterator iter = groups.iterator();
|
||||
for (int i=0; i < index; i++) iter.next();
|
||||
return (BundleGroup)iter.next();
|
||||
}
|
||||
|
||||
/**
|
||||
* Looks for a bundle group of a given name within a bundle and
|
||||
* returns it if found.
|
||||
*/
|
||||
|
||||
public BundleGroup getBundleGroup(String groupName) {
|
||||
Iterator iter = groups.iterator();
|
||||
while(iter.hasNext()) {
|
||||
BundleGroup group = (BundleGroup)iter.next();
|
||||
if (group.getName().equals(groupName)) return group;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Looks up and returns a bundle item stored in the bundle based on its
|
||||
* NLS lookup key.
|
||||
*/
|
||||
|
||||
public BundleItem getBundleItem(String key) {
|
||||
return (BundleItem)allItems.get(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* One group is created for all bundles called 'Ungrouped Items'. This is the bundle
|
||||
* group in which bundle items are placed that are not specifically grouped in the
|
||||
* resource bundle file. This method returns that bundle group.
|
||||
*/
|
||||
|
||||
public BundleGroup getUngroupedGroup() {
|
||||
return getBundleGroup("Ungrouped Items");
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a bundle group to the bundle
|
||||
*/
|
||||
|
||||
public void addBundleGroup(BundleGroup bg) {
|
||||
groups.add(bg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a bundle item to the bundle. This bundle item should all ready have its
|
||||
* bundle group assigned.
|
||||
*/
|
||||
|
||||
public void addBundleItem(BundleItem item) {
|
||||
if (allItems.containsKey(item.getKey())) {
|
||||
duplicates.addElement(item);
|
||||
} else {
|
||||
if (!(groups.contains(item.getParentGroup()))) addBundleGroup(item.getParentGroup());
|
||||
item.getParentGroup().addBundleItem(item);
|
||||
allItems.put(item.getKey(), item);
|
||||
if (!item.isTranslated()) addUntranslatedItem(item);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A method useful in debugging. The string returned displays the encoding
|
||||
* information about the bundle and wether or not it is the base class of
|
||||
* a resource bundle.
|
||||
*/
|
||||
|
||||
public String toString() {
|
||||
String retStr = new String();
|
||||
if (language != null && !language.equals("")) retStr = language;
|
||||
if (country != null && !country.equals("")) retStr += ", " + country;
|
||||
if (variant != null && !variant.equals("")) retStr += ", " + variant;
|
||||
|
||||
retStr += " (" + (encoding == null || encoding.equals("") ? "Base Class" : encoding) + ")";
|
||||
return retStr;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method produces a String which is suitable for inclusion in a .properties
|
||||
* style resource bundle. It attaches (in comments) the meta data that RBManager
|
||||
* reads to manage the resource bundle file. This portion of the output should
|
||||
* be included at the beginning of the resource bundle file.
|
||||
*/
|
||||
|
||||
public String toOutputString() {
|
||||
String retStr = "# @file " + name + "\n";
|
||||
if (encoding != null) retStr += "# @fileEncoding " + encoding + "\n";
|
||||
if (language != null) retStr += "# @fileLanguage " + language + "\n";
|
||||
if (country != null) retStr += "# @fileCountry " + country + "\n";
|
||||
if (variant != null) retStr += "# @fileVariant " + variant + "\n";
|
||||
if (manager != null) retStr += "# @fileManager " + manager + "\n";
|
||||
if (comment != null) retStr += "# @fileComment " + comment + "\n";
|
||||
return retStr;
|
||||
}
|
||||
|
||||
/**
|
||||
* A helping method for outputting the formatted contents of the bundle to a
|
||||
* print stream. The method first outputs the header information and then outputs
|
||||
* each bundle group's formatted data which includes each bundle item.
|
||||
*/
|
||||
|
||||
public void writeContents(PrintStream ps) {
|
||||
ps.println(this.toOutputString());
|
||||
Iterator iter = groups.iterator();
|
||||
while (iter.hasNext()) {
|
||||
((BundleGroup)iter.next()).writeContents(ps);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A helping method for outputting the formatted contents of the bundle to a
|
||||
* ouput Writer (such as a FileWriter). The method first outputs the header
|
||||
* information and then outputs each bundle group's formatted data which includes
|
||||
* each bundle item.
|
||||
*/
|
||||
|
||||
public void writeContents(Writer w) throws IOException {
|
||||
w.write(this.toOutputString() + "\n");
|
||||
Iterator iter = groups.iterator();
|
||||
while (iter.hasNext()) {
|
||||
((BundleGroup)iter.next()).writeContents(w);
|
||||
}
|
||||
}
|
||||
}
|
204
tools/unicodetools/com/ibm/rbm/BundleGroup.java
Normal file
204
tools/unicodetools/com/ibm/rbm/BundleGroup.java
Normal file
@ -0,0 +1,204 @@
|
||||
/*
|
||||
*****************************************************************************
|
||||
* Copyright (C) 2000-2002, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*****************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/unicodetools/com/ibm/rbm/BundleGroup.java,v $
|
||||
* $Date: 2002/05/20 18:53:10 $
|
||||
* $Revision: 1.1 $
|
||||
*
|
||||
*****************************************************************************
|
||||
*/
|
||||
package com.ibm.rbm;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintStream;
|
||||
import java.io.Writer;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* A class representing a group of BundleItems and the meta data associated with that group
|
||||
*
|
||||
* @author Jared Jackson - Email: <a href="mailto:jjared@almaden.ibm.com">jjared@almaden.ibm.com</a>
|
||||
* @see com.ibm.rbm.RBManager
|
||||
*/
|
||||
public class BundleGroup {
|
||||
private String name; // The name of the group
|
||||
private String comment; // A comment describing this group
|
||||
private TreeSet items; // The NLS items contained in this group
|
||||
private Bundle bundle; // The parent Bundle object of this group
|
||||
|
||||
/**
|
||||
* Basic data constructor. Creates a BundleGroup with a parent bundle and a given name.
|
||||
*/
|
||||
|
||||
public BundleGroup(Bundle parent, String name) {
|
||||
bundle = parent;
|
||||
this.name = name;
|
||||
comment = null;
|
||||
items = new TreeSet(new Comparator(){
|
||||
public boolean equals(Object o) { return false; }
|
||||
public int compare(Object o1, Object o2) {
|
||||
if (!(o1 instanceof BundleItem) || !(o2 instanceof BundleItem)) return 0;
|
||||
BundleItem i1 = (BundleItem)o1;
|
||||
BundleItem i2 = (BundleItem)o2;
|
||||
return i1.getKey().compareTo(i2.getKey());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Two bundle groups are considered equal iff their names are the same.
|
||||
*/
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (o instanceof BundleGroup && ((BundleGroup)o).getName().equals(name)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
// This should be changed anywhere it is used
|
||||
|
||||
protected Vector getItemsAsVector() {
|
||||
Vector v = new Vector();
|
||||
Iterator iter = items.iterator();
|
||||
while (iter.hasNext()) {
|
||||
v.addElement(iter.next());
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a BundleItem to the group as long as that item is not currently in the group. If the
|
||||
* item.group is not equal to this group, then it is changed to be this group. <BR/>
|
||||
* This method should, in most cases, only be called from the Bundle class.
|
||||
*/
|
||||
|
||||
public void addBundleItem(BundleItem item) {
|
||||
Iterator iter = items.iterator();
|
||||
boolean found = false;
|
||||
while (iter.hasNext()) {
|
||||
BundleItem oldItem = (BundleItem)iter.next();
|
||||
if (oldItem == item) found = true;
|
||||
}
|
||||
if (!found) {
|
||||
item.setParentGroup(this);
|
||||
items.add(item);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an item of the given name from the group
|
||||
*/
|
||||
|
||||
public void removeBundleItem(String itemName) {
|
||||
Iterator iter = items.iterator();
|
||||
while(iter.hasNext()) {
|
||||
BundleItem item = (BundleItem)iter.next();
|
||||
if (item.getKey().equals(itemName)) {
|
||||
items.remove(item);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of items stored in the group
|
||||
*/
|
||||
|
||||
public int getItemCount() {
|
||||
return items.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a BundleItem from the set of items at a particular index point. If the index is greater than or equal
|
||||
* to the number of items in the set, null is returned.
|
||||
*/
|
||||
|
||||
public BundleItem getBundleItem(int index) {
|
||||
if (index >= items.size()) return null;
|
||||
Iterator iter = items.iterator();
|
||||
for (int i=0; i < index; i++) iter.next();
|
||||
return (BundleItem)iter.next();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the bundle to which this group belongs
|
||||
*/
|
||||
|
||||
public Bundle getParentBundle() {
|
||||
return bundle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the comment associated with this bundle
|
||||
*/
|
||||
|
||||
public String getComment() {
|
||||
return comment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the bundle
|
||||
*/
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
protected void setParentBundle(Bundle bundle) {
|
||||
this.bundle = bundle;
|
||||
}
|
||||
|
||||
protected void setComment(String comment) {
|
||||
this.comment = comment;
|
||||
}
|
||||
|
||||
protected void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* The translation to a string returns the name of the group
|
||||
*/
|
||||
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the output for a group heading. This will be found in comment lines above the group items
|
||||
*/
|
||||
|
||||
public String toOutputString() {
|
||||
String retStr = "\n#\n# @group " + name + "\n#\n";
|
||||
if (comment != null) retStr += "# @groupComment " + comment + "\n";
|
||||
return retStr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the output contents to a particular PrintStream. The output will be suitable for a properly
|
||||
* formatted .properties file.
|
||||
*/
|
||||
|
||||
public void writeContents(PrintStream ps) {
|
||||
if (!name.equals("Ungrouped Items")) ps.println(this.toOutputString());
|
||||
Iterator iter = items.iterator();
|
||||
while (iter.hasNext()) {
|
||||
((BundleItem) iter.next()).writeContents(ps);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the output contents to a particular Writer. The output will be suitable for a properly
|
||||
* formatted .properties file.
|
||||
*/
|
||||
|
||||
public void writeContents(Writer w) throws IOException {
|
||||
if (!name.equals("Ungrouped Items")) w.write(this.toOutputString() + "\n");
|
||||
Iterator iter = items.iterator();
|
||||
while (iter.hasNext()) {
|
||||
((BundleItem) iter.next()).writeContents(w);
|
||||
}
|
||||
}
|
||||
}
|
390
tools/unicodetools/com/ibm/rbm/BundleItem.java
Normal file
390
tools/unicodetools/com/ibm/rbm/BundleItem.java
Normal file
@ -0,0 +1,390 @@
|
||||
/*
|
||||
*****************************************************************************
|
||||
* Copyright (C) 2000-2002, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*****************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/unicodetools/com/ibm/rbm/BundleItem.java,v $
|
||||
* $Date: 2002/05/20 18:53:10 $
|
||||
* $Revision: 1.1 $
|
||||
*
|
||||
*****************************************************************************
|
||||
*/
|
||||
package com.ibm.rbm;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintStream;
|
||||
import java.io.Writer;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.text.ParseException;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* A class representing a single translation item and all of the meta-data associated with that translation
|
||||
*
|
||||
* @author Jared Jackson - Email: <a href="mailto:jjared@almaden.ibm.com">jjared@almaden.ibm.com</a>
|
||||
* @see com.ibm.rbm.RBManager
|
||||
*/
|
||||
public class BundleItem {
|
||||
private String name; // The name of the NLS item key
|
||||
private String value; // The translation of the key item
|
||||
private String comment; // A comment about this item
|
||||
private boolean translated; // Has this item been translated?
|
||||
private Date created; // The date of creation of the item
|
||||
private Date modified; // The last modification date of the item
|
||||
private String creator; // The name of the person who created the item
|
||||
private String modifier; // The name of the person who last modified the item
|
||||
private Hashtable lookups; // A hastable of lookups for the item (i.e. ({#}, Meaning) pairs)
|
||||
private BundleGroup group; // The parent group of the item
|
||||
|
||||
/**
|
||||
* Basic data constructor for a resource bundle item.
|
||||
* @param parent The BundleGroup to which the item belongs. This group will have its own Bundle parent.
|
||||
* @param name The NLS lookup key common across all bundle files in the resource bundle
|
||||
* @param value The translated value of the item appropriate for the encoding of the bundle file to which the item belongs
|
||||
*/
|
||||
|
||||
public BundleItem(BundleGroup parent, String name, String value) {
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
this.group = parent;
|
||||
comment = null;
|
||||
translated = false;
|
||||
created = new Date(); // Defaults to the system's current date
|
||||
modified = new Date(); // Defaults to the system's current date
|
||||
creator = null;
|
||||
modifier = null;
|
||||
lookups = new Hashtable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the BundleGroup to which this item belongs
|
||||
*/
|
||||
|
||||
public BundleGroup getParentGroup() {
|
||||
return group;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the date this item was last modified.
|
||||
*/
|
||||
|
||||
public Date getModifiedDate() {
|
||||
return modified;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the date the item was first created.
|
||||
*/
|
||||
|
||||
public Date getCreatedDate() {
|
||||
return created;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the login name of the user that created the item.
|
||||
*/
|
||||
|
||||
public String getCreator() {
|
||||
return creator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the login name of the user that last modified the item.
|
||||
*/
|
||||
|
||||
public String getModifier() {
|
||||
return modifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the NLS lookup key for the item.
|
||||
*/
|
||||
|
||||
public String getKey() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the translation value for the item.
|
||||
*/
|
||||
|
||||
public String getTranslation() {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a comment associated with the item.
|
||||
*/
|
||||
|
||||
public String getComment() {
|
||||
return comment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Has the item yet been translated, or was it merely derived from a previous
|
||||
* bundle file?
|
||||
*/
|
||||
|
||||
public boolean isTranslated() {
|
||||
return translated;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a hashtable of the various lookups associated with the item. Lookups are
|
||||
* context sensitive information stored within the resource item and have their own
|
||||
* meta-data associated with themselves.
|
||||
*/
|
||||
|
||||
public Hashtable getLookups() {
|
||||
return lookups;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the translated value of the item. A true mark indicates that the item has
|
||||
* been examined or modified and is ready for use in the encoding specified by the
|
||||
* parent Bundle.
|
||||
*/
|
||||
|
||||
public void setTranslated(boolean isTranslated) {
|
||||
if (translated == isTranslated) return;
|
||||
translated = isTranslated;
|
||||
if (this.getParentGroup() != null && this.getParentGroup().getParentBundle() != null) {
|
||||
Bundle bundle = this.getParentGroup().getParentBundle();
|
||||
if (isTranslated) bundle.removeUntranslatedItem(this.name);
|
||||
else bundle.addUntranslatedItem(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the comment associated with this item.
|
||||
*/
|
||||
|
||||
public void setComment(String comment) {
|
||||
this.comment = comment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a hashtable of lookups, associates those lookups with this item.
|
||||
*/
|
||||
|
||||
protected void setLookups(Hashtable lookups) {
|
||||
this.lookups = lookups;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the NLS key associated with this item. Be careful using this method, as
|
||||
* it does not change the lookup value of any other items in the resource bundle.
|
||||
* This must be done at a higher level.
|
||||
*/
|
||||
|
||||
public void setKey(String keyName) {
|
||||
name = keyName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the translation value of the item.
|
||||
*/
|
||||
|
||||
public void setTranslation(String translationValue) {
|
||||
value = translationValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the parent BundleGroup of the item.
|
||||
*/
|
||||
|
||||
public void setParentGroup(BundleGroup group) {
|
||||
this.group = group;
|
||||
}
|
||||
|
||||
/**
|
||||
* Associates a login name of the creator of the item with the item.
|
||||
*/
|
||||
|
||||
public void setCreator(String name) {
|
||||
creator = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Associates a login name of the last modifier of the item with the item.
|
||||
*/
|
||||
|
||||
public void setModifier(String name) {
|
||||
modifier = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the created date of the item given a date formatted string.
|
||||
* The format can be either 'YYYY-MM-DD' (e.g. 20002-02-05) or
|
||||
* the format can be 'YYYMMDDTHHMMSSZ' (e.g. 20020205T103000Z)
|
||||
*/
|
||||
|
||||
public void setCreatedDate(String dateStr) {
|
||||
if (dateStr != null) created = parseDateFromString(dateStr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the created date of the item.
|
||||
*/
|
||||
|
||||
public void setCreatedDate(Date date) {
|
||||
created = date;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the last modififcation date of the item given a date formatted string.
|
||||
* The format can be either 'YYYY-MM-DD' (e.g. 20002-02-05) or
|
||||
* the format can be 'YYYMMDDTHHMMSSZ' (e.g. 20020205T103000Z)
|
||||
*/
|
||||
|
||||
public void setModifiedDate(String dateStr) {
|
||||
if (dateStr != null) modified = parseDateFromString(dateStr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the last modification date of the item.
|
||||
*/
|
||||
|
||||
public void setModifiedDate(Date date) {
|
||||
modified = date;
|
||||
}
|
||||
|
||||
/**
|
||||
* Simply returns the lookup name of the item.
|
||||
*/
|
||||
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the formatted output of this bundle item as it would be included in a .properties
|
||||
* formatted resource bundle file. This format also contains the meta-data used by RBManager in
|
||||
* the form of parseable comments.
|
||||
*/
|
||||
|
||||
public String toOutputString() {
|
||||
String retStr = (translated ? "# @translated true" : "# @translated false");
|
||||
if (created != null) {
|
||||
GregorianCalendar createdCal = new GregorianCalendar();
|
||||
createdCal.setTime(created);
|
||||
int year = createdCal.get(Calendar.YEAR);
|
||||
int month = createdCal.get(Calendar.MONTH)+1;
|
||||
int day = createdCal.get(Calendar.DAY_OF_MONTH);
|
||||
retStr += " @created " + String.valueOf(year) + "-"
|
||||
+ (month > 9 ? String.valueOf(month) : "0" + String.valueOf(month)) + "-"
|
||||
+ (day > 9 ? String.valueOf(day) : "0" + String.valueOf(day));
|
||||
}
|
||||
if (modified != null) {
|
||||
GregorianCalendar modifiedCal = new GregorianCalendar();
|
||||
modifiedCal.setTime(modified);
|
||||
int year = modifiedCal.get(Calendar.YEAR);
|
||||
int month = modifiedCal.get(Calendar.MONTH)+1;
|
||||
int day = modifiedCal.get(Calendar.DAY_OF_MONTH);
|
||||
retStr += " @modified " + String.valueOf(year) + "-"
|
||||
+ (month > 9 ? String.valueOf(month) : "0" + String.valueOf(month)) + "-"
|
||||
+ (day > 9 ? String.valueOf(day) : "0" + String.valueOf(day));
|
||||
}
|
||||
if (creator != null) retStr += " @creator " + creator;
|
||||
if (modifier != null) retStr += " @modifier " + modifier;
|
||||
Enumeration enum = lookups.keys();
|
||||
while (enum.hasMoreElements()) {
|
||||
String str = (String)enum.nextElement();
|
||||
retStr += "\n# @{" + str + "} " + (String)lookups.get(str);
|
||||
}
|
||||
if (comment != null) retStr += "\n# @comment " + comment;
|
||||
|
||||
retStr += "\n" + name + "=" + saveConvert(value);
|
||||
return retStr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the formatted contents to a PrintStream.
|
||||
*/
|
||||
|
||||
public void writeContents(PrintStream ps) {
|
||||
ps.println(this.toOutputString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the formatted contents to a writer such as a FileWriter.
|
||||
*/
|
||||
|
||||
public void writeContents(Writer w) throws IOException {
|
||||
w.write(this.toOutputString() + "\n");
|
||||
}
|
||||
|
||||
/*
|
||||
* Converts unicodes to encoded \\uxxxx
|
||||
* and writes out any of the characters in specialSaveChars
|
||||
* with a preceding slash
|
||||
*/
|
||||
// Taken from java.util.Properties
|
||||
private String saveConvert(String theString) {
|
||||
char aChar;
|
||||
int len = theString.length();
|
||||
StringBuffer outBuffer = new StringBuffer(len*2);
|
||||
|
||||
for(int x=0; x<len; ) {
|
||||
aChar = theString.charAt(x++);
|
||||
switch(aChar) {
|
||||
case '\\':outBuffer.append('\\'); outBuffer.append('\\');
|
||||
continue;
|
||||
case '\t':outBuffer.append('\\'); outBuffer.append('t');
|
||||
continue;
|
||||
case '\n':outBuffer.append('\\'); outBuffer.append('n');
|
||||
continue;
|
||||
case '\r':outBuffer.append('\\'); outBuffer.append('r');
|
||||
continue;
|
||||
case '\f':outBuffer.append('\\'); outBuffer.append('f');
|
||||
continue;
|
||||
default:
|
||||
if ((aChar < 20) || (aChar > 127)) {
|
||||
outBuffer.append('\\');
|
||||
outBuffer.append('u');
|
||||
outBuffer.append(toHex((aChar >> 12) & 0xF));
|
||||
outBuffer.append(toHex((aChar >> 8) & 0xF));
|
||||
outBuffer.append(toHex((aChar >> 4) & 0xF));
|
||||
outBuffer.append(toHex((aChar >> 0) & 0xF));
|
||||
}
|
||||
else {
|
||||
if (specialSaveChars.indexOf(aChar) != -1)
|
||||
outBuffer.append('\\');
|
||||
outBuffer.append(aChar);
|
||||
}
|
||||
}
|
||||
}
|
||||
return outBuffer.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a nibble to a hex character
|
||||
* @param nibble the nibble to convert.
|
||||
*/
|
||||
// Taken from java.util.Properties
|
||||
private static char toHex(int nibble) {
|
||||
return hexDigit[(nibble & 0xF)];
|
||||
}
|
||||
|
||||
/** A table of hex digits */
|
||||
// Taken from java.util.Properties
|
||||
private static final char[] hexDigit = {
|
||||
'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'
|
||||
};
|
||||
|
||||
// Taken from java.util.Properties
|
||||
private static final String specialSaveChars = "=: \t\r\n\f#!";
|
||||
|
||||
private Date parseDateFromString(String dateStr) {
|
||||
SimpleDateFormat format = null;
|
||||
if (dateStr.length() == 10) format = new SimpleDateFormat("yyyy-MM-dd"); // Simple format
|
||||
else format = new SimpleDateFormat("yyyyMMdd'T'HHmmss'Z'"); // TMX ISO format
|
||||
try {
|
||||
return format.parse(dateStr);
|
||||
} catch (ParseException pe) {
|
||||
return new Date();
|
||||
}
|
||||
}
|
||||
}
|
71
tools/unicodetools/com/ibm/rbm/Occurance.java
Normal file
71
tools/unicodetools/com/ibm/rbm/Occurance.java
Normal file
@ -0,0 +1,71 @@
|
||||
/*
|
||||
*****************************************************************************
|
||||
* Copyright (C) 2000-2002, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*****************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/unicodetools/com/ibm/rbm/Occurance.java,v $
|
||||
* $Date: 2002/05/20 18:53:10 $
|
||||
* $Revision: 1.1 $
|
||||
*
|
||||
*****************************************************************************
|
||||
*/
|
||||
package com.ibm.rbm;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* This is a class used by the RBReporter to track occurances of a resource
|
||||
* key found while scanning a text code file. It is used mainly to produce error
|
||||
* messages with helpful context information.
|
||||
*
|
||||
* @author Jared Jackson - Email: <a href="mailto:jjared@almaden.ibm.com">jjared@almaden.ibm.com</a>
|
||||
* @see com.ibm.rbm.RBReporter
|
||||
*/
|
||||
public class Occurance {
|
||||
private String file_name;
|
||||
private String file_path;
|
||||
private int line_number;
|
||||
|
||||
/**
|
||||
* Basic data constructor.
|
||||
*/
|
||||
|
||||
Occurance (String file_name, String file_path, int line_number) {
|
||||
this.file_name = file_name;
|
||||
this.file_path = file_path;
|
||||
this.line_number = line_number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the associated file name of the occurance
|
||||
*/
|
||||
|
||||
public String getFileName() {
|
||||
return file_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the associated file path of the occurance
|
||||
*/
|
||||
|
||||
public String getFilePath() {
|
||||
return file_path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the line number of the occurance.
|
||||
*/
|
||||
|
||||
public int getLineNumber() {
|
||||
return line_number;
|
||||
}
|
||||
|
||||
/**
|
||||
* A representation of the occurance of the form 'Occurance: _file_path_ (_line_number_)'
|
||||
*/
|
||||
|
||||
public String toString() {
|
||||
return "Occurance: " + file_path + " (" + line_number + ")";
|
||||
}
|
||||
}
|
190
tools/unicodetools/com/ibm/rbm/Preferences.java
Normal file
190
tools/unicodetools/com/ibm/rbm/Preferences.java
Normal file
@ -0,0 +1,190 @@
|
||||
/*
|
||||
*****************************************************************************
|
||||
* Copyright (C) 2000-2002, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*****************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/unicodetools/com/ibm/rbm/Preferences.java,v $
|
||||
* $Date: 2002/05/20 18:53:10 $
|
||||
* $Revision: 1.1 $
|
||||
*
|
||||
*****************************************************************************
|
||||
*/
|
||||
package com.ibm.rbm;
|
||||
|
||||
import java.util.*;
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* This class defines the methods used by RBManager to access, set, and store
|
||||
* individual user preferences for the application. All of the public methods defined
|
||||
* in this class are static, and so the class need not be instantiated.
|
||||
*
|
||||
* @author Jared Jackson - Email: <a href="mailto:jjared@almaden.ibm.com">jjared@almaden.ibm.com</a>
|
||||
* @see com.ibm.rbm.RBManager
|
||||
*/
|
||||
public class Preferences {
|
||||
// Default values
|
||||
private static final int NUM_RECENT_FILES = 4;
|
||||
private static final int _Y = 2002;
|
||||
private static final int _M = 6;
|
||||
private static final int _D = 15;
|
||||
private static final String EMPTY_STRING = "";
|
||||
private static Properties prop;
|
||||
|
||||
/**
|
||||
* Retrieve a preference by its key name
|
||||
* @param name The name of the key associated with one preference
|
||||
* @return The value of the preference sought
|
||||
*/
|
||||
|
||||
public static String getPreference(String name) {
|
||||
if (prop == null) init();
|
||||
Object o = prop.get(name);
|
||||
if (o == null || !(o instanceof String)) return EMPTY_STRING;
|
||||
return (String)o;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a preference by key name and value. If the key name all ready exists, that
|
||||
* preference is overwritten without warning.
|
||||
* @param name The name of the key associated with the preference
|
||||
* @param value The value of the preference to be set and later retrieved. If this value is null, the property of this name is erased.
|
||||
*/
|
||||
|
||||
public static void setPreference(String name, String value) {
|
||||
if (prop == null) init();
|
||||
if (value == null) {
|
||||
// In this case, we will remove the property
|
||||
prop.remove(name);
|
||||
}
|
||||
prop.put(name, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the results of the buffered preferences to file. There is no option for
|
||||
* where this file is saved on the file system.
|
||||
*/
|
||||
|
||||
public static void savePreferences() throws IOException {
|
||||
if (prop == null) init();
|
||||
FileOutputStream fos = new FileOutputStream("preferences.properties");
|
||||
prop.store(fos, "RBManager Preferences");
|
||||
fos.flush();
|
||||
fos.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Given the name of a resource bundle and the file path location of the base
|
||||
* document for that resource bundle, this method will insert that file into
|
||||
* a list of recent files. Currently the past 4 resource bundles visited will
|
||||
* be displayed. This method also sorts the prefences so that the most recently
|
||||
* added will be the first returned, even if that file had all ready existed
|
||||
* in the preferences when it was added.
|
||||
* @param name The name of this file as it will be displayed to the user
|
||||
* @param location The file path to this file (should be absolute).
|
||||
*/
|
||||
|
||||
public static void addRecentFilePreference(String name, String location) {
|
||||
Vector existingNames = new Vector();
|
||||
Vector existingLocations = new Vector();
|
||||
for (int i=0; i < NUM_RECENT_FILES; i++) {
|
||||
String oldName = getPreference("recentfileid" + String.valueOf(i));
|
||||
String oldLocation = getPreference("recentfileloc" + String.valueOf(i));
|
||||
if (oldName.equals(EMPTY_STRING) || oldLocation.equals(EMPTY_STRING)) break;
|
||||
existingNames.addElement(oldName);
|
||||
existingLocations.addElement(oldLocation);
|
||||
}
|
||||
// Check to see if the file is all ready in there
|
||||
int swap_start = 0;
|
||||
int old_size = existingLocations.size();
|
||||
for (int i=0; i <= old_size; i++) {
|
||||
if (i == existingLocations.size()) {
|
||||
// No match was found, pull all the elements down one
|
||||
swap_start = i;
|
||||
if (swap_start >= NUM_RECENT_FILES) swap_start = NUM_RECENT_FILES-1;
|
||||
else {
|
||||
// Extend the length of the vectors
|
||||
existingNames.addElement(EMPTY_STRING);
|
||||
existingLocations.addElement(EMPTY_STRING);
|
||||
}
|
||||
} else {
|
||||
String oldLocation = (String)existingLocations.elementAt(i);
|
||||
if (oldLocation.equals(location)) {
|
||||
// We found a match, pull this one to the front
|
||||
swap_start = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Move the files down the line as appropriate
|
||||
for (int i=swap_start; i > 0; i--) {
|
||||
existingLocations.setElementAt(existingLocations.elementAt(i-1),i);
|
||||
existingNames.setElementAt(existingNames.elementAt(i-1),i);
|
||||
}
|
||||
existingLocations.setElementAt(location, 0);
|
||||
existingNames.setElementAt(name, 0);
|
||||
|
||||
// Set the properties
|
||||
for (int i=0; i < existingLocations.size(); i++) {
|
||||
setPreference("recentfileid" + String.valueOf(i), (String)existingNames.elementAt(i));
|
||||
setPreference("recentfileloc" + String.valueOf(i), (String)existingLocations.elementAt(i));
|
||||
}
|
||||
for (int i=existingLocations.size(); i < NUM_RECENT_FILES; i++) {
|
||||
setPreference("recentfileid" + String.valueOf(i), EMPTY_STRING);
|
||||
setPreference("recentfileloc" + String.valueOf(i), EMPTY_STRING);
|
||||
}
|
||||
try {
|
||||
savePreferences();
|
||||
} catch (IOException ioe) {} // Ignore, its not critical
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of the names and locations of the various recently used files.
|
||||
* @return A Vector of Strings which is twice in length the number of files known about. The vector contains name 1 then location 1, then name 2 ...
|
||||
*/
|
||||
|
||||
public static Vector getRecentFilesPreferences() {
|
||||
if (prop == null) init();
|
||||
Vector existing = new Vector();
|
||||
for (int i=0; i < NUM_RECENT_FILES; i++) {
|
||||
String name = getPreference("recentfileid" + String.valueOf(i));
|
||||
String location = getPreference("recentfileloc" + String.valueOf(i));
|
||||
if (name.equals(EMPTY_STRING) || location.equals(EMPTY_STRING)) break;
|
||||
existing.addElement(name);
|
||||
existing.addElement(location);
|
||||
}
|
||||
return existing;
|
||||
}
|
||||
|
||||
private static void init() {
|
||||
Properties defaults = new Properties();
|
||||
// This values are needed and are specified by default
|
||||
// If they exist in the file, they will be overwritten
|
||||
defaults.put("username", Resources.getTranslation("unknown_user"));
|
||||
defaults.put("locale", "en");
|
||||
defaults.put("lookandfeel", "");
|
||||
|
||||
prop = new Properties(defaults);
|
||||
try {
|
||||
FileInputStream fis = new FileInputStream("preferences.properties");
|
||||
prop.load(fis);
|
||||
} catch (IOException ioe) {
|
||||
System.err.println("Error reading properties");
|
||||
ioe.printStackTrace(System.err);
|
||||
}
|
||||
try {
|
||||
savePreferences();
|
||||
} catch (IOException ioe) {
|
||||
System.err.println("Error saving preferences " + ioe.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
public static void main(String args[]) {
|
||||
// Test
|
||||
init();
|
||||
}
|
||||
*/
|
||||
}
|
35
tools/unicodetools/com/ibm/rbm/RBExporter.java
Normal file
35
tools/unicodetools/com/ibm/rbm/RBExporter.java
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
*****************************************************************************
|
||||
* Copyright (C) 2000-2002, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*****************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/unicodetools/com/ibm/rbm/RBExporter.java,v $
|
||||
* $Date: 2002/05/20 18:53:10 $
|
||||
* $Revision: 1.1 $
|
||||
*
|
||||
*****************************************************************************
|
||||
*/
|
||||
package com.ibm.rbm;
|
||||
|
||||
import java.io.*;
|
||||
import javax.swing.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* This is the super class for all exporter plug-in classes. As of yet, there
|
||||
* is little contained in this class.
|
||||
*
|
||||
* @author Jared Jackson - Email: <a href="mailto:jjared@almaden.ibm.com">jjared@almaden.ibm.com</a>
|
||||
* @see com.ibm.rbm.RBManager
|
||||
*/
|
||||
public class RBExporter {
|
||||
protected static JFileChooser chooser;
|
||||
|
||||
/**
|
||||
* Basic empty constructor.
|
||||
*/
|
||||
public RBExporter() {
|
||||
|
||||
}
|
||||
}
|
198
tools/unicodetools/com/ibm/rbm/RBICUExporter.java
Normal file
198
tools/unicodetools/com/ibm/rbm/RBICUExporter.java
Normal file
@ -0,0 +1,198 @@
|
||||
/*
|
||||
*****************************************************************************
|
||||
* Copyright (C) 2000-2002, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*****************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/unicodetools/com/ibm/rbm/RBICUExporter.java,v $
|
||||
* $Date: 2002/05/20 18:53:10 $
|
||||
* $Revision: 1.1 $
|
||||
*
|
||||
*****************************************************************************
|
||||
*/
|
||||
package com.ibm.rbm;
|
||||
|
||||
import java.io.*;
|
||||
import javax.swing.*;
|
||||
import javax.swing.filechooser.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* This class provides a plug-in exporter utility for RBManager that outputs ICU
|
||||
* resource bundle files in the according to the file structure of Resource
|
||||
* Bundles. Most of the meta-data is lost in this export.
|
||||
*
|
||||
* @author George Rhoten
|
||||
* @see com.ibm.rbm.RBManager
|
||||
*/
|
||||
public class RBICUExporter extends RBExporter {
|
||||
/** Do characters beyond \\u007f need \\u escape notation? */
|
||||
private boolean escapeNonAscii = false;
|
||||
|
||||
/** Write the meta data for each resource? */
|
||||
private boolean writeMetaData = true;
|
||||
|
||||
/** Write the groups as keys? */
|
||||
private boolean writeGroupsAsKeys = false;
|
||||
|
||||
public RBICUExporter() {
|
||||
super();
|
||||
|
||||
// Initialize the file chooser if necessary
|
||||
if (chooser == null) {
|
||||
chooser = new JFileChooser();
|
||||
chooser.setFileFilter(new javax.swing.filechooser.FileFilter(){
|
||||
public String getDescription() {
|
||||
return "root ICU File";
|
||||
}
|
||||
public boolean accept(File f) {
|
||||
if (f.isDirectory()) return true;
|
||||
return (f.getName().startsWith("root."));
|
||||
}
|
||||
});
|
||||
} // end if
|
||||
}
|
||||
|
||||
protected void export(RBManager rbm) throws IOException {
|
||||
if (rbm == null) return;
|
||||
// Open the Save Dialog
|
||||
int ret_val = chooser.showSaveDialog(null);
|
||||
if (ret_val != JFileChooser.APPROVE_OPTION) {
|
||||
return;
|
||||
}
|
||||
// Retrieve basic file information
|
||||
File file = chooser.getSelectedFile(); // The file(s) we will be working with
|
||||
File directory = new File(file.getParent()); // The directory we will be writing to
|
||||
String base_name = file.getName(); // The base name of the files we will write
|
||||
if (base_name == null || base_name.equals("")) {
|
||||
base_name = rbm.getBaseClass();
|
||||
}
|
||||
if (base_name.toLowerCase().endsWith(".properties")) {
|
||||
base_name = base_name.substring(0,base_name.length()-11);
|
||||
}
|
||||
|
||||
Vector bundle_v = rbm.getBundles();
|
||||
for (int i=0; i < bundle_v.size(); i++) {
|
||||
Bundle bundle = (Bundle)bundle_v.elementAt(i);
|
||||
String base_enc = base_name;
|
||||
if (bundle.encoding != null && !bundle.encoding.equals("")) {
|
||||
base_enc = base_enc + "_" + bundle.encoding;
|
||||
}
|
||||
String file_name = base_enc + ".txt";
|
||||
String header = "\ufeff// Resource Bundle: " + file_name + " - File automatically generated by RBManager at " + (new Date());
|
||||
|
||||
OutputStream fos = new FileOutputStream(new File(directory, file_name));
|
||||
PrintWriter resOut = new PrintWriter(new OutputStreamWriter(fos, "UTF-8"));
|
||||
|
||||
Vector group_v = bundle.getGroupsAsVector();
|
||||
resOut.println(header);
|
||||
resOut.println(base_enc + " { ");
|
||||
for (int j=0; j < group_v.size(); j++) {
|
||||
BundleGroup group = (BundleGroup)group_v.elementAt(j);
|
||||
|
||||
Vector itemVect = group.getItemsAsVector();
|
||||
int itemVectSize = itemVect.size();
|
||||
if (itemVectSize > 0) {
|
||||
if (writeMetaData) {
|
||||
String groupComment = group.getComment();
|
||||
if (groupComment != null && !groupComment.equals("")) {
|
||||
resOut.println(" // @groupComment " + groupComment);
|
||||
}
|
||||
}
|
||||
|
||||
boolean writeGroupName = !bundle.getUngroupedGroup().getName().equals(group.getName());
|
||||
if (writeGroupName) {
|
||||
if (writeGroupsAsKeys) {
|
||||
resOut.println(" " + escapeString(group.getName(), true) + " { ");
|
||||
}
|
||||
else if (writeMetaData) {
|
||||
resOut.println(" // @group " + escapeString(group.getName(), true));
|
||||
}
|
||||
}
|
||||
for (int k=0; k < itemVectSize; k++) {
|
||||
BundleItem item = (BundleItem)itemVect.elementAt(k);
|
||||
|
||||
if (writeMetaData) {
|
||||
resOut.print(" //");
|
||||
resOut.print(" @translated " + item.isTranslated());
|
||||
resOut.print(" @created " + item.getCreatedDate());
|
||||
resOut.print(" @modified " + item.getModifiedDate());
|
||||
resOut.print(" @creator " + item.getCreator());
|
||||
resOut.println(" @modifier " + item.getModifier());
|
||||
String itemComment = item.getComment();
|
||||
if (itemComment != null && !itemComment.equals("")) {
|
||||
resOut.println(" // @comment " + itemComment);
|
||||
}
|
||||
}
|
||||
|
||||
resOut.println(" " + escapeString(item.getKey(), true)
|
||||
+ " { " + escapeString(item.getTranslation(), false) + " }");
|
||||
} // end for - k
|
||||
if (writeGroupName && writeGroupsAsKeys) {
|
||||
resOut.println(" }");
|
||||
}
|
||||
}
|
||||
} // end for - j
|
||||
resOut.println("}");
|
||||
|
||||
// Write out the file
|
||||
resOut.close();
|
||||
fos.close();
|
||||
} // end for - i
|
||||
}
|
||||
|
||||
/**
|
||||
* Escape a string according to how the ICU tool "genrb" handles strings.
|
||||
* @param str The string to escape
|
||||
* @param isKey If this is a key, then quotes are optional.
|
||||
* @return A string that can be used in an ICU resource bundle.
|
||||
*/
|
||||
protected String escapeString(String str, boolean isKey) throws IOException {
|
||||
StringBuffer strBuf = new StringBuffer();
|
||||
int len = str.length();
|
||||
boolean quoteRequired = !isKey;
|
||||
for (int idx = 0; idx < len; idx++) {
|
||||
char ch = str.charAt(idx);
|
||||
if (ch <= ' ' || '~' < ch) {
|
||||
if (isKey && ch != ' ') {
|
||||
IOException e = new IOException(str + " needs to use invariant characters for the key.");
|
||||
e.fillInStackTrace();
|
||||
throw e;
|
||||
} else if (escapeNonAscii && ch != ' ') {
|
||||
String zeros;
|
||||
String hexNum;
|
||||
if ((ch & 0xf800) == 0xd800) {
|
||||
// We assume that we found a valid UTF-16 string with a surrogate
|
||||
int ch2 = str.charAt(idx++);
|
||||
int chSurrogate = ((((int)ch)<<10)+(ch2)-((0xd800<<10)+0xdc00-0x10000));
|
||||
|
||||
zeros = "00000000";
|
||||
hexNum = Integer.toHexString(chSurrogate);
|
||||
strBuf.append("\\U");
|
||||
} else {
|
||||
zeros = "0000";
|
||||
hexNum = Integer.toHexString(ch);
|
||||
strBuf.append("\\u");
|
||||
}
|
||||
strBuf.append(zeros.substring(hexNum.length()) + hexNum.toUpperCase());
|
||||
} else {
|
||||
quoteRequired = true;
|
||||
strBuf.append(ch);
|
||||
}
|
||||
} else if (ch == '\"') {
|
||||
quoteRequired = true;
|
||||
strBuf.append("\\\"");
|
||||
} else {
|
||||
if (ch == '{' || ch == '}') {
|
||||
quoteRequired = true;
|
||||
}
|
||||
strBuf.append(ch);
|
||||
}
|
||||
}
|
||||
if (quoteRequired) {
|
||||
strBuf.insert(0, '\"');
|
||||
strBuf.append('\"');
|
||||
}
|
||||
return strBuf.toString();
|
||||
}
|
||||
}
|
441
tools/unicodetools/com/ibm/rbm/RBImporter.java
Normal file
441
tools/unicodetools/com/ibm/rbm/RBImporter.java
Normal file
@ -0,0 +1,441 @@
|
||||
/*
|
||||
*****************************************************************************
|
||||
* Copyright (C) 2000-2002, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*****************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/unicodetools/com/ibm/rbm/RBImporter.java,v $
|
||||
* $Date: 2002/05/20 18:53:10 $
|
||||
* $Revision: 1.1 $
|
||||
*
|
||||
*****************************************************************************
|
||||
*/
|
||||
package com.ibm.rbm;
|
||||
|
||||
import java.io.*;
|
||||
import javax.swing.*;
|
||||
import java.util.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
/**
|
||||
* <P>This is the super class for all importer plug-in classes.</P>
|
||||
* <P>
|
||||
* In terms of general functionality of this class or its children classes, the following steps should happen in order:
|
||||
* <OL>
|
||||
* <LI>A Dialog is shown from which the user may select options about the import, including the file from which to import.</LI>
|
||||
* <LI>The 'Import' button is pressed, closing the options dialog and opening a progress bar dialog box.</LI>
|
||||
* <LI>The class should resolve all conflicts with locale encodings existing in the import files, but not in the active resource bundle.</LI>
|
||||
* <LI>The class should parse resources one at a time and use the importResource() method to insert them into the resource bundle.</LI>
|
||||
* <LI>The class should report when all resources have been read and the import is complete.</LI>
|
||||
* </OL>
|
||||
* </P>
|
||||
*
|
||||
* @author Jared Jackson - Email: <a href="mailto:jjared@almaden.ibm.com">jjared@almaden.ibm.com</a>
|
||||
* @see com.ibm.rbm.RBManager
|
||||
*/
|
||||
public class RBImporter extends JDialog {
|
||||
private final static int FILE_OPTION_POPULATE = 0; // Create a new locale file populated from base file
|
||||
private final static int FILE_OPTION_EMPTY = 1; // Create a new empty locale file
|
||||
private final static int FILE_OPTION_IGNORE = 2; // Ignore all resources from this encoding
|
||||
private final static int FILE_OPTION_PROMPT = 3; // Prompt for each conflict
|
||||
private final static int RESOURCE_OPTION_OVERWRITE = 0; // Use the value from the source import file
|
||||
private final static int RESOURCE_OPTION_IGNORE = 1; // Ignore the import and use existing value
|
||||
private final static int RESOURCE_OPTION_PROMPT = 2; // Propmpt for each conflict
|
||||
|
||||
protected static JFileChooser chooser;
|
||||
protected int num_conflicts;
|
||||
protected int num_extra_files;
|
||||
protected String title;
|
||||
protected RBManager rbm;
|
||||
protected RBManagerGUI gui;
|
||||
protected boolean pathSet = false;
|
||||
|
||||
// Visual Components
|
||||
JRadioButton resourceOverwriteRadio = new JRadioButton(Resources.getTranslation("import_resource_conflict_overwrite"), false);
|
||||
JRadioButton resourceIgnoreRadio = new JRadioButton(Resources.getTranslation("import_resource_conflict_ignore"), false);
|
||||
JRadioButton resourcePromptRadio = new JRadioButton(Resources.getTranslation("import_conflict_prompt"), true);
|
||||
JRadioButton fileGeneratePopulateRadio = new JRadioButton(Resources.getTranslation("import_file_conflict_generate_populate"), false);
|
||||
JRadioButton fileGenerateEmptyRadio = new JRadioButton(Resources.getTranslation("import_file_conflict_generate_empty"), false);
|
||||
JRadioButton fileIgnoreRadio = new JRadioButton(Resources.getTranslation("import_file_conflict_ignore"), false);
|
||||
JRadioButton filePromptRadio = new JRadioButton(Resources.getTranslation("import_conflict_prompt"), true);
|
||||
|
||||
JCheckBox markTranslatedCheck = new JCheckBox(Resources.getTranslation("import_default_translated"), true);
|
||||
JCheckBox createGroupsCheck = new JCheckBox(Resources.getTranslation("import_default_group_creation"), true);
|
||||
JComboBox groupComboBox = new JComboBox();
|
||||
|
||||
JLabel sourceLabel;
|
||||
|
||||
JDialog progressBarDialog;
|
||||
JProgressBar progressBar;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param title The title that appears in the Dialog box
|
||||
* @param rbm An RBManager instance
|
||||
* @param gui The RBManager GUI instance associated with the RBManager instance
|
||||
*/
|
||||
|
||||
public RBImporter(String title, RBManager rbm, RBManagerGUI gui) {
|
||||
super(new Frame(), title, true);
|
||||
this.title = title;
|
||||
this.rbm = rbm;
|
||||
this.gui = gui;
|
||||
init();
|
||||
}
|
||||
|
||||
protected void init() {
|
||||
chooser = new JFileChooser();
|
||||
setupFileChooser();
|
||||
num_conflicts = 0;
|
||||
num_extra_files = 0;
|
||||
initComponents();
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
protected void setupFileChooser() {
|
||||
// To be overwritten
|
||||
}
|
||||
|
||||
protected void beginImport() throws IOException {
|
||||
// To be overwritten
|
||||
if (!pathSet) return;
|
||||
}
|
||||
|
||||
protected void chooseFile() {
|
||||
int result = chooser.showOpenDialog(this);
|
||||
if (result == chooser.APPROVE_OPTION) {
|
||||
File f = chooser.getSelectedFile();
|
||||
sourceLabel.setText(Resources.getTranslation("import_source_file",f.getAbsolutePath()));
|
||||
pathSet = true;
|
||||
}
|
||||
}
|
||||
|
||||
protected File getChosenFile() {
|
||||
return chooser.getSelectedFile();
|
||||
}
|
||||
|
||||
/**
|
||||
* A super class method intended for use of nearly all subclass importers, once a resource
|
||||
* is found by those subclasses. This method is called in order to create the new resource
|
||||
* and handle the various conflict errors that may result as a part of that import.
|
||||
*/
|
||||
|
||||
protected void importResource(BundleItem item, String encoding, String group_name) {
|
||||
Bundle bundle = null;
|
||||
BundleGroup group = null;
|
||||
BundleGroup backup_group = null;
|
||||
|
||||
if (group_name == null) group_name = getDefaultGroup();
|
||||
if (encoding == null) return;
|
||||
// Get the bundle to which we will be adding this resource
|
||||
if (rbm.hasResource(encoding)) {
|
||||
Vector bv = rbm.getBundles();
|
||||
for (int i = 0; i < bv.size(); i++) {
|
||||
Bundle tempb = (Bundle)bv.elementAt(i);
|
||||
if (tempb.encoding.equals(encoding)) {
|
||||
bundle = tempb;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Skip this import if the bundle is non-existent (Should have been resolved if wanted)
|
||||
if (bundle == null) return;
|
||||
// Find the group in the bundle, Ungrouped if non-existent
|
||||
Vector gv = bundle.getGroupsAsVector();
|
||||
for (int i=0; i < gv.size(); i++) {
|
||||
BundleGroup tempg = (BundleGroup)gv.elementAt(i);
|
||||
if (i==0) backup_group = tempg;
|
||||
if (tempg.getName().equals("Ungrouped Items")) backup_group = tempg;
|
||||
else if (tempg.getName().equals(group_name)) {
|
||||
group = tempg;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (group == null) {
|
||||
if (getDefaultGroupCreation()) {
|
||||
// Create a new group by this name
|
||||
bundle.addBundleGroup(group_name, "");
|
||||
gv = bundle.getGroupsAsVector();
|
||||
for (int i=0; i < gv.size(); i++) {
|
||||
BundleGroup tempg = (BundleGroup)gv.elementAt(i);
|
||||
if (tempg.getName().equals(group_name)) {
|
||||
group = tempg;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Use the backup_group
|
||||
group = backup_group;
|
||||
}
|
||||
}
|
||||
// If all group identification efforts fail, we fail
|
||||
if (group == null) return;
|
||||
item.setParentGroup(group);
|
||||
// Check for and resolve conflicts
|
||||
if (bundle.allItems.containsKey(item.getKey())) {
|
||||
resolveResource(bundle,item);
|
||||
RBManagerGUI.debugMsg("Resolve conflict");
|
||||
} else {
|
||||
// Insert the resource
|
||||
bundle.addBundleItem(item);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method should be called when trying to import and item whose key all ready exists within the bundle.
|
||||
*/
|
||||
|
||||
protected void resolveResource(Bundle bundle, BundleItem item) {
|
||||
if (this.getResourceConflictOption() == this.RESOURCE_OPTION_IGNORE) return;
|
||||
else if (this.getResourceConflictOption() == this.RESOURCE_OPTION_OVERWRITE) {
|
||||
bundle.removeItem(item.getKey());
|
||||
bundle.addBundleItem(item);
|
||||
} else if (this.getResourceConflictOption() == this.RESOURCE_OPTION_PROMPT) {
|
||||
BundleItem original = (BundleItem)bundle.allItems.get(item.getKey());
|
||||
if (original == null) return;
|
||||
String trans = original.getTranslation();
|
||||
String options[] = { Resources.getTranslation("import_resource_conflict_overwrite"),
|
||||
Resources.getTranslation("import_resource_conflict_ignore")};
|
||||
String insert[] = {item.getKey(), (bundle.encoding.equals("") ? "(Base Class)" : bundle.encoding)};
|
||||
String result = (String)JOptionPane.showInputDialog(this, Resources.getTranslation("import_resource_conflict_choose", insert) +
|
||||
"\n" + Resources.getTranslation("import_resource_conflict_choose_source", item.getTranslation()) +
|
||||
"\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.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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a vector of strings containing locale encodings (e.g. {"en", "en_us", "de"}), attempts
|
||||
* to resolve those conflicts according to the preferences selected by the user.
|
||||
*/
|
||||
|
||||
protected void resolveEncodings(Vector v) {
|
||||
for (int i=0; i < v.size(); i++) {
|
||||
String encoding = (String)v.elementAt(i);
|
||||
if (encoding == null || encoding.equals("")) continue;
|
||||
if (rbm.hasResource(encoding)) continue;
|
||||
else {
|
||||
// We need to resolve this conflict
|
||||
if (this.getFileConflictOption() == this.FILE_OPTION_IGNORE) continue;
|
||||
else if (this.getFileConflictOption() == this.FILE_OPTION_POPULATE) {
|
||||
rbm.createResource(null, null, null, encoding, null, null, null, true);
|
||||
} else if (this.getFileConflictOption() == this.FILE_OPTION_EMPTY) {
|
||||
rbm.createResource(null, null, null, encoding, null, null, null, true);
|
||||
} else if (this.getFileConflictOption() == this.FILE_OPTION_PROMPT) {
|
||||
String options[] = { Resources.getTranslation("import_file_conflict_generate_populate"),
|
||||
Resources.getTranslation("import_file_conflict_generate_empty"),
|
||||
Resources.getTranslation("import_file_conflict_ignore")};
|
||||
|
||||
String result = (String)JOptionPane.showInputDialog(this, Resources.getTranslation("import_file_conflict_choose", encoding),
|
||||
Resources.getTranslation("import_file_conflicts"), JOptionPane.QUESTION_MESSAGE,
|
||||
null, options, options[0]);
|
||||
if (result == null) continue;
|
||||
if (result.equals(Resources.getTranslation("import_file_conflict_ignore"))) continue;
|
||||
else if (result.equals(Resources.getTranslation("import_file_conflict_generate_populate"))) {
|
||||
rbm.createResource(null, null, null, encoding, null, null, null, true);
|
||||
} else if (result.equals(Resources.getTranslation("import_file_conflict_generate_empty"))) {
|
||||
rbm.createResource(null, null, null, encoding, null, null, null, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
gui.updateDisplayTree();
|
||||
}
|
||||
|
||||
// Returns an integer mask describing the user's selection for file resolving missing file locale conflicts
|
||||
|
||||
private int getFileConflictOption() {
|
||||
if (fileGeneratePopulateRadio.isSelected()) return this.FILE_OPTION_POPULATE;
|
||||
if (fileGenerateEmptyRadio.isSelected()) return this.FILE_OPTION_EMPTY;
|
||||
if (fileIgnoreRadio.isSelected()) return this.FILE_OPTION_IGNORE;
|
||||
if (filePromptRadio.isSelected()) return this.FILE_OPTION_PROMPT;
|
||||
return this.FILE_OPTION_PROMPT;
|
||||
}
|
||||
|
||||
// Returns an integer mask describing the user's selection for duplicate resource key conflicts
|
||||
|
||||
private int getResourceConflictOption() {
|
||||
if (resourceOverwriteRadio.isSelected()) return this.RESOURCE_OPTION_OVERWRITE;
|
||||
if (resourceIgnoreRadio.isSelected()) return this.RESOURCE_OPTION_IGNORE;
|
||||
if (resourcePromptRadio.isSelected()) return this.RESOURCE_OPTION_PROMPT;
|
||||
return this.RESOURCE_OPTION_PROMPT;
|
||||
}
|
||||
|
||||
// Returns the group name for use when no group name is specified
|
||||
|
||||
protected String getDefaultGroup() {
|
||||
return groupComboBox.getSelectedItem().toString();
|
||||
}
|
||||
|
||||
// Returns the default translation value
|
||||
|
||||
protected boolean getDefaultTranslated() {
|
||||
return markTranslatedCheck.isSelected();
|
||||
}
|
||||
|
||||
// Returns whether or not a group of name non-existant in the active bundle is created
|
||||
|
||||
protected boolean getDefaultGroupCreation() {
|
||||
return createGroupsCheck.isSelected();
|
||||
}
|
||||
|
||||
protected void showProgressBar(int steps) {
|
||||
thisWindowClosing();
|
||||
JDialog progressBarDialog = new JDialog(this, Resources.getTranslation("dialog_title_import_progress"), false);
|
||||
JProgressBar progressBar = new JProgressBar(0, steps);
|
||||
progressBar.setValue(0);
|
||||
progressBarDialog.getContentPane().add(progressBar);
|
||||
progressBarDialog.pack();
|
||||
progressBarDialog.show();
|
||||
}
|
||||
|
||||
protected void incrementProgressBar() {
|
||||
if (progressBar == null) return;
|
||||
progressBar.setValue(progressBar.getValue()+1);
|
||||
if (progressBar.getValue() == progressBar.getMaximum()) hideProgressBar();
|
||||
}
|
||||
|
||||
protected void hideProgressBar() {
|
||||
if (progressBarDialog != null) progressBarDialog.setVisible(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the visual components for selecting an import file and setting the appropriate
|
||||
* options
|
||||
*/
|
||||
|
||||
protected void initComponents() {
|
||||
// Create Components
|
||||
JLabel titleLabel = new JLabel(title);
|
||||
sourceLabel = new JLabel(Resources.getTranslation("import_source_file","--"));
|
||||
JLabel insertGroupLabel = new JLabel(Resources.getTranslation("import_insert_group"));
|
||||
|
||||
JButton fileChooseButton = new JButton(Resources.getTranslation("button_choose"));
|
||||
JButton cancelButton = new JButton(Resources.getTranslation("button_cancel"));
|
||||
JButton importButton = new JButton(Resources.getTranslation("button_import"));
|
||||
|
||||
ButtonGroup resourceGroup = new ButtonGroup();
|
||||
ButtonGroup fileGroup = new ButtonGroup();
|
||||
|
||||
JPanel topPanel = new JPanel(new BorderLayout());
|
||||
JPanel midPanel = new JPanel(new BorderLayout());
|
||||
JPanel botPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
|
||||
|
||||
JPanel topInnerPanel = new JPanel(new BorderLayout());
|
||||
|
||||
Box midBox = new Box(BoxLayout.Y_AXIS);
|
||||
|
||||
JPanel resourcePanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
||||
JPanel filePanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
||||
JPanel defaultPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
||||
JPanel defaultPanel2 = new JPanel(new BorderLayout());
|
||||
|
||||
Box resourceBox = new Box(BoxLayout.Y_AXIS);
|
||||
Box fileBox = new Box(BoxLayout.Y_AXIS);
|
||||
Box groupBox = new Box(BoxLayout.X_AXIS);
|
||||
|
||||
// Setup title
|
||||
titleLabel.setFont(new Font("Serif",Font.BOLD,16));
|
||||
|
||||
// Setup panels
|
||||
midPanel.setBorder(BorderFactory.createTitledBorder(Resources.getTranslation("import_options")));
|
||||
resourcePanel.setBorder(BorderFactory.createTitledBorder(Resources.getTranslation("import_resource_conflicts")));
|
||||
filePanel.setBorder(BorderFactory.createTitledBorder(Resources.getTranslation("import_file_conflicts")));
|
||||
defaultPanel.setBorder(BorderFactory.createTitledBorder(Resources.getTranslation("import_default_values")));
|
||||
|
||||
// Arrange button groups
|
||||
fileGroup.add(fileGeneratePopulateRadio);
|
||||
fileGroup.add(fileGenerateEmptyRadio);
|
||||
fileGroup.add(fileIgnoreRadio);
|
||||
fileGroup.add(filePromptRadio);
|
||||
resourceGroup.add(resourceOverwriteRadio);
|
||||
resourceGroup.add(resourceIgnoreRadio);
|
||||
resourceGroup.add(resourcePromptRadio);
|
||||
|
||||
// Add action listeners
|
||||
cancelButton.addActionListener(new ActionListener(){
|
||||
public void actionPerformed(ActionEvent ev) {
|
||||
thisWindowClosing();
|
||||
}
|
||||
});
|
||||
|
||||
importButton.addActionListener(new ActionListener(){
|
||||
public void actionPerformed(ActionEvent ev) {
|
||||
try {
|
||||
beginImport();
|
||||
thisWindowClosing();
|
||||
} catch (IOException ioe) {
|
||||
JOptionPane.showMessageDialog(null,
|
||||
Resources.getTranslation("error") + "\n" + Resources.getTranslation("error"),
|
||||
Resources.getTranslation("error"), JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
fileChooseButton.addActionListener(new ActionListener(){
|
||||
public void actionPerformed(ActionEvent ev) {
|
||||
chooseFile();
|
||||
}
|
||||
});
|
||||
|
||||
// Setup combo box
|
||||
groupComboBox = new JComboBox(((Bundle)rbm.getBundles().elementAt(0)).getGroupsAsVector());
|
||||
|
||||
// Arange components
|
||||
groupBox.add(Box.createHorizontalGlue());
|
||||
groupBox.add(insertGroupLabel);
|
||||
groupBox.add(Box.createHorizontalStrut(5));
|
||||
groupBox.add(groupComboBox);
|
||||
|
||||
defaultPanel2.add(groupBox, BorderLayout.NORTH);
|
||||
defaultPanel2.add(markTranslatedCheck, BorderLayout.CENTER);
|
||||
defaultPanel2.add(createGroupsCheck, BorderLayout.SOUTH);
|
||||
|
||||
fileBox.add(fileGeneratePopulateRadio);
|
||||
fileBox.add(fileGenerateEmptyRadio);
|
||||
fileBox.add(fileIgnoreRadio);
|
||||
fileBox.add(filePromptRadio);
|
||||
|
||||
resourceBox.add(resourceOverwriteRadio);
|
||||
resourceBox.add(resourceIgnoreRadio);
|
||||
resourceBox.add(resourcePromptRadio);
|
||||
|
||||
defaultPanel.add(defaultPanel2);
|
||||
filePanel.add(fileBox);
|
||||
resourcePanel.add(resourceBox);
|
||||
|
||||
midBox.add(resourcePanel);
|
||||
midBox.add(filePanel);
|
||||
midBox.add(defaultPanel);
|
||||
|
||||
midPanel.add(midBox, BorderLayout.CENTER);
|
||||
|
||||
topInnerPanel.add(sourceLabel, BorderLayout.CENTER);
|
||||
topInnerPanel.add(fileChooseButton, BorderLayout.EAST);
|
||||
|
||||
topPanel.add(titleLabel, BorderLayout.NORTH);
|
||||
topPanel.add(topInnerPanel, BorderLayout.CENTER);
|
||||
|
||||
botPanel.add(cancelButton);
|
||||
botPanel.add(importButton);
|
||||
|
||||
getContentPane().setLayout(new BorderLayout());
|
||||
getContentPane().add(topPanel, BorderLayout.NORTH);
|
||||
getContentPane().add(midPanel, BorderLayout.CENTER);
|
||||
getContentPane().add(botPanel, BorderLayout.SOUTH);
|
||||
|
||||
pack();
|
||||
}
|
||||
|
||||
protected void thisWindowClosing() {
|
||||
setVisible(false);
|
||||
dispose();
|
||||
}
|
||||
}
|
210
tools/unicodetools/com/ibm/rbm/RBJavaExporter.java
Normal file
210
tools/unicodetools/com/ibm/rbm/RBJavaExporter.java
Normal file
@ -0,0 +1,210 @@
|
||||
/*
|
||||
*****************************************************************************
|
||||
* Copyright (C) 2000-2002, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*****************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/unicodetools/com/ibm/rbm/RBJavaExporter.java,v $
|
||||
* $Date: 2002/05/20 18:53:10 $
|
||||
* $Revision: 1.1 $
|
||||
*
|
||||
*****************************************************************************
|
||||
*/
|
||||
package com.ibm.rbm;
|
||||
|
||||
import java.io.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.*;
|
||||
import javax.swing.filechooser.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* An exporter plug-in class for RBManager. The resources exported here conform to
|
||||
* the Java standard for Resource Bundles as specified in java.util.ListResourceBundle.
|
||||
* The output files are compilable java files that are not associated with any
|
||||
* package.
|
||||
*
|
||||
* @author Jared Jackson - Email: <a href="mailto:jjared@almaden.ibm.com">jjared@almaden.ibm.com</a>
|
||||
* @see com.ibm.rbm.RBManager
|
||||
*/
|
||||
public class RBJavaExporter extends RBExporter {
|
||||
private String packageName = null;
|
||||
private boolean publicClass = true;
|
||||
private boolean publicMethods = true;
|
||||
|
||||
|
||||
public RBJavaExporter() {
|
||||
super();
|
||||
|
||||
// Initialize the file chooser if necessary
|
||||
if (chooser == null) {
|
||||
chooser = new JFileChooser();
|
||||
chooser.setFileFilter(new javax.swing.filechooser.FileFilter(){
|
||||
public String getDescription() {
|
||||
return "Java Source Files";
|
||||
}
|
||||
public boolean accept(File f) {
|
||||
if (f.isDirectory()) return true;
|
||||
if (f.getName().endsWith(".java") && f.getName().indexOf("_") < 0) return true;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
} // end if
|
||||
}
|
||||
|
||||
protected void export(RBManager rbm) throws IOException {
|
||||
if (rbm == null) return;
|
||||
// Open the additional Dialog
|
||||
RBJavaExporterDialog parametersDialog = new RBJavaExporterDialog();
|
||||
packageName = parametersDialog.getPackageName();
|
||||
publicClass = parametersDialog.isClassPublic();
|
||||
publicMethods = parametersDialog.isMethodsPublic();
|
||||
|
||||
// Open the Save Dialog
|
||||
int ret_val = chooser.showSaveDialog(null);
|
||||
if (ret_val != JFileChooser.APPROVE_OPTION) return;
|
||||
// Retrieve basic file information
|
||||
File file = chooser.getSelectedFile(); // The file(s) we will be working with
|
||||
File directory = new File(file.getParent()); // The directory we will be writing to
|
||||
String base_name = file.getName(); // The base name of the files we will write
|
||||
if (base_name == null || base_name.equals("")) base_name = rbm.getBaseClass();
|
||||
if (base_name.endsWith(".java")) base_name = base_name.substring(0,base_name.length()-5);
|
||||
|
||||
Vector bundle_v = rbm.getBundles();
|
||||
for (int i=0; i < bundle_v.size(); i++) {
|
||||
Bundle bundle = (Bundle)bundle_v.elementAt(i);
|
||||
String base_enc = base_name;
|
||||
if (bundle.encoding != null && !bundle.encoding.equals("")) base_enc = base_enc + "_" + bundle.encoding;
|
||||
String file_name = base_enc + ".java";
|
||||
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("/* File: " + file_name + "\n");
|
||||
buffer.append(" * Date: " + (new Date()) + "\n");
|
||||
buffer.append(" * Comment: This file was generated automatically by RBManager" + "\n");
|
||||
buffer.append(" */\n\n");
|
||||
if (packageName != null) {
|
||||
buffer.append("package " + packageName + ";\n\n");
|
||||
}
|
||||
buffer.append("import java.util.ListResourceBundle;\n\n");
|
||||
buffer.append((publicClass ? "public " : "protected "));
|
||||
buffer.append("class " + base_enc + " extends ListResourceBundle {\n");
|
||||
buffer.append("\t" + (publicMethods ? "public" : "protected") + " Object[][] getContents() {\n");
|
||||
buffer.append("\t\treturn contents;\n");
|
||||
buffer.append("\t}\n");
|
||||
buffer.append("\tprivate static final Object[][] contents = {\n");
|
||||
buffer.append("\t// LOCALIZE THIS\n");
|
||||
|
||||
Vector group_v = bundle.getGroupsAsVector();
|
||||
for (int j=0; j < group_v.size(); j++) {
|
||||
BundleGroup group = (BundleGroup)group_v.elementAt(j);
|
||||
Vector item_v = group.getItemsAsVector();
|
||||
for (int k=0; k < item_v.size(); k++) {
|
||||
BundleItem item = (BundleItem)item_v.elementAt(k);
|
||||
buffer.append("\t\t{\"" + item.getKey() + "\", \"" + item.getTranslation() + "\"},\t// " + item.getComment() + "\n");
|
||||
} // end for - k
|
||||
} // end for - j
|
||||
|
||||
buffer.append("\t// END OF MATERIAL TO LOCALIZE\n");
|
||||
buffer.append("\t};\n");
|
||||
buffer.append("}");
|
||||
|
||||
// Write out the file
|
||||
File write_file = new File(directory, file_name);
|
||||
FileWriter writer = new FileWriter(write_file);
|
||||
writer.write(buffer.toString());
|
||||
writer.flush();
|
||||
writer.close();
|
||||
} // end for - i
|
||||
}
|
||||
}
|
||||
|
||||
class RBJavaExporterDialog extends JDialog {
|
||||
JCheckBox packageCheck;
|
||||
JRadioButton classPublicRadio;
|
||||
JRadioButton classProtectedRadio;
|
||||
JRadioButton methodsPublicRadio;
|
||||
JRadioButton methodsProtectedRadio;
|
||||
JTextField packageField;
|
||||
|
||||
public RBJavaExporterDialog() {
|
||||
super(new JFrame(), Resources.getTranslation("dialog_title_export_java_options"), true);
|
||||
initComponents();
|
||||
}
|
||||
|
||||
public String getPackageName() {
|
||||
if (!(packageCheck.isSelected())) return null;
|
||||
String retVal = packageField.getText();
|
||||
if (retVal == null || retVal.trim().equals("")) return null;
|
||||
return retVal.trim();
|
||||
}
|
||||
|
||||
public boolean isClassPublic() {
|
||||
return classPublicRadio.isSelected();
|
||||
}
|
||||
|
||||
public boolean isMethodsPublic() {
|
||||
return methodsPublicRadio.isSelected();
|
||||
}
|
||||
|
||||
private void handleClose() {
|
||||
setVisible(false);
|
||||
dispose();
|
||||
}
|
||||
|
||||
private void initComponents() {
|
||||
getContentPane().setLayout(new BorderLayout());
|
||||
getContentPane().removeAll();
|
||||
|
||||
packageCheck = new JCheckBox(Resources.getTranslation("export_java_package"), false);
|
||||
classPublicRadio = new JRadioButton(Resources.getTranslation("export_java_class_public"), true);
|
||||
classProtectedRadio = new JRadioButton(Resources.getTranslation("export_java_class_protected"), false);
|
||||
methodsPublicRadio = new JRadioButton(Resources.getTranslation("export_java_class_public"), true);
|
||||
methodsProtectedRadio = new JRadioButton(Resources.getTranslation("export_java_class_protected"), false);
|
||||
packageField = new JTextField();
|
||||
packageField.setColumns(30);
|
||||
|
||||
JButton okButton = new JButton(Resources.getTranslation("OK"));
|
||||
JLabel titleLabel = new JLabel(Resources.getTranslation("export_java_title"), SwingConstants.LEFT);
|
||||
|
||||
JPanel okPanel = new JPanel();
|
||||
okPanel.add(okButton);
|
||||
JPanel centerPanel = new JPanel(new GridLayout(1,1));
|
||||
centerPanel.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
|
||||
Box centerBox = Box.createVerticalBox();
|
||||
Box packageBox = Box.createHorizontalBox();
|
||||
packageBox.add(packageCheck);
|
||||
packageBox.add(packageField);
|
||||
centerBox.add(packageBox);
|
||||
centerBox.add(new JSeparator());
|
||||
centerBox.add(classPublicRadio);
|
||||
centerBox.add(classProtectedRadio);
|
||||
centerBox.add(new JSeparator());
|
||||
centerBox.add(methodsPublicRadio);
|
||||
centerBox.add(methodsProtectedRadio);
|
||||
centerPanel.add(centerBox);
|
||||
|
||||
getContentPane().add(titleLabel, BorderLayout.NORTH);
|
||||
getContentPane().add(okPanel, BorderLayout.SOUTH);
|
||||
getContentPane().add(centerPanel, BorderLayout.CENTER);
|
||||
|
||||
okButton.addActionListener(new ActionListener(){
|
||||
public void actionPerformed(ActionEvent ev) {
|
||||
handleClose();
|
||||
}
|
||||
});
|
||||
|
||||
ButtonGroup classGroup = new ButtonGroup();
|
||||
ButtonGroup methodsGroup = new ButtonGroup();
|
||||
classGroup.add(classPublicRadio);
|
||||
classGroup.add(classProtectedRadio);
|
||||
methodsGroup.add(methodsPublicRadio);
|
||||
methodsGroup.add(methodsProtectedRadio);
|
||||
|
||||
//validateTree();
|
||||
pack();
|
||||
//setLocation(new Point(25,25));
|
||||
setVisible(true);
|
||||
}
|
||||
}
|
91
tools/unicodetools/com/ibm/rbm/RBJavaImporter.java
Normal file
91
tools/unicodetools/com/ibm/rbm/RBJavaImporter.java
Normal file
@ -0,0 +1,91 @@
|
||||
/*
|
||||
*****************************************************************************
|
||||
* Copyright (C) 2000-2002, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*****************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/unicodetools/com/ibm/rbm/RBJavaImporter.java,v $
|
||||
* $Date: 2002/05/20 18:53:09 $
|
||||
* $Revision: 1.1 $
|
||||
*
|
||||
*****************************************************************************
|
||||
*/
|
||||
package com.ibm.rbm;
|
||||
|
||||
|
||||
import java.io.*;
|
||||
import javax.swing.*;
|
||||
import javax.swing.filechooser.*;
|
||||
import java.util.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.net.*;
|
||||
|
||||
/**
|
||||
* This is the super class for all importer plug-in classes. As of yet, there
|
||||
* is little contained in this class.
|
||||
*
|
||||
* @author Jared Jackson - Email: <a href="mailto:jjared@almaden.ibm.com">jjared@almaden.ibm.com</a>
|
||||
* @see com.ibm.rbm.RBManager
|
||||
*/
|
||||
public class RBJavaImporter extends RBImporter {
|
||||
|
||||
public RBJavaImporter(String title, RBManager rbm, RBManagerGUI gui) {
|
||||
super(title, rbm, gui);
|
||||
}
|
||||
|
||||
protected void setupFileChooser() {
|
||||
chooser.setFileFilter(new javax.swing.filechooser.FileFilter(){
|
||||
public boolean accept(File f) {
|
||||
if (f.isDirectory()) return true;
|
||||
if (f.getName().endsWith(".class") && f.getName().indexOf("_") < 0) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return Resources.getTranslation("import_java_file_description");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected void beginImport() throws IOException {
|
||||
super.beginImport();
|
||||
ListResourceBundle base_lrb = null;
|
||||
URLClassLoader urlLoader = null;
|
||||
try {
|
||||
File baseFile = getChosenFile();
|
||||
URL baseURL = baseFile.toURL();
|
||||
URL urls[] = new URL[1];
|
||||
urls[0] = baseURL;
|
||||
urlLoader = new URLClassLoader(urls);
|
||||
String baseName = baseFile.getName();
|
||||
baseName = baseName.substring(0, baseName.indexOf(".class"));
|
||||
|
||||
Class baseClass = urlLoader.loadClass(baseName);
|
||||
base_lrb = (ListResourceBundle)baseClass.newInstance();
|
||||
} catch (Exception e) {
|
||||
RBManagerGUI.debugMsg(e.toString());
|
||||
RBManagerGUI.debugMsg(e.getMessage());
|
||||
e.printStackTrace(System.err);
|
||||
}
|
||||
if (base_lrb != null) {
|
||||
Enumeration enum = base_lrb.getKeys();
|
||||
while (enum.hasMoreElements()) {
|
||||
String key = enum.nextElement().toString();
|
||||
System.out.println("Resource -> " + key + " = " + base_lrb.getString(key));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
class myClassLoader extends ClassLoader {
|
||||
public myClassLoader() {
|
||||
super();
|
||||
}
|
||||
|
||||
public Class myDefineClass(String name, byte array[], int off, int len) {
|
||||
return super.defineClass(name, array, off, len);
|
||||
}
|
||||
}
|
||||
*/
|
1045
tools/unicodetools/com/ibm/rbm/RBManager.java
Normal file
1045
tools/unicodetools/com/ibm/rbm/RBManager.java
Normal file
File diff suppressed because it is too large
Load Diff
5154
tools/unicodetools/com/ibm/rbm/RBManagerGUI.java
Normal file
5154
tools/unicodetools/com/ibm/rbm/RBManagerGUI.java
Normal file
File diff suppressed because it is too large
Load Diff
88
tools/unicodetools/com/ibm/rbm/RBPropertiesExporter.java
Normal file
88
tools/unicodetools/com/ibm/rbm/RBPropertiesExporter.java
Normal file
@ -0,0 +1,88 @@
|
||||
/*
|
||||
*****************************************************************************
|
||||
* Copyright (C) 2000-2002, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*****************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/unicodetools/com/ibm/rbm/RBPropertiesExporter.java,v $
|
||||
* $Date: 2002/05/20 18:53:09 $
|
||||
* $Revision: 1.1 $
|
||||
*
|
||||
*****************************************************************************
|
||||
*/
|
||||
package com.ibm.rbm;
|
||||
|
||||
import java.io.*;
|
||||
import javax.swing.*;
|
||||
import javax.swing.filechooser.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* This class provides a plug-in exporter utility for RBManager that outputs Java
|
||||
* standard .properties files in the according to the file structure of Resource
|
||||
* Bundles. Most all meta-data is lost in this export.
|
||||
*
|
||||
* @author Jared Jackson - Email: <a href="mailto:jjared@almaden.ibm.com">jjared@almaden.ibm.com</a>
|
||||
* @see com.ibm.rbm.RBManager
|
||||
*/
|
||||
public class RBPropertiesExporter extends RBExporter {
|
||||
|
||||
public RBPropertiesExporter() {
|
||||
super();
|
||||
|
||||
// Initialize the file chooser if necessary
|
||||
if (chooser == null) {
|
||||
chooser = new JFileChooser();
|
||||
chooser.setFileFilter(new javax.swing.filechooser.FileFilter(){
|
||||
public String getDescription() {
|
||||
return "Base Class Properties Files";
|
||||
}
|
||||
public boolean accept(File f) {
|
||||
if (f.isDirectory()) return true;
|
||||
String name = f.getName();
|
||||
if (name.toLowerCase().endsWith(".properties") && f.getName().indexOf("_") < 0) return true;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
} // end if
|
||||
}
|
||||
|
||||
protected void export(RBManager rbm) throws IOException {
|
||||
if (rbm == null) return;
|
||||
// Open the Save Dialog
|
||||
int ret_val = chooser.showSaveDialog(null);
|
||||
if (ret_val != JFileChooser.APPROVE_OPTION) return;
|
||||
// Retrieve basic file information
|
||||
File file = chooser.getSelectedFile(); // The file(s) we will be working with
|
||||
File directory = new File(file.getParent()); // The directory we will be writing to
|
||||
String base_name = file.getName(); // The base name of the files we will write
|
||||
if (base_name == null || base_name.equals("")) base_name = rbm.getBaseClass();
|
||||
if (base_name.toLowerCase().endsWith(".properties"))
|
||||
base_name = base_name.substring(0,base_name.length()-11);
|
||||
|
||||
Vector bundle_v = rbm.getBundles();
|
||||
for (int i=0; i < bundle_v.size(); i++) {
|
||||
Properties prop = new Properties();
|
||||
Bundle bundle = (Bundle)bundle_v.elementAt(i);
|
||||
String base_enc = base_name;
|
||||
if (bundle.encoding != null && !bundle.encoding.equals("")) base_enc = base_enc + "_" + bundle.encoding;
|
||||
String file_name = base_enc + ".properties";
|
||||
String header = "Resource Bundle: " + file_name + " - File automatically generated by RBManager at " + (new Date());
|
||||
|
||||
Vector group_v = bundle.getGroupsAsVector();
|
||||
for (int j=0; j < group_v.size(); j++) {
|
||||
BundleGroup group = (BundleGroup)group_v.elementAt(j);
|
||||
Vector item_v = group.getItemsAsVector();
|
||||
for (int k=0; k < item_v.size(); k++) {
|
||||
BundleItem item = (BundleItem)item_v.elementAt(k);
|
||||
prop.setProperty(item.getKey(), item.getTranslation());
|
||||
} // end for - k
|
||||
} // end for - j
|
||||
|
||||
// Write out the file
|
||||
File write_file = new File(directory, file_name);
|
||||
FileOutputStream fos = new FileOutputStream(write_file);
|
||||
prop.store(fos, header);
|
||||
} // end for - i
|
||||
}
|
||||
}
|
125
tools/unicodetools/com/ibm/rbm/RBPropertiesImporter.java
Normal file
125
tools/unicodetools/com/ibm/rbm/RBPropertiesImporter.java
Normal file
@ -0,0 +1,125 @@
|
||||
/*
|
||||
*****************************************************************************
|
||||
* Copyright (C) 2000-2002, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*****************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/unicodetools/com/ibm/rbm/RBPropertiesImporter.java,v $
|
||||
* $Date: 2002/05/20 18:53:09 $
|
||||
* $Revision: 1.1 $
|
||||
*
|
||||
*****************************************************************************
|
||||
*/
|
||||
package com.ibm.rbm;
|
||||
|
||||
import java.io.*;
|
||||
import javax.swing.*;
|
||||
import javax.swing.filechooser.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* This is the super class for all importer plug-in classes. As of yet, there
|
||||
* is little contained in this class.
|
||||
*
|
||||
* @author Jared Jackson - Email: <a href="mailto:jjared@almaden.ibm.com">jjared@almaden.ibm.com</a>
|
||||
* @see com.ibm.rbm.RBManager
|
||||
*/
|
||||
public class RBPropertiesImporter extends RBImporter {
|
||||
|
||||
boolean isRBMFile = true;
|
||||
|
||||
/**
|
||||
* Constructs the importer given the parent data classes and a Dialog title.
|
||||
*/
|
||||
|
||||
public RBPropertiesImporter(String title, RBManager rbm, RBManagerGUI gui) {
|
||||
super(title, rbm, gui);
|
||||
}
|
||||
|
||||
protected void setupFileChooser() {
|
||||
chooser.setFileFilter(new javax.swing.filechooser.FileFilter(){
|
||||
public boolean accept(File f) {
|
||||
if (f.isDirectory()) return true;
|
||||
if (f.getName().toLowerCase().endsWith(".properties") && f.getName().indexOf("_") < 0) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return Resources.getTranslation("import_properties_file_description");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected void beginImport() throws IOException {
|
||||
super.beginImport();
|
||||
File baseFile = getChosenFile();
|
||||
FileReader fr = new FileReader(baseFile);
|
||||
BufferedReader br = new BufferedReader(fr);
|
||||
|
||||
// Test if this is an RBManager generated file or not
|
||||
int count = 0;
|
||||
String line = null;
|
||||
isRBMFile = true;
|
||||
while ((line = br.readLine()) != null) {
|
||||
if (!line.trim().equals("")) count++;
|
||||
if (count == 1 && !line.startsWith("# @file")) {
|
||||
// Not generated by RBManager
|
||||
isRBMFile = false;
|
||||
}
|
||||
} // end while
|
||||
if (isRBMFile) {
|
||||
// Treat the file as generated by RBManager
|
||||
// Parse the resource bundle through RBManager
|
||||
RBManager import_rbm = new RBManager(baseFile);
|
||||
// Merge the two resource bundles
|
||||
Vector bundles = import_rbm.getBundles();
|
||||
Vector encodings = new Vector();
|
||||
for (int i=0; i < bundles.size(); i++) {
|
||||
Bundle b = (Bundle)bundles.elementAt(i);
|
||||
encodings.addElement(b.encoding);
|
||||
}
|
||||
resolveEncodings(encodings);
|
||||
for (int i=0; i < bundles.size(); i++) {
|
||||
Bundle b = (Bundle)bundles.elementAt(i);
|
||||
Enumeration enum = b.allItems.keys();
|
||||
while (enum.hasMoreElements()) {
|
||||
String key = (String)enum.nextElement();
|
||||
BundleItem item = (BundleItem)b.allItems.get(key);
|
||||
importResource(item, b.encoding, (item.getParentGroup() == null ? getDefaultGroup(): item.getParentGroup().getName()));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Just treat it as a regular properties file
|
||||
// Check if there are any missing target locale files
|
||||
String baseName = baseFile.getName().substring(0,baseFile.getName().length()-11); // |'.properties'| == 11
|
||||
File baseDir = new File(baseFile.getParent());
|
||||
String allChildren[] = baseDir.list();
|
||||
Vector children_v = new Vector();
|
||||
for (int i=0; i < allChildren.length; i++) {
|
||||
if (allChildren[i].startsWith(baseName) && allChildren[i].toLowerCase().endsWith(".properties")) {
|
||||
if (allChildren[i].length() == (baseName + ".properties").length()) children_v.addElement("");
|
||||
else children_v.addElement(allChildren[i].substring(baseName.length()+1, allChildren[i].indexOf(".properties")));
|
||||
}
|
||||
}
|
||||
showProgressBar(children_v.size());
|
||||
resolveEncodings(children_v);
|
||||
// Run through each source locale file importing as necessary
|
||||
for (int i=0; i < children_v.size(); i++) {
|
||||
Properties p = new Properties();
|
||||
FileInputStream fis = new FileInputStream(new File(baseDir, baseName +
|
||||
(children_v.elementAt(i).toString().equals("") ? "" : "_" + children_v.elementAt(i).toString()) +
|
||||
".properties"));
|
||||
p.load(fis);
|
||||
Enumeration enum = p.keys();
|
||||
while (enum.hasMoreElements()) {
|
||||
String key = (String)enum.nextElement();
|
||||
BundleItem item = new BundleItem(null, key, p.getProperty(key));
|
||||
item.setTranslated(this.getDefaultTranslated());
|
||||
importResource(item, children_v.elementAt(i).toString(), getDefaultGroup());
|
||||
}
|
||||
incrementProgressBar();
|
||||
}
|
||||
hideProgressBar();
|
||||
}
|
||||
}
|
||||
}
|
2
tools/unicodetools/com/ibm/rbm/RBReporter.bat
Executable file
2
tools/unicodetools/com/ibm/rbm/RBReporter.bat
Executable file
@ -0,0 +1,2 @@
|
||||
@echo off
|
||||
java -classpath lib\RBManager.jar;lib\xerces.jar;. com.ibm.rbm.RBReporter %1
|
1193
tools/unicodetools/com/ibm/rbm/RBReporter.java
Normal file
1193
tools/unicodetools/com/ibm/rbm/RBReporter.java
Normal file
File diff suppressed because it is too large
Load Diff
316
tools/unicodetools/com/ibm/rbm/RBReporterScanner.java
Normal file
316
tools/unicodetools/com/ibm/rbm/RBReporterScanner.java
Normal file
@ -0,0 +1,316 @@
|
||||
/*
|
||||
*****************************************************************************
|
||||
* Copyright (C) 2000-2002, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*****************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/unicodetools/com/ibm/rbm/RBReporterScanner.java,v $
|
||||
* $Date: 2002/05/20 18:53:09 $
|
||||
* $Revision: 1.1 $
|
||||
*
|
||||
*****************************************************************************
|
||||
*/
|
||||
package com.ibm.rbm;
|
||||
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import javax.swing.event.*;
|
||||
import javax.swing.filechooser.*;
|
||||
import java.awt.event.*;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
import org.apache.xerces.parsers.*;
|
||||
import org.apache.xerces.dom.*;
|
||||
import org.apache.xml.serialize.*;
|
||||
import org.w3c.dom.*;
|
||||
import org.xml.sax.*;
|
||||
|
||||
/**
|
||||
* RBReporterScaner is a utility class for RBReporter. It creates a report from an xml settings
|
||||
* file that scans code for resources and compares them against a resource bundle.
|
||||
*
|
||||
* @author Jared Jackson - Email: <a href="mailto:jjared@almaden.ibm.com">jjared@almaden.ibm.com</a>
|
||||
* @see com.ibm.rbm.RBReporter
|
||||
*/
|
||||
public class RBReporterScanner {
|
||||
private Bundle bundle;
|
||||
private DocumentImpl config;
|
||||
private Hashtable fileRules;
|
||||
private Hashtable parseRules;
|
||||
private Hashtable results;
|
||||
private Hashtable missing;
|
||||
private boolean resultsFound;
|
||||
|
||||
protected RBReporterScanner(Bundle bundle, File configFile) throws IOException {
|
||||
resultsFound = false;
|
||||
this.bundle = bundle;
|
||||
|
||||
try {
|
||||
InputSource is = new InputSource(new FileInputStream(configFile));
|
||||
DOMParser parser = new DOMParser();
|
||||
parser.parse(is);
|
||||
config = (DocumentImpl)parser.getDocument();
|
||||
} catch (SAXException saxe) {
|
||||
throw new IOException("Illegal XML Document: " + saxe.getMessage());
|
||||
}
|
||||
|
||||
ElementImpl root = (ElementImpl)config.getDocumentElement();
|
||||
fileRules = getFileRules(root);
|
||||
parseRules = getParseRules(root);
|
||||
|
||||
results = new Hashtable();
|
||||
Enumeration enum = bundle.allItems.keys();
|
||||
while (enum.hasMoreElements()) {
|
||||
String key = (String)enum.nextElement();
|
||||
BundleItem item = (BundleItem)bundle.allItems.get(key);
|
||||
results.put(key, new ScanResult(item));
|
||||
}
|
||||
|
||||
missing = new Hashtable();
|
||||
}
|
||||
|
||||
protected int getNumberResourcesFound() {
|
||||
return results.size();
|
||||
}
|
||||
|
||||
protected int getNumberMissingResources() {
|
||||
return missing.size();
|
||||
}
|
||||
|
||||
protected int getNumberUnusedResources() {
|
||||
int count = 0;
|
||||
Enumeration enum = results.elements();
|
||||
while (enum.hasMoreElements()) {
|
||||
ScanResult result = (ScanResult)enum.nextElement();
|
||||
if (result.getOccurances().size() < 1) count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
protected Vector getMissingResources() {
|
||||
Enumeration enum = missing.elements();
|
||||
Vector v = new Vector();
|
||||
while (enum.hasMoreElements()) v.addElement(enum.nextElement());
|
||||
return v;
|
||||
}
|
||||
|
||||
protected Vector getUnusedResources() {
|
||||
Enumeration enum = results.elements();
|
||||
Vector v = new Vector();
|
||||
while (enum.hasMoreElements()) {
|
||||
ScanResult result = (ScanResult)enum.nextElement();
|
||||
if (result.getOccurances().size() < 1) {
|
||||
v.addElement(result);
|
||||
}
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
protected boolean performScan() throws IOException {
|
||||
resultsFound = false;
|
||||
|
||||
ElementImpl root = (ElementImpl)config.getDocumentElement();
|
||||
NodeList nl = root.getElementsByTagName("Scan");
|
||||
if (nl.getLength() < 1) return resultsFound;
|
||||
ElementImpl scan_elem = (ElementImpl)nl.item(0);
|
||||
nl = scan_elem.getElementsByTagName("Directory");
|
||||
for (int i=0; i < nl.getLength(); i++) {
|
||||
ElementImpl dir_elem = (ElementImpl)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);
|
||||
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);
|
||||
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);
|
||||
ParseRule prule = (ParseRule)parseRules.get(prule_elem.getAttribute("name"));
|
||||
if (prule == null) continue;
|
||||
prules_v.addElement(prule);
|
||||
}
|
||||
if (prules_v.size() < 1) continue;
|
||||
scanDirectory(directory, frule, prules_v, recurse);
|
||||
}
|
||||
}
|
||||
|
||||
return resultsFound;
|
||||
}
|
||||
|
||||
private void scanDirectory(File directory, FileRule frule, Vector prules, boolean recurse) throws IOException {
|
||||
|
||||
// Recursion step
|
||||
if (recurse) {
|
||||
File children[] = directory.listFiles(new java.io.FileFilter(){
|
||||
public boolean accept(File f) {
|
||||
if (f.isDirectory()) return true;
|
||||
else return false;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return "";
|
||||
}
|
||||
});
|
||||
for (int i=0; i < children.length; i++) {
|
||||
File new_directory = children[i];
|
||||
scanDirectory(new_directory, frule, prules, recurse);
|
||||
}
|
||||
}
|
||||
// Go through each acceptable file
|
||||
File children[] = directory.listFiles();
|
||||
for (int i=0; i < children.length; i++) {
|
||||
File f = children[i];
|
||||
if (f.isDirectory() || !(frule.applyRule(f.getName()))) continue;
|
||||
FileReader fr = new FileReader(f);
|
||||
BufferedReader br = new BufferedReader(fr);
|
||||
String line = null;
|
||||
int line_count = 0;
|
||||
// Read the file line by line
|
||||
while ((line = br.readLine()) != null) {
|
||||
line_count++;
|
||||
Vector findings = new Vector();
|
||||
// Apply all parse rules to each line
|
||||
for (int j=0; j < prules.size(); j++) {
|
||||
ParseRule prule = (ParseRule)prules.elementAt(j);
|
||||
Vector temp_results = prule.applyRule(line);
|
||||
for (int k=0; k < temp_results.size(); k++) {
|
||||
findings.addElement(temp_results.elementAt(k));
|
||||
}
|
||||
}
|
||||
for (int j=0; j < findings.size(); j++) {
|
||||
String name = (String)findings.elementAt(j);
|
||||
Occurance occ = new Occurance(f.getName(), f.getAbsolutePath(), line_count);
|
||||
// If the name is found in the resource bundles derived hashtable
|
||||
if (results.containsKey(name)) {
|
||||
ScanResult scan_res = (ScanResult)results.get(name);
|
||||
scan_res.addOccurance(occ);
|
||||
} else {
|
||||
// Add it to the missing results
|
||||
ScanResult scan_res = new ScanResult(new BundleItem(null, name, "*unknown*"));
|
||||
scan_res.addOccurance(occ);
|
||||
missing.put(name, scan_res);
|
||||
results.put(name, scan_res);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Hashtable getFileRules(ElementImpl 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);
|
||||
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);
|
||||
FileRule frule = new FileRule(elem.getAttribute("name"), elem.getAttribute("starts_with"),
|
||||
elem.getAttribute("ends_with"), elem.getAttribute("contains"));
|
||||
result.put(elem.getAttribute("name"), frule);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private Hashtable getParseRules(ElementImpl 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;
|
||||
prules_list = prules_elem.getElementsByTagName("ParseRule");
|
||||
for (int i=0; i < prules_list.getLength(); i++) {
|
||||
ElementImpl elem = (ElementImpl)prules_list.item(i);
|
||||
ParseRule prule = new ParseRule(elem.getAttribute("name"), elem.getAttribute("follows"),
|
||||
elem.getAttribute("precedes"));
|
||||
result.put(elem.getAttribute("name"), prule);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
class FileRule {
|
||||
String name;
|
||||
String starts_with;
|
||||
String ends_with;
|
||||
String contains;
|
||||
|
||||
FileRule(String name, String starts_with, String ends_with, String contains) {
|
||||
this.name = name;
|
||||
this.starts_with = starts_with;
|
||||
this.ends_with = ends_with;
|
||||
this.contains = contains;
|
||||
}
|
||||
|
||||
boolean applyRule(String source) {
|
||||
boolean accept = true;
|
||||
if (starts_with != null && starts_with.length() > 0 && !(source.startsWith(starts_with))) accept = false;
|
||||
if (ends_with != null && ends_with.length() > 0 && !(source.endsWith(ends_with))) accept = false;
|
||||
if (contains != null && contains.length() > 0 && source.indexOf(contains) < 0) accept = false;
|
||||
return accept;
|
||||
}
|
||||
}
|
||||
|
||||
class ParseRule {
|
||||
String name;
|
||||
String before;
|
||||
String after;
|
||||
|
||||
ParseRule(String name, String before, String after) {
|
||||
this.name = name;
|
||||
this.before = before;
|
||||
this.after = after;
|
||||
}
|
||||
|
||||
// returns the vector of strings found after before and before after
|
||||
|
||||
Vector applyRule(String source) {
|
||||
Vector v = new Vector();
|
||||
if (before != null && before.length() > 0) {
|
||||
if (after != null && after.length() > 0) {
|
||||
// Both before and after non-empty
|
||||
int before_index = -1;
|
||||
int after_index = -1;
|
||||
while ((before_index = source.indexOf(before, ++before_index)) >= 0) {
|
||||
//before_index = source.indexOf(before, before_index);
|
||||
after_index = -1;
|
||||
after_index = source.indexOf(after, before_index + before.length()+1);
|
||||
if (after_index < 0 || before_index < 0 || before.length() < 0) break;
|
||||
else {
|
||||
v.addElement(source.substring(before_index + before.length(), after_index));
|
||||
before_index = after_index;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Before non-empty, after empty
|
||||
int index = -1;
|
||||
while (source.indexOf(before, ++index) >= 0) {
|
||||
index = source.indexOf(before, index);
|
||||
String result = source.substring(index + before.length(), source.length());
|
||||
if (result != null && result.length() > 0) v.addElement(result);
|
||||
}
|
||||
}
|
||||
} else if (after != null && after.length() > 0) {
|
||||
// Before empty, after not
|
||||
int index = -1;
|
||||
while (source.indexOf(after, ++index) >= 0) {
|
||||
index = source.indexOf(before, index);
|
||||
String result = source.substring(0, index);
|
||||
if (result != null && result.length() > 0) v.addElement(result);
|
||||
}
|
||||
} else {
|
||||
// Before and after empty
|
||||
v.addElement(source);
|
||||
}
|
||||
return v;
|
||||
}
|
||||
}
|
232
tools/unicodetools/com/ibm/rbm/RBTMXExporter.java
Normal file
232
tools/unicodetools/com/ibm/rbm/RBTMXExporter.java
Normal file
@ -0,0 +1,232 @@
|
||||
/*
|
||||
*****************************************************************************
|
||||
* Copyright (C) 2000-2002, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*****************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/unicodetools/com/ibm/rbm/RBTMXExporter.java,v $
|
||||
* $Date: 2002/05/20 18:53:09 $
|
||||
* $Revision: 1.1 $
|
||||
*
|
||||
*****************************************************************************
|
||||
*/
|
||||
package com.ibm.rbm;
|
||||
|
||||
|
||||
import java.io.*;
|
||||
import javax.swing.*;
|
||||
import javax.swing.filechooser.*;
|
||||
import java.util.*;
|
||||
|
||||
import org.apache.xerces.parsers.*;
|
||||
import org.apache.xerces.dom.*;
|
||||
import org.apache.xml.serialize.*;
|
||||
import org.w3c.dom.*;
|
||||
|
||||
/**
|
||||
* This class is a plug-in to RBManager that allows the user to export Resource Bundles
|
||||
* along with some of the meta-data associated by RBManager to the TMX specification.
|
||||
* For more information on TMX visit the web site <A HREF=http://www.lis.org/tmx>http://www.lisa.org/tmx</A>
|
||||
*
|
||||
* @author Jared Jackson - Email: <a href="mailto:jjared@almaden.ibm.com">jjared@almaden.ibm.com</a>
|
||||
* @see com.ibm.rbm.RBManager
|
||||
*/
|
||||
public class RBTMXExporter extends RBExporter {
|
||||
private static final String VERSION = "0.5a";
|
||||
|
||||
/**
|
||||
* Default constructor for the TMX exporter.
|
||||
*/
|
||||
|
||||
public RBTMXExporter() {
|
||||
super();
|
||||
|
||||
// Initialize the file chooser if necessary
|
||||
if (chooser == null) {
|
||||
chooser = new JFileChooser();
|
||||
chooser.setFileFilter(new javax.swing.filechooser.FileFilter(){
|
||||
public String getDescription() {
|
||||
return "TMX Files";
|
||||
}
|
||||
public boolean accept(File f) {
|
||||
if (f.isDirectory()) return true;
|
||||
if (f.getName().endsWith(".tmx")) return true;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
} // end if
|
||||
}
|
||||
|
||||
private String convertToISO(Date d) {
|
||||
GregorianCalendar gc = new GregorianCalendar();
|
||||
gc.setTime(d);
|
||||
return convertToISO(gc);
|
||||
}
|
||||
|
||||
private String convertToISO(GregorianCalendar gc) {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append(String.valueOf(gc.get(Calendar.YEAR)));
|
||||
int month = gc.get(Calendar.MONTH)+1;
|
||||
buffer.append(((month < 10) ? "0" : "") + String.valueOf(month));
|
||||
int day = gc.get(Calendar.DAY_OF_MONTH);
|
||||
buffer.append(((day < 10) ? "0" : "") + String.valueOf(day));
|
||||
buffer.append("T");
|
||||
int hour = gc.get(Calendar.HOUR_OF_DAY);
|
||||
buffer.append(((hour < 10) ? "0" : "") + String.valueOf(hour));
|
||||
int minute = gc.get(Calendar.MINUTE);
|
||||
buffer.append(((minute < 10) ? "0" : "") + String.valueOf(minute));
|
||||
int second = gc.get(Calendar.SECOND);
|
||||
buffer.append(((second < 10) ? "0" : "") + String.valueOf(second));
|
||||
buffer.append("Z");
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
private String convertEncoding(BundleItem item) {
|
||||
if (item != null && item.getParentGroup() != null && item.getParentGroup().getParentBundle() != null) {
|
||||
String language = item.getParentGroup().getParentBundle().getLanguageEncoding();
|
||||
String country = item.getParentGroup().getParentBundle().getCountryEncoding();
|
||||
String variant = item.getParentGroup().getParentBundle().getVariantEncoding();
|
||||
if (language != null && !language.equals("")) {
|
||||
//language = language.toUpperCase();
|
||||
if (country != null && !country.equals("")) {
|
||||
//country = country.toUpperCase();
|
||||
if (variant != null && !variant.equals("")) {
|
||||
//variant = variant.toUpperCase();
|
||||
return language + "-" + country + "-" + variant;
|
||||
} else return language + "-" + country;
|
||||
} else return language;
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
private void appendTUV(DocumentImpl xml, Element tu, BundleItem item) {
|
||||
Element tuv = xml.createElement("tuv");
|
||||
tuv.setAttribute("lang", convertEncoding(item));
|
||||
tuv.setAttribute("creationdate",convertToISO(item.getCreatedDate()));
|
||||
tuv.setAttribute("creationid",item.getCreator());
|
||||
tuv.setAttribute("changedate",convertToISO(item.getModifiedDate()));
|
||||
tuv.setAttribute("changeid",item.getModifier());
|
||||
item.getComment();
|
||||
item.isTranslated();
|
||||
|
||||
Element comment_prop = xml.createElement("prop");
|
||||
comment_prop.appendChild(xml.createTextNode(item.getComment()));
|
||||
comment_prop.setAttribute("type","x-Comment");
|
||||
tuv.appendChild(comment_prop);
|
||||
|
||||
Element translated_prop = xml.createElement("prop");
|
||||
translated_prop.appendChild(xml.createTextNode(String.valueOf(item.isTranslated())));
|
||||
translated_prop.setAttribute("type","x-Translated");
|
||||
tuv.appendChild(translated_prop);
|
||||
|
||||
Hashtable lookups = item.getLookups();
|
||||
Enumeration enum = lookups.keys();
|
||||
while (enum.hasMoreElements()) {
|
||||
String key = (String)enum.nextElement();
|
||||
String value = (String)lookups.get(key);
|
||||
Element lookup_prop = xml.createElement("prop");
|
||||
lookup_prop.appendChild(xml.createTextNode(key + "=" + value));
|
||||
lookup_prop.setAttribute("type","x-Lookup");
|
||||
tuv.appendChild(lookup_prop);
|
||||
}
|
||||
|
||||
Element seg = xml.createElement("seg");
|
||||
seg.appendChild(xml.createTextNode(item.getTranslation()));
|
||||
tuv.appendChild(seg);
|
||||
|
||||
tu.appendChild(tuv);
|
||||
}
|
||||
|
||||
protected void export(RBManager rbm) throws IOException {
|
||||
if (rbm == null) return;
|
||||
// Open the Save Dialog
|
||||
int ret_val = chooser.showSaveDialog(null);
|
||||
if (ret_val != JFileChooser.APPROVE_OPTION) return;
|
||||
// Retrieve basic file information
|
||||
File file = chooser.getSelectedFile(); // The file(s) we will be working with
|
||||
File directory = new File(file.getParent()); // The directory we will be writing to
|
||||
String base_name = file.getName(); // The base name of the files we will write
|
||||
if (base_name == null || base_name.equals("")) base_name = rbm.getBaseClass();
|
||||
if (base_name.endsWith(".tmx")) base_name = base_name.substring(0,base_name.length()-4);
|
||||
|
||||
String file_name = base_name + ".tmx";
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
|
||||
Vector bundle_v = rbm.getBundles();
|
||||
Bundle main_bundle = (Bundle)bundle_v.elementAt(0);
|
||||
|
||||
DocumentImpl xml = new DocumentImpl();
|
||||
Element root = xml.createElement("tmx");
|
||||
root.setAttribute("version", "1.2");
|
||||
xml.appendChild(root);
|
||||
|
||||
Element header = xml.createElement("header");
|
||||
Element note = xml.createElement("note");
|
||||
note.appendChild(xml.createTextNode("This document was created automatically by RBManager"));
|
||||
header.appendChild(note);
|
||||
header.setAttribute("creationtool", "RBManager");
|
||||
header.setAttribute("creationtoolversion", VERSION);
|
||||
header.setAttribute("datatype", "PlainText");
|
||||
header.setAttribute("segtype", "sentance");
|
||||
header.setAttribute("adminlang", "en-us");
|
||||
header.setAttribute("srclang", "EN");
|
||||
header.setAttribute("o-tmf", "none");
|
||||
header.setAttribute("creationdate", convertToISO(new Date()));
|
||||
root.appendChild(header);
|
||||
|
||||
Element body = xml.createElement("body");
|
||||
root.appendChild(body);
|
||||
|
||||
Vector group_v = main_bundle.getGroupsAsVector();
|
||||
// Loop through each bundle group in main_bundle
|
||||
for (int i=0; i < group_v.size(); i++) {
|
||||
BundleGroup main_group = (BundleGroup)group_v.elementAt(i);
|
||||
// Gather a group of groups of the same name as main_group
|
||||
Vector all_groups_v = new Vector();
|
||||
for (int j=1; j < bundle_v.size(); j++) {
|
||||
Bundle bundle = (Bundle)bundle_v.elementAt(j);
|
||||
if (bundle.hasGroup(main_group.getName())) {
|
||||
Vector groups = bundle.getGroupsAsVector();
|
||||
for (int k=0; k < groups.size(); k++) {
|
||||
BundleGroup group = (BundleGroup)groups.elementAt(k);
|
||||
if (group.getName().equals(main_group.getName())) all_groups_v.addElement(group);
|
||||
}
|
||||
}
|
||||
} // end for - j
|
||||
// Loop through each item in main_group
|
||||
for (int j=0; j < main_group.getItemCount(); j++) {
|
||||
BundleItem main_item = main_group.getBundleItem(j);
|
||||
Element tu = xml.createElement("tu");
|
||||
tu.setAttribute("tuid",main_item.getKey());
|
||||
tu.setAttribute("datatype","Text");
|
||||
// Insert the group name for the item
|
||||
Element group_prop = xml.createElement("prop");
|
||||
group_prop.appendChild(xml.createTextNode(main_group.getName()));
|
||||
group_prop.setAttribute("type", "x-Group");
|
||||
tu.appendChild(group_prop);
|
||||
// Add the main_item to the xml
|
||||
appendTUV(xml, tu, main_item);
|
||||
// Loop through the rest of the groups of the same name as main_group
|
||||
for (int k=0; k < all_groups_v.size(); k++) {
|
||||
BundleGroup group = (BundleGroup)all_groups_v.elementAt(k);
|
||||
// Loop through the items in each group
|
||||
for (int l=0; l < group.getItemCount(); l++) {
|
||||
BundleItem item = group.getBundleItem(l);
|
||||
if (item.getKey().equals(main_item.getKey())) {
|
||||
appendTUV(xml, tu, item);
|
||||
break;
|
||||
}
|
||||
} // end for - l
|
||||
} // end for - k
|
||||
body.appendChild(tu);
|
||||
} // end for - j
|
||||
} // end for - i
|
||||
FileWriter fw = new FileWriter(new File(directory,file_name));
|
||||
OutputFormat of = new OutputFormat(xml);
|
||||
of.setIndenting(true);
|
||||
of.setEncoding("ISO-8859-1");
|
||||
XMLSerializer serializer = new XMLSerializer(fw, of);
|
||||
serializer.serialize(xml);
|
||||
}
|
||||
}
|
223
tools/unicodetools/com/ibm/rbm/RBTMXImporter.java
Normal file
223
tools/unicodetools/com/ibm/rbm/RBTMXImporter.java
Normal file
@ -0,0 +1,223 @@
|
||||
/*
|
||||
*****************************************************************************
|
||||
* Copyright (C) 2000-2002, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*****************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/unicodetools/com/ibm/rbm/RBTMXImporter.java,v $
|
||||
* $Date: 2002/05/20 18:53:09 $
|
||||
* $Revision: 1.1 $
|
||||
*
|
||||
*****************************************************************************
|
||||
*/
|
||||
package com.ibm.rbm;
|
||||
|
||||
import java.io.*;
|
||||
import javax.swing.*;
|
||||
import javax.swing.filechooser.*;
|
||||
import java.util.*;
|
||||
|
||||
import org.apache.xerces.parsers.*;
|
||||
import org.apache.xerces.dom.*;
|
||||
import org.apache.xml.serialize.*;
|
||||
import org.w3c.dom.*;
|
||||
import org.xml.sax.*;
|
||||
|
||||
|
||||
/**
|
||||
* This is the super class for all importer plug-in classes. This class defines the methods
|
||||
* and functionality common to all importers. This includes setting up the options dialog and
|
||||
* displaying it to the user, performing the actual insertions into the resource bundle manager,
|
||||
* and managing any import conflicts.
|
||||
*
|
||||
* @author Jared Jackson - Email: <a href="mailto:jjared@almaden.ibm.com">jjared@almaden.ibm.com</a>
|
||||
* @see com.ibm.rbm.RBManager
|
||||
*/
|
||||
public class RBTMXImporter extends RBImporter {
|
||||
|
||||
DocumentImpl tmx_xml = null;
|
||||
|
||||
/**
|
||||
* Basic constructor for the TMX importer from the parent RBManager data and a Dialog title.
|
||||
*/
|
||||
|
||||
public RBTMXImporter(String title, RBManager rbm, RBManagerGUI gui) {
|
||||
super(title, rbm, gui);
|
||||
}
|
||||
|
||||
protected void setupFileChooser() {
|
||||
chooser.setFileFilter(new javax.swing.filechooser.FileFilter(){
|
||||
public boolean accept(File f) {
|
||||
if (f.isDirectory()) return true;
|
||||
if (f.getName().endsWith(".tmx")) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return Resources.getTranslation("import_TMX_file_description");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected void beginImport() throws IOException {
|
||||
super.beginImport();
|
||||
File tmx_file = getChosenFile();
|
||||
|
||||
try {
|
||||
InputSource is = new InputSource(new FileInputStream(tmx_file));
|
||||
//is.setEncoding("UTF-8");
|
||||
DOMParser parser = new DOMParser();
|
||||
parser.parse(is);
|
||||
tmx_xml = (DocumentImpl)parser.getDocument();
|
||||
} catch (Exception e) {
|
||||
RBManagerGUI.debugMsg(e.getMessage());
|
||||
e.printStackTrace(System.err);
|
||||
}
|
||||
if (tmx_xml == null) return;
|
||||
|
||||
importDoc();
|
||||
}
|
||||
|
||||
private void importDoc() {
|
||||
if (tmx_xml == null) return;
|
||||
ElementImpl root = (ElementImpl)tmx_xml.getDocumentElement();
|
||||
Node node = root.getFirstChild();
|
||||
while (node != null && (node.getNodeType() != Node.ELEMENT_NODE || !(node.getNodeName().equalsIgnoreCase("header")))) {
|
||||
node = node.getNextSibling();
|
||||
}
|
||||
ElementImpl header = (ElementImpl)node;
|
||||
node = root.getFirstChild();
|
||||
while (node != null && (node.getNodeType() != Node.ELEMENT_NODE || !(node.getNodeName().equalsIgnoreCase("body")))) {
|
||||
node = node.getNextSibling();
|
||||
}
|
||||
ElementImpl body = (ElementImpl)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);
|
||||
// Get the key value
|
||||
String name = tu_elem.getAttribute("tuid");
|
||||
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);
|
||||
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);
|
||||
group = text_elem.getNodeValue();
|
||||
}
|
||||
}
|
||||
if (group == null || group.length() < 1) group = getDefaultGroup();
|
||||
|
||||
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);
|
||||
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] = '_';
|
||||
}
|
||||
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);
|
||||
seg_elem.normalize();
|
||||
NodeList text_list = seg_elem.getChildNodes();
|
||||
if (text_list.getLength() < 1) continue;
|
||||
TextImpl text_elem = (TextImpl)text_list.item(0);
|
||||
String value = text_elem.getNodeValue();
|
||||
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"));
|
||||
// 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);
|
||||
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);
|
||||
String comment = text_elem.getNodeValue();
|
||||
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);
|
||||
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());
|
||||
} 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_elem.getNodeValue() != null) {
|
||||
String text = text_elem.getNodeValue();
|
||||
if (text.indexOf("=") > 0) {
|
||||
try {
|
||||
if (lookups == null) lookups = new Hashtable();
|
||||
String lkey = text.substring(0,text.indexOf("="));
|
||||
String lvalue = text.substring(text.indexOf("=")+1,text.length());
|
||||
lookups.put(lkey, lvalue);
|
||||
} catch (Exception ex) { /* String out of bounds - Ignore and go on */ }
|
||||
}
|
||||
} else item.setTranslated(getDefaultTranslated());
|
||||
}
|
||||
}
|
||||
if (lookups != null) item.setLookups(lookups);
|
||||
importResource(item, encoding, group);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Vector getEncodingsVector(ElementImpl body) {
|
||||
String empty = "";
|
||||
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);
|
||||
NodeList tuv_list = tu_elem.getElementsByTagName("tuv");
|
||||
for (int j=0; j < tuv_list.getLength(); j++) {
|
||||
ElementImpl tuv_elem = (ElementImpl)tuv_list.item(j);
|
||||
String encoding = tuv_elem.getAttribute("lang");
|
||||
if (encoding == null) continue;
|
||||
char array[] = encoding.toCharArray();
|
||||
for (int k=0; k < array.length; k++) {
|
||||
if (array[k] == '-') array[k] = '_';
|
||||
}
|
||||
encoding = String.valueOf(array);
|
||||
if (!(hash.containsKey(encoding))) hash.put(encoding,empty);
|
||||
}
|
||||
}
|
||||
Vector v = new Vector();
|
||||
Enumeration enum = hash.keys();
|
||||
while (enum.hasMoreElements()) { v.addElement(enum.nextElement()); }
|
||||
return v;
|
||||
}
|
||||
}
|
220
tools/unicodetools/com/ibm/rbm/Resources.java
Normal file
220
tools/unicodetools/com/ibm/rbm/Resources.java
Normal file
@ -0,0 +1,220 @@
|
||||
/*
|
||||
*****************************************************************************
|
||||
* Copyright (C) 2000-2002, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*****************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/unicodetools/com/ibm/rbm/Resources.java,v $
|
||||
* $Date: 2002/05/20 18:53:08 $
|
||||
* $Revision: 1.1 $
|
||||
*
|
||||
*****************************************************************************
|
||||
*/
|
||||
package com.ibm.rbm;
|
||||
|
||||
|
||||
import java.io.*;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.PropertyResourceBundle;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.Locale;
|
||||
import java.util.MissingResourceException;
|
||||
|
||||
/**
|
||||
* A class not to be instantiated. Provides methods for translating items from a resource bundle. To use this class
|
||||
* make sure you first call initBundle(). Once this is done, calling any of the getTranslation() methods will return
|
||||
* the appropriate String.
|
||||
*
|
||||
* @author Jared Jackson - Email: <a href="mailto:jjared@almaden.ibm.com">jjared@almaden.ibm.com</a>
|
||||
* @see com.ibm.rbm.RBManager
|
||||
*/
|
||||
public class Resources {
|
||||
private static ResourceBundle resource_bundle;
|
||||
private static Locale locale;
|
||||
|
||||
/**
|
||||
* Initialize the properties of this resource bundle. This method must be called once before any
|
||||
* other method can be called (unless that method performs a check that calls this method). This is
|
||||
* also the method to use in case the resource data on the data store has changed and those changes
|
||||
* need to be reflected in future use of this class.
|
||||
*/
|
||||
|
||||
public static void initBundle() {
|
||||
try {
|
||||
if (locale == null) locale = Locale.getDefault();
|
||||
resource_bundle = ResourceBundle.getBundle("com/ibm/rbm/resources/RBManager", locale);
|
||||
} catch(MissingResourceException mre) {
|
||||
System.err.println("Missing Resource for default locale, " + Locale.getDefault().toString());
|
||||
mre.printStackTrace(System.err);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the locale to be used when making a query on the resource
|
||||
*/
|
||||
|
||||
public static void setLocale(Locale locale) {
|
||||
try {
|
||||
Resources.locale = locale;
|
||||
Resources.resource_bundle = ResourceBundle.getBundle("com/ibm/rbm/resources/RBManager", locale);
|
||||
} catch (MissingResourceException mre) {
|
||||
System.err.println("Missing Resource for locale, " + locale.toString());
|
||||
mre.printStackTrace(System.err);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the currently set Locales object.
|
||||
*/
|
||||
|
||||
public static Locale getLocale() {
|
||||
if (Resources.locale == null) Resources.initBundle();
|
||||
return Resources.locale;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of strings containing the locale encoding (e.g. 'en_US', 'de', etc.)
|
||||
* of the locales defined in the current resource bundle. These are all of the locales for
|
||||
* which unique translation of resource bundle items are possible. If a locale encoding is
|
||||
* used to query on that is not in this array, the base class translation will be returned.
|
||||
*/
|
||||
|
||||
public static String[] getAvailableLocales() {
|
||||
Locale loc[] = null;
|
||||
String list[] = null;
|
||||
try {
|
||||
File locDir = new File("Resources");
|
||||
list = locDir.list(new FilenameFilter() {
|
||||
public boolean accept(File dir, String name) {
|
||||
boolean accept = true;
|
||||
if (!name.toLowerCase().endsWith(".properties")) accept = false; // Must be property file
|
||||
if (!name.startsWith("RBManager")) accept = false; // Must be a RBManager file
|
||||
if (name.equals("RBManager.properties")) accept = false; // Base class does not count
|
||||
return accept;
|
||||
}
|
||||
});
|
||||
loc = new Locale[list.length];
|
||||
for (int i=0; i < list.length; i++) {
|
||||
list[i] = list[i].substring(10,list[i].length()-11);
|
||||
}
|
||||
} catch (Exception ioe) {}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Looks up a translation in the currently set Locale by the NLS lookup key provided.
|
||||
* If no resource by that key is found, the key itself is returned.
|
||||
*/
|
||||
|
||||
public static String getTranslation(String key) {
|
||||
if (key == null || resource_bundle == null) return "";
|
||||
try {
|
||||
String retStr = resource_bundle.getString(key);
|
||||
return retStr;
|
||||
} catch (Exception e) {
|
||||
return key;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a locale encoding, returns the language portion of that encoding.
|
||||
*<br>
|
||||
* For instance 'en', 'en_US', 'en_GB', all return 'en'
|
||||
*/
|
||||
|
||||
public static String getLanguage(String encoding) {
|
||||
if (encoding == null) return null;
|
||||
if (encoding.indexOf("_") < 0) return encoding.trim();
|
||||
return encoding.substring(0, encoding.indexOf("_"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a locale encoding, returns the country portion of that encoding.
|
||||
* <br>
|
||||
* For instance 'en_US', 'sp_US', both return 'US'
|
||||
* <br>
|
||||
* Returns null if no country is specified (e.g. 'en' or 'de')
|
||||
*/
|
||||
|
||||
public static String getCountry(String encoding) {
|
||||
if (encoding == null) return null;
|
||||
if (encoding.indexOf("_") < 0) return null;
|
||||
String result = encoding.substring(encoding.indexOf("_")+1, encoding.length());
|
||||
if (result.indexOf("_") < 0) return result.trim();
|
||||
return result.substring(0, encoding.indexOf("_"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a locale encoding, returns the variant portion of that encoding.
|
||||
* <br>
|
||||
* For instance 'en_GB_EURO', 'de_DE_EURO', both return 'EURO'
|
||||
* <br>
|
||||
* Returns null if no variant is specified (e.g. 'en' or 'en_US')
|
||||
*/
|
||||
|
||||
public static String getVariant(String encoding) {
|
||||
RBManagerGUI.debugMsg(encoding);
|
||||
if (encoding == null) return null;
|
||||
if (encoding.indexOf("_") < 0) return null;
|
||||
String result = encoding.substring(encoding.indexOf("_")+1, encoding.length());
|
||||
if (result.indexOf("_") < 0) return null;
|
||||
result = result.substring(result.indexOf("_")+1, result.length());
|
||||
return result.trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a translation given the currently set locale, a lookup key, and a single lookup item replacement.
|
||||
* For an understanding of the lookup item replacement see getTranslation(String key, String[] lookup).
|
||||
*/
|
||||
|
||||
public static String getTranslation(String key, String lookup) {
|
||||
if (key == null || resource_bundle == null) return "";
|
||||
try {
|
||||
Object objects[] = {lookup};
|
||||
String retStr = resource_bundle.getString(key);
|
||||
retStr = MessageFormat.format(retStr, objects);
|
||||
return retStr;
|
||||
} catch (Exception e) {
|
||||
return key;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a translation given the currently set locale, a lookup key, and zero or more lookup item replacements.
|
||||
* Lookup items are contextual translation material stored in the resource according to the format dictated in
|
||||
* the java.text package. In short, numbered markers are replaced by strings passed in as parameters.
|
||||
* <p>
|
||||
* For example, suppose you have the following resource:
|
||||
* <p>
|
||||
* myResource = Hello {1}, Isn't this a great {2}?
|
||||
* <p>
|
||||
* You want to replace the '{1}' witht the current user name and the '{2}' with the name of the day today.
|
||||
* You can do this by calling:
|
||||
* <p>
|
||||
* String lookups[] = { "Joe", "Friday" };
|
||||
* <br>
|
||||
* Resources.getTranslation("myResource", lookups);
|
||||
* <p>
|
||||
* The result would be:
|
||||
* <p>
|
||||
* 'Hello Joe, Isn't this a great Friday?'
|
||||
* <p>
|
||||
* This method (as well as the getTranslation(String key, String lookup) method) is useful for using nested
|
||||
* lookups from the resource bundle. For instance, the above line could be replaced with:
|
||||
* <p>
|
||||
* String lookups[] = { getUserName(), Resources.getTranslation("Friday") };
|
||||
*/
|
||||
|
||||
public static String getTranslation(String key, String[] lookup) {
|
||||
if (key == null || resource_bundle == null) return "";
|
||||
try {
|
||||
Object objects[] = new Object[lookup.length];
|
||||
for (int i=0; i < lookup.length; i++) objects[i] = lookup[i];
|
||||
String retStr = resource_bundle.getString(key);
|
||||
retStr = MessageFormat.format(retStr, lookup);
|
||||
return retStr;
|
||||
} catch (Exception e) {
|
||||
return key;
|
||||
}
|
||||
}
|
||||
}
|
58
tools/unicodetools/com/ibm/rbm/ScanResult.java
Normal file
58
tools/unicodetools/com/ibm/rbm/ScanResult.java
Normal file
@ -0,0 +1,58 @@
|
||||
/*
|
||||
*****************************************************************************
|
||||
* Copyright (C) 2000-2002, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*****************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/unicodetools/com/ibm/rbm/ScanResult.java,v $
|
||||
* $Date: 2002/05/20 18:53:08 $
|
||||
* $Revision: 1.1 $
|
||||
*
|
||||
*****************************************************************************
|
||||
*/
|
||||
package com.ibm.rbm;
|
||||
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* This class represents the results found for each resource key while
|
||||
* performing the code scan done by RBReporter.
|
||||
*
|
||||
* @author Jared Jackson - Email: <a href="mailto:jjared@almaden.ibm.com">jjared@almaden.ibm.com</a>
|
||||
* @see com.ibm.rbm.RBReporter
|
||||
*/
|
||||
public class ScanResult {
|
||||
BundleItem item;
|
||||
Vector occurances;
|
||||
|
||||
ScanResult(BundleItem item) {
|
||||
this.item = item;
|
||||
occurances = new Vector();
|
||||
}
|
||||
|
||||
BundleItem getItem() {
|
||||
return item;
|
||||
}
|
||||
|
||||
int getNumberOccurances() {
|
||||
return occurances.size();
|
||||
}
|
||||
|
||||
Vector getOccurances() {
|
||||
return occurances;
|
||||
}
|
||||
|
||||
void addOccurance(Occurance o) {
|
||||
occurances.addElement(o);
|
||||
}
|
||||
|
||||
String getName() {
|
||||
return item.getKey();
|
||||
}
|
||||
|
||||
String getGroupName() {
|
||||
if (item.getParentGroup() != null) return item.getParentGroup().getName();
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
25
tools/unicodetools/com/ibm/rbm/compile.bat
Executable file
25
tools/unicodetools/com/ibm/rbm/compile.bat
Executable file
@ -0,0 +1,25 @@
|
||||
@echo off
|
||||
|
||||
rem *****************************************************************************
|
||||
rem * Copyright (C) 2000-2002, International Business Machines Corporation and *
|
||||
rem * others. All Rights Reserved. *
|
||||
rem *****************************************************************************
|
||||
|
||||
cd ..\..\..\
|
||||
echo compiling source code %1
|
||||
javac -d . -classpath com/ibm/rbm/lib/xerces.jar -deprecation %1 com/ibm/rbm/*.java
|
||||
if errorlevel 1 goto error
|
||||
|
||||
echo creating jar file
|
||||
erase com\ibm\rbm\RBManager.jar
|
||||
jar cfm com/ibm/rbm/RBManager.jar com/ibm/rbm/manifest.stub com/ibm/rbm/*.class com/ibm/rbm/images/* com/ibm/rbm/resources/*
|
||||
if errorlevel 1 goto error
|
||||
|
||||
echo cleaning up class files
|
||||
cd com\ibm\rbm
|
||||
erase *.class
|
||||
goto end
|
||||
|
||||
:error
|
||||
pause
|
||||
:end
|
8
tools/unicodetools/com/ibm/rbm/createdoc.bat
Executable file
8
tools/unicodetools/com/ibm/rbm/createdoc.bat
Executable file
@ -0,0 +1,8 @@
|
||||
@rem *****************************************************************************
|
||||
@rem * Copyright (C) 2000-2002, International Business Machines Corporation and *
|
||||
@rem * others. All Rights Reserved. *
|
||||
@rem *****************************************************************************
|
||||
mkdir docs\api
|
||||
@set DOC_TYPE=-private
|
||||
javadoc -d docs/api -classpath lib/xerces.jar -sourcepath ../../../ -windowTitle "RBManager" -bottom "Copyright IBM 2000-2002" %DOC_TYPE% com.ibm.rbm
|
||||
@if errorlevel 1 pause
|
62
tools/unicodetools/com/ibm/rbm/install.bat
Executable file
62
tools/unicodetools/com/ibm/rbm/install.bat
Executable file
@ -0,0 +1,62 @@
|
||||
@echo off
|
||||
|
||||
rem *****************************************************************************
|
||||
rem * Copyright (C) 2000-2002, International Business Machines Corporation and *
|
||||
rem * others. All Rights Reserved. *
|
||||
rem *****************************************************************************
|
||||
|
||||
call compile.bat -O
|
||||
|
||||
echo * Making Directories
|
||||
|
||||
mkdir zip
|
||||
cd zip
|
||||
mkdir lib
|
||||
mkdir docs
|
||||
cd docs
|
||||
mkdir Images
|
||||
cd Images
|
||||
mkdir Screenshots
|
||||
cd ..
|
||||
mkdir Tutorial
|
||||
mkdir Views
|
||||
cd ..
|
||||
mkdir Reports
|
||||
cd ..
|
||||
|
||||
echo * Copying Files
|
||||
|
||||
echo ** Copying Batch Files and Properties
|
||||
|
||||
copy RBManager.bat zip
|
||||
copy RBManager.jar zip
|
||||
copy RBReporter.bat zip
|
||||
copy rbmanager_scanner.xml zip
|
||||
copy resources\preferences.properties zip
|
||||
attrib -r zip/preferences.properties
|
||||
|
||||
echo ** Copying Documentation
|
||||
|
||||
cd docs
|
||||
copy *.html ..\zip\docs\
|
||||
cd Images
|
||||
copy *.gif ..\..\zip\docs\Images\
|
||||
copy *.jpg ..\..\zip\docs\Images\
|
||||
cd Screenshots
|
||||
copy *.gif ..\..\..\zip\docs\Images\Screenshots\
|
||||
copy *.jpg ..\..\..\zip\docs\Images\Screenshots\
|
||||
cd ..\..\Tutorial
|
||||
copy *.html ..\..\zip\docs\Tutorial\
|
||||
cd ..\Views
|
||||
copy *.html ..\..\zip\docs\Views\
|
||||
cd ..\..
|
||||
|
||||
echo ** Copying Jar Files
|
||||
|
||||
cd lib
|
||||
copy *.jar ..\zip\lib\
|
||||
cd ..
|
||||
|
||||
@echo * Directory created: zip
|
||||
@echo ** Don't forget to modify preferences.properties
|
||||
pause
|
12
tools/unicodetools/com/ibm/rbm/manifest.stub
Normal file
12
tools/unicodetools/com/ibm/rbm/manifest.stub
Normal file
@ -0,0 +1,12 @@
|
||||
Manifest-Version: 1.0
|
||||
Specification-Title: Resource Bundle Manager
|
||||
Specification-Version: 0.6
|
||||
Specification-Vendor: IBM Corporation
|
||||
Implementation-Title: Resource Bundle Manager
|
||||
Implementation-Version: 0.6
|
||||
Implementation-Vendor: IBM Corporation
|
||||
Implementation-Vendor-Id: com.ibm
|
||||
Main-Class: com.ibm.rbm.RBManager
|
||||
Class-Path: lib/xerces.jar
|
||||
|
||||
Name: com/ibm/rbm
|
33
tools/unicodetools/com/ibm/rbm/preferences.properties
Normal file
33
tools/unicodetools/com/ibm/rbm/preferences.properties
Normal file
@ -0,0 +1,33 @@
|
||||
#RBManager Preferences
|
||||
#Fri May 10 08:57:19 PDT 2002
|
||||
reporter_format_html_file=report.html
|
||||
username=Unknown
|
||||
reporter_format_text_detail=High
|
||||
reporter_format_xml_detail=High
|
||||
reporter_format_hmtl_enabled=Yes
|
||||
reporter_enabled=Yes
|
||||
reporter_format_xml_file=report.xml
|
||||
reporter_interval_defined_hour=1
|
||||
reporter_interval_sequential_value=1
|
||||
reporter_interval_sequential_units=Hours
|
||||
reporter_perform_scan=Yes
|
||||
reporter_format_text_file=report.txt
|
||||
reporter_format_xml_enabled=Yes
|
||||
reporter_interval_defined_day=Saturday
|
||||
locale=en
|
||||
reporter_interval=Sequential
|
||||
recentfileloc3=
|
||||
recentfileloc2=
|
||||
recentfileloc1=
|
||||
recentfileloc0=
|
||||
reporter_scan_file=./rbmanager_scanner.xml
|
||||
reporter_format_html_enabled=Yes
|
||||
recentfileid3=
|
||||
recentfileid2=
|
||||
recentfileid1=
|
||||
recentfileid0=
|
||||
reporter_interval_defined_minute=00
|
||||
reporter_format_text_enabled=Yes
|
||||
reporter_base_class_file=
|
||||
reporter_output_directory=
|
||||
reporter_format_html_detail=High
|
21
tools/unicodetools/com/ibm/rbm/rbmanager_scanner.xml
Normal file
21
tools/unicodetools/com/ibm/rbm/rbmanager_scanner.xml
Normal file
@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" ?>
|
||||
<RBFileScanner name="RBManager Scanner" filename="rbmanager_scanner.xml">
|
||||
<FileRules>
|
||||
<!-- FileRules can have attributes starts_with, ends_with, and contains -->
|
||||
<FileRule name="Java File" ends_with=".java" />
|
||||
<FileRule name="XSL File" ends_with=".xsl" />
|
||||
</FileRules>
|
||||
<ParseRules>
|
||||
<!-- ParseRules can have attributes follows and precedes -->
|
||||
<ParseRule name="Java static resource" follows="Resources.getTranslation("" precedes=""" />
|
||||
</ParseRules>
|
||||
<Scan>
|
||||
<Directory location="." recurse_directories="true">
|
||||
<Rules>
|
||||
<ApplyFileRule name="Java File">
|
||||
<ApplyParseRule name="Java static resource" />
|
||||
</ApplyFileRule>
|
||||
</Rules>
|
||||
</Directory>
|
||||
</Scan>
|
||||
</RBFileScanner>
|
12
tools/unicodetools/com/ibm/rbm/readme.txt
Normal file
12
tools/unicodetools/com/ibm/rbm/readme.txt
Normal file
@ -0,0 +1,12 @@
|
||||
This directory contains the RBManager (Resource Bundle Manager)
|
||||
|
||||
To run the RBManager.jar, double click on RBManager.jar in Windows
|
||||
or run "java -jar RBManager.jar" from the command line.
|
||||
To create the RBManager.jar file, use: compile.bat
|
||||
To create the installation directory, use: install.bat
|
||||
|
||||
Help and documentation are contained in the docs directory.
|
||||
|
||||
This version of the RBManager requires version 3.1.0 of the
|
||||
xerces.jar file to compile, but does not require it for basic
|
||||
functionality.
|
Loading…
Reference in New Issue
Block a user