Changeset 5681 in josm
- Timestamp:
- 2013-01-27T20:07:53+01:00 (12 years ago)
- 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 154 154 * Then add all ways, each preceded by its (remaining) nodes. 155 155 */ 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); 168 166 } 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; 234 233 } 235 234 -
trunk/src/org/openstreetmap/josm/data/gpx/GpxData.java
r5679 r5681 18 18 */ 19 19 public 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";36 20 37 21 public File storageFile; -
trunk/src/org/openstreetmap/josm/data/gpx/GpxTrack.java
r3119 r5681 15 15 */ 16 16 17 public interface GpxTrack {17 public interface GpxTrack extends IWithAttributes { 18 18 19 19 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. 2 2 package org.openstreetmap.josm.data.gpx; 3 3 4 4 import java.util.Collection; 5 import java.util.HashMap;6 import java.util.Map;7 5 8 6 /** 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. 13 8 */ 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); 9 public interface IWithAttributes { 20 10 21 11 /** … … 27 17 * or {@code null} if this map contains no String mapping for the key 28 18 */ 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); 33 20 34 21 /** … … 41 28 * @since 5502 42 29 */ 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); 47 31 } -
trunk/src/org/openstreetmap/josm/data/gpx/ImmutableGpxTrack.java
r5170 r5681 11 11 import org.openstreetmap.josm.data.Bounds; 12 12 13 public class ImmutableGpxTrack implements GpxTrack {13 public class ImmutableGpxTrack extends WithAttributes implements GpxTrack { 14 14 15 private final Map<String, Object> attributes;16 15 private final Collection<GpxTrackSegment> segments; 17 16 private final double length; … … 25 24 } 26 25 } 27 this.attr ibutes= Collections.unmodifiableMap(new HashMap<String, Object>(attributes));26 this.attr = Collections.unmodifiableMap(new HashMap<String, Object>(attributes)); 28 27 this.segments = Collections.unmodifiableCollection(newSegments); 29 28 this.length = calculateLength(); … … 55 54 } 56 55 56 @Override 57 57 public Map<String, Object> getAttributes() { 58 return attr ibutes;58 return attr; 59 59 } 60 60 61 @Override 61 62 public Bounds getBounds() { 62 63 if (bounds == null) … … 66 67 } 67 68 69 @Override 68 70 public double length() { 69 71 return length; 70 72 } 71 73 74 @Override 72 75 public Collection<GpxTrackSegment> getSegments() { 73 76 return segments; 74 77 } 75 78 79 @Override 76 80 public int getUpdateCount() { 77 81 return 0; -
trunk/src/org/openstreetmap/josm/data/gpx/WithAttributes.java
r5502 r5681 1 // License: GPL. 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.data.gpx; 3 3 … … 7 7 8 8 /** 9 * Default implementation for IWithAttributes. 10 * 9 11 * Base class for various classes in the GPX model. 10 12 * … … 12 14 * @since 444 13 15 */ 14 public class WithAttributes {16 public class WithAttributes implements IWithAttributes, GpxConstants { 15 17 16 18 /** … … 20 22 21 23 /** 22 * Returns the String value to which the specified key is mapped, 24 * Returns the String value to which the specified key is mapped, 23 25 * or {@code null} if this map contains no String mapping for the key. 24 * 26 * 25 27 * @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, 27 29 * or {@code null} if this map contains no String mapping for the key 28 30 */ 31 @Override 29 32 public String getString(String key) { 30 33 Object value = attr.get(key); 31 34 return (value instanceof String) ? (String)value : null; 32 35 } 33 36 34 37 /** 35 * Returns the Collection value to which the specified key is mapped, 38 * Returns the Collection value to which the specified key is mapped, 36 39 * or {@code null} if this map contains no Collection mapping for the key. 37 * 40 * 38 41 * @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, 40 43 * or {@code null} if this map contains no Collection mapping for the key 41 44 * @since 5502 42 45 */ 46 @Override 43 47 public Collection<?> getCollection(String key) { 44 48 Object value = attr.get(key); -
trunk/src/org/openstreetmap/josm/data/validation/PaintVisitor.java
r5671 r5681 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.data.validation; 2 3 -
trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java
r5459 r5681 68 68 import org.openstreetmap.josm.data.coor.EastNorth; 69 69 import org.openstreetmap.josm.data.coor.LatLon; 70 import org.openstreetmap.josm.data.gpx.GpxConstants; 70 71 import org.openstreetmap.josm.data.gpx.GpxData; 71 72 import org.openstreetmap.josm.data.gpx.GpxRoute; … … 207 208 208 209 if (data.attr.containsKey("name")) { 209 info.append(tr("Name: {0}", data.attr.get(Gpx Data.META_NAME))).append("<br>");210 info.append(tr("Name: {0}", data.attr.get(GpxConstants.META_NAME))).append("<br>"); 210 211 } 211 212 212 213 if (data.attr.containsKey("desc")) { 213 info.append(tr("Description: {0}", data.attr.get(Gpx Data.META_DESC))).append("<br>");214 info.append(tr("Description: {0}", data.attr.get(GpxConstants.META_DESC))).append("<br>"); 214 215 } 215 216 … … 324 325 325 326 if (data.attr.containsKey("name")) { 326 info.append(tr("Name: {0}", data.attr.get(Gpx Data.META_NAME))).append("<br>");327 info.append(tr("Name: {0}", data.attr.get(GpxConstants.META_NAME))).append("<br>"); 327 328 } 328 329 329 330 if (data.attr.containsKey("desc")) { 330 info.append(tr("Description: {0}", data.attr.get(Gpx Data.META_DESC))).append("<br>");331 info.append(tr("Description: {0}", data.attr.get(GpxConstants.META_DESC))).append("<br>"); 331 332 } 332 333 -
trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/Marker.java
r5501 r5681 23 23 import org.openstreetmap.josm.data.coor.EastNorth; 24 24 import org.openstreetmap.josm.data.coor.LatLon; 25 import org.openstreetmap.josm.data.gpx.Gpx Data;25 import org.openstreetmap.josm.data.gpx.GpxConstants; 26 26 import org.openstreetmap.josm.data.gpx.GpxLink; 27 27 import org.openstreetmap.josm.data.gpx.WayPoint; … … 185 185 // cheapest way to check whether "link" object exists and is a non-empty 186 186 // collection of GpxLink objects... 187 Collection<GpxLink> links = (Collection<GpxLink>)wpt.attr.get(Gpx Data.META_LINKS);187 Collection<GpxLink> links = (Collection<GpxLink>)wpt.attr.get(GpxConstants.META_LINKS); 188 188 if (links != null) { 189 189 for (GpxLink oneLink : links ) { -
trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/MarkerLayer.java
r5564 r5681 32 32 import org.openstreetmap.josm.data.Bounds; 33 33 import org.openstreetmap.josm.data.coor.LatLon; 34 import org.openstreetmap.josm.data.gpx.GpxConstants; 34 35 import org.openstreetmap.josm.data.gpx.GpxData; 35 36 import org.openstreetmap.josm.data.gpx.GpxLink; … … 85 86 /* calculate time differences in waypoints */ 86 87 double time = wpt.time; 87 boolean wpt_has_link = wpt.attr.containsKey(Gpx Data.META_LINKS);88 boolean wpt_has_link = wpt.attr.containsKey(GpxConstants.META_LINKS); 88 89 if (firstTime < 0 && wpt_has_link) { 89 90 firstTime = time; 90 for (Object oneLink : wpt.getCollection(Gpx Data.META_LINKS)) {91 for (Object oneLink : wpt.getCollection(GpxConstants.META_LINKS)) { 91 92 if (oneLink instanceof GpxLink) { 92 93 lastLinkedFile = ((GpxLink)oneLink).uri; … … 96 97 } 97 98 if (wpt_has_link) { 98 for (Object oneLink : wpt.getCollection(Gpx Data.META_LINKS)) {99 for (Object oneLink : wpt.getCollection(GpxConstants.META_LINKS)) { 99 100 if (oneLink instanceof GpxLink) { 100 101 String uri = ((GpxLink)oneLink).uri; -
trunk/src/org/openstreetmap/josm/io/GpxExporter.java
r5397 r5681 27 27 28 28 import org.openstreetmap.josm.Main; 29 import org.openstreetmap.josm.data.gpx.GpxConstants; 29 30 import org.openstreetmap.josm.data.gpx.GpxData; 30 31 import org.openstreetmap.josm.data.osm.DataSet; … … 36 37 import org.openstreetmap.josm.tools.GBC; 37 38 38 public class GpxExporter extends FileExporter {39 public class GpxExporter extends FileExporter implements GpxConstants { 39 40 private final static String warningGpl = "<html><font color='red' size='-2'>" 40 41 + tr("Note: GPL is not compatible with the OSM license. Do not upload GPL licensed tracks.") + "</html>"; … … 82 83 desc.setWrapStyleWord(true); 83 84 desc.setLineWrap(true); 84 desc.setText((String) gpxData.attr.get( GpxData.META_DESC));85 desc.setText((String) gpxData.attr.get(META_DESC)); 85 86 p.add(new JScrollPane(desc), GBC.eop().fill(GBC.BOTH)); 86 87 … … 112 113 p.add(new JLabel(tr("Keywords")), GBC.eol()); 113 114 JTextField keywords = new JTextField(); 114 keywords.setText((String) gpxData.attr.get( GpxData.META_KEYWORDS));115 keywords.setText((String) gpxData.attr.get(META_KEYWORDS)); 115 116 p.add(keywords, GBC.eop().fill(GBC.HORIZONTAL)); 116 117 … … 144 145 if (author.isSelected()) { 145 146 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()); 148 149 } 149 150 if (email.getText().length() > 0) { 150 gpxData.attr.put( GpxData.META_AUTHOR_EMAIL, email.getText());151 gpxData.attr.put(META_AUTHOR_EMAIL, email.getText()); 151 152 } 152 153 if (copyright.getText().length() > 0) { 153 gpxData.attr.put( GpxData.META_COPYRIGHT_LICENSE, copyright.getText());154 gpxData.attr.put(META_COPYRIGHT_LICENSE, copyright.getText()); 154 155 } 155 156 if (copyrightYear.getText().length() > 0) { 156 gpxData.attr.put( GpxData.META_COPYRIGHT_YEAR, copyrightYear.getText());157 gpxData.attr.put(META_COPYRIGHT_YEAR, copyrightYear.getText()); 157 158 } 158 159 } … … 160 161 // add the description to the gpx data 161 162 if (desc.getText().length() > 0) { 162 gpxData.attr.put( GpxData.META_DESC, desc.getText());163 gpxData.attr.put(META_DESC, desc.getText()); 163 164 } 164 165 165 166 // add keywords to the gpx data 166 167 if (keywords.getText().length() > 0) { 167 gpxData.attr.put( GpxData.META_KEYWORDS, keywords.getText());168 gpxData.attr.put(META_KEYWORDS, keywords.getText()); 168 169 } 169 170 … … 193 194 if (enable) { 194 195 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); 196 197 if (sCopyrightYear == null) { 197 198 sCopyrightYear = Integer.toString(Calendar.getInstance().get(Calendar.YEAR)); … … 200 201 } 201 202 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); 203 204 if (sCopyright == null) { 204 205 sCopyright = Main.pref.get("lastCopyright", "http://creativecommons.org/licenses/by-sa/2.5"); … … 243 244 emailLabel.setEnabled(b); 244 245 if (b) { 245 String sAuthorName = (String) data.attr.get( GpxData.META_AUTHOR_NAME);246 String sAuthorName = (String) data.attr.get(META_AUTHOR_NAME); 246 247 if (sAuthorName == null) { 247 248 sAuthorName = Main.pref.get("lastAuthorName"); 248 249 } 249 250 authorName.setText(sAuthorName); 250 String sEmail = (String) data.attr.get( GpxData.META_AUTHOR_EMAIL);251 String sEmail = (String) data.attr.get(META_AUTHOR_EMAIL); 251 252 if (sEmail == null) { 252 253 sEmail = Main.pref.get("lastAuthorEmail"); -
trunk/src/org/openstreetmap/josm/io/GpxReader.java
r5679 r5681 21 21 import org.openstreetmap.josm.data.coor.LatLon; 22 22 import org.openstreetmap.josm.data.gpx.Extensions; 23 import org.openstreetmap.josm.data.gpx.GpxConstants; 23 24 import org.openstreetmap.josm.data.gpx.GpxData; 24 25 import org.openstreetmap.josm.data.gpx.GpxLink; … … 39 40 * @author imi, ramack 40 41 */ 41 public class GpxReader {42 public class GpxReader implements GpxConstants { 42 43 43 44 private String version; … … 140 141 states.push(currentState); 141 142 currentState = State.copyright; 142 data.attr.put( GpxData.META_COPYRIGHT_AUTHOR, atts.getValue("author"));143 data.attr.put(META_COPYRIGHT_AUTHOR, atts.getValue("author")); 143 144 } else if (localName.equals("link")) { 144 145 states.push(currentState); … … 153 154 currentLink = new GpxLink(atts.getValue("href")); 154 155 } 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")); 156 157 } 157 158 break; … … 243 244 case metadata: // GPX 1.1 244 245 if (localName.equals("name")) { 245 data.attr.put( GpxData.META_NAME, accumulator.toString());246 data.attr.put(META_NAME, accumulator.toString()); 246 247 } else if (localName.equals("desc")) { 247 data.attr.put( GpxData.META_DESC, accumulator.toString());248 data.attr.put(META_DESC, accumulator.toString()); 248 249 } else if (localName.equals("time")) { 249 data.attr.put( GpxData.META_TIME, accumulator.toString());250 data.attr.put(META_TIME, accumulator.toString()); 250 251 } else if (localName.equals("keywords")) { 251 data.attr.put( GpxData.META_KEYWORDS, accumulator.toString());252 data.attr.put(META_KEYWORDS, accumulator.toString()); 252 253 } else if (version.equals("1.0") && localName.equals("author")) { 253 254 // 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()); 255 256 } 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()); 257 258 } else if (localName.equals("url") || localName.equals("urlname")) { 258 259 data.attr.put(localName, accumulator.toString()); … … 261 262 convertUrlToLink(data.attr); 262 263 if (currentExtensions != null && !currentExtensions.isEmpty()) { 263 data.attr.put( GpxData.META_EXTENSIONS, currentExtensions);264 data.attr.put(META_EXTENSIONS, currentExtensions); 264 265 } 265 266 currentState = states.pop(); … … 271 272 currentState = states.pop(); 272 273 } else if (localName.equals("name")) { 273 data.attr.put( GpxData.META_AUTHOR_NAME, accumulator.toString());274 data.attr.put(META_AUTHOR_NAME, accumulator.toString()); 274 275 } else if (localName.equals("email")) { 275 276 // do nothing, has been parsed on startElement 276 277 } else if (localName.equals("link")) { 277 data.attr.put( GpxData.META_AUTHOR_LINK, currentLink);278 data.attr.put(META_AUTHOR_LINK, currentLink); 278 279 } 279 280 break; … … 282 283 currentState = states.pop(); 283 284 } else if (localName.equals("year")) { 284 data.attr.put( GpxData.META_COPYRIGHT_YEAR, accumulator.toString());285 data.attr.put(META_COPYRIGHT_YEAR, accumulator.toString()); 285 286 } else if (localName.equals("license")) { 286 data.attr.put( GpxData.META_COPYRIGHT_LICENSE, accumulator.toString());287 data.attr.put(META_COPYRIGHT_LICENSE, accumulator.toString()); 287 288 } 288 289 break; … … 299 300 } 300 301 if (currentState == State.author) { 301 data.attr.put( GpxData.META_AUTHOR_LINK, currentLink);302 data.attr.put(META_AUTHOR_LINK, currentLink); 302 303 } else if (currentState != State.link) { 303 304 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>()); 306 307 } 307 ((Collection<GpxLink>) attr.get( GpxData.META_LINKS)).add(currentLink);308 ((Collection<GpxLink>) attr.get(META_LINKS)).add(currentLink); 308 309 } 309 310 break; … … 364 365 currentState = states.pop(); 365 366 // 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)) { 367 368 currentExtensions.put(localName, accumulator.toString()); 368 369 } … … 382 383 if (!states.empty()) 383 384 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); 385 386 if (metaExt != null && "true".equals(metaExt.get("from-server"))) { 386 387 data.fromServer = true; … … 396 397 String urlname = (String) attr.get("urlname"); 397 398 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>()); 400 401 } 401 402 GpxLink link = new GpxLink(url); 402 403 link.text = urlname; 403 404 @SuppressWarnings("unchecked") 404 Collection<GpxLink> links = (Collection) attr.get( GpxData.META_LINKS);405 Collection<GpxLink> links = (Collection) attr.get(META_LINKS); 405 406 links.add(link); 406 407 } -
trunk/src/org/openstreetmap/josm/io/GpxWriter.java
r5679 r5681 9 9 import java.io.PrintWriter; 10 10 import java.io.UnsupportedEncodingException; 11 import java.util.Arrays;12 11 import java.util.Collection; 13 import java.util.List;14 12 import java.util.Map; 15 13 16 14 import org.openstreetmap.josm.data.Bounds; 17 15 import org.openstreetmap.josm.data.coor.LatLon; 16 import org.openstreetmap.josm.data.gpx.GpxConstants; 18 17 import org.openstreetmap.josm.data.gpx.GpxData; 19 18 import org.openstreetmap.josm.data.gpx.GpxLink; … … 26 25 * Writes GPX files from GPX data or OSM data. 27 26 */ 28 public class GpxWriter extends XmlWriter {27 public class GpxWriter extends XmlWriter implements GpxConstants { 29 28 30 29 public GpxWriter(PrintWriter out) { … … 52 51 out.println("<?xml version='1.0' encoding='UTF-8'?>"); 53 52 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) : "") + 55 54 " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" \n" + 56 55 " xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd\">"); … … 64 63 } 65 64 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");69 65 @SuppressWarnings("unchecked") 70 66 private void writeAttr(Map<String, Object> attr) { … … 72 68 Object value = attr.get(key); 73 69 if (value != null) { 74 if (key.equals( GpxData.META_LINKS)) {70 if (key.equals(META_LINKS)) { 75 71 for (GpxLink link : (Collection<GpxLink>) value) { 76 72 gpxLink(link); … … 89 85 90 86 // 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)); 93 89 } 94 90 95 91 // 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)) { 98 94 openln("author"); 99 95 // write the name 100 simpleTag("name", (String) attr.get( GpxData.META_AUTHOR_NAME));96 simpleTag("name", (String) attr.get(META_AUTHOR_NAME)); 101 97 // 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("@"); 104 100 if (tmp.length == 2) { 105 101 inline("email", "id=\"" + tmp[0] + "\" domain=\""+tmp[1]+"\""); … … 107 103 } 108 104 // write the author link 109 gpxLink((GpxLink) attr.get( GpxData.META_AUTHOR_LINK));105 gpxLink((GpxLink) attr.get(META_AUTHOR_LINK)); 110 106 closeln("author"); 111 107 } 112 108 113 109 // 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))); 122 118 } 123 119 closeln("copyright"); … … 125 121 126 122 // 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)) { 129 125 gpxLink(link); 130 126 } … … 132 128 133 129 // 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)); 136 132 } 137 133
Note:
See TracChangeset
for help on using the changeset viewer.