01: //=============================================================================
02: //=== Copyright (C) 2001-2007 Food and Agriculture Organization of the
03: //=== United Nations (FAO-UN), United Nations World Food Programme (WFP)
04: //=== and United Nations Environment Programme (UNEP)
05: //===
06: //=== This program is free software; you can redistribute it and/or modify
07: //=== it under the terms of the GNU General Public License as published by
08: //=== the Free Software Foundation; either version 2 of the License, or (at
09: //=== your option) any later version.
10: //===
11: //=== This program is distributed in the hope that it will be useful, but
12: //=== WITHOUT ANY WARRANTY; without even the implied warranty of
13: //=== MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: //=== General Public License for more details.
15: //===
16: //=== You should have received a copy of the GNU General Public License
17: //=== along with this program; if not, write to the Free Software
18: //=== Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19: //===
20: //=== Contact: Jeroen Ticheler - FAO - Viale delle Terme di Caracalla 2,
21: //=== Rome - Italy. email: geonetwork@osgeo.org
22: //==============================================================================
23:
24: package org.wfp.vam.intermap.util;
25:
26: import org.jdom.Element;
27: import org.wfp.vam.intermap.kernel.map.mapServices.BoundingBox;
28: import org.wfp.vam.intermap.kernel.map.mapServices.wms.schema.type.WMSEX_GeographicBoundingBox;
29:
30: public class Util {
31:
32: /**
33: * Retrieve bbnorth, bb... from params.
34: * If all of them are parsable coords, the corresponding BoundingBox is returned.
35: *
36: * @return a BoundingBox or null if a bb was not parsable,
37: *
38: * @author ETj
39: */
40: public static BoundingBox parseBoundingBox(Element params) {
41: try {
42: float n = Float.parseFloat(params.getChildText("northBL"));
43: float e = Float.parseFloat(params.getChildText("eastBL"));
44: float s = Float.parseFloat(params.getChildText("southBL"));
45: float w = Float.parseFloat(params.getChildText("westBL"));
46: return new BoundingBox(n, s, e, w);
47: } catch (NullPointerException e) // child not found
48: {
49: System.err.println("No valid bbox found");
50: return null;
51: } catch (NumberFormatException e) //
52: {
53: System.err.println("Bad float value (" + e.getMessage()
54: + ")");
55: return null;
56: }
57: }
58:
59: public static BoundingBox getBB(WMSEX_GeographicBoundingBox gbb) {
60: return new BoundingBox(gbb.getNorth(), gbb.getSouth(), gbb
61: .getEast(), gbb.getWest());
62: }
63:
64: /**
65: * Try and parse a String as an int.
66: *
67: * @return the parsed int, or defaultValue if parsableInteger is null or not parsable (in latter case, an error will be output)
68: *
69: * @author ETj
70: */
71: public static int parseInt(String parsableInteger, int defaultValue) {
72: if (parsableInteger == null)
73: return defaultValue;
74:
75: try {
76: return Integer.parseInt(parsableInteger);
77: } catch (NumberFormatException e) {
78: System.err.println("Bad int value '" + parsableInteger
79: + "'");
80: return defaultValue;
81: }
82: }
83:
84: }
|