Mercurial > dive4elements > river
comparison 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 |
comparison
equal
deleted
inserted
replaced
2165:637dd38d0e2f | 2166:2898b1ff6013 |
---|---|
3 import org.w3c.dom.Document; | 3 import org.w3c.dom.Document; |
4 import org.w3c.dom.Element; | 4 import org.w3c.dom.Element; |
5 | 5 |
6 import java.util.List; | 6 import java.util.List; |
7 import java.util.ArrayList; | 7 import java.util.ArrayList; |
8 import java.util.Arrays; | |
8 | 9 |
9 import java.io.Serializable; | 10 import java.io.Serializable; |
10 | 11 |
11 import de.intevation.artifacts.CallMeta; | 12 import de.intevation.artifacts.CallMeta; |
13 | |
14 import de.intevation.flys.artifacts.resources.Resources; | |
12 | 15 |
13 public class Calculation | 16 public class Calculation |
14 implements Serializable | 17 implements Serializable |
15 { | 18 { |
16 public static class Problem | 19 public static class Problem |
17 implements Serializable | 20 implements Serializable |
18 { | 21 { |
19 protected Double km; | 22 protected Double km; |
20 protected String msg; | 23 protected String msg; |
24 protected Object [] args; | |
21 | 25 |
22 public Problem() { | 26 public Problem() { |
23 } | 27 } |
24 | 28 |
25 public Problem(String msg) { | 29 public Problem(String msg) { |
26 this.msg = msg; | 30 this.msg = msg; |
27 } | 31 } |
28 | 32 |
33 public Problem(String msg, Object [] args) { | |
34 this.msg = msg; | |
35 this.args = args; | |
36 } | |
37 | |
29 public Problem(double km, String msg) { | 38 public Problem(double km, String msg) { |
30 this.km = km; | 39 this.km = km; |
31 this.msg = msg; | 40 this.msg = msg; |
32 } | 41 } |
33 | 42 |
43 public Problem(double km, String msg, Object [] args) { | |
44 this.km = km; | |
45 this.msg = msg; | |
46 this.args = args; | |
47 } | |
48 | |
34 public Element toXML(Document document, CallMeta meta) { | 49 public Element toXML(Document document, CallMeta meta) { |
35 // TODO: i18n | |
36 Element problem = document.createElement("problem"); | 50 Element problem = document.createElement("problem"); |
37 if (km != null) { | 51 if (km != null) { |
38 problem.setAttribute("km", String.valueOf(km)); | 52 problem.setAttribute("km", String.valueOf(km)); |
39 } | 53 } |
40 problem.setTextContent(msg); | 54 String text = args != null |
55 ? Resources.getMsg(meta, msg, msg) | |
56 : Resources.getMsg(meta, msg, msg, args); | |
57 problem.setTextContent(text); | |
41 return problem; | 58 return problem; |
59 } | |
60 | |
61 @Override | |
62 public boolean equals(Object other) { | |
63 if (!(other instanceof Problem)) { | |
64 return false; | |
65 } | |
66 Problem o = (Problem)other; | |
67 return !(!msg.equals(o.msg) | |
68 || (km == null && o.km != null) | |
69 || (km != null && o.km == null) | |
70 || (km != null && !km.equals(o.km)) | |
71 || !Arrays.equals(args, o.args)); | |
42 } | 72 } |
43 } // class Problem | 73 } // class Problem |
44 | 74 |
45 protected List<Problem> problems; | 75 protected List<Problem> problems; |
46 | 76 |
56 problems = new ArrayList<Problem>(); | 86 problems = new ArrayList<Problem>(); |
57 } | 87 } |
58 return problems; | 88 return problems; |
59 } | 89 } |
60 | 90 |
91 public void addProblem(Problem problem) { | |
92 List<Problem> problems = checkProblems(); | |
93 if (!problems.contains(problem)) { | |
94 problems.add(problem); | |
95 } | |
96 } | |
97 | |
61 public void addProblem(String msg) { | 98 public void addProblem(String msg) { |
62 checkProblems().add(new Problem(msg)); | 99 addProblem(new Problem(msg)); |
100 } | |
101 | |
102 public void addProblem(String msg, Object ... args) { | |
103 addProblem(new Problem(msg, args)); | |
63 } | 104 } |
64 | 105 |
65 public void addProblem(double km, String msg) { | 106 public void addProblem(double km, String msg) { |
66 checkProblems().add(new Problem(km, msg)); | 107 addProblem(new Problem(km, msg)); |
108 } | |
109 | |
110 public void addProblem(double km, String msg, Object ... args) { | |
111 addProblem(new Problem(km, msg, args)); | |
67 } | 112 } |
68 | 113 |
69 public boolean hasProblems() { | 114 public boolean hasProblems() { |
70 return problems != null && !problems.isEmpty(); | 115 return problems != null && !problems.isEmpty(); |
71 } | 116 } |