Ignore:
Timestamp:
2016-07-23T23:41:17+02:00 (8 years ago)
Author:
donvip
Message:

checkstyle

Location:
applications/editors/josm/plugins/sds/src/org/openstreetmap/hot/sds
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/sds/src/org/openstreetmap/hot/sds/DetermineSdsModificationsUploadHook.java

    r30738 r32703  
    1 // License: GPL. See LICENSE file for details.
     1// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.hot.sds;
    33
     
    1616/**
    1717 * This upload hook does the following things:
    18  * 
    19  * 1. Find out if there are any changes in the special tags that need to 
     18 *
     19 * 1. Find out if there are any changes in the special tags that need to
    2020 *    be uploaded to a different server.
    21  * 2. Find out if any objects that did have special tags have now been 
     21 * 2. Find out if any objects that did have special tags have now been
    2222 *    deleted, resulting in tag deletions on the special server.
    2323 * 3. Find out if any objects carrying special tags have been newly created.
    2424 * 4. Also, if it is determined that an object modification consists exclusively
    25  *    of special tags, then skip uploading that object, by removing it from 
     25 *    of special tags, then skip uploading that object, by removing it from
    2626 *    the apiDataSet.
    27  *   
     27 *
    2828 * This upload hook stores its findings with the SeparateDataStorePlugin, and
    2929 * changes are sent to the SDS server only after the OSM upload has sucessfully
    3030 * completed. The UploadSuccessHook is responsible for that.
    3131 */
    32 public class DetermineSdsModificationsUploadHook implements UploadHook
    33 {
     32public class DetermineSdsModificationsUploadHook implements UploadHook {
    3433    private SeparateDataStorePlugin plugin;
    3534
    36     DetermineSdsModificationsUploadHook(SeparateDataStorePlugin plugin)    {
     35    DetermineSdsModificationsUploadHook(SeparateDataStorePlugin plugin) {
    3736        this.plugin = plugin;
    3837    }
    39    
     38
     39    @Override
    4040    public boolean checkUpload(APIDataSet apiDataSet) {
    41        
     41
    4242        ArrayList<OsmPrimitive> droplist = new ArrayList<>();
    43        
     43
    4444        // check deleted primitives for special tags.
    4545        for (OsmPrimitive del : apiDataSet.getPrimitivesToDelete()) {
     
    5353        // check modified primitives.
    5454           for (OsmPrimitive upd : apiDataSet.getPrimitivesToUpdate()) {
    55                
     55
    5656               HashSet<String> allKeys = new HashSet<>();
    5757               boolean specialTags = false;
    58                
     58
    5959               // process tags of new object
    6060               for (String key : upd.keySet()) {
     
    6262                   if (!specialTags && isSpecialKey(key)) specialTags = true;
    6363               }
    64                
     64
    6565               // process tags of old object
    6666               IPrimitive old = plugin.getOriginalPrimitive(upd);
     
    7272               // if neither has special tags, done with this object.
    7373               if (!specialTags) continue;
    74                
     74
    7575               // special tags are involved. find out what, exactly, has changed.
    7676               boolean changeInSpecialTags = false;
     
    8282                   }
    8383               }
    84                
     84
    8585               // change *only* in standard tags - done with this object.
    8686               if (!changeInSpecialTags) continue;
    87                
     87
    8888               // assemble new set of special tags. might turn out to be empty.
    8989               HashMap<String, String> newSpecialTags = new HashMap<>();
     
    9191                   if (isSpecialKey(key)) newSpecialTags.put(key, upd.get(key));
    9292               }
    93                
     93
    9494               boolean uploadToOsm = changeInOtherTags;
    95                
    96                // not done yet: if no changes in standard tags, we need to find out if 
     95
     96               // not done yet: if no changes in standard tags, we need to find out if
    9797               // there were changes in the other properties (node: lat/lon, way/relation:
    98                // member list). If the answer is no, then the object must be removed from 
     98               // member list). If the answer is no, then the object must be removed from
    9999               // JOSM's normal upload queue, else we would be uploading a non-edit.
    100100               if (!changeInOtherTags) {
     
    111111                           uploadToOsm = true;
    112112                           break;
    113                        } 
     113                       }
    114114                       for (int i = 0; i < wold.getNodesCount(); i++) {
    115115                           if (wold.getNodeId(i) != wupd.getNodeId(i)) {
     
    122122                       IRelation rold = (IRelation) old;
    123123                       IRelation rupd = (IRelation) upd;
    124                        if (rold.getMembersCount()!= rupd.getMembersCount()) {
     124                       if (rold.getMembersCount() != rupd.getMembersCount()) {
    125125                           uploadToOsm = true;
    126126                           break;
    127                        } 
     127                       }
    128128                       for (int i = 0; i < rold.getMembersCount(); i++) {
    129129                           if (rold.getMemberType(i) != rupd.getMemberType(i) ||
     
    136136                   }
    137137               }
    138                
     138
    139139               // request that new set of special tags be uploaded
    140140               plugin.enqueueForUpload(upd, newSpecialTags, !uploadToOsm);
    141                
    142                // we cannot remove from getPrimitivesToUpdate, this would result in a 
     141
     142               // we cannot remove from getPrimitivesToUpdate, this would result in a
    143143               // ConcurrentModificationException.
    144144               if (!uploadToOsm) droplist.add(upd);
    145                
     145
    146146        }
    147            
     147
    148148        apiDataSet.getPrimitivesToUpdate().removeAll(droplist);
    149                    
    150            // check added primitives. 
     149
     150           // check added primitives.
    151151           for (OsmPrimitive add : apiDataSet.getPrimitivesToAdd()) {
    152152               // assemble new set of special tags. might turn out to be empty.
     
    157157               if (!newSpecialTags.isEmpty()) plugin.enqueueForUpload(add, newSpecialTags, false);
    158158        }
    159        
     159
    160160           // FIXME it is possible that the list of OSM edits is totally empty.
    161161        return true;
    162162
    163163    }
    164    
     164
    165165    boolean hasSpecialTags(IPrimitive p) {
    166166        for (String key : p.keySet()) {
    167167            if (isSpecialKey(key)) return true;
    168         }   
     168        }
    169169        return false;
    170170    }
    171    
     171
    172172    boolean isSpecialKey(String key) {
    173173        return key.startsWith(plugin.getIgnorePrefix());
  • applications/editors/josm/plugins/sds/src/org/openstreetmap/hot/sds/ReadPostprocessor.java

    r30738 r32703  
    2424
    2525public class ReadPostprocessor implements OsmServerReadPostprocessor {
    26    
     26
    2727    private ArrayList<Long> nodeList;
    2828    private ArrayList<Long> wayList;
    2929    private ArrayList<Long> relationList;
    30    
     30
    3131    private SeparateDataStorePlugin plugin;
    3232
     
    3434        this.plugin = plugin;
    3535    }
    36    
     36
    3737    @Override
    3838    public void postprocessDataSet(DataSet ds, ProgressMonitor progress) {
    39        
     39
    4040        nodeList = new ArrayList<>();
    4141        wayList = new ArrayList<>();
     
    4848                plugin.originalNodes.put(n.getId(), n.save());
    4949            }
     50
    5051            @Override
    5152            public void visit(Way w) {
     
    5354                plugin.originalWays.put(w.getId(), w.save());
    5455            }
     56
    5557            @Override
    5658            public void visit(Relation e) {
     
    5860                plugin.originalNodes.put(e.getId(), e.save());
    5961            }
     62
    6063            @Override
    6164            public void visit(Changeset cs) {}
    6265        };
    63        
     66
    6467        for (OsmPrimitive p : ds.allPrimitives()) {
    6568            p.accept(adder);
    6669        }
    67            
     70
    6871        SdsApi api = SdsApi.getSdsApi();
    6972        String rv = "";
     
    7477            e.printStackTrace();
    7578        }
    76        
    77         // this is slightly inefficient, as we're re-making the string into 
     79
     80        // this is slightly inefficient, as we're re-making the string into
    7881        // an input stream when there was an input stream to be had inside the
    7982        // SdsApi already, but this encapsulates things better.
  • applications/editors/josm/plugins/sds/src/org/openstreetmap/hot/sds/SdsApi.java

    r31152 r32703  
    1 //License: GPL. See README for details.
     1// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.hot.sds;
    33
     
    3838public class SdsApi extends SdsConnection {
    3939    /** max number of retries to send a request in case of HTTP 500 errors or timeouts */
    40     static public final int DEFAULT_MAX_NUM_RETRIES = 5;
     40    public static final int DEFAULT_MAX_NUM_RETRIES = 5;
    4141
    4242    /** the collection of instantiated OSM APIs */
     
    5151     *
    5252     */
    53     static public SdsApi getSdsApi(String serverUrl) {
     53    public static SdsApi getSdsApi(String serverUrl) {
    5454        SdsApi api = instances.get(serverUrl);
    5555        if (api == null) {
    5656            api = new SdsApi(serverUrl);
    57             instances.put(serverUrl,api);
     57            instances.put(serverUrl, api);
    5858        }
    5959        return api;
    6060    }
     61
    6162    /**
    6263     * replies the {@see OsmApi} for the URL given by the preference <code>sds-server.url</code>
     
    6566     *
    6667     */
    67     static public SdsApi getSdsApi() {
     68    public static SdsApi getSdsApi() {
    6869        String serverUrl = Main.pref.get("sds-server.url", "http://datastore.hotosm.org");
    6970        if (serverUrl == null)
     
    8687     * @exception IllegalArgumentException thrown, if serverUrl is null
    8788     */
    88     protected SdsApi(String serverUrl)  {
     89    protected SdsApi(String serverUrl) {
    8990        CheckParameterUtil.ensureParameterNotNull(serverUrl, "serverUrl");
    9091        this.serverUrl = serverUrl;
     
    9899        return version;
    99100    }
    100 
    101101
    102102    /**
     
    113113        // this works around a ruby (or lighttpd) bug where two consecutive slashes in
    114114        // an URL will cause a "404 not found" response.
    115         int p; while ((p = rv.indexOf("//", 6)) > -1) { rv.delete(p, p + 1); }
     115        int p;
     116        while ((p = rv.indexOf("//", 6)) > -1) {
     117            rv.delete(p, p + 1);
     118        }
    116119        return rv.toString();
    117120    }
    118121
    119     /**
     122    /*
    120123     * Creates an OSM primitive on the server. The OsmPrimitive object passed in
    121124     * is modified by giving it the server-assigned id.
     
    123126     * @param osm the primitive
    124127     * @throws SdsTransferException if something goes wrong
    125 
    126128    public void createPrimitive(IPrimitive osm, ProgressMonitor monitor) throws SdsTransferException {
    127129        String ret = "";
     
    132134            osm.setOsmId(Long.parseLong(ret.trim()), 1);
    133135            osm.setChangesetId(getChangeset().getId());
    134         } catch(NumberFormatException e){
     136        } catch (NumberFormatException e){
    135137            throw new SdsTransferException(tr("Unexpected format of ID replied by the server. Got ''{0}''.", ret));
    136138        }
     
    138140    */
    139141
    140     /**
     142    /*
    141143     * Modifies an OSM primitive on the server.
    142144     *
     
    144146     * @param monitor the progress monitor
    145147     * @throws SdsTransferException if something goes wrong
    146 
    147148    public void modifyPrimitive(IPrimitive osm, ProgressMonitor monitor) throws SdsTransferException {
    148149        String ret = null;
     
    155156            osm.setChangesetId(getChangeset().getId());
    156157            osm.setVisible(true);
    157         } catch(NumberFormatException e) {
     158        } catch (NumberFormatException e) {
    158159            throw new SdsTransferException(tr("Unexpected format of new version of modified primitive ''{0}''. Got ''{1}''.", osm.getId(), ret));
    159160        }
     
    161162    */
    162163
    163     /**
     164    /*
    164165     * Deletes an OSM primitive on the server.
    165166     * @param osm the primitive
    166167     * @throws SdsTransferException if something goes wrong
    167 
    168168    public void deletePrimitive(IPrimitive osm, ProgressMonitor monitor) throws SdsTransferException {
    169169        ensureValidChangeset();
     
    177177    */
    178178
    179     /**
     179    /*
    180180     * Uploads a list of changes in "diff" form to the server.
    181181     *
     
    186186     * @throws SdsTransferException
    187187     * @throws SdsTransferException if something is wrong
    188 
    189188    public Collection<IPrimitive> uploadDiff(Collection<? extends IPrimitive> list, ProgressMonitor monitor) throws SdsTransferException {
    190189        try {
     
    218217                    monitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false)
    219218            );
    220         } catch(SdsTransferException e) {
     219        } catch (SdsTransferException e) {
    221220            throw e;
    222         } catch(OsmDataParsingException e) {
     221        } catch (OsmDataParsingException e) {
    223222            throw new SdsTransferException(e);
    224223        } finally {
     
    228227    */
    229228
    230     public String requestShadowsFromSds(List<Long> nodes, List<Long> ways, List<Long> relations, ProgressMonitor pm) throws SdsTransferException {
     229    public String requestShadowsFromSds(List<Long> nodes, List<Long> ways, List<Long> relations, ProgressMonitor pm)
     230            throws SdsTransferException {
    231231
    232232        StringBuilder request = new StringBuilder();
     
    268268        }
    269269
    270         return sendRequest("POST", "collectshadows", request.toString(), pm ,true);
    271 
     270        return sendRequest("POST", "collectshadows", request.toString(), pm, true);
    272271    }
    273272
    274273    private void sleepAndListen(int retry, ProgressMonitor monitor) throws SdsTransferException {
    275274        System.out.print(tr("Waiting 10 seconds ... "));
    276         for(int i=0; i < 10; i++) {
     275        for (int i = 0; i < 10; i++) {
    277276            if (monitor != null) {
    278                 monitor.setCustomText(tr("Starting retry {0} of {1} in {2} seconds ...", getMaxRetries() - retry,getMaxRetries(), 10-i));
     277                monitor.setCustomText(tr("Starting retry {0} of {1} in {2} seconds ...", getMaxRetries() - retry, getMaxRetries(), 10-i));
    279278            }
    280279            if (cancel)
     
    282281            try {
    283282                Thread.sleep(1000);
    284             } catch (InterruptedException ex) {}
     283            } catch (InterruptedException ex) {
     284                Main.trace(ex);
     285            }
    285286        }
    286287        System.out.println(tr("OK - trying again."));
     
    294295    protected int getMaxRetries() {
    295296        int ret = Main.pref.getInteger("osm-server.max-num-retries", DEFAULT_MAX_NUM_RETRIES);
    296         return Math.max(ret,0);
     297        return Math.max(ret, 0);
    297298    }
    298299
     
    301302    }
    302303
    303     private String sendRequest(String requestMethod, String urlSuffix, String requestBody, ProgressMonitor monitor, boolean doAuth) throws SdsTransferException {
     304    private String sendRequest(String requestMethod, String urlSuffix, String requestBody, ProgressMonitor monitor, boolean doAuth)
     305            throws SdsTransferException {
    304306        return sendRequest(requestMethod, urlSuffix, requestBody, monitor, doAuth, false);
    305307    }
     
    334336     *    been exhausted), or rewrapping a Java exception.
    335337     */
    336     private String sendRequest(String requestMethod, String urlSuffix, String requestBody, ProgressMonitor monitor, boolean doAuthenticate, boolean fastFail) throws SdsTransferException {
     338    private String sendRequest(String requestMethod, String urlSuffix, String requestBody, ProgressMonitor monitor,
     339            boolean doAuthenticate, boolean fastFail) throws SdsTransferException {
    337340        StringBuffer responseBody = new StringBuffer();
    338341        int retries = getMaxRetries();
    339342
    340         while(true) { // the retry loop
     343        while (true) { // the retry loop
    341344            try {
    342345                URL url = new URL(new URL(getBaseUrl()), urlSuffix);
    343346                System.out.print(requestMethod + " " + url + "... ");
    344                 activeConnection = (HttpURLConnection)url.openConnection();
    345                 activeConnection.setConnectTimeout(fastFail ? 1000 : Main.pref.getInteger("socket.timeout.connect",15)*1000);
     347                activeConnection = (HttpURLConnection) url.openConnection();
     348                activeConnection.setConnectTimeout(fastFail ? 1000 : Main.pref.getInteger("socket.timeout.connect", 15)*1000);
    346349                activeConnection.setRequestMethod(requestMethod);
    347350                if (doAuthenticate) {
     
    375378                    if (retries-- > 0) {
    376379                        sleepAndListen(retries, monitor);
    377                         System.out.println(tr("Starting retry {0} of {1}.", getMaxRetries() - retries,getMaxRetries()));
     380                        System.out.println(tr("Starting retry {0} of {1}.", getMaxRetries() - retries, getMaxRetries()));
    378381                        continue;
    379382                    }
     
    398401                    BufferedReader in = new BufferedReader(new InputStreamReader(i));
    399402                    String s;
    400                     while((s = in.readLine()) != null) {
     403                    while ((s = in.readLine()) != null) {
    401404                        responseBody.append(s);
    402405                        responseBody.append("\n");
     
    408411                    errorHeader = activeConnection.getHeaderField("Error");
    409412                    System.err.println("Error header: " + errorHeader);
    410                 } else if (retCode != 200 && responseBody.length()>0) {
     413                } else if (retCode != 200 && responseBody.length() > 0) {
    411414                    System.err.println("Error body: " + responseBody);
    412415                }
    413416                activeConnection.disconnect();
    414417
    415                 errorHeader = errorHeader == null? null : errorHeader.trim();
    416                 String errorBody = responseBody.length() == 0? null : responseBody.toString().trim();
     418                errorHeader = errorHeader == null ? null : errorHeader.trim();
     419                String errorBody = responseBody.length() == 0 ? null : responseBody.toString().trim();
    417420                switch(retCode) {
    418421                case HttpURLConnection.HTTP_OK:
     
    435438                }
    436439                throw new SdsTransferException(e);
    437             } catch(IOException e){
     440            } catch (IOException e) {
    438441                throw new SdsTransferException(e);
    439             } catch(SdsTransferException e) {
     442            } catch (SdsTransferException e) {
    440443                throw e;
    441444            }
     
    449452            try {
    450453                url = new URL(urlStr.replace(" ", "%20"));
    451             } catch(MalformedURLException e) {
     454            } catch (MalformedURLException e) {
    452455                throw new SdsTransferException(e);
    453456            }
    454457            try {
    455                 activeConnection = (HttpURLConnection)url.openConnection();
    456             } catch(Exception e) {
     458                activeConnection = (HttpURLConnection) url.openConnection();
     459            } catch (Exception e) {
    457460                throw new SdsTransferException(tr("Failed to open connection to API {0}.", url.toExternalForm()), e);
    458461            }
     
    470473            }
    471474
    472             activeConnection.setConnectTimeout(Main.pref.getInteger("socket.timeout.connect",15)*1000);
     475            activeConnection.setConnectTimeout(Main.pref.getInteger("socket.timeout.connect", 15)*1000);
    473476
    474477            try {
     
    481484            try {
    482485                if (activeConnection.getResponseCode() == HttpURLConnection.HTTP_UNAUTHORIZED)
    483                     throw new OsmApiException(HttpURLConnection.HTTP_UNAUTHORIZED,null,null);
     486                    throw new OsmApiException(HttpURLConnection.HTTP_UNAUTHORIZED, null, null);
    484487
    485488                if (activeConnection.getResponseCode() == HttpURLConnection.HTTP_PROXY_AUTH)
     
    490493                    String errorHeader = activeConnection.getHeaderField("Error");
    491494                    StringBuilder errorBody = new StringBuilder();
    492                     try
    493                     {
     495                    try {
    494496                        InputStream i = FixEncoding(activeConnection.getErrorStream(), encoding);
    495497                        if (i != null) {
    496498                            BufferedReader in = new BufferedReader(new InputStreamReader(i));
    497499                            String s;
    498                             while((s = in.readLine()) != null) {
     500                            while ((s = in.readLine()) != null) {
    499501                                errorBody.append(s);
    500502                                errorBody.append("\n");
    501503                            }
    502504                        }
    503                     }
    504                     catch(Exception e) {
     505                    } catch (Exception e) {
    505506                        errorBody.append(tr("Reading error text failed."));
    506507                    }
     
    510511
    511512                return FixEncoding(new ProgressInputStream(activeConnection, progressMonitor), encoding);
    512             } catch(Exception e) {
     513            } catch (Exception e) {
    513514                if (e instanceof SdsTransferException)
    514                     throw (SdsTransferException)e;
     515                    throw (SdsTransferException) e;
    515516                else
    516517                    throw new SdsTransferException(e);
     
    522523    }
    523524
    524     private InputStream FixEncoding(InputStream stream, String encoding) throws IOException
    525     {
     525    private InputStream FixEncoding(InputStream stream, String encoding) throws IOException {
    526526        if (encoding != null && encoding.equalsIgnoreCase("gzip")) {
    527527            stream = new GZIPInputStream(stream);
    528         }
    529         else if (encoding != null && encoding.equalsIgnoreCase("deflate")) {
     528        } else if (encoding != null && encoding.equalsIgnoreCase("deflate")) {
    530529            stream = new InflaterInputStream(stream, new Inflater(true));
    531530        }
    532531        return stream;
    533532    }
    534 
    535 
    536533}
  • applications/editors/josm/plugins/sds/src/org/openstreetmap/hot/sds/SdsConnection.java

    r32702 r32703  
    1 // License: GPL. Copyright 2007 by Immanuel Scholz and others
     1// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.hot.sds;
    33
     
    77import java.util.Base64;
    88
     9import org.openstreetmap.josm.Main;
    910import org.openstreetmap.josm.io.auth.CredentialsAgentException;
    1011import org.openstreetmap.josm.io.auth.CredentialsAgentResponse;
     
    1314 * Base class that handles common things like authentication for the reader and writer
    1415 * to the SDS server.
    15  * 
     16 *
    1617 * Modeled after JOSM's OsmConnection class.
    1718 */
    1819public class SdsConnection {
    19    
     20
    2021    protected boolean cancel = false;
    2122    protected HttpURLConnection activeConnection;
    2223    private SdsCredentialAgent credAgent = new SdsCredentialAgent();
    23    
     24
    2425    /**
    2526     * Initialize the http defaults and the authenticator.
     
    4445            Thread.sleep(100);
    4546        } catch (InterruptedException ex) {
     47            Main.trace(ex);
    4648        }
    4749
     
    6365        String token;
    6466        try {
    65             response = credAgent.getCredentials(RequestorType.SERVER, con.getURL().getHost(), false /* don't know yet whether the credentials will succeed */);
     67            response = credAgent.getCredentials(RequestorType.SERVER, con.getURL().getHost(),
     68                    false /* don't know yet whether the credentials will succeed */);
    6669        } catch (CredentialsAgentException e) {
    6770            throw new SdsTransferException(e);
     
    7376            return;
    7477        } else {
    75             String username= response.getUsername() == null ? "" : response.getUsername();
     78            String username = response.getUsername() == null ? "" : response.getUsername();
    7679            String password = response.getPassword() == null ? "" : String.valueOf(response.getPassword());
    7780            token = username + ":" + password;
     
    8891     *
    8992     * @return true if this connection is canceled
    90      * @return
    9193     */
    9294    public boolean isCanceled() {
  • applications/editors/josm/plugins/sds/src/org/openstreetmap/hot/sds/SdsCredentialAgent.java

    r30738 r32703  
    2323
    2424/**
    25  * Factored after JOSM's JosmPreferencesCredentialAgent. 
     25 * Factored after JOSM's JosmPreferencesCredentialAgent.
    2626 */
    2727public class SdsCredentialAgent extends AbstractCredentialsAgent {
     
    3333     */
    3434    @Override
    35     public PasswordAuthentication lookup(RequestorType requestorType, String host) throws CredentialsAgentException{
     35    public PasswordAuthentication lookup(RequestorType requestorType, String host) throws CredentialsAgentException {
    3636        if (requestorType == null)
    3737            return null;
     
    101101    public Component getPreferencesDecorationPanel() {
    102102        HtmlPanel pnlMessage = new HtmlPanel();
    103         HTMLEditorKit kit = (HTMLEditorKit)pnlMessage.getEditorPane().getEditorKit();
    104         kit.getStyleSheet().addRule(".warning-body {background-color:rgb(253,255,221);padding: 10pt; border-color:rgb(128,128,128);border-style: solid;border-width: 1px;}");
     103        HTMLEditorKit kit = (HTMLEditorKit) pnlMessage.getEditorPane().getEditorKit();
     104        kit.getStyleSheet().addRule(
     105                ".warning-body {background-color:rgb(253,255,221);padding: 10pt; " +
     106                "border-color:rgb(128,128,128);border-style: solid;border-width: 1px;}");
    105107        pnlMessage.setText(
    106108                tr(
     
    114116        return pnlMessage;
    115117    }
    116    
     118
    117119    @Override
    118120    public String getSaveUsernameAndPasswordCheckboxText() {
     
    124126            throws CredentialsAgentException {
    125127        // no-op
    126        
    127     }
    128    
    129     @Override
    130     public CredentialsAgentResponse getCredentials(RequestorType requestorType, String host, boolean noSuccessWithLastResponse) throws CredentialsAgentException{
     128
     129    }
     130
     131    @Override
     132    public CredentialsAgentResponse getCredentials(RequestorType requestorType, String host, boolean noSuccessWithLastResponse)
     133            throws CredentialsAgentException {
    131134        if (requestorType == null)
    132135            return null;
    133         PasswordAuthentication credentials =  lookup(requestorType, host);
     136        PasswordAuthentication credentials = lookup(requestorType, host);
    134137        String username = (credentials == null || credentials.getUserName() == null) ? "" : credentials.getUserName();
    135138        String password = (credentials == null || credentials.getPassword() == null) ? "" : String.valueOf(credentials.getPassword());
     
    158161            CredentialDialog dialog = null;
    159162            switch(requestorType) {
    160             case SERVER: dialog = SdsCredentialDialog.getSdsApiCredentialDialog(username, password, host, getSaveUsernameAndPasswordCheckboxText()); break;
    161             case PROXY: dialog = CredentialDialog.getHttpProxyCredentialDialog(username, password, host, getSaveUsernameAndPasswordCheckboxText()); break;
     163            case SERVER:
     164                dialog = SdsCredentialDialog.getSdsApiCredentialDialog(username, password, host, getSaveUsernameAndPasswordCheckboxText());
     165                break;
     166            case PROXY:
     167                dialog = CredentialDialog.getHttpProxyCredentialDialog(username, password, host, getSaveUsernameAndPasswordCheckboxText());
     168                break;
    162169            }
    163170            dialog.setVisible(true);
     
    190197        return response;
    191198    }
    192    
     199
    193200}
  • applications/editors/josm/plugins/sds/src/org/openstreetmap/hot/sds/SdsCredentialDialog.java

    r30738 r32703  
    1111public class SdsCredentialDialog extends CredentialDialog {
    1212
    13     static public SdsCredentialDialog getSdsApiCredentialDialog(String username, String password, String host, String saveUsernameAndPasswordCheckboxText) {
     13    public static SdsCredentialDialog getSdsApiCredentialDialog(String username, String password, String host,
     14            String saveUsernameAndPasswordCheckboxText) {
    1415        SdsCredentialDialog dialog = new SdsCredentialDialog(saveUsernameAndPasswordCheckboxText);
    1516        dialog.prepareForSdsApiCredentials(username, password);
     
    2324        super(saveUsernameAndPasswordCheckboxText);
    2425    }
    25          
     26
    2627    public void prepareForSdsApiCredentials(String username, String password) {
    2728        setTitle(tr("Enter credentials for Separate Data Store API"));
     
    3031        validate();
    3132    }
    32  
     33
    3334    private static class SdsApiCredentialsPanel extends CredentialPanel {
    3435
     
    4445        }
    4546
    46         public SdsApiCredentialsPanel(SdsCredentialDialog owner) {
     47        SdsApiCredentialsPanel(SdsCredentialDialog owner) {
    4748            super(owner);
    4849            build();
    4950        }
    5051    }
    51 
    52   }
     52}
  • applications/editors/josm/plugins/sds/src/org/openstreetmap/hot/sds/SdsDiskAccessAction.java

    r30738 r32703  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.hot.sds;
    23
     
    1617@SuppressWarnings("serial")
    1718public abstract class SdsDiskAccessAction extends DiskAccessAction {
    18    
     19
    1920    public SdsDiskAccessAction(String name, String iconName, String tooltip,
    2021            Shortcut shortcut) {
     
    3536        fc.setMultiSelectionEnabled(multiple);
    3637        fc.setAcceptAllFileFilterUsed(false);
    37                
     38
    3839        fc.setFileFilter(new FileFilter() {
    39             public boolean accept(File pathname) { return pathname.getName().endsWith(".sds") || pathname.isDirectory(); }
    40             public String getDescription() { return (tr("SDS data file")); }
    41         });     
     40            @Override
     41            public boolean accept(File pathname) {
     42                return pathname.getName().endsWith(".sds") || pathname.isDirectory();
     43            }
     44
     45            @Override
     46            public String getDescription() {
     47                return (tr("SDS data file"));
     48            }
     49        });
    4250
    4351        int answer = open ? fc.showOpenDialog(Main.parent) : fc.showSaveDialog(Main.parent);
     
    8189        fc.setMultiSelectionEnabled(false);
    8290        fc.setAcceptAllFileFilterUsed(false);
    83        
     91
    8492        fc.setFileFilter(new FileFilter() {
    85             public boolean accept(File pathname) { return pathname.getName().endsWith(".sds") || pathname.isDirectory(); }
    86             public String getDescription() { return (tr("SDS data file")); }
    87         });
    88        
     93            @Override
     94            public boolean accept(File pathname) {
     95                return pathname.getName().endsWith(".sds") || pathname.isDirectory();
     96            }
     97
     98            @Override
     99            public String getDescription() {
     100                return (tr("SDS data file"));
     101            }
     102        });
     103
    89104        int answer = fc.showSaveDialog(Main.parent);
    90105        if (answer != JFileChooser.APPROVE_OPTION)
     
    101116        return file;
    102117    }
    103    
     118
    104119    public static boolean confirmOverwrite(File file) {
    105120        if (file == null || (file.exists())) {
  • applications/editors/josm/plugins/sds/src/org/openstreetmap/hot/sds/SdsLoadAction.java

    r32480 r32703  
    1 //License: GPL.
     1// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.hot.sds;
    33
     
    2626@SuppressWarnings("serial")
    2727public class SdsLoadAction extends SdsDiskAccessAction {
    28    
     28
    2929    private SeparateDataStorePlugin plugin;
    3030
     
    3333        plugin = p;
    3434    }
    35    
     35
     36    @Override
    3637    public void actionPerformed(ActionEvent e) {
    3738        SwingFileChooser fc = createAndOpenFileChooser(true, true, null);
  • applications/editors/josm/plugins/sds/src/org/openstreetmap/hot/sds/SdsMenu.java

    r32480 r32703  
    1 //License: GPL. See README for details.
     1// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.hot.sds;
    33
     
    5252        aboutItem = new JMenuItem(new SdsAboutAction());
    5353        menu.add(aboutItem);
    54        
     54
    5555        Main.getLayerManager().addLayerChangeListener(this);
    5656        Main.getLayerManager().addActiveLayerChangeListener(this);
     
    6363        saveItem.setEnabled(en);
    6464    }
    65  
     65
    6666    @Override
    67     public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) {    setEnabledState(); }
     67    public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) {
     68        setEnabledState();
     69    }
    6870
    6971    @Override
     
    7173
    7274    @Override
    73     public void layerAdded(LayerAddEvent e) { setEnabledState(); }
     75    public void layerAdded(LayerAddEvent e) {
     76        setEnabledState();
     77    }
    7478
    7579    @Override
    76     public void layerRemoving(LayerRemoveEvent e) { setEnabledState(); }
     80    public void layerRemoving(LayerRemoveEvent e) {
     81        setEnabledState();
     82    }
    7783
    7884    private class SdsAboutAction extends JosmAction {
    7985
    80         public SdsAboutAction() {
     86        SdsAboutAction() {
    8187            super(tr("About"), "sds", tr("Information about SDS."), null, true);
    8288        }
    8389
     90        @Override
    8491        public void actionPerformed(ActionEvent e) {
    8592            JPanel about = new JPanel();
     
    8996            l.setWrapStyleWord(true);
    9097            l.setEditable(false);
    91             l.setText("Separate Data Store\n\nThis plugin provides access to a \"Separate Data Store\" server. " +
    92                     "Whenever data is loaded from the OSM API, it queries the SDS for additional tags that have been stored for the objects just loaded, " +
    93                     "and adds these tags. When you upload data to JOSM, SDS tags will again be separated and, instead of sending them to OSM, they will be uplaoded to SDS." +
    94                     "\n\n" +
    95                     "This depends on SDS tags starting with a special prefix, which can be configured in the SDS preferences." +
    96                     "\n\n" +
    97                     "Using the SDS server will usually require an account to be set up there, which is completely independent of your OSM account.");
    98            
    99             l.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
     98            l.setText(
     99                "Separate Data Store\n\nThis plugin provides access to a \"Separate Data Store\" server. " +
     100                "Whenever data is loaded from the OSM API, " +
     101                "it queries the SDS for additional tags that have been stored for the objects just loaded, " +
     102                "and adds these tags. When you upload data to JOSM, SDS tags will again be separated and, " +
     103                "instead of sending them to OSM, they will be uploaded to SDS." +
     104                "\n\n" +
     105                "This depends on SDS tags starting with a special prefix, which can be configured in the SDS preferences." +
     106                "\n\n" +
     107                "Using the SDS server will usually require an account to be set up there, which is completely independent of your OSM account.");
     108
     109            l.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    100110            l.setOpaque(false);
    101             l.setPreferredSize(new Dimension(500,300));
     111            l.setPreferredSize(new Dimension(500, 300));
    102112            JScrollPane sp = new JScrollPane(l);
    103113            sp.setBorder(null);
    104114            sp.setOpaque(false);
    105                        
     115
    106116            about.add(sp);
    107            
    108             about.setPreferredSize(new Dimension(500,300));
     117
     118            about.setPreferredSize(new Dimension(500, 300));
    109119
    110120            JOptionPane.showMessageDialog(Main.parent, about, tr("About SDS..."),
     
    112122        }
    113123    }
    114    
    115     private class SdsPreferencesAction extends JosmAction implements Runnable {
     124
     125    private final class SdsPreferencesAction extends JosmAction implements Runnable {
    116126
    117127        private SdsPreferencesAction() {
     
    124134         * Launch the preferences dialog.
    125135         */
     136        @Override
    126137        public void actionPerformed(ActionEvent e) {
    127138            run();
    128139        }
    129140
     141        @Override
    130142        public void run() {
    131143            PreferenceDialog pd = new PreferenceDialog(Main.parent);
    132             // unusual reflection mechanism to cater for older JOSM versions where 
     144            // unusual reflection mechanism to cater for older JOSM versions where
    133145            // the selectPreferencesTabByName method was not public
    134146            try {
     
    136148                sptbn.invoke(pd, "sds");
    137149            } catch (Exception ex) {
    138                 // ignore
     150                Main.trace(ex);
    139151            }
    140152            pd.setVisible(true);
    141153        }
    142154    }
    143 
    144 
    145155}
  • applications/editors/josm/plugins/sds/src/org/openstreetmap/hot/sds/SdsOsmWriter.java

    r30738 r32703  
    1 // License: GPL. Copyright 2007 by Immanuel Scholz and others
     1// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.hot.sds;
    33
     
    1717 * sure that special tags are never written to JOSM's standard
    1818 * output channels.
    19  * 
     19 *
    2020 * In the context of HOT's separate data store, this is very
    2121 * important as otherwise private/confidential information could
    2222 * end up on public servers.
    23  * 
     23 *
    2424 * @author Frederik Ramm
    2525 *
     
    2828
    2929    private SeparateDataStorePlugin plugin;
    30    
     30
    3131    public SdsOsmWriter(SeparateDataStorePlugin plugin, PrintWriter out, boolean osmConform, String version) {
    3232        super(out, osmConform, version);
     
    4545                String key = e.getKey();
    4646                if (!(osm instanceof Changeset) && ("created_by".equals(key))) continue;
    47                 if (key.startsWith(plugin.getIgnorePrefix())) continue;         
     47                if (key.startsWith(plugin.getIgnorePrefix())) continue;
    4848                out.println("    <tag k='"+ XmlWriter.encode(e.getKey()) +
    4949                            "' v='"+XmlWriter.encode(e.getValue())+ "' />");
  • applications/editors/josm/plugins/sds/src/org/openstreetmap/hot/sds/SdsParser.java

    r30738 r32703  
    1111/**
    1212 * Parser for answers from SDS. These anwers look like this:
    13  * 
     13 *
    1414 * <pre>
    1515<?xml version="1.0" encoding="UTF-8"?>
     
    2424 * @author Frederik Ramm
    2525 */
    26 public class SdsParser extends DefaultHandler
    27 {
     26public class SdsParser extends DefaultHandler {
    2827    private DataSet dataSet;
    2928    private OsmPrimitive currentPrimitive;
    3029    private SeparateDataStorePlugin plugin;
    3130    private boolean ensureMatch;
    32    
     31
    3332    public SdsParser(DataSet ds, SeparateDataStorePlugin p, boolean ensureMatch) {
    3433        this.dataSet = ds;
     
    3635        this.ensureMatch = ensureMatch;
    3736    }
    38    
     37
    3938    public SdsParser(DataSet ds, SeparateDataStorePlugin p) {
    4039        this(ds, p, true);
    4140    }
    42    
    43     @Override public void endElement(String namespaceURI, String localName, String qName)
    44     {
     41
     42    @Override public void endElement(String namespaceURI, String localName, String qName) {
    4543        // after successfully reading a full set of tags from the separate data store,
    4644        // update it in our cache so we can determine changes later.
     
    4947        }
    5048    }
    51     @Override public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException
    52     {
    53         if ("osm_shadow".equals(qName))
    54         {
     49
     50    @Override public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
     51        if ("osm_shadow".equals(qName)) {
    5552            String type = atts.getValue("osm_type");
    56             String id = atts.getValue("osm_id");         
     53            String id = atts.getValue("osm_id");
    5754            currentPrimitive = dataSet.getPrimitiveById(Long.parseLong(id), OsmPrimitiveType.fromApiTypeName(type));
    5855            if (currentPrimitive == null && ensureMatch) {
    5956                throw new SAXException("unexpected object in response");
    6057            }
    61         }
    62         else if ("tag".equals(qName))
    63         {
     58        } else if ("tag".equals(qName)) {
    6459            String v = atts.getValue("v");
    6560            String k = atts.getValue("k");
  • applications/editors/josm/plugins/sds/src/org/openstreetmap/hot/sds/SdsPluginPreferences.java

    r30738 r32703  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.hot.sds;
    23
     
    3334    private final JPasswordField password = new JPasswordField(8);
    3435    private final JTextField prefix = new JTextField(8);
    35    
     36
    3637    public SdsPluginPreferences() {
    3738        super("sds", tr("Separate Data Store"), tr("Configures access to the Separate Data Store."));
    3839    }
     40
    3941    @Override
    4042    public void addGui(final PreferenceTabbedPane gui) {
    4143        final JPanel tab = gui.createPreferenceTab(this);
    42            
     44
    4345        final JPanel access = new JPanel(new GridBagLayout());
    4446        access.setBorder(BorderFactory.createTitledBorder(tr("Server")));
     
    5456
    5557        access.add(new JLabel(tr("SDS server URL")), GBC.std());
    56         access.add(server, GBC.eol().fill(GBC.HORIZONTAL).insets(5,0,0,5));
     58        access.add(server, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 0, 0, 5));
    5759
    5860        access.add(new JLabel(tr("SDS username")), GBC.std());
    59         access.add(username, GBC.eol().fill(GBC.HORIZONTAL).insets(5,0,0,5));
     61        access.add(username, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 0, 0, 5));
    6062
    6163        access.add(new JLabel(tr("SDS password")), GBC.std());
    62         access.add(password, GBC.eol().fill(GBC.HORIZONTAL).insets(5,0,0,5));
     64        access.add(password, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 0, 0, 5));
    6365
    6466        JButton test = new JButton(tr("Test credentials now"));
    65         access.add(test, GBC.eol().anchor(GBC.EAST).insets(5,0,0,5));
     67        access.add(test, GBC.eol().anchor(GBC.EAST).insets(5, 0, 0, 5));
    6668
    6769        tab.add(access, GBC.eol().fill(GBC.HORIZONTAL));
    6870
    6971        tab.add(new JLabel(tr("SDS tag prefix")), GBC.std());
    70         tab.add(prefix, GBC.eol().fill(GBC.HORIZONTAL).insets(5,0,0,5));
     72        tab.add(prefix, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 0, 0, 5));
    7173
    7274        tab.add(Box.createVerticalGlue(), GBC.eol().fill(GBC.VERTICAL));
    7375
    7476        test.addActionListener(new ActionListener() {
     77            @Override
    7578            public void actionPerformed(ActionEvent ev) {
    7679                SdsApi api = new SdsApi(server.getText());
     
    8790                            JOptionPane.PLAIN_MESSAGE
    8891                    );
    89                 } catch(Exception ex) {
     92                } catch (Exception ex) {
    9093                    JOptionPane.showMessageDialog(
    9194                            Main.parent,
    92                             tr("Cannot connect to SDS server: ") + ex.getMessage(), 
     95                            tr("Cannot connect to SDS server: ") + ex.getMessage(),
    9396                            tr("Error"),
    9497                            JOptionPane.ERROR_MESSAGE
    9598                    );
    9699                }
    97                 // restore old credentials even if successful; user might still 
     100                // restore old credentials even if successful; user might still
    98101                // choose to press cancel!
    99102                Main.pref.put(SDS_USERNAME, olduser);
  • applications/editors/josm/plugins/sds/src/org/openstreetmap/hot/sds/SdsSaveAction.java

    r32329 r32703  
    1 //License: GPL.
     1// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.hot.sds;
    33
  • applications/editors/josm/plugins/sds/src/org/openstreetmap/hot/sds/SdsWriter.java

    r30738 r32703  
    1 // License: GPL. Copyright 2007 by Immanuel Scholz and others
     1// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.hot.sds;
    33
     
    2424        out.print("<osm_sds>");
    2525    }
     26
    2627    public void footer() {
    2728        out.println("</osm_sds>");
    2829    }
    2930
    30     public void write(IPrimitive what, Map<String,String> tags) {
     31    public void write(IPrimitive what, Map<String, String> tags) {
    3132        out.print("<osm_shadow osm_type=\"");
    3233        out.print(what.getType().getAPIName());
     
    3435        out.print(what.getId());
    3536        out.println("\">");
    36        
     37
    3738        if (tags != null) {
    38             for(Entry<String,String> e : tags.entrySet()) {
     39            for (Entry<String, String> e : tags.entrySet()) {
    3940                out.println("    <tag k='"+ XmlWriter.encode(e.getKey()) +
    4041                        "' v='"+XmlWriter.encode(e.getValue())+ "' />");
    4142            }
    4243        }
    43        
     44
    4445        out.println("</osm_shadow>");
    4546    }
    4647
     48    @Override
    4749    public void close() {
    4850        out.close();
  • applications/editors/josm/plugins/sds/src/org/openstreetmap/hot/sds/SeparateDataStorePlugin.java

    r30738 r32703  
    1 // License: GPL. See LICENSE file for details.
     1// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.hot.sds;
    33
     
    2424 * Plugin that loads extra data from HOT separate data store.
    2525 *
    26  * @author Frederik Ramm <frederik.ramm@geofabrik.de>
     26 * @author Frederik Ramm &lt;frederik.ramm@geofabrik.de&gt;
    2727 */
    28 public class SeparateDataStorePlugin extends Plugin
    29 {
     28public class SeparateDataStorePlugin extends Plugin {
    3029
    3130    public HashMap<Long, IPrimitive> originalNodes = new HashMap<>();
    3231    public HashMap<Long, IPrimitive> originalWays = new HashMap<>();
    3332    public HashMap<Long, IPrimitive> originalRelations = new HashMap<>();
    34    
     33
    3534    public ArrayList<QueueItem> uploadQueue = new ArrayList<>();
    36    
     35
    3736    private PrimitiveVisitor learnVisitor = new PrimitiveVisitor() {
    38         public void visit(INode i) { originalNodes.put(i.getId(), i); }
    39         public void visit(IWay i) { originalWays.put(i.getId(), i); }
    40         public void visit(IRelation i) { originalRelations.put(i.getId(), i); }
     37        @Override
     38        public void visit(INode i) {
     39            originalNodes.put(i.getId(), i);
     40        }
     41
     42        @Override
     43        public void visit(IWay i) {
     44            originalWays.put(i.getId(), i);
     45        }
     46
     47        @Override
     48        public void visit(IRelation i) {
     49            originalRelations.put(i.getId(), i);
     50        }
    4151    };
    42    
     52
    4353    class QueueItem {
    4454        public IPrimitive primitive;
    45         public HashMap<String,String> tags;
     55        public HashMap<String, String> tags;
    4656        public boolean sdsOnly;
    4757        public boolean processed;
    48         public QueueItem(IPrimitive p, HashMap<String,String> t, boolean s) {
     58        QueueItem(IPrimitive p, HashMap<String, String> t, boolean s) {
    4959            primitive = p;
    5060            tags = t;
     
    5363        }
    5464    }
    55    
     65
    5666    /**
    5767     * Creates the plugin
    5868     */
    59     public SeparateDataStorePlugin(PluginInformation info)
    60     {
     69    public SeparateDataStorePlugin(PluginInformation info) {
    6170        super(info);
    6271        System.out.println("initializing SDS plugin");
    63        
     72
    6473        // this lets us see what JOSM load from the server, and augment it with our data:
    6574        OsmReader.registerPostprocessor(new ReadPostprocessor(this));
    66        
     75
    6776        // this makes sure that our data is never written to the OSM server on a low level;
    6877        OsmWriterFactory.theFactory = new SdsOsmWriterFactory(this);
    69        
     78
    7079        // this lets us see what JOSM is planning to upload, and prepare our own uploads
    7180        // accordingly
    7281        UploadAction.registerUploadHook(new DetermineSdsModificationsUploadHook(this));
    73        
     82
    7483        // this lets us perform our own uploads after JOSM has succeeded:
    7584        OsmServerWriter.registerPostprocessor(new WritePostprocessor(this));
     
    8291        return Main.pref.get("sds-server.tag-prefix", "hot:");
    8392    }
    84    
     93
    8594    public IPrimitive getOriginalPrimitive(IPrimitive other) {
    8695        switch (other.getType()) {
     
    8998        case RELATION: return originalRelations.get(other.getId());
    9099        }
    91         return null;   
     100        return null;
    92101    }
    93    
     102
    94103    protected void enqueueForUpload(IPrimitive prim, HashMap<String, String> tags, boolean onlySds) {
    95104        uploadQueue.add(new QueueItem(prim, tags, onlySds));
    96105    }
    97    
    98     /** 
     106
     107    /**
    99108     * Stores the given primitive in the plugin's cache in order to
    100109     * determine changes later.
    101      * @param prim
    102110     */
    103111    protected void learn(IPrimitive prim) {
    104112        if (prim instanceof OsmPrimitive) {
    105             ((OsmPrimitive)prim).save().accept(learnVisitor);
     113            ((OsmPrimitive) prim).save().accept(learnVisitor);
    106114        } else {
    107115            prim.accept(learnVisitor);
    108116        }
    109117    }
    110    
     118
    111119    /**
    112120     * removes all elements from the upload queue that have the processed flag set.
     
    119127        uploadQueue = newQueue;
    120128    }
    121    
     129
    122130    /**
    123131     * reset the processed flag for all elements of the queue.
     
    129137    }
    130138
     139    @Override
    131140    public PreferenceSetting getPreferenceSetting() {
    132141        return new SdsPluginPreferences();
Note: See TracChangeset for help on using the changeset viewer.