ingo@927: package de.intevation.flys.artifacts.states; ingo@927: christian@4656: import de.intevation.artifactdatabase.ProtocolUtils; christian@4656: import de.intevation.artifacts.Artifact; christian@4656: import de.intevation.artifacts.CallContext; christian@4656: import de.intevation.artifacts.CallMeta; christian@4656: import de.intevation.artifacts.common.utils.FileTools; christian@4656: import de.intevation.artifacts.common.utils.XMLUtils; christian@4656: import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator; christian@4656: import de.intevation.flys.artifacts.FLYSArtifact; christian@4656: import de.intevation.flys.artifacts.resources.Resources; christian@4656: import de.intevation.flys.utils.FLYSUtils; christian@4656: raimund@2639: import java.io.File; raimund@2639: ingo@927: import org.apache.log4j.Logger; ingo@927: import org.w3c.dom.Element; ingo@927: ingo@927: /** ingo@927: * @author Ingo Weinzierl ingo@927: */ ingo@927: public class ScenarioSelect extends DefaultState { ingo@927: ingo@927: /** The logger that is used in this class.*/ ingo@927: private static Logger logger = Logger.getLogger(ScenarioSelect.class); ingo@927: ingo@927: ingo@1064: public static final String FIELD_MODE = "scenario"; ingo@1064: public static final String FIELD_BARRIERS = "uesk.barriers"; ingo@927: ingo@927: public static final String SCENARIO_CURRENT = "scenario.current"; ingo@927: public static final String SCENARIO_POTENTIEL = "scenario.potentiel"; ingo@927: public static final String SCENARIO_SCENRAIO = "scenario.scenario"; ingo@927: ingo@927: public static final String[] SCENARIOS = { ingo@927: SCENARIO_CURRENT, ingo@927: SCENARIO_POTENTIEL, ingo@927: SCENARIO_SCENRAIO }; ingo@927: ingo@927: ingo@1064: ingo@1064: @Override ingo@1064: protected String getUIProvider() { ingo@1064: return "map_digitize"; ingo@1064: } ingo@1064: ingo@1064: ingo@927: @Override ingo@1159: protected void appendStaticData( ingo@1159: FLYSArtifact flys, ingo@1180: CallContext cc, ingo@1159: ElementCreator creator, ingo@1159: Element ui, ingo@1159: String name ingo@1159: ) { ingo@1159: if (name != null && name.equals(FIELD_BARRIERS)) { ingo@1159: return; ingo@1159: } ingo@1159: else { ingo@1180: super.appendStaticData(flys, cc, creator, ui, name); ingo@1159: } ingo@1159: } ingo@1159: ingo@1159: ingo@1159: @Override ingo@927: protected Element[] createItems( ingo@927: XMLUtils.ElementCreator cr, ingo@927: Artifact artifact, ingo@927: String name, ingo@927: CallContext context) ingo@927: { ingo@1064: CallMeta meta = context.getMeta(); ingo@927: ingo@1064: if (name.equals(FIELD_MODE)) { ingo@1064: Element[] scenarios = new Element[SCENARIOS.length]; ingo@1064: ingo@1064: int i = 0; ingo@1064: ingo@1064: for (String scenario: SCENARIOS) { ingo@1064: scenarios[i++] = createItem( ingo@1064: cr, new String[] { ingo@1064: Resources.getMsg(meta, scenario, scenario), ingo@1064: scenario ingo@1064: }); ingo@1064: } ingo@1064: ingo@1064: return scenarios; ingo@927: } ingo@1064: else { ingo@1064: FLYSArtifact flys = (FLYSArtifact) artifact; ingo@1064: String data = flys.getDataAsString(name); ingo@927: ingo@1064: return new Element[] { createItem( ingo@1064: cr, ingo@1064: new String[] { ingo@1064: Resources.getMsg(meta, name, name), ingo@1064: data ingo@1064: } ingo@1064: )}; ingo@1064: } ingo@927: } ingo@927: ingo@927: christian@4656: @Override ingo@927: protected Element createItem(XMLUtils.ElementCreator cr, Object obj) { ingo@927: Element item = ProtocolUtils.createArtNode(cr, "item", null, null); ingo@927: Element label = ProtocolUtils.createArtNode(cr, "label", null, null); ingo@927: Element value = ProtocolUtils.createArtNode(cr, "value", null, null); ingo@927: ingo@927: String[] arr = (String[]) obj; ingo@927: ingo@927: label.setTextContent(arr[0]); ingo@927: value.setTextContent(arr[1]); ingo@927: ingo@927: item.appendChild(label); ingo@927: item.appendChild(value); ingo@927: ingo@927: return item; ingo@927: } raimund@2639: raimund@2639: raimund@2639: raimund@2639: @Override raimund@2639: public void endOfLife(Artifact artifact, Object callContext) { raimund@2639: super.endOfLife(artifact, callContext); raimund@2639: logger.info("ScenarioSelect.endOfLife: " + artifact.identifier()); raimund@2639: raimund@2639: FLYSArtifact flys = (FLYSArtifact) artifact; raimund@2639: removeDirectory(flys); raimund@2639: } raimund@2639: raimund@2639: raimund@2639: /** raimund@2639: * Removes the directory and all its content where the required data and the raimund@2639: * results of WSPLGEN are stored. Should be called in endOfLife(). raimund@2639: */ christian@4656: // FIXME: I've seen this code somewhere else... raimund@2639: protected void removeDirectory(FLYSArtifact artifact) { raimund@2639: String shapePath = FLYSUtils.getXPathString( christian@4656: FLYSUtils.XPATH_FLOODMAP_SHAPEFILE_DIR); raimund@2639: raimund@2639: File artifactDir = new File(shapePath, artifact.identifier()); raimund@2639: raimund@2639: if (artifactDir.exists()) { teichmann@4049: logger.debug("Delete directory: " + artifactDir.getAbsolutePath()); raimund@2639: boolean success = FileTools.deleteRecursive(artifactDir); teichmann@4049: if (!success) { teichmann@4049: logger.warn("could not remove dir '" + artifactDir + "'"); teichmann@4049: } raimund@2639: } raimund@2639: else { raimund@2639: logger.debug("There is no directory to remove."); raimund@2639: } raimund@2639: } raimund@2639: raimund@2639: ingo@927: } ingo@927: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :