Changeset 32877 in osm
- Timestamp:
- 2016-08-24T23:57:01+02:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/rasterfilters/src/org/openstreetmap/josm/plugins/rasterfilters/preferences/FiltersDownloader.java
r32853 r32877 43 43 public static List<FilterInfo> downloadFiltersInfoList() { 44 44 45 JsonObject jsonRequest = Json 46 .createObjectBuilder() 47 .add("id", new Random().nextInt()) 48 .add("method", "wiki.getPageHTML") 49 .add("params", 50 Json.createArrayBuilder().add("ImageFilters").build()) 51 .build(); 52 53 String jsonRequestString = jsonRequest.toString(); 54 55 URL wikiApi; 56 HttpURLConnection wikiConnection; 45 // JsonObject jsonRequest = Json 46 // .createObjectBuilder() 47 // .add("id", new Random().nextInt()) 48 // .add("method", "wiki.getPageHTML") 49 // .add("params", 50 // Json.createArrayBuilder().add("ImageFilters").build()) 51 // .build(); 52 53 // String jsonRequestString = jsonRequest.toString(); 54 55 // URL wikiApi; 56 // HttpURLConnection wikiConnection; 57 57 try { 58 wikiApi = new URL("https://josm.openstreetmap.de/jsonrpc"); 59 wikiConnection = (HttpURLConnection) wikiApi.openConnection(); 60 wikiConnection.setDoOutput(true); 61 wikiConnection.setDoInput(true); 62 63 wikiConnection.setRequestProperty("Content-Type", 64 "application/json"); 65 wikiConnection.setRequestProperty("Method", "POST"); 66 wikiConnection.connect(); 67 68 OutputStream os = wikiConnection.getOutputStream(); 69 os.write(jsonRequestString.getBytes("UTF-8")); 70 os.close(); 71 72 int HttpResult = wikiConnection.getResponseCode(); 73 if (HttpResult == HttpURLConnection.HTTP_OK) { 74 75 JsonReader jsonStream = Json 76 .createReader(new InputStreamReader(wikiConnection 77 .getInputStream(), "utf-8")); 78 79 JsonObject jsonResponse = jsonStream.readObject(); 80 jsonStream.close(); 81 82 Elements trTagElems = Jsoup.parse( 83 jsonResponse.getString("result")) 84 .getElementsByTag("tr"); 85 for (Element element : trTagElems) { 86 87 Elements elems = element.getElementsByTag("td"); 88 if (!elems.isEmpty()) { 89 String name = elems.get(0).text(); 90 String owner = elems.get(1).text(); 91 String description = elems.get(2).text(); 92 93 String link = elems.get(0).getElementsByTag("a") 94 .attr("href"); 95 96 JsonObject meta = loadMeta(link); 97 98 String paramName = "rasterfilters." 99 + meta.getString("name"); 100 101 boolean needToLoad = Main.pref.getBoolean(paramName); 102 103 if (needToLoad) { 104 JsonArray binaries = meta.getJsonArray("binaries"); 105 filterTitles.add(meta.getString("title")); 106 for (int i = 0; i < binaries.size(); i++) { 107 filtersMetaToLoad.add(meta); 108 loadBinaryToFile(binaries.getString(i)); 109 } 110 } 111 FilterInfo newFilterInfo = new FilterInfo(name, 112 description, meta, needToLoad); 113 newFilterInfo.setOwner(owner); 114 115 if (!filtersInfoList.contains(newFilterInfo)) { 116 filtersInfoList.add(newFilterInfo); 58 // wikiApi = new URL("https://josm.openstreetmap.de/wiki/ImageFilters"); 59 // wikiConnection = (HttpURLConnection) wikiApi.openConnection(); 60 // wikiConnection.setDoOutput(true); 61 // wikiConnection.setDoInput(true); 62 // 63 // wikiConnection.setRequestProperty("Content-Type", 64 // "application/json"); 65 // wikiConnection.setRequestProperty("Method", "POST"); 66 // wikiConnection.connect(); 67 68 // OutputStream os = wikiConnection.getOutputStream(); 69 // os.write(jsonRequestString.getBytes("UTF-8")); 70 // os.close(); 71 72 // int HttpResult = wikiConnection.getResponseCode(); 73 // if (HttpResult == HttpURLConnection.HTTP_OK) { 74 75 // JsonReader jsonStream = Json 76 // .createReader(new InputStreamReader(wikiConnection 77 // .getInputStream(), "utf-8")); 78 79 // BufferedReader inReader = new BufferedReader(new InputStreamReader(wikiConnection.getInputStream())); 80 81 // JsonObject jsonResponse = jsonStream.readObject(); 82 // jsonStream.close(); 83 Document doc = Jsoup.connect("https://josm.openstreetmap.de/wiki/ImageFilters").get(); 84 Elements trTagElems = doc.getElementsByTag("tr"); 85 86 // Elements trTagElems = Jsoup.parse( 87 // jsonResponse.getString("result")) 88 // .getElementsByTag("tr"); 89 for (Element element : trTagElems) { 90 91 Elements elems = element.getElementsByTag("td"); 92 if (!elems.isEmpty()) { 93 String name = elems.get(0).text(); 94 String owner = elems.get(1).text(); 95 String description = elems.get(2).text(); 96 97 String link = elems.get(0).getElementsByTag("a") 98 .attr("href"); 99 100 JsonObject meta = loadMeta(link); 101 102 String paramName = "rasterfilters." 103 + meta.getString("name"); 104 105 boolean needToLoad = Main.pref.getBoolean(paramName); 106 107 if (needToLoad) { 108 JsonArray binaries = meta.getJsonArray("binaries"); 109 filterTitles.add(meta.getString("title")); 110 for (int i = 0; i < binaries.size(); i++) { 111 filtersMetaToLoad.add(meta); 112 loadBinaryToFile(binaries.getString(i)); 117 113 } 118 114 } 119 } 120 121 } else { 122 Main.debug("Error happenned while requesting for the list of filters"); 123 } 115 FilterInfo newFilterInfo = new FilterInfo(name, 116 description, meta, needToLoad); 117 newFilterInfo.setOwner(owner); 118 119 if (!filtersInfoList.contains(newFilterInfo)) { 120 filtersInfoList.add(newFilterInfo); 121 } 122 } 123 } 124 125 // } else { 126 // Main.debug("Error happenned while requesting for the list of filters"); 127 // } 124 128 } catch (IOException e1) { 125 129 // TODO Auto-generated catch block … … 141 145 } 142 146 143 JsonObject jsonRequest = Json.createObjectBuilder() 144 .add("id", new Random().nextInt()) 145 .add("method", "wiki.getPageHTML") 146 .add("params", Json.createArrayBuilder().add(link).build()) 147 .build(); 148 149 String jsonStringRequest = jsonRequest.toString(); 147 // JsonObject jsonRequest = Json.createObjectBuilder() 148 // .add("id", new Random().nextInt()) 149 // .add("method", "wiki.getPageHTML") 150 // .add("params", Json.createArrayBuilder().add(link).build()) 151 // .build(); 152 153 // String jsonStringRequest = jsonRequest.toString(); 150 154 151 155 URL wikiApi; … … 154 158 155 159 try { 156 wikiApi = new URL("https://josm.openstreetmap.de/jsonrpc"); 157 wikiConnection = (HttpURLConnection) wikiApi.openConnection(); 158 wikiConnection.setDoOutput(true); 159 wikiConnection.setDoInput(true); 160 161 wikiConnection.setRequestProperty("Content-Type", 162 "application/json"); 163 wikiConnection.setRequestProperty("Method", "POST"); 164 wikiConnection.connect(); 165 166 OutputStream os = wikiConnection.getOutputStream(); 167 os.write(jsonStringRequest.getBytes("UTF-8")); 168 os.close(); 169 170 int HttpResult = wikiConnection.getResponseCode(); 171 if (HttpResult == HttpURLConnection.HTTP_OK) { 172 173 174 175 176 177 178 179 180 181 182 parse(jsonPage, "UTF-8");183 184 185 186 187 188 189 } else { 190 Main.debug(wikiConnection.getResponseMessage()); 191 } 160 // wikiApi = new URL("https://josm.openstreetmap.de/jsonrpc"); 161 // wikiConnection = (HttpURLConnection) wikiApi.openConnection(); 162 // wikiConnection.setDoOutput(true); 163 // wikiConnection.setDoInput(true); 164 // 165 // wikiConnection.setRequestProperty("Content-Type", 166 // "application/json"); 167 // wikiConnection.setRequestProperty("Method", "POST"); 168 // wikiConnection.connect(); 169 // 170 // OutputStream os = wikiConnection.getOutputStream(); 171 // os.write(jsonStringRequest.getBytes("UTF-8")); 172 // os.close(); 173 // 174 // int HttpResult = wikiConnection.getResponseCode(); 175 // if (HttpResult == HttpURLConnection.HTTP_OK) { 176 177 // JsonReader jsonStream = Json 178 // .createReader(new InputStreamReader(wikiConnection 179 // .getInputStream(), "UTF-8")); 180 181 // JsonObject jsonResponse = jsonStream.readObject(); 182 // jsonStream.close(); 183 184 // String jsonPage = jsonResponse.getString("result"); 185 186 Document doc = Jsoup.connect("https://josm.openstreetmap.de/wiki/" + link).get(); 187 String json = doc.getElementsByTag("pre").first().text(); 188 189 JsonReader reader = Json.createReader(new StringReader(json)); 190 meta = reader.readObject(); 191 reader.close(); 192 193 // } else { 194 // Main.debug(wikiConnection.getResponseMessage()); 195 // } 192 196 } catch (IOException e1) { 193 197 e1.printStackTrace();
Note:
See TracChangeset
for help on using the changeset viewer.