org.jfree.report.modules.gui.base.resources
public final class: ResourceCompareTool [javadoc |
source]
java.lang.Object
org.jfree.report.modules.gui.base.resources.ResourceCompareTool
The ResourceCompareTool provides simple reporting capabilities to compare a
localized resource bundle with the default resource bundle.
This report contains all keys, which are undefined in the localisation, which
are defined with an incompabile object value or which are not defined in the
default resource bundle, but defined in the localized version.
Using the automated comparing will help to make translations more easier.
| Method from org.jfree.report.modules.gui.base.resources.ResourceCompareTool Summary: |
|---|
|
executeTest, main |
| Method from org.jfree.report.modules.gui.base.resources.ResourceCompareTool Detail: |
public static void executeTest(String base,
String locale) {
final JFreeReportResources resources = loadLocale(base, null);
final JFreeReportResources compare = loadLocale(base, locale);
if (compare == null)
{
System.err.println("The locale " + locale + " is not implemented.");
System.exit(1);
}
final Object[][] contentsRes = resources.getContents();
final Object[][] contentsComp = compare.getContents();
if (compare.getContents() == null)
{
throw new IllegalArgumentException("The given localisation is not a valid implementation");
}
final Hashtable baseContentTable = new Hashtable();
final Hashtable compContentTable = new Hashtable();
for (int i = 0; i < contentsRes.length; i++)
{
final String name = (String) contentsRes[i][0];
final Object value = contentsRes[i][1];
baseContentTable.put(name, value);
}
for (int i = 0; i < contentsComp.length; i++)
{
final String name = (String) contentsComp[i][0];
final Object value = contentsComp[i][1];
compContentTable.put(name, value);
}
final ArrayList notImplemented = new ArrayList();
final ArrayList wrongType = new ArrayList();
final ArrayList invalidKey = new ArrayList();
Enumeration en = baseContentTable.keys();
while (en.hasMoreElements())
{
final String key = (String) en.nextElement();
final Object valueBase = baseContentTable.get(key);
final Object valueComp = compContentTable.get(key);
if (valueComp == null)
{
notImplemented.add(key);
}
else if (valueBase.getClass().isAssignableFrom(valueComp.getClass()) == false)
{
wrongType.add(key);
}
}
en = compContentTable.keys();
while (en.hasMoreElements())
{
final String key = (String) en.nextElement();
final Object valueBase = baseContentTable.get(key);
if (valueBase == null)
{
invalidKey.add(key);
}
}
Collections.sort(wrongType);
Collections.sort(invalidKey);
Collections.sort(notImplemented);
System.out.println("The following keys return values, which are not of the same baseclass as "
+ "the original key.");
for (int i = 0; i < wrongType.size(); i++)
{
System.out.println(wrongType.get(i));
}
System.out.println("---------------------------------------");
System.out.println(" " + wrongType.size() + " elements listed ");
System.out.println("---------------------------------------\n\n");
System.out.println("The following keys are not implemented by the localisation.");
System.out.println("This does not always indicate an error, if the key does not need to be "
+ "translated.");
for (int i = 0; i < notImplemented.size(); i++)
{
System.out.println(notImplemented.get(i));
}
System.out.println("---------------------------------------");
System.out.println(" " + notImplemented.size() + " elements listed ");
System.out.println("---------------------------------------\n\n");
System.out.println("The following are invalid. These keys are not implemented by the base "
+ "class.");
for (int i = 0; i < invalidKey.size(); i++)
{
System.out.println(invalidKey.get(i));
}
System.out.println("---------------------------------------");
System.out.println(" " + invalidKey.size() + " elements listed ");
System.out.println("---------------------------------------\n\n");
System.exit(0);
}
Executes the test for the given localisation. This compares that all defined values
are valid and that no extra keys are defined. It also prints some status information
that may be helpfull to verify the integrity of the translation. |
public static void main(String[] args) {
if (args.length != 2)
{
throw new IllegalArgumentException("Need locale identifier as argument.");
}
executeTest(args[0], args[1]);
}
Starts the resource comparing process. |