Ignore:
Timestamp:
2016-07-02T03:55:03+02:00 (9 years ago)
Author:
donvip
Message:

checkstyle

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/imagery_offset_db/src/iodb/SimpleOffsetQueryTask.java

    r29450 r32528  
     1// License: WTFPL. For details, see LICENSE file.
    12package iodb;
     3
     4import static org.openstreetmap.josm.tools.I18n.tr;
    25
    36import java.io.IOException;
    47import java.io.InputStream;
    5 import java.net.*;
    6 import java.util.*;
    7 import java.util.regex.*;
     8import java.net.HttpURLConnection;
     9import java.net.MalformedURLException;
     10import java.net.URL;
     11import java.util.Scanner;
     12import java.util.regex.Matcher;
     13import java.util.regex.Pattern;
     14
    815import javax.swing.JOptionPane;
     16
    917import org.openstreetmap.josm.Main;
    1018import org.openstreetmap.josm.gui.PleaseWaitRunnable;
    11 import static org.openstreetmap.josm.tools.I18n.tr;
    1219
    1320/**
     
    2936     * @param title A title for the progress monitor.
    3037     */
    31     public SimpleOffsetQueryTask( String query, String title ) {
     38    SimpleOffsetQueryTask(String query, String title) {
    3239        super(ImageryOffsetTools.DIALOG_TITLE);
    3340        this.query = query;
     
    3946     * In case a query was not specified when the object was constructed,
    4047     * it can be set with this method.
    41      * @see #SimpleOffsetQueryTask(java.lang.String, java.lang.String) 
     48     * @see #SimpleOffsetQueryTask(java.lang.String, java.lang.String)
    4249     */
    43     public void setQuery( String query ) {
     50    public void setQuery(String query) {
    4451        this.query = query;
    4552    }
     
    4855     * Install a listener for successful responses. There can be only one.
    4956     */
    50     public void setListener( QuerySuccessListener listener ) {
     57    public void setListener(QuerySuccessListener listener) {
    5158        this.listener = listener;
    5259    }
     
    6875            errorMessage = null;
    6976            doQuery(query);
    70         } catch( UploadException e ) {
     77        } catch (UploadException e) {
    7178            errorMessage = tr("Server has rejected the request") + ":\n" + e.getMessage();
    72         } catch( IOException e ) {
     79        } catch (IOException e) {
    7380            errorMessage = tr("Unable to connect to the server") + "\n" + e.getMessage();
    7481        }
     
    7885     * Sends a request to the imagery offset server. Processes exceptions and
    7986     * return codes, calls {@link #processResponse(java.io.InputStream)} on success.
    80      * @param query
    81      * @throws iodb.SimpleOffsetQueryTask.UploadException
    82      * @throws IOException
    8387     */
    84     private void doQuery( String query ) throws UploadException, IOException {
     88    private void doQuery(String query) throws UploadException, IOException {
    8589        try {
    8690            String serverURL = Main.pref.get("iodb.server.url", "http://offsets.textual.ru/");
    8791            URL url = new URL(serverURL + query);
    88 //            Main.info("IODB URL = " + url); // todo: remove in release
    89             HttpURLConnection connection = (HttpURLConnection)url.openConnection();
     92            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
    9093            connection.connect();
    91             if( connection.getResponseCode() != 200 ) {
     94            if (connection.getResponseCode() != 200) {
    9295                throw new IOException("HTTP Response code " + connection.getResponseCode() + " (" + connection.getResponseMessage() + ")");
    9396            }
    9497            InputStream inp = connection.getInputStream();
    95             if( inp == null )
     98            if (inp == null)
    9699                throw new IOException("Empty response");
    97100            try {
    98                 if( !cancelled )
     101                if (!cancelled)
    99102                    processResponse(inp);
    100103            } finally {
    101104                connection.disconnect();
    102105            }
    103         } catch( MalformedURLException ex ) {
     106        } catch (MalformedURLException ex) {
    104107            throw new IOException("Malformed URL: " + ex.getMessage());
    105108        }
     
    120123    @Override
    121124    protected void finish() {
    122         if( errorMessage != null ) {
     125        if (errorMessage != null) {
    123126            JOptionPane.showMessageDialog(Main.parent, errorMessage,
    124127                    ImageryOffsetTools.DIALOG_TITLE, JOptionPane.ERROR_MESSAGE);
    125         } else if( listener != null ) {
     128        } else if (listener != null) {
    126129            listener.queryPassed();
    127130        }
     
    133136     * @throws iodb.SimpleOffsetQueryTask.UploadException Thrown if an error message was found.
    134137     */
    135     protected void processResponse( InputStream inp ) throws UploadException {
     138    protected void processResponse(InputStream inp) throws UploadException {
    136139        String response = "";
    137         if( inp != null ) {
     140        if (inp != null) {
    138141            Scanner sc = new Scanner(inp).useDelimiter("\\A");
    139142            response = sc.hasNext() ? sc.next() : "";
     
    141144        Pattern p = Pattern.compile("<(\\w+)>([^<]+)</\\1>");
    142145        Matcher m = p.matcher(response);
    143         if( m.find() ) {
    144             if( m.group(1).equals("error") ) {
     146        if (m.find()) {
     147            if (m.group(1).equals("error")) {
    145148                throw new UploadException(m.group(2));
    146149            }
     
    154157     */
    155158    public static class UploadException extends Exception {
    156         public UploadException( String message ) {
     159        UploadException(String message) {
    157160            super(message);
    158161        }
Note: See TracChangeset for help on using the changeset viewer.