Changeset 210 in josm for src/org/openstreetmap


Ignore:
Timestamp:
2007-04-04T13:21:40+02:00 (17 years ago)
Author:
imi
Message:
  • added the possibility for <wpt> tags in GPX files to construct markers from relative file:// urls
  • fixed NPE when illegal characters in HTTP response from the server (fix for the fix)
Location:
src/org/openstreetmap/josm
Files:
5 edited

Legend:

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

    r200 r210  
    6262                                Collection<Marker> markerData = null;
    6363                                if (ExtensionFileFilter.filters[ExtensionFileFilter.GPX].acceptName(fn)) {
    64                                         RawGpsReader r = new RawGpsReader(new FileInputStream(file));
     64                                        RawGpsReader r = new RawGpsReader(new FileInputStream(file), file.getAbsoluteFile().getParentFile());
    6565                                        gpsData = r.trackData;
    6666                                        markerData = r.markerData;
  • src/org/openstreetmap/josm/gui/layer/markerlayer/Marker.java

    r200 r210  
    55import java.awt.event.ActionEvent;
    66import java.awt.event.ActionListener;
     7import java.io.File;
    78import java.util.HashMap;
    89import java.util.LinkedList;
     
    1617import org.openstreetmap.josm.gui.MapView;
    1718import org.openstreetmap.josm.tools.ImageProvider;
     19
     20import com.sun.org.apache.xerces.internal.util.URI;
    1821
    1922/**
     
    6871        static {
    6972                Marker.markerProducers.add(new MarkerProducers() {
    70                         public Marker createMarker(LatLon ll, Map<String,String> data) {
     73                        public Marker createMarker(LatLon ll, Map<String,String> data, File relativePath) {
    7174                                String link = data.get("link");
     75
     76                                // Try a relative file:// url, if the link is not in an URL-compatible form
     77                                if (relativePath != null && !URI.isWellFormedAddress(link))
     78                                        link = new File(relativePath, link).toURI().toString();
     79
    7280                                if (link == null)
    7381                                        return new Marker(ll, data.get("name"), data.get("symbol"));
     
    138146         * @param ll lat/lon for marker
    139147         * @param data hash containing keys and values from the GPX waypoint structure
     148         * @param relativePath An path to use for constructing relative URLs or
     149         *        <code>null</code> for no relative URLs
    140150         * @return a new Marker object
    141151         */
    142         public static Marker createMarker(LatLon ll, HashMap<String,String> data) {
     152        public static Marker createMarker(LatLon ll, HashMap<String,String> data, File relativePath) {
    143153                for (MarkerProducers maker : Marker.markerProducers) {
    144                         Marker marker = maker.createMarker(ll, data);
     154                        Marker marker = maker.createMarker(ll, data, relativePath);
    145155                        if (marker != null)
    146156                                return marker;
  • src/org/openstreetmap/josm/gui/layer/markerlayer/MarkerProducers.java

    r200 r210  
    11package org.openstreetmap.josm.gui.layer.markerlayer;
    22
     3import java.io.File;
    34import java.util.Map;
    45
     
    2021         * @param ll lat/lon for the marker position
    2122         * @param data A map of all tags found in the <wpt> node of the gpx file.
     23         * @param relativePath An path to use for constructing relative URLs or
     24         *        <code>null</code> for no relative URLs
    2225         * @return A Marker object, or <code>null</code>.
    2326         */
    24         public Marker createMarker(LatLon ll, Map<String,String> data);
     27        public Marker createMarker(LatLon ll, Map<String,String> data, File relativePath);
    2528}
  • src/org/openstreetmap/josm/io/BoundingBoxDownloader.java

    r204 r210  
    4949                                break;
    5050                        // Use only track points, since the server mix everything together
    51                         Collection<Collection<GpsPoint>> allWays = new RawGpsReader(in).trackData;
     51                        Collection<Collection<GpsPoint>> allWays = new RawGpsReader(in, null).trackData;
    5252
    5353                        boolean foundSomething = false;
     
    7070                if (cancel)
    7171                        return null;
    72                 throw e;
     72                throw new SAXException("Illegal characters within the HTTP-header response", e);
    7373        } catch (IOException e) {
    7474                if (cancel)
  • src/org/openstreetmap/josm/io/RawGpsReader.java

    r200 r210  
    33import static org.openstreetmap.josm.tools.I18n.tr;
    44
     5import java.io.File;
    56import java.io.IOException;
    67import java.io.InputStream;
     
    1516import org.openstreetmap.josm.gui.layer.RawGpsLayer.GpsPoint;
    1617import org.openstreetmap.josm.gui.layer.markerlayer.Marker;
     18import org.openstreetmap.josm.gui.layer.markerlayer.MarkerProducers;
    1719import org.xml.sax.Attributes;
    1820import org.xml.sax.SAXException;
     
    2628 */
    2729public class RawGpsReader {
     30
     31        /**
     32         * The relative path when constructing markers from wpt-tags. Passed to
     33         * {@link MarkerProducers#createMarker(LatLon, java.util.Map, String)}
     34         */
     35        private File relativeMarkerPath;
    2836
    2937        /**
     
    9098                                currentTagValues.clear();
    9199                        } else if (qName.equals("wpt")) {
    92                                 markerData.add(Marker.createMarker(currentLatLon, currentTagValues));
     100                                markerData.add(Marker.createMarker(currentLatLon, currentTagValues, relativeMarkerPath));
    93101                                currentTagValues.clear();
    94102                        } else if (qName.equals("trkseg") || qName.equals("trk") || qName.equals("gpx")) {
     
    107115        }
    108116
    109 
    110117        /**
    111          * Parse the input stream and store the result in trackData and markerData
     118         * Parse the input stream and store the result in trackData and markerData
     119         *
     120         * @param relativeMarkerPath The directory to use as relative path for all &lt;wpt&gt;
     121         *    marker tags. Maybe <code>null</code>, in which case no relative urls are constructed for the markers.
    112122         */
    113         public RawGpsReader(InputStream source) throws SAXException, IOException {
     123        public RawGpsReader(InputStream source, File relativeMarkerPath) throws SAXException, IOException {
     124                this.relativeMarkerPath = relativeMarkerPath;
    114125                Parser parser = new Parser();
    115126                parser.parse(new InputStreamReader(source, "UTF-8"));
Note: See TracChangeset for help on using the changeset viewer.