Mercurial > hg > release > thermostat-0.9
changeset 1090:9372e2088954
Localization of errors during validation
Reviewed-by: neugens, jerboaa, omajid
Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2013-May/006537.html
author | Giovanni Astarita <gastarit@redhat.com> |
---|---|
date | Thu, 16 May 2013 14:22:47 +0200 |
parents | 6458910333b7 |
children | cc4b35354a39 |
files | launcher/src/main/java/com/redhat/thermostat/launcher/internal/LocaleResources.java launcher/src/main/java/com/redhat/thermostat/launcher/internal/PluginConfigurationParser.java launcher/src/main/resources/com/redhat/thermostat/launcher/internal/strings.properties |
diffstat | 3 files changed, 32 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/launcher/src/main/java/com/redhat/thermostat/launcher/internal/LocaleResources.java Thu May 16 12:39:05 2013 +0200 +++ b/launcher/src/main/java/com/redhat/thermostat/launcher/internal/LocaleResources.java Thu May 16 14:22:47 2013 +0200 @@ -51,6 +51,10 @@ OPTION_DB_URL_DESC, OPTION_LOG_LEVEL_DESC, + + VALIDATION_WARNING, + VALIDATION_ERROR, + VALIDATION_FATAL_ERROR ; static final String RESOURCE_BUNDLE = "com.redhat.thermostat.launcher.internal.strings";
--- a/launcher/src/main/java/com/redhat/thermostat/launcher/internal/PluginConfigurationParser.java Thu May 16 12:39:05 2013 +0200 +++ b/launcher/src/main/java/com/redhat/thermostat/launcher/internal/PluginConfigurationParser.java Thu May 16 14:22:47 2013 +0200 @@ -48,7 +48,9 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.logging.Logger; import javax.xml.parsers.DocumentBuilder; @@ -70,6 +72,7 @@ import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; +import com.redhat.thermostat.common.locale.Translate; import com.redhat.thermostat.common.utils.LoggingUtils; import com.redhat.thermostat.launcher.internal.PluginConfiguration.CommandExtensions; import com.redhat.thermostat.launcher.internal.PluginConfiguration.NewCommand; @@ -533,28 +536,35 @@ private static class ConfigurationValidatorErrorHandler implements ErrorHandler { private int warningsErrorsCounter = 0; + private static final Translate<LocaleResources> translator = LocaleResources.createLocalizer(); + + private enum ErrorType { + WARNING, + ERROR, + FATAL_ERROR; + } @Override public void warning(SAXParseException exception) throws SAXException { warningsErrorsCounter++; - printInfo(exception, "Warning"); + printInfo(exception, ErrorType.WARNING); } @Override public void error(SAXParseException exception) throws SAXParseException { warningsErrorsCounter++; - printInfo(exception, "Error"); + printInfo(exception, ErrorType.ERROR); } @Override public void fatalError(SAXParseException exception) throws SAXParseException { if (warningsErrorsCounter == 0) { - printInfo(exception, "Fatal error"); + printInfo(exception, ErrorType.FATAL_ERROR); logger.warning("XML not well formed"); } } - private static void printInfo(SAXParseException e, String errorType) { + private static void printInfo(SAXParseException e, ErrorType type) { int columnNumber = e.getColumnNumber(); int lineNumber = e.getLineNumber(); @@ -568,6 +578,11 @@ String absolutePath = e.getSystemId(); absolutePath = absolutePath.substring(5); + Map<ErrorType,LocaleResources> translateKeys = new HashMap<>(); + translateKeys.put(ErrorType.ERROR, LocaleResources.VALIDATION_ERROR); + translateKeys.put(ErrorType.WARNING, LocaleResources.VALIDATION_WARNING); + translateKeys.put(ErrorType.FATAL_ERROR, LocaleResources.VALIDATION_FATAL_ERROR); + try { BufferedReader br = new BufferedReader(new FileReader(absolutePath)); for (int i = 1; i < lineNumber-3; i++) { @@ -587,7 +602,12 @@ System.out.println("File not found!");; } - buffer.append(errorType + " in file " + absolutePath + ":" + lineNumber + "." + columnNumber + "\n"); + buffer.append(translator.localize( + translateKeys.get(type), + absolutePath, + Integer.toString(lineNumber), + Integer.toString(columnNumber))); + buffer.append(formatMessage(e.getLocalizedMessage()) + "\n\n"); buffer.append(firstLine + "\n"); buffer.append(secondLine + "\n"); @@ -596,7 +616,6 @@ buffer.append(pointer + "\n"); logger.warning("\n" + buffer.toString()); - } private static String formatMessage(String message) {
--- a/launcher/src/main/resources/com/redhat/thermostat/launcher/internal/strings.properties Thu May 16 12:39:05 2013 +0200 +++ b/launcher/src/main/resources/com/redhat/thermostat/launcher/internal/strings.properties Thu May 16 14:22:47 2013 +0200 @@ -12,3 +12,6 @@ for <logLevel> in decreasing severity are: SEVERE, WARNING, INFO, CONFIG, FINE, \ FINER, FINEST and OFF +VALIDATION_WARNING = Warning in file {0}:{1}.{2}\n +VALIDATION_ERROR = Error in file {0}:{1}.{2}\n +VALIDATION_FATAL_ERROR = Fatal error in file {0}:{1}.{2}\n