# HG changeset patch # User Sascha L. Teichmann # Date 1328693586 0 # Node ID 6f4a1f513e890c6ab81c55fcaf3a0ff5102e3c3a # Parent fe3ea0f1609841e84173cac7578b0a20a4e1502f Calculation error report: i18n the km of the error report. flys-artifacts/trunk@3954 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r fe3ea0f16098 -r 6f4a1f513e89 flys-artifacts/ChangeLog --- a/flys-artifacts/ChangeLog Tue Feb 07 18:12:08 2012 +0000 +++ b/flys-artifacts/ChangeLog Wed Feb 08 09:33:06 2012 +0000 @@ -1,3 +1,21 @@ +2012-02-08 Sascha L. Teichmann + + * src/main/java/de/intevation/flys/artifacts/model/Calculation.java: + i18n the km of the error report. + + * src/main/java/de/intevation/flys/artifacts/resources/Resources.java: + Fixed potential race conditions. + + * src/main/java/de/intevation/flys/utils/Formatter.java: Added + formatter for error report kms. + + * src/main/java/de/intevation/flys/exports/WaterlevelExporter.java, + src/main/java/de/intevation/flys/exports/DurationCurveExporter.java: + Removed superfluous imports. + + * src/main/java/de/intevation/flys/exports/ReferenceCurveExporter.java: + Commented out some imports. They are used be out commented code. + 2012-02-07 Ingo Weinzierl * src/main/java/de/intevation/flys/artifacts/model/LocationProvider.java: diff -r fe3ea0f16098 -r 6f4a1f513e89 flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Calculation.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Calculation.java Tue Feb 07 18:12:08 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Calculation.java Wed Feb 08 09:33:06 2012 +0000 @@ -13,6 +13,8 @@ import de.intevation.flys.artifacts.resources.Resources; +import de.intevation.flys.utils.Formatter; + public class Calculation implements Serializable { @@ -49,7 +51,9 @@ public Element toXML(Document document, CallMeta meta) { Element problem = document.createElement("problem"); if (km != null) { - problem.setAttribute("km", String.valueOf(km)); + problem.setAttribute( + "km", + Formatter.getCalculationKm(meta).format(km)); } String text = args != null ? Resources.getMsg(meta, msg, msg, args) diff -r fe3ea0f16098 -r 6f4a1f513e89 flys-artifacts/src/main/java/de/intevation/flys/artifacts/resources/Resources.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/resources/Resources.java Tue Feb 07 18:12:08 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/resources/Resources.java Wed Feb 08 09:33:06 2012 +0000 @@ -37,7 +37,7 @@ * * @return the supported locales. */ - public Locale[] getLocales() { + public synchronized Locale [] getLocales() { if (locales == null) { readLocales(); } @@ -58,10 +58,15 @@ } - public static Locale getLocale(CallMeta meta) { + private static synchronized void ensureInstance() { if (INSTANCE == null) { INSTANCE = new Resources(); } + } + + + public static Locale getLocale(CallMeta meta) { + ensureInstance(); Locale[] locales = INSTANCE.getLocales(); return meta.getPreferredLocale(locales); @@ -80,9 +85,8 @@ * @return the translated message. */ public static String getMsg(CallMeta meta, String key, String def) { - if (INSTANCE == null) { - INSTANCE = new Resources(); - } + + ensureInstance(); Locale[] locales = INSTANCE.getLocales(); Locale locale = meta.getPreferredLocale(locales); diff -r fe3ea0f16098 -r 6f4a1f513e89 flys-artifacts/src/main/java/de/intevation/flys/exports/DurationCurveExporter.java --- a/flys-artifacts/src/main/java/de/intevation/flys/exports/DurationCurveExporter.java Tue Feb 07 18:12:08 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/DurationCurveExporter.java Wed Feb 08 09:33:06 2012 +0000 @@ -16,7 +16,6 @@ import au.com.bytecode.opencsv.CSVWriter; -import java.text.NumberFormat; import net.sf.jasperreports.engine.JasperExportManager; import net.sf.jasperreports.engine.JasperFillManager; import net.sf.jasperreports.engine.JasperPrint; diff -r fe3ea0f16098 -r 6f4a1f513e89 flys-artifacts/src/main/java/de/intevation/flys/exports/ReferenceCurveExporter.java --- a/flys-artifacts/src/main/java/de/intevation/flys/exports/ReferenceCurveExporter.java Tue Feb 07 18:12:08 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/ReferenceCurveExporter.java Wed Feb 08 09:33:06 2012 +0000 @@ -5,11 +5,14 @@ import java.text.NumberFormat; import java.util.ArrayList; import java.util.List; + +/* import java.util.Map; import java.util.HashMap; import java.util.Date; import java.text.DateFormat; import java.util.Locale; +*/ import org.w3c.dom.Document; @@ -17,25 +20,32 @@ import au.com.bytecode.opencsv.CSVWriter; +/* import net.sf.jasperreports.engine.JasperExportManager; import net.sf.jasperreports.engine.JasperFillManager; import net.sf.jasperreports.engine.JasperPrint; import net.sf.jasperreports.engine.JRException; - +*/ import de.intevation.artifacts.CallContext; +/* import de.intevation.artifacts.CallMeta; import de.intevation.artifacts.common.utils.Config; +*/ import de.intevation.flys.artifacts.FLYSArtifact; +/* import de.intevation.flys.artifacts.WINFOArtifact; +*/ import de.intevation.flys.artifacts.model.CalculationResult; import de.intevation.flys.artifacts.model.WWQQ; import de.intevation.flys.artifacts.model.WKmsJRDataSource; +/* import de.intevation.flys.artifacts.resources.Resources; +import de.intevation.flys.utils.Formatter; +*/ import de.intevation.flys.utils.FLYSUtils; -import de.intevation.flys.utils.Formatter; /** * (CSV)Exporter for Reference Curves. diff -r fe3ea0f16098 -r 6f4a1f513e89 flys-artifacts/src/main/java/de/intevation/flys/exports/WaterlevelExporter.java --- a/flys-artifacts/src/main/java/de/intevation/flys/exports/WaterlevelExporter.java Tue Feb 07 18:12:08 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/WaterlevelExporter.java Wed Feb 08 09:33:06 2012 +0000 @@ -13,8 +13,6 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import java.text.NumberFormat; - import org.w3c.dom.Document; import org.apache.log4j.Logger; diff -r fe3ea0f16098 -r 6f4a1f513e89 flys-artifacts/src/main/java/de/intevation/flys/utils/Formatter.java --- a/flys-artifacts/src/main/java/de/intevation/flys/utils/Formatter.java Tue Feb 07 18:12:08 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/utils/Formatter.java Wed Feb 08 09:33:06 2012 +0000 @@ -5,12 +5,17 @@ import java.util.Locale; import de.intevation.artifacts.CallContext; +import de.intevation.artifacts.CallMeta; import de.intevation.flys.artifacts.resources.Resources; public final class Formatter { + // KMS IN ERROR REPORTS. + public static final int CALCULATION_REPORT_KM_MIN_DIGITS = 0; + public static final int CALCULATION_REPORT_KM_MAX_DIGITS = 3; + // WATERLEVEL FORMATTER CONSTANTS public static final int WATERLEVEL_KM_MIN_DIGITS = 3; public static final int WATERLEVEL_KM_MAX_DIGITS = 3; @@ -43,8 +48,8 @@ public static final int DURATION_D_MAX_DIGITS = 0; - public static NumberFormat getFormatter(CallContext c, int min, int max){ - Locale locale = Resources.getLocale(c.getMeta()); + public static NumberFormat getFormatter(CallMeta m, int min, int max){ + Locale locale = Resources.getLocale(m); NumberFormat nf = NumberFormat.getInstance(locale); nf.setMaximumFractionDigits(max); @@ -53,6 +58,10 @@ return nf; } + public static NumberFormat getFormatter(CallContext c, int min, int max){ + return getFormatter(c.getMeta(), min, max); + } + /** * Returns a number formatter with no max or min digits set. @@ -208,5 +217,12 @@ DURATION_D_MIN_DIGITS, DURATION_D_MAX_DIGITS); } + + public static NumberFormat getCalculationKm(CallMeta meta) { + return getFormatter( + meta, + CALCULATION_REPORT_KM_MIN_DIGITS, + CALCULATION_REPORT_KM_MAX_DIGITS); + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :