Changeset 29736 in osm for applications/editors/josm/plugins/openstreetbugs/src/org
- Timestamp:
- 2013-07-02T23:50:50+02:00 (12 years ago)
- Location:
- applications/editors/josm/plugins/openstreetbugs/src/org/openstreetmap/josm/plugins/osb
- Files:
-
- 1 deleted
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/openstreetbugs/src/org/openstreetmap/josm/plugins/osb/OsbPlugin.java
r29373 r29736 273 273 } 274 274 275 public void setLayer(OsbLayer layer) {276 this.layer = layer;277 }278 279 275 public DataSet getDataSet() { 280 276 return dataSet; 281 277 } 282 278 283 public void setDataSet(DataSet dataSet) {284 this.dataSet = dataSet;285 }286 287 279 public OsbDialog getDialog() { 288 280 return dialog; -
applications/editors/josm/plugins/openstreetbugs/src/org/openstreetmap/josm/plugins/osb/api/CloseAction.java
r16134 r29736 54 54 result = "ok"; 55 55 } else { 56 result = HttpUtils.post(uri, null,post, CHARSET);56 result = HttpUtils.post(uri, post, CHARSET); 57 57 } 58 58 -
applications/editors/josm/plugins/openstreetbugs/src/org/openstreetmap/josm/plugins/osb/api/DownloadAction.java
r19050 r29736 64 64 65 65 // download the data 66 String content = HttpUtils.get(uri, null,CHARSET);66 String content = HttpUtils.get(uri, CHARSET); 67 67 68 68 // clear dataset -
applications/editors/josm/plugins/openstreetbugs/src/org/openstreetmap/josm/plugins/osb/api/EditAction.java
r16134 r29736 57 57 result = "ok"; 58 58 } else { 59 result = HttpUtils.post(uri, null,post, CHARSET);59 result = HttpUtils.post(uri, post, CHARSET); 60 60 } 61 61 -
applications/editors/josm/plugins/openstreetbugs/src/org/openstreetmap/josm/plugins/osb/api/NewAction.java
r26345 r29736 65 65 result = "ok 12345"; 66 66 } else { 67 result = HttpUtils.post(uri, null,post, CHARSET);67 result = HttpUtils.post(uri, post, CHARSET); 68 68 } 69 69 -
applications/editors/josm/plugins/openstreetbugs/src/org/openstreetmap/josm/plugins/osb/api/util/HttpUtils.java
r13497 r29736 28 28 package org.openstreetmap.josm.plugins.osb.api.util; 29 29 30 import static org.openstreetmap.josm.tools.I18n.tr;31 32 30 import java.io.ByteArrayOutputStream; 33 31 import java.io.IOException; … … 36 34 import java.net.URL; 37 35 import java.net.URLConnection; 38 import java.util.Iterator; 39 import java.util.List; 40 import java.util.Map; 41 import java.util.Map.Entry; 36 37 import org.openstreetmap.josm.tools.Utils; 42 38 43 39 public class HttpUtils { 44 public static String get(String url, Map<String, String> headers, String charset) throws IOException { 45 URL page = new URL(url); 46 URLConnection con = page.openConnection(); 47 if(headers != null) { 48 for (Iterator<Entry<String,String>> iterator = headers.entrySet().iterator(); iterator.hasNext();) { 49 Entry<String, String> entry = iterator.next(); 50 con.setRequestProperty(entry.getKey(), entry.getValue()); 51 } 52 } 53 40 public static String get(String url, String charset) throws IOException { 54 41 ByteArrayOutputStream bos = new ByteArrayOutputStream(); 55 42 int length = -1; 56 43 byte[] b = new byte[1024]; 57 InputStream in = con.getInputStream();44 InputStream in = Utils.openURL(new URL(url)); 58 45 while( (length = in.read(b)) > 0 ) { 59 46 bos.write(b, 0, length); 60 47 } 48 Utils.close(in); 61 49 62 50 return new String(bos.toByteArray(), charset); 63 }64 65 public static HttpResponse getResponse(String url, Map<String, String> headers, String charset) throws IOException {66 URL page = new URL(url);67 URLConnection con = page.openConnection();68 if(headers != null) {69 for (Iterator<Entry<String,String>> iterator = headers.entrySet().iterator(); iterator.hasNext();) {70 Entry<String, String> entry = iterator.next();71 con.setRequestProperty(entry.getKey(), entry.getValue());72 }73 }74 75 ByteArrayOutputStream bos = new ByteArrayOutputStream();76 int length = -1;77 byte[] b = new byte[1024];78 InputStream in = con.getInputStream();79 while( (length = in.read(b)) > 0 ) {80 bos.write(b, 0, length);81 }82 83 HttpResponse response = new HttpResponse(new String(bos.toByteArray(), charset), con.getHeaderFields());84 return response;85 51 } 86 52 … … 88 54 * 89 55 * @param url 90 * @param headers91 56 * @param content the post body 92 57 * @param responseCharset the expected charset of the response … … 94 59 * @throws IOException 95 60 */ 96 public static String post(String url, Map<String, String> headers,String content, String responseCharset) throws IOException {61 public static String post(String url, String content, String responseCharset) throws IOException { 97 62 // initialize the connection 98 63 URL page = new URL(url); 99 64 URLConnection con = page.openConnection(); 100 65 con.setDoOutput(true); 101 if(headers != null) {102 for (Iterator<Entry<String,String>> iterator = headers.entrySet().iterator(); iterator.hasNext();) {103 Entry<String, String> entry = iterator.next();104 con.setRequestProperty(entry.getKey(), entry.getValue());105 }106 }107 66 108 67 //send the post … … 119 78 bos.write(b, 0, length); 120 79 } 80 Utils.close(in); 81 Utils.close(os); 121 82 122 83 return new String(bos.toByteArray(), responseCharset); 123 84 } 124 125 /**126 * Adds a parameter to a given URI127 * @param uri128 * @param param129 * @param value130 * @return131 */132 public static String addParameter(String uri, String param, String value) {133 StringBuilder sb = new StringBuilder(uri);134 if(uri.contains("?")) {135 sb.append('&');136 } else {137 sb.append('?');138 }139 140 sb.append(param);141 sb.append('=');142 sb.append(value);143 144 return sb.toString();145 }146 147 public static Map<String, List<String>> head(String url, Map<String, String> headers, String charset) throws IOException {148 URL page = new URL(url);149 URLConnection con = page.openConnection();150 if(headers != null) {151 for (Iterator<Entry<String,String>> iterator = headers.entrySet().iterator(); iterator.hasNext();) {152 Entry<String, String> entry = iterator.next();153 con.setRequestProperty(entry.getKey(), entry.getValue());154 }155 }156 157 return con.getHeaderFields();158 }159 160 public static String getHeaderField(Map<String, List<String>> headers, String headerField) {161 if(!headers.containsKey(headerField)) {162 return null;163 }164 165 List<String> value = headers.get(headerField);166 if(value.size() == 1) {167 return value.get(0);168 } else {169 throw new RuntimeException(tr("Header contains several values and cannot be mapped to a single string"));170 }171 }172 85 } -
applications/editors/josm/plugins/openstreetbugs/src/org/openstreetmap/josm/plugins/osb/gui/dialogs/TextInputDialog.java
r23191 r29736 49 49 import javax.swing.SwingConstants; 50 50 import javax.swing.SwingUtilities; 51 import javax.swing.WindowConstants; 51 52 52 53 import org.openstreetmap.josm.gui.widgets.ComboBoxHistory; … … 153 154 } 154 155 } 155 setDefaultCloseOperation( JDialog.DISPOSE_ON_CLOSE);156 setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); 156 157 } 157 158
Note:
See TracChangeset
for help on using the changeset viewer.