Changeset 1574 in josm for trunk/src/org
- Timestamp:
- 2009-05-05T16:44:44+02:00 (16 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/GpxExportAction.java
r1509 r1574 28 28 import org.openstreetmap.josm.Main; 29 29 import org.openstreetmap.josm.data.gpx.GpxData; 30 import org.openstreetmap.josm.gui.ExtendedDialog; 30 31 import org.openstreetmap.josm.gui.layer.GpxLayer; 31 32 import org.openstreetmap.josm.gui.layer.Layer; 32 33 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 33 34 import org.openstreetmap.josm.io.GpxWriter; 34 import org.openstreetmap.josm.gui.ExtendedDialog;35 35 import org.openstreetmap.josm.tools.GBC; 36 36 import org.openstreetmap.josm.tools.Shortcut; … … 107 107 p.add(warning, GBC.eol().fill(GBC.HORIZONTAL).insets(15,0,0,0)); 108 108 addDependencies(author, authorName, email, copyright, predefined, copyrightYear, nameLabel, emailLabel, copyrightLabel, copyrightYearLabel, warning); 109 110 // if the user name is not the email address, but the osm user name 111 // move it from the email textfield to the author textfield 112 if(!email.getText().contains("@")) { 113 authorName.setText(email.getText()); 114 email.setText(""); 115 } 109 116 110 117 p.add(new JLabel(tr("Keywords")), GBC.eol()); … … 133 140 else 134 141 gpxData = OsmDataLayer.toGpxData(Main.ds, file); 135 // TODO: add copyright, etc. 142 143 // add author and copyright details to the gpx data 144 if(author.isSelected()) { 145 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()); 148 } 149 if(email.getText().length() > 0) gpxData.attr.put(GpxData.META_AUTHOR_EMAIL, email.getText()); 150 if(copyright.getText().length() > 0) gpxData.attr.put(GpxData.META_COPYRIGHT_LICENSE, copyright.getText()); 151 if(copyrightYear.getText().length() > 0) gpxData.attr.put(GpxData.META_COPYRIGHT_YEAR, copyrightYear.getText()); 152 } 153 154 // add the description to the gpx data 155 if(desc.getText().length() > 0) gpxData.attr.put(GpxData.META_DESC, desc.getText()); 156 157 // add keywords to the gpx data 158 if(keywords.getText().length() > 0) gpxData.attr.put(GpxData.META_KEYWORDS, keywords.getText()); 159 136 160 try { 137 161 FileOutputStream fo = new FileOutputStream(file); -
trunk/src/org/openstreetmap/josm/data/gpx/GpxData.java
r1169 r1574 19 19 */ 20 20 public class GpxData extends WithAttributes { 21 22 public static final String META_PREFIX = "meta."; 23 public static final String META_AUTHOR_NAME = META_PREFIX + "author.name"; 24 public static final String META_AUTHOR_EMAIL = META_PREFIX + "author.email"; 25 public static final String META_AUTHOR_LINK = META_PREFIX + "author.link"; 26 public static final String META_COPYRIGHT_AUTHOR = META_PREFIX + "copyright.author"; 27 public static final String META_COPYRIGHT_LICENSE = META_PREFIX + "copyright.license"; 28 public static final String META_COPYRIGHT_YEAR = META_PREFIX + "copyright.year"; 29 public static final String META_DESC = META_PREFIX + "desc"; 30 public static final String META_KEYWORDS = META_PREFIX + "keywords"; 31 public static final String META_LINKS = META_PREFIX + "links"; 32 public static final String META_NAME = META_PREFIX + "name"; 33 public static final String META_TIME = META_PREFIX + "time"; 34 21 35 public File storageFile; 22 36 public boolean fromServer; … … 37 51 // TODO: Detect conflicts. 38 52 String k = ent.getKey(); 39 if (k.equals( "link") && attr.containsKey("link")) {40 ((Collection<GpxLink>) attr.get( "link")).addAll(53 if (k.equals(META_LINKS) && attr.containsKey(META_LINKS)) { 54 ((Collection<GpxLink>) attr.get(META_LINKS)).addAll( 41 55 (Collection<GpxLink>) ent.getValue()); 42 56 } else { -
trunk/src/org/openstreetmap/josm/io/GpxReader.java
r1425 r1574 41 41 */ 42 42 public GpxData data; 43 public enum state { init, metadata, wpt, rte, trk, ext, author, link, trkseg 43 public enum state { init, metadata, wpt, rte, trk, ext, author, link, trkseg, copyright} 44 44 45 45 private class Parser extends DefaultHandler { … … 106 106 currentState = state.link; 107 107 currentLink = new GpxLink(atts.getValue("href")); 108 } else if (qName.equals("email")) { 109 currentData.attr.put(GpxData.META_AUTHOR_EMAIL, atts.getValue("id") + "@" + atts.getValue("domain")); 108 110 } 109 111 break; … … 129 131 states.push(currentState); 130 132 currentState = state.ext; 133 } else if (qName.equals("copyright")) { 134 states.push(currentState); 135 currentState = state.copyright; 136 currentData.attr.put(GpxData.META_COPYRIGHT_AUTHOR, atts.getValue("author")); 137 } else if (qName.equals("link")) { 138 states.push(currentState); 139 currentState = state.link; 140 currentLink = new GpxLink(atts.getValue("href")); 131 141 } 132 142 break; … … 184 194 switch (currentState) { 185 195 case metadata: 186 if (qName.equals("name") || qName.equals("desc") || 187 qName.equals("time") || qName.equals("keywords")) { 188 currentData.attr.put(qName, accumulator.toString()); 196 if (qName.equals("name")) { 197 currentData.attr.put(GpxData.META_NAME, accumulator.toString()); 198 } else if (qName.equals("desc")) { 199 currentData.attr.put(GpxData.META_DESC, accumulator.toString()); 200 } else if (qName.equals("time")) { 201 currentData.attr.put(GpxData.META_TIME, accumulator.toString()); 202 } else if (qName.equals("keywords")) { 203 currentData.attr.put(GpxData.META_KEYWORDS, accumulator.toString()); 189 204 } else if (qName.equals("metadata")) { 190 205 currentState = states.pop(); 191 206 } 192 //TODO: parse copyright,bounds, extensions207 //TODO: parse bounds, extensions 193 208 break; 194 209 case author: 195 210 if (qName.equals("author")) { 196 211 currentState = states.pop(); 197 } else if (qName.equals("name") || qName.equals("email")) { 198 currentData.attr.put("author" + qName, accumulator.toString()); 212 } else if (qName.equals("name")) { 213 currentData.attr.put(GpxData.META_AUTHOR_NAME, accumulator.toString()); 214 } else if (qName.equals("email")) { 215 // do nothing, has been parsed on startElement 199 216 } else if (qName.equals("link")) { 200 currentData.attr.put("authorlink", currentLink); 217 currentData.attr.put(GpxData.META_AUTHOR_LINK, currentLink); 218 } 219 break; 220 case copyright: 221 if (qName.equals("copyright")) { 222 currentState = states.pop(); 223 } else if (qName.equals("year")) { 224 currentData.attr.put(GpxData.META_COPYRIGHT_YEAR, accumulator.toString()); 225 } else if (qName.equals("license")) { 226 currentData.attr.put(GpxData.META_COPYRIGHT_LICENSE, accumulator.toString()); 201 227 } 202 228 break; … … 207 233 currentLink.type = accumulator.toString(); 208 234 } else if (qName.equals("link")) { 209 // <link>URL</link>210 if (currentLink.uri == null)211 currentLink.uri = accumulator.toString();212 213 235 currentState = states.pop(); 214 236 } 215 237 if (currentState == state.author) { 216 currentData.attr.put( "authorlink", currentLink);217 } else if (currentState != state.link) {238 currentData.attr.put(GpxData.META_AUTHOR_LINK, currentLink); 239 } else if (currentState == state.metadata) { 218 240 Map<String, Object> attr = getAttr(); 219 if (!attr.containsKey( "link")) {220 attr.put( "link", new LinkedList<GpxLink>());241 if (!attr.containsKey(GpxData.META_LINKS)) { 242 attr.put(GpxData.META_LINKS, new LinkedList<GpxLink>()); 221 243 } 222 ((Collection<GpxLink>) attr.get( "link")).add(currentLink);244 ((Collection<GpxLink>) attr.get(GpxData.META_LINKS)).add(currentLink); 223 245 } 224 246 break; -
trunk/src/org/openstreetmap/josm/io/GpxWriter.java
r1169 r1574 45 45 this.data = data; 46 46 out.println("<?xml version='1.0' encoding='UTF-8'?>"); 47 out.println("<gpx version=\"1.1\" creator=\"JOSM GPX export\" xmlns=\"http://www.topografix.com/GPX/1/1\">"); 47 out.println("<gpx version=\"1.1\" creator=\"JOSM GPX export\" xmlns=\"http://www.topografix.com/GPX/1/1\"\n" + 48 " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" \n" + 49 " xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd\">"); 48 50 indent = " "; 49 51 writeMetaData(); … … 56 58 57 59 private void writeAttr(Map<String, Object> attr) { 58 boolean hasAuthor = false; 60 // FIXME this loop is evil, because it does not assure the 61 // correct element order specified by the xml schema. 62 // for now it works, but future extension could get very complex and unmaintainable 59 63 for (Map.Entry<String, Object> ent : attr.entrySet()) { 60 64 String k = ent.getKey(); 61 if (k.indexOf("author") == 0) { 62 hasAuthor = true; 63 } else if (k.equals("link")) { 65 if (k.equals("link")) { 64 66 for (GpxLink link : (Collection<GpxLink>) ent.getValue()) { 65 67 gpxLink(link); … … 69 71 } 70 72 } 71 72 if (hasAuthor) { 73 open("author"); 74 simpleTag("name", (String) attr.get("authorname")); 75 simpleTag("email", (String) attr.get("authoremail")); 76 gpxLink((GpxLink) attr.get("authorlink")); 73 } 74 75 private void writeMetaData() { 76 Map<String, Object> attr = data.attr; 77 openln("metadata"); 78 79 // write the description 80 if (attr.containsKey(GpxData.META_DESC)) simpleTag("desc", (String)attr.get(GpxData.META_DESC)); 81 82 // write the author details 83 if (attr.containsKey(GpxData.META_AUTHOR_NAME) 84 || attr.containsKey(GpxData.META_AUTHOR_EMAIL)) { 85 openln("author"); 86 // write the name 87 simpleTag("name", (String) attr.get(GpxData.META_AUTHOR_NAME)); 88 // write the email address 89 if(attr.containsKey(GpxData.META_AUTHOR_EMAIL)) { 90 String[] tmp = ((String)attr.get(GpxData.META_AUTHOR_EMAIL)).split("@"); 91 if(tmp.length == 2) { 92 inline("email", "id=\"" + tmp[0] + "\" domain=\""+tmp[1]+"\""); 93 } 94 } 95 // write the author link 96 gpxLink((GpxLink) attr.get(GpxData.META_AUTHOR_LINK)); 77 97 closeln("author"); 78 98 } 79 99 80 // TODO: copyright 81 } 82 83 private void writeMetaData() { 84 openln("metadata"); 85 writeAttr(data.attr); 100 // write the copyright details 101 if(attr.containsKey(GpxData.META_COPYRIGHT_LICENSE) 102 || attr.containsKey(GpxData.META_COPYRIGHT_YEAR)) { 103 openAtt("copyright", "author=\""+ attr.get(GpxData.META_COPYRIGHT_AUTHOR) +"\""); 104 if(attr.containsKey(GpxData.META_COPYRIGHT_YEAR)) { 105 simpleTag("year", (String) attr.get(GpxData.META_COPYRIGHT_YEAR)); 106 } 107 if(attr.containsKey(GpxData.META_COPYRIGHT_LICENSE)) { 108 simpleTag("license", encode((String) attr.get(GpxData.META_COPYRIGHT_LICENSE))); 109 } 110 closeln("copyright"); 111 } 112 113 // write links 114 if(attr.containsKey(GpxData.META_LINKS)) { 115 for (GpxLink link : (Collection<GpxLink>) attr.get(GpxData.META_LINKS)) { 116 gpxLink(link); 117 } 118 } 119 120 // write keywords 121 if (attr.containsKey(GpxData.META_KEYWORDS)) simpleTag("keywords", (String)attr.get(GpxData.META_KEYWORDS)); 86 122 87 123 data.recalculateBounds();
Note:
See TracChangeset
for help on using the changeset viewer.