# HG changeset patch # User Christian Lins # Date 1347716564 0 # Node ID 04309ca24614ef1852637d9836f44a65a17507e4 # Parent 6a08f4dc790b2e5810f412036f47568cd771eb74 Locales fix flys-artifacts/trunk@5476 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 6a08f4dc790b -r 04309ca24614 flys-artifacts/ChangeLog --- a/flys-artifacts/ChangeLog Sat Sep 15 07:07:51 2012 +0000 +++ b/flys-artifacts/ChangeLog Sat Sep 15 13:42:44 2012 +0000 @@ -1,3 +1,11 @@ +2012-09-15 Christian Lins + + * src/main/java/de/intevation/flys/artifacts/resources/Resources.java, + src/main/java/de/intevation/flys/utils/Formatter.java, + src/main/java/de/intevation/flys/exports/CrossSectionGenerator.java: + i18n messages are now formatted with correct (client) locale, not + server VM locale (#852).. + 2012-09-15 Christian Lins * doc/conf/artifacts/fixanalysis.xml, diff -r 6a08f4dc790b -r 04309ca24614 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 Sat Sep 15 07:07:51 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/resources/Resources.java Sat Sep 15 13:42:44 2012 +0000 @@ -85,7 +85,6 @@ * @return the translated message. */ public static String getMsg(CallMeta meta, String key, String def) { - ensureInstance(); Locale[] locales = INSTANCE.getLocales(); @@ -95,10 +94,10 @@ } public static String getMsg( - CallMeta meta, - String key, - Object[] args - ) { + CallMeta meta, + String key, + Object[] args + ) { return getMsg(meta, key, key, args); } @@ -114,10 +113,10 @@ * @return a translated string. */ public static String getMsg( - CallMeta meta, - String key, - String def, - Object[] args) + CallMeta meta, + String key, + String def, + Object[] args) { String template = getMsg(meta, key, (String)null); @@ -125,22 +124,33 @@ return def; } - return MessageFormat.format(template, args); + return format(meta, template, args); } public static String format( - CallMeta meta, - String key, - String def, - Object ... args - ) { + CallMeta meta, + String key, + String def, + Object ... args + ) { String template = getMsg(meta, key, (String)null); if (template == null) { template = def; } - return MessageFormat.format(template, args); + return format(meta, template, args); + } + + /** + * Formats the given template using the arguments with respect of the + * appropriate locale given by the CallMeta instance. + */ + public static String format(CallMeta meta, String templ, Object ... args) { + Locale locale = getLocale(meta); + MessageFormat mf = new MessageFormat(templ, locale); + + return mf.format(args, new StringBuffer(), null).toString(); } /** diff -r 6a08f4dc790b -r 04309ca24614 flys-artifacts/src/main/java/de/intevation/flys/exports/CrossSectionGenerator.java --- a/flys-artifacts/src/main/java/de/intevation/flys/exports/CrossSectionGenerator.java Sat Sep 15 07:07:51 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/CrossSectionGenerator.java Sat Sep 15 13:42:44 2012 +0000 @@ -1,20 +1,5 @@ package de.intevation.flys.exports; -import de.intevation.artifactdatabase.state.ArtifactAndFacet; -import de.intevation.artifacts.DataProvider; -import de.intevation.flys.artifacts.geom.Lines; -import de.intevation.flys.artifacts.model.CrossSectionFacet; -import de.intevation.flys.artifacts.model.FacetTypes; -import de.intevation.flys.artifacts.model.HYKFactory; -import de.intevation.flys.jfree.FLYSAnnotation; -import de.intevation.flys.jfree.StyledXYSeries; -import de.intevation.flys.model.FastCrossSectionLine; -import de.intevation.flys.themes.LineStyle; -import de.intevation.flys.themes.TextStyle; -import de.intevation.flys.themes.ThemeAccess; -import de.intevation.flys.utils.Formatter; -import de.intevation.flys.utils.ThemeUtil; - import java.awt.BasicStroke; import java.awt.Color; import java.awt.Paint; @@ -30,6 +15,22 @@ import org.jfree.data.xy.XYSeries; import org.w3c.dom.Document; +import de.intevation.artifactdatabase.state.ArtifactAndFacet; +import de.intevation.artifacts.DataProvider; +import de.intevation.flys.artifacts.geom.Lines; +import de.intevation.flys.artifacts.model.CrossSectionFacet; +import de.intevation.flys.artifacts.model.FacetTypes; +import de.intevation.flys.artifacts.model.HYKFactory; +import de.intevation.flys.artifacts.resources.Resources; +import de.intevation.flys.jfree.FLYSAnnotation; +import de.intevation.flys.jfree.StyledXYSeries; +import de.intevation.flys.model.FastCrossSectionLine; +import de.intevation.flys.themes.LineStyle; +import de.intevation.flys.themes.TextStyle; +import de.intevation.flys.themes.ThemeAccess; +import de.intevation.flys.utils.Formatter; +import de.intevation.flys.utils.ThemeUtil; + /** * An OutGenerator that generates cross section graphs. @@ -40,19 +41,19 @@ { /** The logger that is used in this generator. */ private static Logger logger = - Logger.getLogger(CrossSectionGenerator.class); + Logger.getLogger(CrossSectionGenerator.class); public static final String I18N_CHART_TITLE = - "chart.cross_section.title"; + "chart.cross_section.title"; public static final String I18N_CHART_SUBTITLE = - "chart.cross_section.subtitle"; + "chart.cross_section.subtitle"; public static final String I18N_XAXIS_LABEL = - "chart.cross_section.xaxis.label"; + "chart.cross_section.xaxis.label"; public static final String I18N_YAXIS_LABEL = - "chart.cross_section.yaxis.label"; + "chart.cross_section.yaxis.label"; public static final String I18N_CHART_TITLE_DEFAULT = "Querprofildiagramm"; public static final String I18N_XAXIS_LABEL_DEFAULT = "Abstand [m]"; @@ -88,7 +89,7 @@ @Override public String getDefaultChartTitle() { Object[] i18n_msg_args = new Object[] { - getRiverName() + getRiverName() }; return msg(I18N_CHART_TITLE, I18N_CHART_TITLE_DEFAULT, i18n_msg_args); } @@ -110,20 +111,22 @@ @Override protected String getDefaultChartSubtitle() { List providers = - context.getDataProvider(CrossSectionFacet.BLACKBOARD_CS_MASTER_DATA); + context.getDataProvider(CrossSectionFacet.BLACKBOARD_CS_MASTER_DATA); double km = 0d; if (providers.size() > 0) { FastCrossSectionLine csl = (FastCrossSectionLine) providers.get(0). - provideData(CrossSectionFacet.BLACKBOARD_CS_MASTER_DATA, - null, context); + provideData(CrossSectionFacet.BLACKBOARD_CS_MASTER_DATA, + null, context); km = csl == null ? -1 : csl.getKm(); } Object[] args = new Object[] { - getRiverName(), - km + getRiverName(), + km }; + logger.debug("Locale: " + Resources.getLocale(context.getMeta())); + return msg(I18N_CHART_SUBTITLE, "", args); } @@ -166,8 +169,8 @@ // OPTMIMIZE: Pre-calculate positions ChartArea area = new ChartArea( - plot.getDomainAxis(0).getRange(), - plot.getRangeAxis().getRange()); + plot.getDomainAxis(0).getRange(), + plot.getRangeAxis().getRange()); for(FLYSAnnotation fa : this.annotations) { @@ -203,13 +206,13 @@ fillPaint = colorForHYKZone(zone.getName()); XYBoxAnnotation boxA = new XYBoxAnnotation(zone.getFrom(), area.atGround(), - zone.getTo(), area.ofGround(0.03f), basicStroke, tranPaint, fillPaint); + zone.getTo(), area.ofGround(0.03f), basicStroke, tranPaint, fillPaint); XYBoxAnnotation boxB = new XYBoxAnnotation(zone.getFrom(), area.atGround(), - zone.getTo(), area.atTop(), basicStroke, fillPaint, tranPaint); + zone.getTo(), area.atTop(), basicStroke, fillPaint, tranPaint); XYTextAnnotation tex = new XYTextAnnotation(zone.getName(), - zone.getFrom() + (zone.getTo() - zone.getFrom()) / 1.0d, - area.ofGround(0.015f)); + zone.getFrom() + (zone.getTo() - zone.getFrom()) / 1.0d, + area.ofGround(0.015f)); if (textStyle != null) { textStyle.apply(tex); } @@ -238,10 +241,10 @@ */ @Override public void doOut( - ArtifactAndFacet artifactFacet, - Document attr, - boolean visible - ) { + ArtifactAndFacet artifactFacet, + Document attr, + boolean visible + ) { String name = artifactFacet.getFacetName(); logger.debug("CrossSectionGenerator.doOut: " + name); @@ -253,41 +256,41 @@ if (name.equals(CROSS_SECTION)) { doCrossSectionOut( - artifactFacet.getData(context), - artifactFacet.getFacetDescription(), - attr, - visible); + artifactFacet.getData(context), + artifactFacet.getFacetDescription(), + attr, + visible); } else if (name.equals(CROSS_SECTION_WATER_LINE)) { doCrossSectionWaterLineOut( - artifactFacet.getData(context), - artifactFacet.getFacetDescription(), - attr, - visible); + artifactFacet.getData(context), + artifactFacet.getFacetDescription(), + attr, + visible); } else if (FacetTypes.IS.AREA(name)) { doArea(artifactFacet.getData(context), - artifactFacet, - attr, - visible); + artifactFacet, + attr, + visible); } else if (name.equals(HYK)) { doHyk(artifactFacet.getData(context), - artifactFacet.getFacetDescription(), - attr, - visible); + artifactFacet.getFacetDescription(), + attr, + visible); } else if (FacetTypes.IS.MANUALLINE(name)) { doCrossSectionWaterLineOut( - artifactFacet.getData(context), - artifactFacet.getFacetDescription(), - attr, - visible); + artifactFacet.getData(context), + artifactFacet.getFacetDescription(), + attr, + visible); } else if (FacetTypes.IS.MANUALPOINTS(name)) { doPoints(artifactFacet.getData(context), - artifactFacet, - attr, visible, YAXIS.W.idx); + artifactFacet, + attr, visible, YAXIS.W.idx); } else { logger.warn("CrossSection.doOut: Unknown facet name: " + name); @@ -311,11 +314,11 @@ * @param theme Theme for the data series. */ protected void doCrossSectionWaterLineOut( - Object o, - String seriesName, - Document theme, - boolean visible - ) { + Object o, + String seriesName, + Document theme, + boolean visible + ) { logger.debug("CrossSectionGenerator.doCrossSectionWaterLineOut"); Lines.LineData lines = (Lines.LineData) o; @@ -329,7 +332,7 @@ NumberFormat nf = Formatter.getMeterFormat(this.context); String labelAdd = "b=" + nf.format(lines.width) + "m"; if (series.getLabel().length() == 0) { - series.setLabel(labelAdd); + series.setLabel(labelAdd); } else { series.setLabel(series.getLabel() + ", " + labelAdd); @@ -340,7 +343,7 @@ NumberFormat nf = Formatter.getMeterFormat(this.context); String labelAdd = "W=" + nf.format(lines.points[1][0]) + "NN+m"; if (series.getLabel().length() == 0) { - series.setLabel(labelAdd); + series.setLabel(labelAdd); } else { series.setLabel(series.getLabel() + ", " + labelAdd); @@ -349,9 +352,9 @@ if (ThemeUtil.parseShowMiddleHeight(theme) && lines.width != 0) { NumberFormat nf = Formatter.getMeterFormat(this.context); String labelAdd = "T=" + nf.format(lines.area / lines.width) + "m"; - // : " + lines.area + "/" + lines.width); + // : " + lines.area + "/" + lines.width); if (series.getLabel().length() == 0) { - series.setLabel(labelAdd); + series.setLabel(labelAdd); } else { series.setLabel(series.getLabel() + ", " + labelAdd); @@ -366,11 +369,11 @@ /** Add HYK-Annotations (colorize and label some areas, draw lines. */ protected void doHyk( - Object o, - String seriesName, - Document theme, - boolean visible - ) { + Object o, + String seriesName, + Document theme, + boolean visible + ) { logger.debug("CrossSectionGenerator.doHyk"); List zones = (List) o; @@ -394,11 +397,11 @@ * @param theme Theme for the data series. */ protected void doCrossSectionOut( - Object o, - String seriesName, - Document theme, - boolean visible - ) { + Object o, + String seriesName, + Document theme, + boolean visible + ) { logger.debug("CrossSectionGenerator.doCrossSectionOut"); XYSeries series = new StyledXYSeries(seriesName, theme); diff -r 6a08f4dc790b -r 04309ca24614 flys-artifacts/src/main/java/de/intevation/flys/utils/Formatter.java --- a/flys-artifacts/src/main/java/de/intevation/flys/utils/Formatter.java Sat Sep 15 07:07:51 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/utils/Formatter.java Sat Sep 15 13:42:44 2012 +0000 @@ -1,15 +1,13 @@ package de.intevation.flys.utils; -import de.intevation.artifacts.CallContext; -import de.intevation.artifacts.CallMeta; - -import de.intevation.flys.artifacts.resources.Resources; - import java.text.DateFormat; import java.text.NumberFormat; import java.text.SimpleDateFormat; +import java.util.Locale; -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 { @@ -81,7 +79,7 @@ public static final int FIX_DELTA_W_DELTA_Q_MAX_DIGITS = 2; /** - * Creates a localised NumberFormatter with given range of decimal digits. + * Creates a localized NumberFormatter with given range of decimal digits. * @param m CallMeta to find the locale. * @param min minimum number of decimal ("fraction") digits. * @param max maximum number of decimal ("fraction") digits. @@ -141,16 +139,16 @@ */ public static NumberFormat getWaterlevelKM(CallContext context) { return getFormatter( - context, - WATERLEVEL_KM_MIN_DIGITS, - WATERLEVEL_KM_MAX_DIGITS); + context, + WATERLEVEL_KM_MIN_DIGITS, + WATERLEVEL_KM_MAX_DIGITS); } public static NumberFormat getWaterlevelW(CallMeta meta) { return getFormatter( - meta, - WATERLEVEL_W_MIN_DIGITS, - WATERLEVEL_W_MAX_DIGITS); + meta, + WATERLEVEL_W_MIN_DIGITS, + WATERLEVEL_W_MAX_DIGITS); } /** @@ -160,9 +158,9 @@ */ public static NumberFormat getWaterlevelW(CallContext context) { return getFormatter( - context, - WATERLEVEL_W_MIN_DIGITS, - WATERLEVEL_W_MAX_DIGITS); + context, + WATERLEVEL_W_MIN_DIGITS, + WATERLEVEL_W_MAX_DIGITS); } @@ -173,16 +171,16 @@ */ public static NumberFormat getWaterlevelQ(CallContext context) { return getFormatter( - context, - WATERLEVEL_Q_MIN_DIGITS, - WATERLEVEL_Q_MAX_DIGITS); + context, + WATERLEVEL_Q_MIN_DIGITS, + WATERLEVEL_Q_MAX_DIGITS); } public static NumberFormat getWaterlevelQ(CallMeta meta) { return getFormatter( - meta, - WATERLEVEL_Q_MIN_DIGITS, - WATERLEVEL_Q_MAX_DIGITS); + meta, + WATERLEVEL_Q_MIN_DIGITS, + WATERLEVEL_Q_MAX_DIGITS); } /** @@ -193,9 +191,9 @@ */ public static NumberFormat getComputedDischargeW(CallContext context) { return getFormatter( - context, - COMPUTED_DISCHARGE_W_MIN_DIGITS, - COMPUTED_DISCHARGE_W_MAX_DIGITS); + context, + COMPUTED_DISCHARGE_W_MIN_DIGITS, + COMPUTED_DISCHARGE_W_MAX_DIGITS); } @@ -207,9 +205,9 @@ */ public static NumberFormat getComputedDischargeQ(CallContext context) { return getFormatter( - context, - COMPUTED_DISCHARGE_Q_MIN_DIGITS, - COMPUTED_DISCHARGE_Q_MAX_DIGITS); + context, + COMPUTED_DISCHARGE_Q_MIN_DIGITS, + COMPUTED_DISCHARGE_Q_MAX_DIGITS); } @@ -221,9 +219,9 @@ */ public static NumberFormat getHistoricalDischargeW(CallContext context) { return getFormatter( - context, - HISTORICAL_DISCHARGE_W_MIN_DIGITS, - HISTORICAL_DISCHARGE_W_MAX_DIGITS); + context, + HISTORICAL_DISCHARGE_W_MIN_DIGITS, + HISTORICAL_DISCHARGE_W_MAX_DIGITS); } @@ -235,9 +233,9 @@ */ public static NumberFormat getHistoricalDischargeQ(CallContext context) { return getFormatter( - context, - HISTORICAL_DISCHARGE_Q_MIN_DIGITS, - HISTORICAL_DISCHARGE_Q_MAX_DIGITS); + context, + HISTORICAL_DISCHARGE_Q_MIN_DIGITS, + HISTORICAL_DISCHARGE_Q_MAX_DIGITS); } @@ -248,9 +246,9 @@ */ public static NumberFormat getDurationW(CallContext context) { return getFormatter( - context, - DURATION_W_MIN_DIGITS, - DURATION_W_MAX_DIGITS); + context, + DURATION_W_MIN_DIGITS, + DURATION_W_MAX_DIGITS); } @@ -261,9 +259,9 @@ */ public static NumberFormat getDurationQ(CallContext context) { return getFormatter( - context, - DURATION_Q_MIN_DIGITS, - DURATION_Q_MAX_DIGITS); + context, + DURATION_Q_MIN_DIGITS, + DURATION_Q_MAX_DIGITS); } @@ -274,123 +272,123 @@ */ public static NumberFormat getDurationD(CallContext context) { return getFormatter( - context, - DURATION_D_MIN_DIGITS, - DURATION_D_MAX_DIGITS); + context, + 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); + meta, + CALCULATION_REPORT_KM_MIN_DIGITS, + CALCULATION_REPORT_KM_MAX_DIGITS); } public static NumberFormat getFlowVelocityKM(CallContext context) { return getFormatter( - context, - FLOW_VELOCITY_KM_MIN_DIGITS, - FLOW_VELOCITY_KM_MAX_DIGITS); + context, + FLOW_VELOCITY_KM_MIN_DIGITS, + FLOW_VELOCITY_KM_MAX_DIGITS); } public static NumberFormat getFlowVelocityValues(CallContext context) { return getFormatter( - context, - FLOW_VELOCITY_VALUES_MIN_DIGITS, - FLOW_VELOCITY_VALUES_MAX_DIGITS); + context, + FLOW_VELOCITY_VALUES_MIN_DIGITS, + FLOW_VELOCITY_VALUES_MAX_DIGITS); } public static NumberFormat getFlowVelocityQ(CallContext context) { return getFormatter( - context, - FLOW_VELOCITY_Q_MIN_DIGITS, - FLOW_VELOCITY_Q_MAX_DIGITS); + context, + FLOW_VELOCITY_Q_MIN_DIGITS, + FLOW_VELOCITY_Q_MAX_DIGITS); } public static NumberFormat getMiddleBedHeightKM(CallContext context) { return getFormatter( - context, - MIDDLE_BED_HEIGHT_KM_MIN_DIGITS, - MIDDLE_BED_HEIGHT_KM_MAX_DIGITS); + context, + MIDDLE_BED_HEIGHT_KM_MIN_DIGITS, + MIDDLE_BED_HEIGHT_KM_MAX_DIGITS); } public static NumberFormat getMiddleBedHeightHeight(CallContext context) { return getFormatter( - context, - MIDDLE_BED_HEIGHT_HEIGHT_MIN_DIGITS, - MIDDLE_BED_HEIGHT_HEIGHT_MAX_DIGITS); + context, + MIDDLE_BED_HEIGHT_HEIGHT_MIN_DIGITS, + MIDDLE_BED_HEIGHT_HEIGHT_MAX_DIGITS); } public static NumberFormat getMiddleBedHeightUncert(CallContext context) { return getFormatter( - context, - MIDDLE_BED_HEIGHT_UNCERT_MIN_DIGITS, - MIDDLE_BED_HEIGHT_UNCERT_MAX_DIGITS); + context, + MIDDLE_BED_HEIGHT_UNCERT_MIN_DIGITS, + MIDDLE_BED_HEIGHT_UNCERT_MAX_DIGITS); } public static NumberFormat getMiddleBedHeightDataGap(CallContext context) { return getFormatter( - context, - MIDDLE_BED_HEIGHT_DATAGAP_MIN_DIGITS, - MIDDLE_BED_HEIGHT_DATAGAP_MAX_DIGITS); + context, + MIDDLE_BED_HEIGHT_DATAGAP_MIN_DIGITS, + MIDDLE_BED_HEIGHT_DATAGAP_MAX_DIGITS); } public static NumberFormat getMiddleBedHeightSounding(CallContext context) { return getFormatter( - context, - MIDDLE_BED_HEIGHT_SOUNDING_WIDTH_MIN_DIGITS, - MIDDLE_BED_HEIGHT_SOUNDING_WIDTH_MAX_DIGITS); + context, + MIDDLE_BED_HEIGHT_SOUNDING_WIDTH_MIN_DIGITS, + MIDDLE_BED_HEIGHT_SOUNDING_WIDTH_MAX_DIGITS); } public static NumberFormat getMiddleBedHeightWidth(CallContext context) { return getFormatter( - context, - MIDDLE_BED_HEIGHT_WIDTH_MIN_DIGITS, - MIDDLE_BED_HEIGHT_WIDTH_MAX_DIGITS); + context, + MIDDLE_BED_HEIGHT_WIDTH_MIN_DIGITS, + MIDDLE_BED_HEIGHT_WIDTH_MAX_DIGITS); } public static NumberFormat getFixDeltaWKM(CallContext context) { return getFormatter( - context, - FIX_DELTA_W_KM_MIN_DIGITS, - FIX_DELTA_W_KM_MAX_DIGITS); + context, + FIX_DELTA_W_KM_MIN_DIGITS, + FIX_DELTA_W_KM_MAX_DIGITS); } public static NumberFormat getFixDeltaWDeltaW(CallContext context) { return getFormatter( - context, - FIX_DELTA_W_DELTA_W_MIN_DIGITS, - FIX_DELTA_W_DELTA_W_MAX_DIGITS); + context, + FIX_DELTA_W_DELTA_W_MIN_DIGITS, + FIX_DELTA_W_DELTA_W_MAX_DIGITS); } public static NumberFormat getFixDeltaWQ(CallContext context) { return getFormatter( - context, - FIX_DELTA_W_DELTA_Q_MIN_DIGITS, - FIX_DELTA_W_DELTA_Q_MAX_DIGITS); + context, + FIX_DELTA_W_DELTA_Q_MIN_DIGITS, + FIX_DELTA_W_DELTA_Q_MAX_DIGITS); } public static NumberFormat getFixDeltaWW(CallContext context) { return getFormatter( - context, - FIX_DELTA_W_DELTA_W_MIN_DIGITS, - FIX_DELTA_W_DELTA_W_MAX_DIGITS); + context, + FIX_DELTA_W_DELTA_W_MIN_DIGITS, + FIX_DELTA_W_DELTA_W_MAX_DIGITS); } public static NumberFormat getMeterFormat(CallContext context) { return getFormatter( - context, - 0, - 2); + context, + 0, + 2); }