comparison flys-artifacts/src/main/java/org/dive4elements/river/artifacts/states/ScenarioSelect.java @ 5831:bd047b71ab37

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

http://dive4elements.wald.intevation.org