comparison flys-artifacts/src/main/java/de/intevation/flys/utils/ThemeUtil.java @ 3399:e08a6352fe24

Change bandwidth theme attribute type to double (but bugged). flys-artifacts/trunk@5035 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Wed, 18 Jul 2012 10:02:37 +0000
parents 2a8919e0ed28
children b0ba96bbf01d
comparison
equal deleted inserted replaced
3398:7f9fe694f8d1 3399:e08a6352fe24
154 return defaultsTo; 154 return defaultsTo;
155 } 155 }
156 } 156 }
157 157
158 158
159 /**
160 * Attempt converting \param value to an integer, in failing cases,
161 * return \param defaultsTo.
162 * @param value String to be converted to integer.
163 * @param defaultsTo Default to return if conversion failed.
164 * @return \param value as integer or defaultsto if conversion failed.
165 */
159 public static int parseInteger(String value, int defaultsTo) { 166 public static int parseInteger(String value, int defaultsTo) {
160 if (value == null || value.length() == 0) { 167 if (value == null || value.length() == 0) {
161 return defaultsTo; 168 return defaultsTo;
162 } 169 }
163 170
164 try { 171 try {
165 return Integer.valueOf(value); 172 return Integer.valueOf(value);
173 }
174 catch (NumberFormatException nfe) {
175 // do nothing
176 }
177
178 return defaultsTo;
179 }
180
181
182 /**
183 * Attempt converting \param value to a double, in failing cases,
184 * return \param defaultsTo.
185 * @param value String to be converted to double.
186 * @param defaultsTo Default to return if conversion failed.
187 * @return \param value as integer or defaultsto if conversion failed.
188 */
189 public static double parseDouble(String value, double defaultsTo) {
190 if (value == null || value.length() == 0) {
191 return defaultsTo;
192 }
193
194 try {
195 return Double.valueOf(value);
166 } 196 }
167 catch (NumberFormatException nfe) { 197 catch (NumberFormatException nfe) {
168 // do nothing 198 // do nothing
169 } 199 }
170 200
194 224
195 /** 225 /**
196 * Parse band width, defaulting to 0. 226 * Parse band width, defaulting to 0.
197 * @param theme the theme. 227 * @param theme the theme.
198 */ 228 */
199 public static int parseBandWidth(Document theme) { 229 public static double parseBandWidth(Document theme) {
200 String bandWidth = XMLUtils.xpathString(theme, XPATH_BANDWIDTH, null); 230 String bandWidth = XMLUtils.xpathString(theme, XPATH_BANDWIDTH, null);
201 231
202 return parseInteger(bandWidth, 0); 232 return parseDouble(bandWidth, 0);
203 } 233 }
204 234
205 235
206 public static int parsePointWidth(Document theme) { 236 public static int parsePointWidth(Document theme) {
207 String width = XMLUtils.xpathString(theme, XPATH_POINT_SIZE, null); 237 String width = XMLUtils.xpathString(theme, XPATH_POINT_SIZE, null);

http://dive4elements.wald.intevation.org