ingo@2709: package de.intevation.flys.artifacts.states;
ingo@2709:
ingo@2709: import org.w3c.dom.Element;
ingo@2709:
ingo@2709: import org.apache.log4j.Logger;
ingo@2709:
ingo@2709: import de.intevation.artifacts.Artifact;
ingo@2709: import de.intevation.artifacts.CallContext;
ingo@2709:
ingo@2709: import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator;
ingo@2709: import de.intevation.artifacts.common.model.KVP;
ingo@2709:
ingo@2709: import de.intevation.flys.artifacts.FLYSArtifact;
ingo@2709: import de.intevation.flys.artifacts.resources.Resources;
ingo@2709:
ingo@2709:
ingo@2709: /**
ingo@2709: *
ingo@2709: * @author Ingo Weinzierl
ingo@2709: */
ingo@2709: public abstract class MultiStringArrayState extends DefaultState {
ingo@2709:
ingo@2709: private static final Logger logger =
ingo@2709: Logger.getLogger(MultiStringArrayState.class);
ingo@2709:
ingo@2709:
ingo@2709: @Override
ingo@2709: protected void appendItems(
ingo@2709: Artifact artifact,
ingo@2709: ElementCreator creator,
ingo@2709: String name,
ingo@2709: CallContext context,
ingo@2709: Element select
ingo@2709: ) {
ingo@2709: try {
ingo@2709: creator.addAttr(select, "type", "options", true);
ingo@2709:
ingo@2709: for (KVP kvp: getOptions(artifact, name)) {
ingo@2709: Element item = creator.create("item");
ingo@2709: creator.addAttr(item, "label", kvp.getValue().toString(), true);
ingo@2709: creator.addAttr(item, "value", kvp.getKey().toString(), true);
ingo@2709:
ingo@2709: select.appendChild(item);
ingo@2709: }
ingo@2709: }
ingo@2709: catch (IllegalArgumentException iae) {
ingo@2709: logger.warn("Illegal argument", iae);
ingo@2709: }
ingo@2709: }
ingo@2709:
ingo@2709:
ingo@2709: @Override
ingo@2709: protected Element createStaticData(
ingo@2709: FLYSArtifact flys,
ingo@2709: ElementCreator creator,
ingo@2709: CallContext cc,
ingo@2709: String name,
ingo@2709: String value,
ingo@2709: String type
ingo@2709: ) {
ingo@2709: Element data = creator.create("data");
ingo@2709: creator.addAttr(data, "name", name, true);
ingo@2709: creator.addAttr(data, "type", type, true);
ingo@2709: creator.addAttr(data, "label",
ingo@2709: Resources.getMsg(cc.getMeta(), name, name), true);
ingo@2709:
ingo@2709: String[] values = value.split(";");
ingo@2709:
ingo@2709: for (String val: values) {
ingo@2709: Element item = creator.create("item");
ingo@2709: creator.addAttr(item, "value", val, true);
ingo@2709: creator.addAttr(item, "label", getLabelFor(cc, name, val), true);
ingo@2709:
ingo@2709: data.appendChild(item);
ingo@2709: }
ingo@2709:
ingo@2709: return data;
ingo@2709: }
ingo@2709:
ingo@2709:
ingo@2709: protected abstract KVP[] getOptions(
ingo@2709: Artifact artifact,
ingo@2709: String parameterName
ingo@2709: )
ingo@2709: throws IllegalArgumentException;
ingo@2709:
ingo@2709:
ingo@2709: protected abstract String getLabelFor(
ingo@2709: CallContext cc,
ingo@2709: String parameterName,
ingo@2709: String value
ingo@2709: )
ingo@2709: throws IllegalArgumentException;
ingo@2709: }
sascha@3083: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :