Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/states/ScenarioSelect.java @ 9277:2323d005f9a5
compile error fix
author | gernotbelger |
---|---|
date | Fri, 20 Jul 2018 10:39:02 +0200 |
parents | 0beb34d55630 |
children |
comparison
equal
deleted
inserted
replaced
9276:3141f0e7314e | 9277:2323d005f9a5 |
---|---|
6 * documentation coming with Dive4Elements River for details. | 6 * documentation coming with Dive4Elements River for details. |
7 */ | 7 */ |
8 | 8 |
9 package org.dive4elements.river.artifacts.states; | 9 package org.dive4elements.river.artifacts.states; |
10 | 10 |
11 import org.dive4elements.artifactdatabase.ProtocolUtils; | 11 import java.io.File; |
12 | |
13 import org.apache.log4j.Logger; | |
12 import org.dive4elements.artifacts.Artifact; | 14 import org.dive4elements.artifacts.Artifact; |
13 import org.dive4elements.artifacts.CallContext; | 15 import org.dive4elements.artifacts.CallContext; |
14 import org.dive4elements.artifacts.CallMeta; | 16 import org.dive4elements.artifacts.CallMeta; |
15 import org.dive4elements.artifacts.common.utils.FileTools; | 17 import org.dive4elements.artifacts.common.utils.FileTools; |
16 import org.dive4elements.artifacts.common.utils.XMLUtils; | 18 import org.dive4elements.artifacts.common.utils.XMLUtils; |
17 import org.dive4elements.river.artifacts.D4EArtifact; | 19 import org.dive4elements.river.artifacts.D4EArtifact; |
18 import org.dive4elements.river.artifacts.resources.Resources; | 20 import org.dive4elements.river.artifacts.resources.Resources; |
19 import org.dive4elements.river.utils.RiverUtils; | 21 import org.dive4elements.river.utils.RiverUtils; |
20 | |
21 import java.io.File; | |
22 | |
23 import org.apache.log4j.Logger; | |
24 import org.w3c.dom.Element; | 22 import org.w3c.dom.Element; |
25 | 23 |
26 /** | 24 /** |
27 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | 25 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
28 */ | 26 */ |
29 public class ScenarioSelect extends DefaultState { | 27 public class ScenarioSelect extends DefaultState { |
30 | 28 |
31 /** The log that is used in this class.*/ | 29 /** The log that is used in this class. */ |
32 private static Logger log = Logger.getLogger(ScenarioSelect.class); | 30 private static Logger log = Logger.getLogger(ScenarioSelect.class); |
33 | 31 |
32 public static final String FIELD_MODE = "scenario"; | |
34 | 33 |
35 public static final String FIELD_MODE = "scenario"; | 34 public static final String SCENARIO_CURRENT = "scenario.current"; |
35 public static final String SCENARIO_POTENTIEL = "scenario.potentiel"; | |
36 public static final String SCENARIO_SCENRAIO = "scenario.scenario"; | |
36 | 37 |
37 public static final String SCENARIO_CURRENT = "scenario.current"; | 38 public static final String[] SCENARIOS = { SCENARIO_CURRENT, SCENARIO_POTENTIEL, SCENARIO_SCENRAIO }; |
38 public static final String SCENARIO_POTENTIEL = "scenario.potentiel"; | |
39 public static final String SCENARIO_SCENRAIO = "scenario.scenario"; | |
40 | |
41 public static final String[] SCENARIOS = { | |
42 SCENARIO_CURRENT, | |
43 SCENARIO_POTENTIEL, | |
44 SCENARIO_SCENRAIO }; | |
45 | |
46 | 39 |
47 @Override | 40 @Override |
48 protected String getUIProvider() { | 41 protected String getUIProvider() { |
49 return ""; | 42 return ""; |
50 } | 43 } |
51 | 44 |
52 @Override | 45 @Override |
53 protected Element[] createItems( | 46 protected Element[] createItems(final XMLUtils.ElementCreator cr, final Artifact artifact, final String name, final CallContext context) { |
54 XMLUtils.ElementCreator cr, | 47 final CallMeta meta = context.getMeta(); |
55 Artifact artifact, | |
56 String name, | |
57 CallContext context) | |
58 { | |
59 CallMeta meta = context.getMeta(); | |
60 | 48 |
61 if (name.equals(FIELD_MODE)) { | 49 if (name.equals(FIELD_MODE)) { |
62 Element[] scenarios = new Element[SCENARIOS.length]; | 50 final Element[] scenarios = new Element[SCENARIOS.length]; |
63 | 51 |
64 int i = 0; | 52 int i = 0; |
65 | 53 |
66 for (String scenario: SCENARIOS) { | 54 for (final String scenario : SCENARIOS) { |
67 scenarios[i++] = createItem( | 55 scenarios[i++] = createItem(cr, new String[] { Resources.getMsg(meta, scenario, scenario), scenario }); |
68 cr, new String[] { | |
69 Resources.getMsg(meta, scenario, scenario), | |
70 scenario | |
71 }); | |
72 } | 56 } |
73 | 57 |
74 return scenarios; | 58 return scenarios; |
75 } | 59 } else { |
76 else { | 60 final D4EArtifact flys = (D4EArtifact) artifact; |
77 D4EArtifact flys = (D4EArtifact) artifact; | 61 final String data = flys.getDataAsString(name); |
78 String data = flys.getDataAsString(name); | |
79 | 62 |
80 return new Element[] { createItem( | 63 return new Element[] { createItem(cr, new String[] { Resources.getMsg(meta, name, name), data }) }; |
81 cr, | |
82 new String[] { | |
83 Resources.getMsg(meta, name, name), | |
84 data | |
85 } | |
86 )}; | |
87 } | 64 } |
88 } | 65 } |
89 | 66 |
67 // ist mit super identisch | |
68 // @Override | |
69 // protected Element createItem(XMLUtils.ElementCreator cr, Object obj) { | |
70 // Element item = ProtocolUtils.createArtNode(cr, "item", null, null); | |
71 // Element label = ProtocolUtils.createArtNode(cr, "label", null, null); | |
72 // Element value = ProtocolUtils.createArtNode(cr, "value", null, null); | |
73 // | |
74 // String[] arr = (String[]) obj; | |
75 // | |
76 // label.setTextContent(arr[0]); | |
77 // value.setTextContent(arr[1]); | |
78 // | |
79 // item.appendChild(label); | |
80 // item.appendChild(value); | |
81 // | |
82 // return item; | |
83 // } | |
90 | 84 |
91 @Override | 85 @Override |
92 protected Element createItem(XMLUtils.ElementCreator cr, Object obj) { | 86 public void endOfLife(final Artifact artifact, final Object callContext) { |
93 Element item = ProtocolUtils.createArtNode(cr, "item", null, null); | |
94 Element label = ProtocolUtils.createArtNode(cr, "label", null, null); | |
95 Element value = ProtocolUtils.createArtNode(cr, "value", null, null); | |
96 | |
97 String[] arr = (String[]) obj; | |
98 | |
99 label.setTextContent(arr[0]); | |
100 value.setTextContent(arr[1]); | |
101 | |
102 item.appendChild(label); | |
103 item.appendChild(value); | |
104 | |
105 return item; | |
106 } | |
107 | |
108 | |
109 | |
110 @Override | |
111 public void endOfLife(Artifact artifact, Object callContext) { | |
112 super.endOfLife(artifact, callContext); | 87 super.endOfLife(artifact, callContext); |
113 log.info("ScenarioSelect.endOfLife: " + artifact.identifier()); | 88 log.info("ScenarioSelect.endOfLife: " + artifact.identifier()); |
114 | 89 |
115 D4EArtifact flys = (D4EArtifact) artifact; | 90 final D4EArtifact flys = (D4EArtifact) artifact; |
116 removeDirectory(flys); | 91 removeDirectory(flys); |
117 } | 92 } |
118 | |
119 | 93 |
120 /** | 94 /** |
121 * Removes the directory and all its content where the required data and the | 95 * Removes the directory and all its content where the required data and the |
122 * results of WSPLGEN are stored. Should be called in endOfLife(). | 96 * results of WSPLGEN are stored. Should be called in endOfLife(). |
123 */ | 97 */ |
124 // FIXME: I've seen this code somewhere else... | 98 // FIXME: I've seen this code somewhere else... |
125 protected void removeDirectory(D4EArtifact artifact) { | 99 protected void removeDirectory(final D4EArtifact artifact) { |
126 String shapePath = RiverUtils.getXPathString( | 100 final String shapePath = RiverUtils.getXPathString(RiverUtils.XPATH_FLOODMAP_SHAPEFILE_DIR); |
127 RiverUtils.XPATH_FLOODMAP_SHAPEFILE_DIR); | |
128 | 101 |
129 File artifactDir = new File(shapePath, artifact.identifier()); | 102 final File artifactDir = new File(shapePath, artifact.identifier()); |
130 | 103 |
131 if (artifactDir.exists()) { | 104 if (artifactDir.exists()) { |
132 log.debug("Delete directory: " + artifactDir.getAbsolutePath()); | 105 log.debug("Delete directory: " + artifactDir.getAbsolutePath()); |
133 boolean success = FileTools.deleteRecursive(artifactDir); | 106 final boolean success = FileTools.deleteRecursive(artifactDir); |
134 if (!success) { | 107 if (!success) { |
135 log.warn("could not remove dir '" + artifactDir + "'"); | 108 log.warn("could not remove dir '" + artifactDir + "'"); |
136 } | 109 } |
137 } | 110 } else { |
138 else { | |
139 log.debug("There is no directory to remove."); | 111 log.debug("There is no directory to remove."); |
140 } | 112 } |
141 } | 113 } |
142 | 114 |
143 | |
144 } | 115 } |
145 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : | 116 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |