30 searchword = GeneralFunctions.encodeURIComponent(searchword);
31 String url_string =
"http://api.geonames.org/searchJSON?q=" + searchword +
"&maxRows=" + RetcatResource.getLimit() +
"&username=" + ConfigProperties.getPropertyParam(
"geonames");
32 URL url =
new URL(url_string);
33 HttpURLConnection conn = (HttpURLConnection) url.openConnection();
34 conn.setRequestProperty(
"Accept",
"application/json");
35 BufferedReader br =
new BufferedReader(
new InputStreamReader(conn.getInputStream(),
"UTF-8"));
37 StringBuilder response =
new StringBuilder();
38 while ((inputLine = br.readLine()) !=
null) {
39 response.append(inputLine);
43 JSONObject jsonObject = (JSONObject)
new JSONParser().parse(response.toString());
44 JSONArray resultsArray = (JSONArray) jsonObject.get(
"geonames");
45 Map<String, SuggestionItem> autosuggests =
new HashMap<String, SuggestionItem>();
46 for (Object element : resultsArray) {
47 JSONObject tmpElement = (JSONObject) element;
48 Long uriValue = (Long) tmpElement.get(
"geonameId");
49 String uri =
"http://sws.geonames.org/" + uriValue;
50 autosuggests.put(uri,
new SuggestionItem(uri));
51 SuggestionItem tmpAutosuggest = autosuggests.get(uri);
52 String labelValue = (String) tmpElement.get(
"name");
53 tmpAutosuggest.setLabel(labelValue);
54 String adminName1 = (String) tmpElement.get(
"adminName1");
55 String countryName = (String) tmpElement.get(
"countryName");
56 String lat = (String) tmpElement.get(
"lat");
57 String lon = (String) tmpElement.get(
"lng");
58 tmpAutosuggest.setDescription(adminName1 +
", " + countryName);
59 tmpAutosuggest.setSchemeTitle(
"GeoNames");
61 String type =
"geonames";
64 for (RetcatItem item : LocalRetcatItems.getLocalCatalogue()) {
65 if (item.getType().equals(type)) {
66 quality = item.getQuality();
67 group = item.getGroup();
70 tmpAutosuggest.setType(type);
71 tmpAutosuggest.setQuality(quality);
72 tmpAutosuggest.setGroup(group);