comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/ScenarioSelect.java @ 3786:4adc35aa655c

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

http://dive4elements.wald.intevation.org