Changeset 5681 in josm


Ignore:
Timestamp:
2013-01-27T20:07:53+01:00 (11 years ago)
Author:
bastiK
Message:

some simple refactoring

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/command/PurgeCommand.java

    r5674 r5681  
    154154         * Then add all ways, each preceded by its (remaining) nodes.
    155155         */
    156         top:
    157             while (!in.isEmpty()) {
    158                 for (Iterator<OsmPrimitive> it = in.iterator(); it.hasNext();) {
    159                     OsmPrimitive u = it.next();
    160                     if (u instanceof Way) {
    161                         Way w = (Way) u;
    162                         it.remove();
    163                         for (Node n : w.getNodes()) {
    164                             if (in.contains(n)) {
    165                                 in.remove(n);
    166                                 out.add(n);
    167                             }
     156        top: while (!in.isEmpty()) {
     157            for (Iterator<OsmPrimitive> it = in.iterator(); it.hasNext();) {
     158                OsmPrimitive u = it.next();
     159                if (u instanceof Way) {
     160                    Way w = (Way) u;
     161                    it.remove();
     162                    for (Node n : w.getNodes()) {
     163                        if (in.contains(n)) {
     164                            in.remove(n);
     165                            out.add(n);
    168166                        }
    169                         out.add(w);
    170                         continue top;
    171                     }
    172                 }
    173                 break; // no more ways left
    174             }
    175 
    176             /**
    177              * Rest are relations. Do topological sorting on a DAG where each
    178              * arrow points from child to parent. (Because it is faster to
    179              * loop over getReferrers() than getMembers().)
    180              */
    181             Set<Relation> inR = (Set) in;
    182             Set<Relation> childlessR = new HashSet<Relation>();
    183             List<Relation> outR = new ArrayList<Relation>(inR.size());
    184 
    185             HashMap<Relation, Integer> numChilds = new HashMap<Relation, Integer>();
    186 
    187             // calculate initial number of childs
    188             for (Relation r : inR) {
    189                 numChilds.put(r, 0);
    190             }
    191             for (Relation r : inR) {
    192                 for (OsmPrimitive parent : r.getReferrers()) {
    193                     if (!(parent instanceof Relation))
    194                         throw new AssertionError();
    195                     Integer i = numChilds.get(parent);
    196                     if (i != null) {
    197                         numChilds.put((Relation)parent, i+1);
    198                     }
    199                 }
    200             }
    201             for (Relation r : inR) {
    202                 if (numChilds.get(r).equals(0)) {
    203                     childlessR.add(r);
    204                 }
    205             }
    206 
    207             while (!childlessR.isEmpty()) {
    208                 // Identify one childless Relation and
    209                 // let it virtually die. This makes other
    210                 // relations childless.
    211                 Iterator<Relation> it  = childlessR.iterator();
    212                 Relation next = it.next();
    213                 it.remove();
    214                 outR.add(next);
    215 
    216                 for (OsmPrimitive parentPrim : next.getReferrers()) {
    217                     Relation parent = (Relation) parentPrim;
    218                     Integer i = numChilds.get(parent);
    219                     if (i != null) {
    220                         numChilds.put(parent, i-1);
    221                         if (i-1 == 0) {
    222                             childlessR.add(parent);
    223                         }
    224                     }
    225                 }
    226             }
    227 
    228             if (outR.size() != inR.size())
    229                 throw new AssertionError("topo sort algorithm failed");
    230 
    231             out.addAll(outR);
    232 
    233             return out;
     167                    }
     168                    out.add(w);
     169                    continue top;
     170                }
     171            }
     172            break; // no more ways left
     173        }
     174
     175        /**
     176            * Rest are relations. Do topological sorting on a DAG where each
     177            * arrow points from child to parent. (Because it is faster to
     178            * loop over getReferrers() than getMembers().)
     179            */
     180        Set<Relation> inR = (Set) in;
     181        Set<Relation> childlessR = new HashSet<Relation>();
     182        List<Relation> outR = new ArrayList<Relation>(inR.size());
     183
     184        HashMap<Relation, Integer> numChilds = new HashMap<Relation, Integer>();
     185
     186        // calculate initial number of childs
     187        for (Relation r : inR) {
     188            numChilds.put(r, 0);
     189        }
     190        for (Relation r : inR) {
     191            for (OsmPrimitive parent : r.getReferrers()) {
     192                if (!(parent instanceof Relation))
     193                    throw new AssertionError();
     194                Integer i = numChilds.get(parent);
     195                if (i != null) {
     196                    numChilds.put((Relation)parent, i+1);
     197                }
     198            }
     199        }
     200        for (Relation r : inR) {
     201            if (numChilds.get(r).equals(0)) {
     202                childlessR.add(r);
     203            }
     204        }
     205
     206        while (!childlessR.isEmpty()) {
     207            // Identify one childless Relation and
     208            // let it virtually die. This makes other
     209            // relations childless.
     210            Iterator<Relation> it  = childlessR.iterator();
     211            Relation next = it.next();
     212            it.remove();
     213            outR.add(next);
     214
     215            for (OsmPrimitive parentPrim : next.getReferrers()) {
     216                Relation parent = (Relation) parentPrim;
     217                Integer i = numChilds.get(parent);
     218                if (i != null) {
     219                    numChilds.put(parent, i-1);
     220                    if (i-1 == 0) {
     221                        childlessR.add(parent);
     222                    }
     223                }
     224            }
     225        }
     226
     227        if (outR.size() != inR.size())
     228            throw new AssertionError("topo sort algorithm failed");
     229
     230        out.addAll(outR);
     231
     232        return out;
    234233    }
    235234
  • trunk/src/org/openstreetmap/josm/data/gpx/GpxData.java

    r5679 r5681  
    1818 */
    1919public class GpxData extends WithAttributes {
    20 
    21     public static final String META_PREFIX = "meta.";
    22     public static final String META_AUTHOR_NAME = META_PREFIX + "author.name";
    23     public static final String META_AUTHOR_EMAIL = META_PREFIX + "author.email";
    24     public static final String META_AUTHOR_LINK = META_PREFIX + "author.link";
    25     public static final String META_COPYRIGHT_AUTHOR = META_PREFIX + "copyright.author";
    26     public static final String META_COPYRIGHT_LICENSE = META_PREFIX + "copyright.license";
    27     public static final String META_COPYRIGHT_YEAR = META_PREFIX + "copyright.year";
    28     public static final String META_DESC = META_PREFIX + "desc";
    29     public static final String META_KEYWORDS = META_PREFIX + "keywords";
    30     public static final String META_LINKS = META_PREFIX + "links";
    31     public static final String META_NAME = META_PREFIX + "name";
    32     public static final String META_TIME = META_PREFIX + "time";
    33     public static final String META_EXTENSIONS = META_PREFIX + "extensions";
    34 
    35     public static final String JOSM_EXTENSIONS_NAMESPACE_URI = "http://josm.openstreetmap.de/gpx-extensions";
    3620
    3721    public File storageFile;
  • trunk/src/org/openstreetmap/josm/data/gpx/GpxTrack.java

    r3119 r5681  
    1515 */
    1616
    17 public interface GpxTrack {
     17public interface GpxTrack extends IWithAttributes {
    1818
    1919    Collection<GpxTrackSegment> getSegments();
  • trunk/src/org/openstreetmap/josm/data/gpx/IWithAttributes.java

    r5677 r5681  
    1 // License: GPL.
     1// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.data.gpx;
    33
    44import java.util.Collection;
    5 import java.util.HashMap;
    6 import java.util.Map;
    75
    86/**
    9  * Base class for various classes in the GPX model.
    10  *
    11  * @author Frederik Ramm <frederik@remote.org>
    12  * @since 444
     7 * Object with attributes.
    138 */
    14 public class WithAttributes {
    15 
    16     /**
    17      * The "attr" hash is used to store the XML payload (not only XML attributes!)
    18      */
    19     public Map<String, Object> attr = new HashMap<String, Object>(0);
     9public interface IWithAttributes {
    2010
    2111    /**
     
    2717     *         or {@code null} if this map contains no String mapping for the key
    2818     */
    29     public String getString(String key) {
    30         Object value = attr.get(key);
    31         return (value instanceof String) ? (String)value : null;
    32     }
     19    String getString(String key);
    3320   
    3421    /**
     
    4128     * @since 5502
    4229     */
    43     public Collection<?> getCollection(String key) {
    44         Object value = attr.get(key);
    45         return (value instanceof Collection<?>) ? (Collection<?>)value : null;
    46     }
     30    Collection<?> getCollection(String key);
    4731}
  • trunk/src/org/openstreetmap/josm/data/gpx/ImmutableGpxTrack.java

    r5170 r5681  
    1111import org.openstreetmap.josm.data.Bounds;
    1212
    13 public class ImmutableGpxTrack implements GpxTrack {
     13public class ImmutableGpxTrack extends WithAttributes implements GpxTrack {
    1414
    15     private final Map<String, Object> attributes;
    1615    private final Collection<GpxTrackSegment> segments;
    1716    private final double length;
     
    2524            }
    2625        }
    27         this.attributes = Collections.unmodifiableMap(new HashMap<String, Object>(attributes));
     26        this.attr = Collections.unmodifiableMap(new HashMap<String, Object>(attributes));
    2827        this.segments = Collections.unmodifiableCollection(newSegments);
    2928        this.length = calculateLength();
     
    5554    }
    5655
     56    @Override
    5757    public Map<String, Object> getAttributes() {
    58         return attributes;
     58        return attr;
    5959    }
    6060
     61    @Override
    6162    public Bounds getBounds() {
    6263        if (bounds == null)
     
    6667    }
    6768
     69    @Override
    6870    public double length() {
    6971        return length;
    7072    }
    7173
     74    @Override
    7275    public Collection<GpxTrackSegment> getSegments() {
    7376        return segments;
    7477    }
    7578
     79    @Override
    7680    public int getUpdateCount() {
    7781        return 0;
  • trunk/src/org/openstreetmap/josm/data/gpx/WithAttributes.java

    r5502 r5681  
    1 // License: GPL.
     1// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.data.gpx;
    33
     
    77
    88/**
     9 * Default implementation for IWithAttributes.
     10 *
    911 * Base class for various classes in the GPX model.
    1012 *
     
    1214 * @since 444
    1315 */
    14 public class WithAttributes {
     16public class WithAttributes implements IWithAttributes, GpxConstants {
    1517
    1618    /**
     
    2022
    2123    /**
    22      * Returns the String value to which the specified key is mapped, 
     24     * Returns the String value to which the specified key is mapped,
    2325     * or {@code null} if this map contains no String mapping for the key.
    24      * 
     26     *
    2527     * @param key the key whose associated value is to be returned
    26      * @return the String value to which the specified key is mapped, 
     28     * @return the String value to which the specified key is mapped,
    2729     *         or {@code null} if this map contains no String mapping for the key
    2830     */
     31    @Override
    2932    public String getString(String key) {
    3033        Object value = attr.get(key);
    3134        return (value instanceof String) ? (String)value : null;
    3235    }
    33    
     36
    3437    /**
    35      * Returns the Collection value to which the specified key is mapped, 
     38     * Returns the Collection value to which the specified key is mapped,
    3639     * or {@code null} if this map contains no Collection mapping for the key.
    37      * 
     40     *
    3841     * @param key the key whose associated value is to be returned
    39      * @return the Collection value to which the specified key is mapped, 
     42     * @return the Collection value to which the specified key is mapped,
    4043     *         or {@code null} if this map contains no Collection mapping for the key
    4144     * @since 5502
    4245     */
     46    @Override
    4347    public Collection<?> getCollection(String key) {
    4448        Object value = attr.get(key);
  • trunk/src/org/openstreetmap/josm/data/validation/PaintVisitor.java

    r5671 r5681  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.data.validation;
    23
  • trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java

    r5459 r5681  
    6868import org.openstreetmap.josm.data.coor.EastNorth;
    6969import org.openstreetmap.josm.data.coor.LatLon;
     70import org.openstreetmap.josm.data.gpx.GpxConstants;
    7071import org.openstreetmap.josm.data.gpx.GpxData;
    7172import org.openstreetmap.josm.data.gpx.GpxRoute;
     
    207208
    208209        if (data.attr.containsKey("name")) {
    209             info.append(tr("Name: {0}", data.attr.get(GpxData.META_NAME))).append("<br>");
     210            info.append(tr("Name: {0}", data.attr.get(GpxConstants.META_NAME))).append("<br>");
    210211        }
    211212
    212213        if (data.attr.containsKey("desc")) {
    213             info.append(tr("Description: {0}", data.attr.get(GpxData.META_DESC))).append("<br>");
     214            info.append(tr("Description: {0}", data.attr.get(GpxConstants.META_DESC))).append("<br>");
    214215        }
    215216
     
    324325
    325326        if (data.attr.containsKey("name")) {
    326             info.append(tr("Name: {0}", data.attr.get(GpxData.META_NAME))).append("<br>");
     327            info.append(tr("Name: {0}", data.attr.get(GpxConstants.META_NAME))).append("<br>");
    327328        }
    328329
    329330        if (data.attr.containsKey("desc")) {
    330             info.append(tr("Description: {0}", data.attr.get(GpxData.META_DESC))).append("<br>");
     331            info.append(tr("Description: {0}", data.attr.get(GpxConstants.META_DESC))).append("<br>");
    331332        }
    332333
  • trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/Marker.java

    r5501 r5681  
    2323import org.openstreetmap.josm.data.coor.EastNorth;
    2424import org.openstreetmap.josm.data.coor.LatLon;
    25 import org.openstreetmap.josm.data.gpx.GpxData;
     25import org.openstreetmap.josm.data.gpx.GpxConstants;
    2626import org.openstreetmap.josm.data.gpx.GpxLink;
    2727import org.openstreetmap.josm.data.gpx.WayPoint;
     
    185185                // cheapest way to check whether "link" object exists and is a non-empty
    186186                // collection of GpxLink objects...
    187                 Collection<GpxLink> links = (Collection<GpxLink>)wpt.attr.get(GpxData.META_LINKS);
     187                Collection<GpxLink> links = (Collection<GpxLink>)wpt.attr.get(GpxConstants.META_LINKS);
    188188                if (links != null) {
    189189                    for (GpxLink oneLink : links ) {
  • trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/MarkerLayer.java

    r5564 r5681  
    3232import org.openstreetmap.josm.data.Bounds;
    3333import org.openstreetmap.josm.data.coor.LatLon;
     34import org.openstreetmap.josm.data.gpx.GpxConstants;
    3435import org.openstreetmap.josm.data.gpx.GpxData;
    3536import org.openstreetmap.josm.data.gpx.GpxLink;
     
    8586            /* calculate time differences in waypoints */
    8687            double time = wpt.time;
    87             boolean wpt_has_link = wpt.attr.containsKey(GpxData.META_LINKS);
     88            boolean wpt_has_link = wpt.attr.containsKey(GpxConstants.META_LINKS);
    8889            if (firstTime < 0 && wpt_has_link) {
    8990                firstTime = time;
    90                 for (Object oneLink : wpt.getCollection(GpxData.META_LINKS)) {
     91                for (Object oneLink : wpt.getCollection(GpxConstants.META_LINKS)) {
    9192                    if (oneLink instanceof GpxLink) {
    9293                        lastLinkedFile = ((GpxLink)oneLink).uri;
     
    9697            }
    9798            if (wpt_has_link) {
    98                 for (Object oneLink : wpt.getCollection(GpxData.META_LINKS)) {
     99                for (Object oneLink : wpt.getCollection(GpxConstants.META_LINKS)) {
    99100                    if (oneLink instanceof GpxLink) {
    100101                        String uri = ((GpxLink)oneLink).uri;
  • trunk/src/org/openstreetmap/josm/io/GpxExporter.java

    r5397 r5681  
    2727
    2828import org.openstreetmap.josm.Main;
     29import org.openstreetmap.josm.data.gpx.GpxConstants;
    2930import org.openstreetmap.josm.data.gpx.GpxData;
    3031import org.openstreetmap.josm.data.osm.DataSet;
     
    3637import org.openstreetmap.josm.tools.GBC;
    3738
    38 public class GpxExporter extends FileExporter {
     39public class GpxExporter extends FileExporter implements GpxConstants {
    3940    private final static String warningGpl = "<html><font color='red' size='-2'>"
    4041        + tr("Note: GPL is not compatible with the OSM license. Do not upload GPL licensed tracks.") + "</html>";
     
    8283        desc.setWrapStyleWord(true);
    8384        desc.setLineWrap(true);
    84         desc.setText((String) gpxData.attr.get(GpxData.META_DESC));
     85        desc.setText((String) gpxData.attr.get(META_DESC));
    8586        p.add(new JScrollPane(desc), GBC.eop().fill(GBC.BOTH));
    8687
     
    112113        p.add(new JLabel(tr("Keywords")), GBC.eol());
    113114        JTextField keywords = new JTextField();
    114         keywords.setText((String) gpxData.attr.get(GpxData.META_KEYWORDS));
     115        keywords.setText((String) gpxData.attr.get(META_KEYWORDS));
    115116        p.add(keywords, GBC.eop().fill(GBC.HORIZONTAL));
    116117
     
    144145        if (author.isSelected()) {
    145146            if (authorName.getText().length() > 0) {
    146                 gpxData.attr.put(GpxData.META_AUTHOR_NAME, authorName.getText());
    147                 gpxData.attr.put(GpxData.META_COPYRIGHT_AUTHOR, authorName.getText());
     147                gpxData.attr.put(META_AUTHOR_NAME, authorName.getText());
     148                gpxData.attr.put(META_COPYRIGHT_AUTHOR, authorName.getText());
    148149            }
    149150            if (email.getText().length() > 0) {
    150                 gpxData.attr.put(GpxData.META_AUTHOR_EMAIL, email.getText());
     151                gpxData.attr.put(META_AUTHOR_EMAIL, email.getText());
    151152            }
    152153            if (copyright.getText().length() > 0) {
    153                 gpxData.attr.put(GpxData.META_COPYRIGHT_LICENSE, copyright.getText());
     154                gpxData.attr.put(META_COPYRIGHT_LICENSE, copyright.getText());
    154155            }
    155156            if (copyrightYear.getText().length() > 0) {
    156                 gpxData.attr.put(GpxData.META_COPYRIGHT_YEAR, copyrightYear.getText());
     157                gpxData.attr.put(META_COPYRIGHT_YEAR, copyrightYear.getText());
    157158            }
    158159        }
     
    160161        // add the description to the gpx data
    161162        if (desc.getText().length() > 0) {
    162             gpxData.attr.put(GpxData.META_DESC, desc.getText());
     163            gpxData.attr.put(META_DESC, desc.getText());
    163164        }
    164165
    165166        // add keywords to the gpx data
    166167        if (keywords.getText().length() > 0) {
    167             gpxData.attr.put(GpxData.META_KEYWORDS, keywords.getText());
     168            gpxData.attr.put(META_KEYWORDS, keywords.getText());
    168169        }
    169170
     
    193194        if (enable) {
    194195            if (copyrightYear.getText().length()==0) {
    195                 String sCopyrightYear = (String) data.attr.get(GpxData.META_COPYRIGHT_YEAR);
     196                String sCopyrightYear = (String) data.attr.get(META_COPYRIGHT_YEAR);
    196197                if (sCopyrightYear == null) {
    197198                    sCopyrightYear = Integer.toString(Calendar.getInstance().get(Calendar.YEAR));
     
    200201            }
    201202            if (copyright.getText().length()==0) {
    202                 String sCopyright = (String) data.attr.get(GpxData.META_COPYRIGHT_LICENSE);
     203                String sCopyright = (String) data.attr.get(META_COPYRIGHT_LICENSE);
    203204                if (sCopyright == null) {
    204205                    sCopyright = Main.pref.get("lastCopyright", "http://creativecommons.org/licenses/by-sa/2.5");
     
    243244                emailLabel.setEnabled(b);
    244245                if (b) {
    245                     String sAuthorName = (String) data.attr.get(GpxData.META_AUTHOR_NAME);
     246                    String sAuthorName = (String) data.attr.get(META_AUTHOR_NAME);
    246247                    if (sAuthorName == null) {
    247248                        sAuthorName = Main.pref.get("lastAuthorName");
    248249                    }
    249250                    authorName.setText(sAuthorName);
    250                     String sEmail = (String) data.attr.get(GpxData.META_AUTHOR_EMAIL);
     251                    String sEmail = (String) data.attr.get(META_AUTHOR_EMAIL);
    251252                    if (sEmail == null) {
    252253                        sEmail = Main.pref.get("lastAuthorEmail");
  • trunk/src/org/openstreetmap/josm/io/GpxReader.java

    r5679 r5681  
    2121import org.openstreetmap.josm.data.coor.LatLon;
    2222import org.openstreetmap.josm.data.gpx.Extensions;
     23import org.openstreetmap.josm.data.gpx.GpxConstants;
    2324import org.openstreetmap.josm.data.gpx.GpxData;
    2425import org.openstreetmap.josm.data.gpx.GpxLink;
     
    3940 * @author imi, ramack
    4041 */
    41 public class GpxReader {
     42public class GpxReader implements GpxConstants {
    4243
    4344    private String version;
     
    140141                    states.push(currentState);
    141142                    currentState = State.copyright;
    142                     data.attr.put(GpxData.META_COPYRIGHT_AUTHOR, atts.getValue("author"));
     143                    data.attr.put(META_COPYRIGHT_AUTHOR, atts.getValue("author"));
    143144                } else if (localName.equals("link")) {
    144145                    states.push(currentState);
     
    153154                    currentLink = new GpxLink(atts.getValue("href"));
    154155                } else if (localName.equals("email")) {
    155                     data.attr.put(GpxData.META_AUTHOR_EMAIL, atts.getValue("id") + "@" + atts.getValue("domain"));
     156                    data.attr.put(META_AUTHOR_EMAIL, atts.getValue("id") + "@" + atts.getValue("domain"));
    156157                }
    157158                break;
     
    243244            case metadata:  // GPX 1.1
    244245                if (localName.equals("name")) {
    245                     data.attr.put(GpxData.META_NAME, accumulator.toString());
     246                    data.attr.put(META_NAME, accumulator.toString());
    246247                } else if (localName.equals("desc")) {
    247                     data.attr.put(GpxData.META_DESC, accumulator.toString());
     248                    data.attr.put(META_DESC, accumulator.toString());
    248249                } else if (localName.equals("time")) {
    249                     data.attr.put(GpxData.META_TIME, accumulator.toString());
     250                    data.attr.put(META_TIME, accumulator.toString());
    250251                } else if (localName.equals("keywords")) {
    251                     data.attr.put(GpxData.META_KEYWORDS, accumulator.toString());
     252                    data.attr.put(META_KEYWORDS, accumulator.toString());
    252253                } else if (version.equals("1.0") && localName.equals("author")) {
    253254                    // author is a string in 1.0, but complex element in 1.1
    254                     data.attr.put(GpxData.META_AUTHOR_NAME, accumulator.toString());
     255                    data.attr.put(META_AUTHOR_NAME, accumulator.toString());
    255256                } else if (version.equals("1.0") && localName.equals("email")) {
    256                     data.attr.put(GpxData.META_AUTHOR_EMAIL, accumulator.toString());
     257                    data.attr.put(META_AUTHOR_EMAIL, accumulator.toString());
    257258                } else if (localName.equals("url") || localName.equals("urlname")) {
    258259                    data.attr.put(localName, accumulator.toString());
     
    261262                    convertUrlToLink(data.attr);
    262263                    if (currentExtensions != null && !currentExtensions.isEmpty()) {
    263                         data.attr.put(GpxData.META_EXTENSIONS, currentExtensions);
     264                        data.attr.put(META_EXTENSIONS, currentExtensions);
    264265                    }
    265266                    currentState = states.pop();
     
    271272                    currentState = states.pop();
    272273                } else if (localName.equals("name")) {
    273                     data.attr.put(GpxData.META_AUTHOR_NAME, accumulator.toString());
     274                    data.attr.put(META_AUTHOR_NAME, accumulator.toString());
    274275                } else if (localName.equals("email")) {
    275276                    // do nothing, has been parsed on startElement
    276277                } else if (localName.equals("link")) {
    277                     data.attr.put(GpxData.META_AUTHOR_LINK, currentLink);
     278                    data.attr.put(META_AUTHOR_LINK, currentLink);
    278279                }
    279280                break;
     
    282283                    currentState = states.pop();
    283284                } else if (localName.equals("year")) {
    284                     data.attr.put(GpxData.META_COPYRIGHT_YEAR, accumulator.toString());
     285                    data.attr.put(META_COPYRIGHT_YEAR, accumulator.toString());
    285286                } else if (localName.equals("license")) {
    286                     data.attr.put(GpxData.META_COPYRIGHT_LICENSE, accumulator.toString());
     287                    data.attr.put(META_COPYRIGHT_LICENSE, accumulator.toString());
    287288                }
    288289                break;
     
    299300                }
    300301                if (currentState == State.author) {
    301                     data.attr.put(GpxData.META_AUTHOR_LINK, currentLink);
     302                    data.attr.put(META_AUTHOR_LINK, currentLink);
    302303                } else if (currentState != State.link) {
    303304                    Map<String, Object> attr = getAttr();
    304                     if (!attr.containsKey(GpxData.META_LINKS)) {
    305                         attr.put(GpxData.META_LINKS, new LinkedList<GpxLink>());
     305                    if (!attr.containsKey(META_LINKS)) {
     306                        attr.put(META_LINKS, new LinkedList<GpxLink>());
    306307                    }
    307                     ((Collection<GpxLink>) attr.get(GpxData.META_LINKS)).add(currentLink);
     308                    ((Collection<GpxLink>) attr.get(META_LINKS)).add(currentLink);
    308309                }
    309310                break;
     
    364365                    currentState = states.pop();
    365366                // only interested in extensions written by JOSM
    366                 } else if (GpxData.JOSM_EXTENSIONS_NAMESPACE_URI.equals(namespaceURI)) {
     367                } else if (JOSM_EXTENSIONS_NAMESPACE_URI.equals(namespaceURI)) {
    367368                    currentExtensions.put(localName, accumulator.toString());
    368369                }
     
    382383            if (!states.empty())
    383384                throw new SAXException(tr("Parse error: invalid document structure for GPX document."));
    384             Extensions metaExt = (Extensions) data.attr.get(GpxData.META_EXTENSIONS);
     385            Extensions metaExt = (Extensions) data.attr.get(META_EXTENSIONS);
    385386            if (metaExt != null && "true".equals(metaExt.get("from-server"))) {
    386387                data.fromServer = true;
     
    396397            String urlname = (String) attr.get("urlname");
    397398            if (url != null) {
    398                 if (!attr.containsKey(GpxData.META_LINKS)) {
    399                     attr.put(GpxData.META_LINKS, new LinkedList<GpxLink>());
     399                if (!attr.containsKey(META_LINKS)) {
     400                    attr.put(META_LINKS, new LinkedList<GpxLink>());
    400401                }
    401402                GpxLink link = new GpxLink(url);
    402403                link.text = urlname;
    403404                @SuppressWarnings("unchecked")
    404                 Collection<GpxLink> links = (Collection) attr.get(GpxData.META_LINKS);
     405                Collection<GpxLink> links = (Collection) attr.get(META_LINKS);
    405406                links.add(link);
    406407            }
  • trunk/src/org/openstreetmap/josm/io/GpxWriter.java

    r5679 r5681  
    99import java.io.PrintWriter;
    1010import java.io.UnsupportedEncodingException;
    11 import java.util.Arrays;
    1211import java.util.Collection;
    13 import java.util.List;
    1412import java.util.Map;
    1513
    1614import org.openstreetmap.josm.data.Bounds;
    1715import org.openstreetmap.josm.data.coor.LatLon;
     16import org.openstreetmap.josm.data.gpx.GpxConstants;
    1817import org.openstreetmap.josm.data.gpx.GpxData;
    1918import org.openstreetmap.josm.data.gpx.GpxLink;
     
    2625 * Writes GPX files from GPX data or OSM data.
    2726 */
    28 public class GpxWriter extends XmlWriter {
     27public class GpxWriter extends XmlWriter implements GpxConstants {
    2928
    3029    public GpxWriter(PrintWriter out) {
     
    5251        out.println("<?xml version='1.0' encoding='UTF-8'?>");
    5352        out.println("<gpx version=\"1.1\" creator=\"JOSM GPX export\" xmlns=\"http://www.topografix.com/GPX/1/1\"\n" +
    54                 (data.fromServer ? String.format("    xmlns:josm=\"%s\"\n", GpxData.JOSM_EXTENSIONS_NAMESPACE_URI) : "") +
     53                (data.fromServer ? String.format("    xmlns:josm=\"%s\"\n", JOSM_EXTENSIONS_NAMESPACE_URI) : "") +
    5554                "    xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" \n" +
    5655                "    xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd\">");
     
    6463    }
    6564
    66     public static List<String> WPT_KEYS = Arrays.asList("ele", "time", "magvar", "geoidheight",
    67             "name", "cmt", "desc", "src", GpxData.META_LINKS, "sym", "number", "type",
    68             "fix", "sat", "hdop", "vdop", "pdop", "ageofdgpsdata", "dgpsid");
    6965    @SuppressWarnings("unchecked")
    7066    private void writeAttr(Map<String, Object> attr) {
     
    7268            Object value = attr.get(key);
    7369            if (value != null) {
    74                 if (key.equals(GpxData.META_LINKS)) {
     70                if (key.equals(META_LINKS)) {
    7571                    for (GpxLink link : (Collection<GpxLink>) value) {
    7672                        gpxLink(link);
     
    8985
    9086        // write the description
    91         if (attr.containsKey(GpxData.META_DESC)) {
    92             simpleTag("desc", (String)attr.get(GpxData.META_DESC));
     87        if (attr.containsKey(META_DESC)) {
     88            simpleTag("desc", (String)attr.get(META_DESC));
    9389        }
    9490
    9591        // write the author details
    96         if (attr.containsKey(GpxData.META_AUTHOR_NAME)
    97                 || attr.containsKey(GpxData.META_AUTHOR_EMAIL)) {
     92        if (attr.containsKey(META_AUTHOR_NAME)
     93                || attr.containsKey(META_AUTHOR_EMAIL)) {
    9894            openln("author");
    9995            // write the name
    100             simpleTag("name", (String) attr.get(GpxData.META_AUTHOR_NAME));
     96            simpleTag("name", (String) attr.get(META_AUTHOR_NAME));
    10197            // write the email address
    102             if (attr.containsKey(GpxData.META_AUTHOR_EMAIL)) {
    103                 String[] tmp = ((String)attr.get(GpxData.META_AUTHOR_EMAIL)).split("@");
     98            if (attr.containsKey(META_AUTHOR_EMAIL)) {
     99                String[] tmp = ((String)attr.get(META_AUTHOR_EMAIL)).split("@");
    104100                if (tmp.length == 2) {
    105101                    inline("email", "id=\"" + tmp[0] + "\" domain=\""+tmp[1]+"\"");
     
    107103            }
    108104            // write the author link
    109             gpxLink((GpxLink) attr.get(GpxData.META_AUTHOR_LINK));
     105            gpxLink((GpxLink) attr.get(META_AUTHOR_LINK));
    110106            closeln("author");
    111107        }
    112108
    113109        // write the copyright details
    114         if (attr.containsKey(GpxData.META_COPYRIGHT_LICENSE)
    115                 || attr.containsKey(GpxData.META_COPYRIGHT_YEAR)) {
    116             openAtt("copyright", "author=\""+ attr.get(GpxData.META_COPYRIGHT_AUTHOR) +"\"");
    117             if (attr.containsKey(GpxData.META_COPYRIGHT_YEAR)) {
    118                 simpleTag("year", (String) attr.get(GpxData.META_COPYRIGHT_YEAR));
    119             }
    120             if (attr.containsKey(GpxData.META_COPYRIGHT_LICENSE)) {
    121                 simpleTag("license", encode((String) attr.get(GpxData.META_COPYRIGHT_LICENSE)));
     110        if (attr.containsKey(META_COPYRIGHT_LICENSE)
     111                || attr.containsKey(META_COPYRIGHT_YEAR)) {
     112            openAtt("copyright", "author=\""+ attr.get(META_COPYRIGHT_AUTHOR) +"\"");
     113            if (attr.containsKey(META_COPYRIGHT_YEAR)) {
     114                simpleTag("year", (String) attr.get(META_COPYRIGHT_YEAR));
     115            }
     116            if (attr.containsKey(META_COPYRIGHT_LICENSE)) {
     117                simpleTag("license", encode((String) attr.get(META_COPYRIGHT_LICENSE)));
    122118            }
    123119            closeln("copyright");
     
    125121
    126122        // write links
    127         if (attr.containsKey(GpxData.META_LINKS)) {
    128             for (GpxLink link : (Collection<GpxLink>) attr.get(GpxData.META_LINKS)) {
     123        if (attr.containsKey(META_LINKS)) {
     124            for (GpxLink link : (Collection<GpxLink>) attr.get(META_LINKS)) {
    129125                gpxLink(link);
    130126            }
     
    132128
    133129        // write keywords
    134         if (attr.containsKey(GpxData.META_KEYWORDS)) {
    135             simpleTag("keywords", (String)attr.get(GpxData.META_KEYWORDS));
     130        if (attr.containsKey(META_KEYWORDS)) {
     131            simpleTag("keywords", (String)attr.get(META_KEYWORDS));
    136132        }
    137133
Note: See TracChangeset for help on using the changeset viewer.