# HG changeset patch # User Ingo Weinzierl # Date 1316162829 0 # Node ID 1aba1a75beb202199b910ad7f8f44df7c761a527 # Parent ebb48bef35290d524b130c5365255b847b9e5620 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE. flys-artifacts/trunk@2770 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r ebb48bef3529 -r 1aba1a75beb2 flys-artifacts/ChangeLog --- a/flys-artifacts/ChangeLog Fri Sep 16 06:52:16 2011 +0000 +++ b/flys-artifacts/ChangeLog Fri Sep 16 08:47:09 2011 +0000 @@ -1,3 +1,25 @@ +2011-09-16 Ingo Weinzierl + + * src/main/java/de/intevation/flys/artifacts/states/DefaultState.java: + Defined createItem() here and adapted some method signatures, because I + need the CallContext deeper in code than expected. + + * src/main/java/de/intevation/flys/artifacts/states/WaterlevelSelectState.java: + Write the name of the selected waterlevel into the static DESCRIBE. + + * src/main/java/de/intevation/flys/artifacts/states/ScenarioSelect.java: + Adapted method signatures that have been changed in DefaultState. + + * src/main/java/de/intevation/flys/artifacts/states/CalculationSelect.java: + Removed method createItem() which is now defined in the upper class + DefaultState. + + * src/main/resources/messages.properties, + src/main/resources/messages_de_DE.properties, + src/main/resources/messages_en.properties, + src/main/resources/messages_de.properties: Added string for selected + waterlevel that is displayed in static UI. + 2011-09-16 Ingo Weinzierl * src/main/resources/messages.properties, diff -r ebb48bef3529 -r 1aba1a75beb2 flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/CalculationSelect.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/CalculationSelect.java Fri Sep 16 06:52:16 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/CalculationSelect.java Fri Sep 16 08:47:09 2011 +0000 @@ -99,23 +99,6 @@ } - protected Element createItem(XMLUtils.ElementCreator cr, Object obj) { - Element item = ProtocolUtils.createArtNode(cr, "item", null, null); - Element label = ProtocolUtils.createArtNode(cr, "label", null, null); - Element value = ProtocolUtils.createArtNode(cr, "value", null, null); - - String[] arr = (String[]) obj; - - label.setTextContent(arr[0]); - value.setTextContent(arr[1]); - - item.appendChild(label); - item.appendChild(value); - - return item; - } - - @Override public boolean validate(Artifact artifact) throws IllegalArgumentException diff -r ebb48bef3529 -r 1aba1a75beb2 flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DefaultState.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DefaultState.java Fri Sep 16 06:52:16 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DefaultState.java Fri Sep 16 08:47:09 2011 +0000 @@ -83,7 +83,7 @@ while (iter.hasNext()) { String name = iter.next(); - appendStaticData(flys, meta, creator, ui, name); + appendStaticData(flys, context, creator, ui, name); } return ui; @@ -92,8 +92,8 @@ protected void appendStaticData( FLYSArtifact flys, - CallMeta meta, - ElementCreator creator, + CallContext context, + ElementCreator cr, Element ui, String name ) { @@ -106,9 +106,36 @@ logger.debug("Append element '" + name + "' (" + value + ")"); + Element e = createStaticData(cr, context, name, value, data.getType()); + + ui.appendChild(e); + + } + + + /** + * Creates a data element used in the static part of the DESCRIBE + * document. + * + * @param creator The ElementCreator that is used to build new Elements. + * @param meta The CallMeta object used for i18n. + * @param name The name of the data item. + * @param value The value as string. + * + * @return an Element. + */ + protected Element createStaticData( + ElementCreator creator, + CallContext cc, + String name, + String value, + String type + ) { + CallMeta meta = cc.getMeta(); + Element dataElement = creator.create("data"); creator.addAttr(dataElement, "name", name, true); - creator.addAttr(dataElement, "type", data.getType(), true); + creator.addAttr(dataElement, "type", type, true); Element itemElement = creator.create("item"); creator.addAttr(itemElement, "value", value, true); @@ -128,9 +155,9 @@ } creator.addAttr(itemElement, "label", attrValue, true); + dataElement.appendChild(itemElement); - dataElement.appendChild(itemElement); - ui.appendChild(dataElement); + return dataElement; } @@ -260,6 +287,34 @@ /** + * This method is used to create an item Element that contains two + * further elements label and value. The label and value + * elements both have text nodes. + * + * @param cr The ElementCreator used to build new Elements. + * @param obj This implementation awaits a String array with [0] = label and + * [1] = value. + * + * @return an Element. + */ + protected Element createItem(XMLUtils.ElementCreator cr, Object obj) { + Element item = ProtocolUtils.createArtNode(cr, "item", null, null); + Element label = ProtocolUtils.createArtNode(cr, "label", null, null); + Element value = ProtocolUtils.createArtNode(cr, "value", null, null); + + String[] arr = (String[]) obj; + + label.setTextContent(arr[0]); + value.setTextContent(arr[1]); + + item.appendChild(label); + item.appendChild(value); + + return item; + } + + + /** * This method transform a given value into a StateData object. * * @param flys The FLYSArtifact. diff -r ebb48bef3529 -r 1aba1a75beb2 flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/ScenarioSelect.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/ScenarioSelect.java Fri Sep 16 06:52:16 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/ScenarioSelect.java Fri Sep 16 08:47:09 2011 +0000 @@ -48,7 +48,7 @@ @Override protected void appendStaticData( FLYSArtifact flys, - CallMeta meta, + CallContext cc, ElementCreator creator, Element ui, String name @@ -57,7 +57,7 @@ return; } else { - super.appendStaticData(flys, meta, creator, ui, name); + super.appendStaticData(flys, cc, creator, ui, name); } } diff -r ebb48bef3529 -r 1aba1a75beb2 flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WaterlevelSelectState.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WaterlevelSelectState.java Fri Sep 16 06:52:16 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WaterlevelSelectState.java Fri Sep 16 08:47:09 2011 +0000 @@ -2,13 +2,21 @@ import org.apache.log4j.Logger; +import org.w3c.dom.Element; + import de.intevation.artifacts.Artifact; import de.intevation.artifacts.CallContext; +import de.intevation.artifacts.CallMeta; import de.intevation.artifactdatabase.data.DefaultStateData; import de.intevation.artifactdatabase.data.StateData; +import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator; + import de.intevation.flys.artifacts.FLYSArtifact; +import de.intevation.flys.artifacts.model.CalculationResult; +import de.intevation.flys.artifacts.model.WQKms; +import de.intevation.flys.artifacts.resources.Resources; import de.intevation.flys.utils.FLYSUtils; @@ -22,6 +30,10 @@ public static final String SPLIT_CHAR = ";"; + public static final String WINFO_WSP_STATE_ID = "state.winfo.waterlevel"; + + public static final String I18N_STATIC_KEY = "wsp.selected.string"; + @Override protected String getUIProvider() { @@ -61,6 +73,58 @@ } + @Override + protected Element createStaticData( + ElementCreator creator, + CallContext cc, + String name, + String value, + String type + ) { + Element dataElement = creator.create("data"); + creator.addAttr(dataElement, "name", name, true); + creator.addAttr(dataElement, "type", type, true); + + Element itemElement = creator.create("item"); + creator.addAttr(itemElement, "value", value, true); + + String[] labels = getLabels(cc, value); + Object[] obj = new Object[] { labels[0] }; + + String attrValue = Resources.getMsg( + cc.getMeta(), I18N_STATIC_KEY, I18N_STATIC_KEY, obj); + + creator.addAttr(itemElement, "label", attrValue, true); + dataElement.appendChild(itemElement); + + return dataElement; + } + + + public static String[] getLabels(CallContext cc, String value) { + String[] parts = value.split(SPLIT_CHAR); + + FLYSArtifact artifact = FLYSUtils.getArtifact(parts[0], cc); + + CalculationResult rawData = (CalculationResult) artifact.compute( + cc, + null, + WINFO_WSP_STATE_ID, + ComputeType.ADVANCE, + false); + + WQKms[] wqkms = (WQKms[]) rawData.getData(); + + int idx = -1; + try { + idx = Integer.parseInt(parts[2]); + } + catch (NumberFormatException nfe) { /* do nothing */ } + + return new String[] { wqkms[idx].getName() }; + } + + public static String strip(String value) { int start = value.indexOf("["); int end = value.indexOf("]"); diff -r ebb48bef3529 -r 1aba1a75beb2 flys-artifacts/src/main/resources/messages.properties --- a/flys-artifacts/src/main/resources/messages.properties Fri Sep 16 06:52:16 2011 +0000 +++ b/flys-artifacts/src/main/resources/messages.properties Fri Sep 16 08:47:09 2011 +0000 @@ -79,3 +79,5 @@ wsplgen.job.queued = WSPLGEN job in queue. wsplgen.job.error = An unexpected error while starting WSPLGEN occured. + +wsp.selected.string = {0} diff -r ebb48bef3529 -r 1aba1a75beb2 flys-artifacts/src/main/resources/messages_de.properties --- a/flys-artifacts/src/main/resources/messages_de.properties Fri Sep 16 06:52:16 2011 +0000 +++ b/flys-artifacts/src/main/resources/messages_de.properties Fri Sep 16 08:47:09 2011 +0000 @@ -80,3 +80,5 @@ wsplgen.job.queued = WSPLGEN Berechnung befindet sich in Warteschlange. wsplgen.job.error = Ein unerwarteter Fehler beim Starten von WSPLGEN ist aufgetreten. + +wsp.selected.string = {0} diff -r ebb48bef3529 -r 1aba1a75beb2 flys-artifacts/src/main/resources/messages_de_DE.properties --- a/flys-artifacts/src/main/resources/messages_de_DE.properties Fri Sep 16 06:52:16 2011 +0000 +++ b/flys-artifacts/src/main/resources/messages_de_DE.properties Fri Sep 16 08:47:09 2011 +0000 @@ -79,3 +79,5 @@ wsplgen.job.queued = WSPLGEN Berechnung befindet sich in Warteschlange. wsplgen.job.error = Ein unerwarteter Fehler beim Starten von WSPLGEN ist aufgetreten. + +wsp.selected.string = {0} diff -r ebb48bef3529 -r 1aba1a75beb2 flys-artifacts/src/main/resources/messages_en.properties --- a/flys-artifacts/src/main/resources/messages_en.properties Fri Sep 16 06:52:16 2011 +0000 +++ b/flys-artifacts/src/main/resources/messages_en.properties Fri Sep 16 08:47:09 2011 +0000 @@ -77,3 +77,5 @@ wsplgen.job.queued = WSPLGEN job in queue. wsplgen.job.error = An unexpected error while starting WSPLGEN occured. + +wsp.selected.string = {0}