Changeset 9241 in josm for trunk/src/org


Ignore:
Timestamp:
2016-01-01T18:52:02+01:00 (9 years ago)
Author:
simon04
Message:

see #7670 - Possibility to download from mirror with all download action

Set preference key download.overpass.for-multi-fetch to true in order to use Overpass API

Location:
trunk/src/org/openstreetmap/josm
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/OverpassDownloadAction.java

    r8932 r9241  
    6060
    6161    /**
     62     * The {@link StringProperty property} of the currently selected Overpass server.
     63     *
     64     * @since 9241
     65     */
     66    public static final StringProperty OVERPASS_SERVER = new StringProperty("download.overpass.server", "http://overpass-api.de/api/");
     67
     68    /**
    6269     * Constructs a new {@code OverpassDownloadAction}.
    6370     */
     
    121128        private JosmTextArea overpassQuery;
    122129        private static OverpassDownloadDialog instance;
    123         private static final StringProperty OVERPASS_SERVER = new StringProperty("download.overpass.server", "http://overpass-api.de/api/");
    124130        private static final CollectionProperty OVERPASS_SERVER_HISTORY = new CollectionProperty("download.overpass.servers",
    125131                Arrays.asList("http://overpass-api.de/api/", "http://overpass.osm.rambler.ru/cgi/"));
  • trunk/src/org/openstreetmap/josm/actions/UpdateSelectionAction.java

    r8510 r9241  
    3939     */
    4040    public static void handlePrimitiveGoneException(long id, OsmPrimitiveType type) {
    41         MultiFetchServerObjectReader reader = new MultiFetchServerObjectReader();
     41        MultiFetchServerObjectReader reader = MultiFetchServerObjectReader.create();
    4242        reader.append(getCurrentDataSet(), id, type);
    4343        try {
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadReferrersTask.java

    r8510 r9241  
    220220            nodes.removeAll(targetLayer.data.getNodes());
    221221            if (!nodes.isEmpty()) {
    222                 reader = new MultiFetchServerObjectReader();
     222                reader = MultiFetchServerObjectReader.create();
    223223                ((MultiFetchServerObjectReader) reader).append(nodes);
    224224                DataSet wayNodes = reader.parseOsm(progressMonitor.createSubTaskMonitor(1, false));
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/DownloadRelationMemberTask.java

    r9078 r9241  
    117117            synchronized (this) {
    118118                if (canceled) return;
    119                 objectReader = new MultiFetchServerObjectReader();
     119                objectReader = MultiFetchServerObjectReader.create();
    120120            }
    121121            objectReader.append(children);
  • trunk/src/org/openstreetmap/josm/gui/io/DownloadPrimitivesTask.java

    r8510 r9241  
    141141            synchronized (this) {
    142142                if (canceled) return;
    143                 multiObjectReader = new MultiFetchServerObjectReader();
     143                multiObjectReader = MultiFetchServerObjectReader.create();
    144144            }
    145145            initMultiFetchReader(multiObjectReader);
  • trunk/src/org/openstreetmap/josm/gui/io/UpdatePrimitivesTask.java

    r9078 r9241  
    128128            synchronized (this) {
    129129                if (canceled) return;
    130                 multiObjectReader = new MultiFetchServerObjectReader();
     130                multiObjectReader = MultiFetchServerObjectReader.create();
    131131            }
    132132            initMultiFetchReaderWithNodes(multiObjectReader);
  • trunk/src/org/openstreetmap/josm/io/MultiFetchServerObjectReader.java

    r9231 r9241  
    1010import java.util.ArrayList;
    1111import java.util.Collection;
     12import java.util.Collections;
    1213import java.util.HashSet;
    1314import java.util.Iterator;
     
    7475     * Constructs a {@code MultiFetchServerObjectReader}.
    7576     */
    76     public MultiFetchServerObjectReader() {
     77    protected MultiFetchServerObjectReader() {
    7778        nodes = new LinkedHashSet<>();
    7879        ways = new LinkedHashSet<>();
     
    8081        this.outputDataSet = new DataSet();
    8182        this.missingPrimitives = new LinkedHashSet<>();
     83    }
     84
     85    /**
     86     * Creates a new instance of {@link MultiFetchServerObjectReader} or {@link MultiFetchOverpassObjectReader}
     87     * depending on the {@code download.overpass.for-multi-fetch} preference.
     88     *
     89     * @return a new instance
     90     * @since 9241
     91     */
     92    public static MultiFetchServerObjectReader create() {
     93        return create(Main.pref.getBoolean("download.overpass.for-multi-fetch", false));
     94    }
     95
     96    /**
     97     * Creates a new instance of {@link MultiFetchServerObjectReader} or {@link MultiFetchOverpassObjectReader}
     98     * depending on the {@code fromMirror} parameter.
     99     *
     100     * @param fromMirror {@code false} for {@link MultiFetchServerObjectReader}, {@code true} for {@link MultiFetchOverpassObjectReader}
     101     * @return a new instance
     102     * @since 9241
     103     */
     104    static MultiFetchServerObjectReader create(final boolean fromMirror) {
     105        if (fromMirror) {
     106            return new MultiFetchOverpassObjectReader();
     107        } else {
     108            return new MultiFetchServerObjectReader();
     109        }
    82110    }
    83111
     
    240268     * @return the request string
    241269     */
    242     protected static String buildRequestString(OsmPrimitiveType type, Set<Long> idPackage) {
    243         StringBuilder sb = new StringBuilder();
    244         sb.append(type.getAPIName()).append("s?")
    245         .append(type.getAPIName()).append("s=");
    246 
    247         Iterator<Long> it = idPackage.iterator();
    248         for (int i = 0; i < idPackage.size(); i++) {
    249             sb.append(it.next());
    250             if (i < idPackage.size()-1) {
    251                 sb.append(',');
    252             }
    253         }
    254         return sb.toString();
    255     }
    256 
    257     /**
    258      * builds the Multi Get request string for a single id and a given {@link OsmPrimitiveType}.
    259      *
    260      * @param type The primitive type. Must be one of {@link OsmPrimitiveType#NODE NODE}, {@link OsmPrimitiveType#WAY WAY},
    261      * {@link OsmPrimitiveType#RELATION RELATION}
    262      * @param id the id
    263      * @return the request string
    264      */
    265     protected static String buildRequestString(OsmPrimitiveType type, long id) {
    266         StringBuilder sb = new StringBuilder();
    267         sb.append(type.getAPIName()).append("s?")
    268         .append(type.getAPIName()).append("s=")
    269         .append(id);
    270         return sb.toString();
     270    protected String buildRequestString(final OsmPrimitiveType type, Set<Long> idPackage) {
     271        return type.getAPIName() + "s?" + type.getAPIName() + "s=" + Utils.join(",", idPackage);
     272    }
     273
     274    @Override
     275    protected String getBaseUrl() {
     276        return super.getBaseUrl();
    271277    }
    272278
     
    304310    protected void fetchPrimitives(Set<Long> ids, OsmPrimitiveType type, ProgressMonitor progressMonitor) throws OsmTransferException {
    305311        String msg = "";
    306         String baseUrl = OsmApi.getOsmApi().getBaseUrl();
     312        final String baseUrl = getBaseUrl();
    307313        switch (type) {
    308314            case NODE:     msg = tr("Fetching a package of nodes from ''{0}''",     baseUrl); break;
     
    429435     * @see FetchResult
    430436     */
    431     protected static class Fetcher extends OsmServerReader implements Callable<FetchResult> {
     437    protected class Fetcher extends OsmServerReader implements Callable<FetchResult> {
    432438
    433439        private final Set<Long> pkg;
     
    477483                }
    478484            }
     485        }
     486
     487        @Override
     488        protected String getBaseUrl() {
     489            return MultiFetchServerObjectReader.this.getBaseUrl();
    479490        }
    480491
     
    520531         */
    521532        protected DataSet singleGetId(OsmPrimitiveType type, long id, ProgressMonitor progressMonitor) throws OsmTransferException {
    522             String request = buildRequestString(type, id);
     533            String request = buildRequestString(type, Collections.singleton(id));
    523534            DataSet result = null;
    524535            try (InputStream in = getInputStream(request, NullProgressMonitor.INSTANCE)) {
Note: See TracChangeset for help on using the changeset viewer.