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: // JUST A TEST CLASS!!!
25:
26: package org.wfp.vam.intermap.kernel;
27:
28: import java.io.*;
29: import java.net.*;
30:
31: import org.jdom.*;
32:
33: import org.wfp.vam.intermap.http.ConcurrentHTTPTransactionHandler;
34: import org.wfp.vam.intermap.http.cache.HttpGetFileCache;
35: import jeeves.utils.Xml;
36: import java.util.Hashtable;
37: import org.apache.commons.httpclient.*;
38: import org.apache.commons.httpclient.methods.*;
39: import org.apache.commons.httpclient.cookie.CookiePolicy;
40:
41: public class Geonet {
42:
43: public static Element getGeonetRecords(float minx, float miny,
44: float maxx, float maxy, int from, int to)
45: throws MalformedURLException, IOException, Exception {
46: // Get initial state object
47: HttpClient httpclient = new HttpClient();
48: httpclient.getParams().setCookiePolicy(CookiePolicy.RFC_2109);
49: //HostConfiguration hConf = httpclient.getHostConfiguration(); // DEBUG
50: //hConf.setProxy("10.11.40.110", 8080); // DEBUG
51:
52: // portal.search request
53: String request = "http://www.fao.org/geonetwork/srv/en/portal.search?extended=on&remote=off®ion=0000&selregion=%3B180%3B-180%3B-90%3B90&relation=overlaps&any=&title=&abstract=&themekey=&radfrom=&siteId=&category=&hitsPerPage=10"
54: + "&northBL="
55: + maxy
56: + "&westBL="
57: + minx
58: + "&eastBL="
59: + maxx + "&southBL=" + miny;
60: request += "&from=&to=";
61:
62: System.out.println("request: " + request);
63:
64: HttpMethod method = new GetMethod(request);
65:
66: int statusCode = httpclient.executeMethod(method);
67: if (statusCode == HttpStatus.SC_OK)
68: method.releaseConnection();
69: else
70: throw new Exception();
71:
72: // portal.present request
73: request = "http://www.fao.org/geonetwork/srv/en/portal.present?siteId=&hitsPerPage=10";
74: if (from != -1 && to != -1)
75: request += "&from=" + from + "&to=" + to;
76: else
77: request += "&from=&to=";
78:
79: method = new GetMethod(request);
80: statusCode = httpclient.executeMethod(method);
81: if (statusCode == HttpStatus.SC_OK) {
82: Element xml = Xml.loadStream(method
83: .getResponseBodyAsStream());
84: method.releaseConnection();
85: System.out.println(Xml.getString(xml)); // DEBUG
86: return xml;
87: } else
88: throw new Exception();
89:
90: }
91:
92: }
|