comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/MinMaxState.java @ 2202:d1660809daab

Added default values for min and max items prepared by MinMaxState. flys-artifacts/trunk@3821 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Mon, 30 Jan 2012 10:08:25 +0000
parents 2792d2617be9
children a22e0cb6eace
comparison
equal deleted inserted replaced
2201:4e3bfa2d9584 2202:d1660809daab
1 package de.intevation.flys.artifacts.states; 1 package de.intevation.flys.artifacts.states;
2 2
3 import org.w3c.dom.Element; 3 import org.w3c.dom.Element;
4
5 import org.apache.log4j.Logger;
4 6
5 import de.intevation.artifacts.Artifact; 7 import de.intevation.artifacts.Artifact;
6 import de.intevation.artifacts.CallContext; 8 import de.intevation.artifacts.CallContext;
7 9
8 import de.intevation.artifacts.common.ArtifactNamespaceContext; 10 import de.intevation.artifacts.common.ArtifactNamespaceContext;
16 /** 18 /**
17 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> 19 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
18 */ 20 */
19 public abstract class MinMaxState extends DefaultState { 21 public abstract class MinMaxState extends DefaultState {
20 22
23 private static final Logger logger = Logger.getLogger(MinMaxState.class);
24
21 @Override 25 @Override
22 protected void appendItems( 26 protected void appendItems(
23 Artifact artifact, 27 Artifact artifact,
24 ElementCreator creator, 28 ElementCreator creator,
25 String name, 29 String name,
31 select.setAttributeNS( 35 select.setAttributeNS(
32 ArtifactNamespaceContext.NAMESPACE_URI, 36 ArtifactNamespaceContext.NAMESPACE_URI,
33 "art:type", 37 "art:type",
34 getType()); 38 getType());
35 39
40 String[] defMinMax = getDefaults(artifact, name);
41
36 Element min = ProtocolUtils.createArtNode( 42 Element min = ProtocolUtils.createArtNode(
37 creator, 43 creator,
38 "min", 44 "min",
39 new String[] { "value" }, 45 new String[] { "value", "default" },
40 new String[] { String.valueOf(getLower(flys)) }); 46 new String[] { String.valueOf(getLower(flys)), defMinMax[0] });
41 47
42 Element max = ProtocolUtils.createArtNode( 48 Element max = ProtocolUtils.createArtNode(
43 creator, 49 creator,
44 "max", 50 "max",
45 new String[] { "value" }, 51 new String[] { "value", "default" },
46 new String[] { String.valueOf(getUpper(flys)) }); 52 new String[] { String.valueOf(getUpper(flys)), defMinMax[1] });
47 53
48 select.appendChild(min); 54 select.appendChild(min);
49 select.appendChild(max); 55 select.appendChild(max);
56 }
57
58
59 /**
60 * This method returns the default values for min and max. If the static
61 * field DefaultState.USE_DEFAULTS is set, the minimum and maximum inserted
62 * by the user is returned as string. Otherwise, the absolute minimum and
63 * maximum are returned.
64 *
65 * @param artifact The FLYSArtifact.
66 * @param name The name of the parameter.
67 *
68 * @return a string array [min,max] that contains the minimum and maximum
69 * values for the parameter <i>name</i>.
70 */
71 protected String[] getDefaults(Artifact artifact, String name) {
72 if (DefaultState.USE_DEFAULTS) {
73 String[] tmp = getMinMaxByParameter(artifact, name);
74
75 return tmp != null ? tmp : getMinMaxDefaults(artifact, name);
76 }
77 else {
78 return getMinMaxDefaults(artifact, name);
79 }
80 }
81
82
83 /**
84 * Returns a string array with minimum and maximum inserted by the user as
85 * [min,max].
86 *
87 * @param artifact The FLYSArtifact that stores the parameter.
88 * @param name The name of the parameter for raw min/max value string.
89 *
90 * @return a string array [min,max].
91 */
92 protected String[] getMinMaxByParameter(Artifact artifact, String name) {
93 FLYSArtifact flys = (FLYSArtifact) artifact;
94 String rawValue = flys.getDataAsString(name);
95
96 if (rawValue == null) {
97 logger.debug("No value for '" + rawValue + "' existing.");
98 return null;
99 }
100
101 logger.debug("Raw value for '" + name + "' = " + rawValue);
102
103 return rawValue.split(";");
104 }
105
106
107 /**
108 * Returns a string array with absolute minimum and maximum as [min,max].
109 *
110 * @param artifact The FLYSArtifact (not used in this implementation).
111 * @param name The parameter name (not used in this implementation).
112 *
113 * @return a string array [min,max].
114 */
115 protected String[] getMinMaxDefaults(Artifact artifact, String name) {
116 FLYSArtifact flys = (FLYSArtifact) artifact;
117
118 Object lower = getLower(flys);
119 Object upper = getUpper(flys);
120
121 return new String[] { String.valueOf(lower), String.valueOf(upper) };
50 } 122 }
51 123
52 124
53 protected abstract Object getLower(FLYSArtifact flys); 125 protected abstract Object getLower(FLYSArtifact flys);
54 126

http://dive4elements.wald.intevation.org