Ignore:
Timestamp:
2013-07-02T23:50:50+02:00 (12 years ago)
Author:
donvip
Message:

[josm_openstreetbugs] code cleanup before even thinking about bringing it into core for future notes support

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  
    273273    }
    274274
    275     public void setLayer(OsbLayer layer) {
    276         this.layer = layer;
    277     }
    278 
    279275    public DataSet getDataSet() {
    280276        return dataSet;
    281277    }
    282278
    283     public void setDataSet(DataSet dataSet) {
    284         this.dataSet = dataSet;
    285     }
    286 
    287279    public OsbDialog getDialog() {
    288280        return dialog;
  • applications/editors/josm/plugins/openstreetbugs/src/org/openstreetmap/josm/plugins/osb/api/CloseAction.java

    r16134 r29736  
    5454            result = "ok";
    5555        } else {
    56             result = HttpUtils.post(uri, null, post, CHARSET);
     56            result = HttpUtils.post(uri, post, CHARSET);
    5757        }
    5858
  • applications/editors/josm/plugins/openstreetbugs/src/org/openstreetmap/josm/plugins/osb/api/DownloadAction.java

    r19050 r29736  
    6464
    6565        // download the data
    66         String content = HttpUtils.get(uri, null, CHARSET);
     66        String content = HttpUtils.get(uri, CHARSET);
    6767
    6868        // clear dataset
  • applications/editors/josm/plugins/openstreetbugs/src/org/openstreetmap/josm/plugins/osb/api/EditAction.java

    r16134 r29736  
    5757            result = "ok";
    5858        } else {
    59             result = HttpUtils.post(uri, null, post, CHARSET);
     59            result = HttpUtils.post(uri, post, CHARSET);
    6060        }
    6161
  • applications/editors/josm/plugins/openstreetbugs/src/org/openstreetmap/josm/plugins/osb/api/NewAction.java

    r26345 r29736  
    6565            result = "ok 12345";
    6666        } else {
    67             result = HttpUtils.post(uri, null, post, CHARSET);
     67            result = HttpUtils.post(uri, post, CHARSET);
    6868        }
    6969
  • applications/editors/josm/plugins/openstreetbugs/src/org/openstreetmap/josm/plugins/osb/api/util/HttpUtils.java

    r13497 r29736  
    2828package org.openstreetmap.josm.plugins.osb.api.util;
    2929
    30 import static org.openstreetmap.josm.tools.I18n.tr;
    31 
    3230import java.io.ByteArrayOutputStream;
    3331import java.io.IOException;
     
    3634import java.net.URL;
    3735import 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
     37import org.openstreetmap.josm.tools.Utils;
    4238
    4339public 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 {
    5441        ByteArrayOutputStream bos = new ByteArrayOutputStream();
    5542        int length = -1;
    5643        byte[] b = new byte[1024];
    57         InputStream in = con.getInputStream();
     44        InputStream in = Utils.openURL(new URL(url));
    5845        while( (length = in.read(b)) > 0 ) {
    5946            bos.write(b, 0, length);
    6047        }
     48        Utils.close(in);
    6149
    6250        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;
    8551    }
    8652
     
    8854     *
    8955     * @param url
    90      * @param headers
    9156     * @param content the post body
    9257     * @param responseCharset the expected charset of the response
     
    9459     * @throws IOException
    9560     */
    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 {
    9762        // initialize the connection
    9863        URL page = new URL(url);
    9964        URLConnection con = page.openConnection();
    10065        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         }
    10766
    10867        //send the post
     
    11978            bos.write(b, 0, length);
    12079        }
     80        Utils.close(in);
     81        Utils.close(os);
    12182
    12283        return new String(bos.toByteArray(), responseCharset);
    12384    }
    124 
    125     /**
    126      * Adds a parameter to a given URI
    127      * @param uri
    128      * @param param
    129      * @param value
    130      * @return
    131      */
    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     }
    17285}
  • applications/editors/josm/plugins/openstreetbugs/src/org/openstreetmap/josm/plugins/osb/gui/dialogs/TextInputDialog.java

    r23191 r29736  
    4949import javax.swing.SwingConstants;
    5050import javax.swing.SwingUtilities;
     51import javax.swing.WindowConstants;
    5152
    5253import org.openstreetmap.josm.gui.widgets.ComboBoxHistory;
     
    153154            }
    154155        }
    155         setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
     156        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    156157    }
    157158
Note: See TracChangeset for help on using the changeset viewer.