Ignore:
Timestamp:
2014-05-10T02:51:06+02:00 (6 years ago)
Author:
Don-vip
Message:

refactor duplicated code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/io/OsmServerBackreferenceReader.java

    r7050 r7092  
    2222 * OsmServerBackreferenceReader fetches the primitives from the OSM server which
    2323 * refer to a specific primitive. For a {@link org.openstreetmap.josm.data.osm.Node Node}, ways and relations are retrieved
    24  * which refer to the node. For a {@link Way} or a {@link Relation}, only relations are
    25  * read.
     24 * which refer to the node. For a {@link Way} or a {@link Relation}, only relations are read.
    2625 *
    2726 * OsmServerBackreferenceReader uses the API calls <code>[node|way|relation]/#id/relations</code>
     
    3231 * to complete incomplete primitives.
    3332 *
    34  *
     33 * @since 1806
    3534 */
    3635public class OsmServerBackreferenceReader extends OsmServerReader {
     
    123122    }
    124123
    125     /**
    126      * Reads referring ways from the API server and replies them in a {@link DataSet}
    127      *
    128      * @return the data set
    129      * @throws OsmTransferException
    130      */
    131     protected DataSet getReferringWays(ProgressMonitor progressMonitor) throws OsmTransferException {
     124    private DataSet getReferringPrimitives(ProgressMonitor progressMonitor, String type, String message) throws OsmTransferException {
    132125        progressMonitor.beginTask(null, 2);
    133126        try {
    134             progressMonitor.indeterminateSubTask(tr("Downloading from OSM Server..."));
     127            progressMonitor.subTask(tr("Contacting OSM Server..."));
    135128            StringBuilder sb = new StringBuilder();
    136             sb.append(primitiveType.getAPIName())
    137             .append("/").append(id).append("/ways");
     129            sb.append(primitiveType.getAPIName()).append("/").append(id).append(type);
    138130
    139131            try (InputStream in = getInputStream(sb.toString(), progressMonitor.createSubTaskMonitor(1, true))) {
    140132                if (in == null)
    141133                    return null;
    142                 progressMonitor.subTask(tr("Downloading referring ways ..."));
     134                progressMonitor.subTask(message);
    143135                return OsmReader.parseDataSet(in, progressMonitor.createSubTaskMonitor(1, true));
    144136            }
     
    156148
    157149    /**
     150     * Reads referring ways from the API server and replies them in a {@link DataSet}
     151     *
     152     * @return the data set
     153     * @throws OsmTransferException
     154     */
     155    protected DataSet getReferringWays(ProgressMonitor progressMonitor) throws OsmTransferException {
     156        return getReferringPrimitives(progressMonitor, "/ways", tr("Downloading referring ways ..."));
     157    }
     158
     159    /**
    158160     * Reads referring relations from the API server and replies them in a {@link DataSet}
    159161     *
     
    163165     */
    164166    protected DataSet getReferringRelations(ProgressMonitor progressMonitor) throws OsmTransferException {
    165         progressMonitor.beginTask(null, 2);
    166         try {
    167             progressMonitor.subTask(tr("Contacting OSM Server..."));
    168             StringBuilder sb = new StringBuilder();
    169             sb.append(primitiveType.getAPIName())
    170             .append("/").append(id).append("/relations");
    171 
    172             try (InputStream in = getInputStream(sb.toString(), progressMonitor.createSubTaskMonitor(1, true))) {
    173                 if (in == null)
    174                     return null;
    175                 progressMonitor.subTask(tr("Downloading referring relations ..."));
    176                 return OsmReader.parseDataSet(in, progressMonitor.createSubTaskMonitor(1, true));
    177             }
    178         } catch(OsmTransferException e) {
    179             throw e;
    180         } catch (Exception e) {
    181             if (cancel)
    182                 return null;
    183             throw new OsmTransferException(e);
    184         } finally {
    185             progressMonitor.finishTask();
    186             activeConnection = null;
    187         }
     167        return getReferringPrimitives(progressMonitor, "/relations", tr("Downloading referring relations ..."));
    188168    }
    189169
Note: See TracChangeset for help on using the changeset viewer.