Mercurial > dive4elements > river
changeset 2087:bda04ae1154f
#196 Localized the WQ labels in CSV exports.
flys-artifacts/trunk@3609 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Fri, 06 Jan 2012 09:38:58 +0000 |
parents | a107b42ab553 |
children | 701658081f4f |
files | flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQ.java flys-artifacts/src/main/java/de/intevation/flys/exports/WaterlevelExporter.java flys-artifacts/src/main/java/de/intevation/flys/utils/Formatter.java |
diffstat | 4 files changed, 106 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Fri Jan 06 08:06:00 2012 +0000 +++ b/flys-artifacts/ChangeLog Fri Jan 06 09:38:58 2012 +0000 @@ -1,3 +1,17 @@ +2012-01-06 Ingo Weinzierl <ingo@intevation.de> + + flys/issue196 (i18n/l10n: Zahlenformate einheitlich) + + * src/main/java/de/intevation/flys/artifacts/model/WQ.java: New method + getRawValue() that extracts the raw double value from 'name' parameter. + + * src/main/java/de/intevation/flys/utils/Formatter.java: New method + getRawFormatter() that returns a NumberFormat instance for the current + locale. + + * src/main/java/de/intevation/flys/exports/WaterlevelExporter.java: + Localized the W/Q labels in CSV exports. + 2011-01-06 Felix Wolfsteller <felix.wolfsteller@intevation.de> flys/issue442 (i18n: Datenkorb: flood-protections)
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQ.java Fri Jan 06 08:06:00 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQ.java Fri Jan 06 09:38:58 2012 +0000 @@ -1,5 +1,8 @@ package de.intevation.flys.artifacts.model; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + import de.intevation.flys.utils.DataUtil; import gnu.trove.TDoubleArrayList; @@ -9,6 +12,10 @@ public class WQ extends NamedObjectImpl { + public static final Pattern NUMBERS_PATTERN = + Pattern.compile("\\D*(\\d++.\\d*)\\D*"); + + private static Logger logger = Logger.getLogger(WQ.class); // TODO: s/w/ws/g @@ -47,6 +54,30 @@ q = new TDoubleArrayList(qs); } + + public Double getRawValue() { + if (name == null || name.length() == 0) { + // this should never happen + return null; + } + + Matcher m = NUMBERS_PATTERN.matcher(name); + + if (m.matches()) { + String raw = m.group(1); + + try { + return Double.valueOf(raw); + } + catch (NumberFormatException nfe) { + // do nothing + } + } + + return null; + } + + public void add(double w, double q) { this.w.add(w); this.q.add(q);
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/WaterlevelExporter.java Fri Jan 06 08:06:00 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/WaterlevelExporter.java Fri Jan 06 09:38:58 2012 +0000 @@ -198,6 +198,53 @@ } + protected String getCSVRowTitle(WINFOArtifact winfo, WQKms wqkms) { + logger.debug("WaterlevelExporter.prepareNamedValue"); + + String name = wqkms.getName(); + + logger.debug("Name of WQKms = '" + name + "'"); + + WQ_MODE wqmode = FLYSUtils.getWQMode(winfo); + + if (wqmode == WQ_MODE.WFREE || wqmode == WQ_MODE.QGAUGE) { + return localizeWQKms(winfo, wqkms); + } + + Double v = wqkms.getRawValue(); + + String nmv = FLYSUtils.getNamedMainValue(winfo, v); + + if (nmv != null && nmv.length() > 0) { + nmv = FLYSUtils.stripNamedMainValue(nmv); + logger.debug("Set named main value '" + nmv + "'"); + + return nmv; + } + + return localizeWQKms(winfo, wqkms); + } + + + protected String localizeWQKms(WINFOArtifact winfo, WQKms wqkms) { + WQ_MODE wqmode = FLYSUtils.getWQMode(winfo); + Double rawValue = wqkms.getRawValue(); + + if (rawValue == null) { + return wqkms.getName(); + } + + NumberFormat nf = Formatter.getRawFormatter(context); + + if (wqmode == WQ_MODE.WFREE || wqmode == WQ_MODE.WGAUGE) { + return "W=" + nf.format(rawValue); + } + else { + return "Q=" + nf.format(rawValue); + } + } + + @Override protected void writeCSVData(CSVWriter writer) { logger.info("WaterlevelExporter.writeData"); @@ -383,7 +430,7 @@ double b = gauge.getRange().getB().doubleValue(); if (flys instanceof WINFOArtifact && isQ) { - desc = getColumnTitle((WINFOArtifact)flys, wqkms); + desc = getCSVRowTitle((WINFOArtifact)flys, wqkms); } else if (!isQ) { Double value = FLYSUtils.getValueFromWQ(wqkms);
--- a/flys-artifacts/src/main/java/de/intevation/flys/utils/Formatter.java Fri Jan 06 08:06:00 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/utils/Formatter.java Fri Jan 06 09:38:58 2012 +0000 @@ -47,6 +47,19 @@ /** + * Returns a number formatter with no max or min digits set. + * + * @param c The CallContext. + * + * @return a number formatter. + */ + public static NumberFormat getRawFormatter(CallContext c) { + Locale locale = Resources.getLocale(c.getMeta()); + return NumberFormat.getInstance(locale); + } + + + /** * Returns the number formatter for kilometer values in waterlevel exports. * * @return the number formatter for kilometer values.