Ignore:
Timestamp:
2011-12-10T06:44:44+01:00 (12 years ago)
Author:
framm
Message:

Added three new hooks for plugins, allowing plugins to mess with JOSM's server I/O. Plugins can now add postprocessors to server reading (so they may change what JOSM receives from the OSM server), and they can add postprocessors to server writing (so they can react to an upload action *after* it happened and after IDs for new objects have been assigned - this is in addition to the existing UploadHook which is a server writing preprocessor). Thirdly, plugins can now substitute their own version of OsmWriter. Taken together, these changes make it possible for a plugin to introduce extra information from a non-OSM source into the JOSM editing process, and upon upload split away that extra information and send it to another destination. - Also made minor changes to CredentialDialog to allow plugins to subclass the dialog in case they need their own authentication.

File:
1 edited

Legend:

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

    r4191 r4645  
    3636     */
    3737    private Collection<IPrimitive> processed;
     38
     39    private static ArrayList<OsmServerWritePostprocessor> postprocessors;
     40    public static void registerPostprocessor(OsmServerWritePostprocessor pp) {
     41        if (postprocessors == null) {
     42            postprocessors = new ArrayList<OsmServerWritePostprocessor>();
     43        }
     44        postprocessors.add(pp);
     45    }
     46    public static void unregisterPostprocessor(OsmServerWritePostprocessor pp) {
     47        if (postprocessors != null) {
     48            postprocessors.remove(pp);
     49        }
     50    }
    3851
    3952    private OsmApi api = OsmApi.getOsmApi();
     
    205218            throw e;
    206219        } finally {
     220            executePostprocessors(monitor);
    207221            monitor.finishTask();
    208222            api.setChangeset(null);
     
    216230            api.createPrimitive(osm, progressMonitor);
    217231        } else {
    218             api.modifyPrimitive(osm,progressMonitor);
     232            api.modifyPrimitive(osm, progressMonitor);
    219233        }
    220234    }
     
    235249        return processed;
    236250    }
     251
     252    /**
     253     * Calls all registered upload postprocessors.
     254     */
     255    public void executePostprocessors(ProgressMonitor pm) {
     256        if (postprocessors != null) {
     257            for (OsmServerWritePostprocessor pp : postprocessors) {
     258                pp.postprocessUploadedPrimitives(processed, pm);
     259            }
     260        }
     261    }
    237262}
Note: See TracChangeset for help on using the changeset viewer.