Mercurial > dive4elements > river
diff flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Calculation.java @ 2166:2898b1ff6013
I18N for WINFO calculation result messages.
flys-artifacts/trunk@3758 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Tue, 24 Jan 2012 22:59:44 +0000 |
parents | c09c9e05ecfa |
children | 5400631d2f96 |
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Calculation.java Mon Jan 23 17:39:51 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Calculation.java Tue Jan 24 22:59:44 2012 +0000 @@ -5,19 +5,23 @@ import java.util.List; import java.util.ArrayList; +import java.util.Arrays; import java.io.Serializable; import de.intevation.artifacts.CallMeta; +import de.intevation.flys.artifacts.resources.Resources; + public class Calculation implements Serializable { public static class Problem implements Serializable { - protected Double km; - protected String msg; + protected Double km; + protected String msg; + protected Object [] args; public Problem() { } @@ -26,20 +30,46 @@ this.msg = msg; } + public Problem(String msg, Object [] args) { + this.msg = msg; + this.args = args; + } + public Problem(double km, String msg) { this.km = km; this.msg = msg; } + public Problem(double km, String msg, Object [] args) { + this.km = km; + this.msg = msg; + this.args = args; + } + public Element toXML(Document document, CallMeta meta) { - // TODO: i18n Element problem = document.createElement("problem"); if (km != null) { problem.setAttribute("km", String.valueOf(km)); } - problem.setTextContent(msg); + String text = args != null + ? Resources.getMsg(meta, msg, msg) + : Resources.getMsg(meta, msg, msg, args); + problem.setTextContent(text); return problem; } + + @Override + public boolean equals(Object other) { + if (!(other instanceof Problem)) { + return false; + } + Problem o = (Problem)other; + return !(!msg.equals(o.msg) + || (km == null && o.km != null) + || (km != null && o.km == null) + || (km != null && !km.equals(o.km)) + || !Arrays.equals(args, o.args)); + } } // class Problem protected List<Problem> problems; @@ -58,12 +88,27 @@ return problems; } + public void addProblem(Problem problem) { + List<Problem> problems = checkProblems(); + if (!problems.contains(problem)) { + problems.add(problem); + } + } + public void addProblem(String msg) { - checkProblems().add(new Problem(msg)); + addProblem(new Problem(msg)); + } + + public void addProblem(String msg, Object ... args) { + addProblem(new Problem(msg, args)); } public void addProblem(double km, String msg) { - checkProblems().add(new Problem(km, msg)); + addProblem(new Problem(km, msg)); + } + + public void addProblem(double km, String msg, Object ... args) { + addProblem(new Problem(km, msg, args)); } public boolean hasProblems() {