Changeset 29505 in osm for applications/editors/josm/plugins/CommandLine/src
- Timestamp:
- 2013-04-16T20:18:30+02:00 (12 years ago)
- Location:
- applications/editors/josm/plugins/CommandLine/src/CommandLine
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/CommandLine/src/CommandLine/AnyAction.java
r27551 r29505 8 8 package CommandLine; 9 9 10 import static org.openstreetmap.josm.tools.I18n.tr;11 12 10 import java.awt.AWTEvent; 13 11 import java.awt.Cursor; 14 12 import java.awt.EventQueue; 13 import java.awt.Point; 14 import java.awt.Toolkit; 15 15 import java.awt.event.AWTEventListener; 16 16 import java.awt.event.KeyEvent; 17 17 import java.awt.event.MouseEvent; 18 import java.awt.Point;19 import java.awt.Toolkit;20 import java.util.Collection;21 import javax.swing.JOptionPane;22 18 23 19 import org.openstreetmap.josm.Main; 24 20 import org.openstreetmap.josm.actions.mapmode.MapMode; 25 import org.openstreetmap.josm.data.coor.LatLon;26 import org.openstreetmap.josm.data.osm.DataSet;27 import org.openstreetmap.josm.data.osm.Node;28 21 import org.openstreetmap.josm.data.osm.OsmPrimitive; 29 import org.openstreetmap.josm.data.osm.PrimitiveId;30 22 import org.openstreetmap.josm.gui.MapFrame; 31 23 import org.openstreetmap.josm.tools.ImageProvider; -
applications/editors/josm/plugins/CommandLine/src/CommandLine/Command.java
r25052 r29505 1 1 /* 2 2 * Command.java 3 * 3 * 4 4 * Copyright 2011 Hind <foxhind@gmail.com> 5 * 5 * 6 6 */ 7 7 … … 10 10 import java.util.ArrayList; 11 11 import java.util.Collection; 12 import java.util. List;13 import java.util.regex. *;12 import java.util.regex.Matcher; 13 import java.util.regex.Pattern; 14 14 15 15 import org.openstreetmap.josm.data.osm.Node; … … 17 17 import org.openstreetmap.josm.data.osm.Relation; 18 18 import org.openstreetmap.josm.data.osm.Way; 19 import org.openstreetmap.josm.data.osm.DataSet;20 19 21 20 public class Command { 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 21 public String name; // Command name 22 public String run; // Executable file with arguments ("nya.exe {arg1} {arg2} ... {argn}") 23 public String icon; // Icon file name 24 public ArrayList<Parameter> parameters; // Required parameters list 25 public ArrayList<Parameter> optParameters; // Optional parameters list 26 public int currentParameterNum; 27 public boolean tracks; 28 29 public Command () { parameters = new ArrayList<Parameter>(); optParameters = new ArrayList<Parameter>(); currentParameterNum = 0; tracks = false; icon = ""; } 30 31 public boolean loadObject(Object obj) { 32 Parameter currentParameter = parameters.get(currentParameterNum); 33 //System.out.println("Parameter " + String.valueOf(currentParameterNum) + " (" + currentParameter.name + ")"); 34 if (currentParameter.maxInstances == 1) { 35 //System.out.println("mI = 1"); 36 //System.out.println("Candidate: " + String.valueOf(obj)); 37 if (isPair(obj, currentParameter)) { 38 currentParameter.setValue(obj); 39 //System.out.println("Accepted"); 40 return true; 41 } 42 } 43 else { 44 //System.out.println("mI = " + String.valueOf(currentParameter.maxInstances)); 45 ArrayList<OsmPrimitive> multiValue = currentParameter.getValueList(); 46 if (obj instanceof Collection) { 47 if ( ((Collection<?>)obj).size() > currentParameter.maxInstances && currentParameter.maxInstances != 0) 48 return false; 49 //System.out.println("Candidate (selected) accepted"); 50 multiValue.clear(); 51 multiValue.addAll((Collection<OsmPrimitive>)obj); 52 return true; 53 } 54 else if (obj instanceof OsmPrimitive) { 55 if (multiValue.size() < currentParameter.maxInstances || currentParameter.maxInstances == 0) { 56 //System.out.println("Candidate: " + String.valueOf(obj)); 57 if (isPair(obj, currentParameter)) { 58 multiValue.add((OsmPrimitive)obj); 59 //System.out.println("Accepted, added to list"); 60 return true; 61 } 62 else { 63 if (nextParameter() && multiValue.size() > 0) { 64 //System.out.println("Not accepted but considering for next Parameter"); 65 return loadObject(obj); 66 } 67 } 68 } 69 else { 70 if (nextParameter()) { 71 //System.out.println("Not accepted but considering for next Parameter"); 72 return loadObject(obj); 73 } 74 } 75 } 76 else if (obj instanceof String) { 77 //System.out.println("Candidate: " + (String)obj); 78 if (isPair(obj, currentParameter)) { 79 currentParameter.setValue(obj); 80 //System.out.println("Accepted"); 81 return true; 82 } 83 } 84 } 85 return false; 86 } 87 88 public boolean nextParameter() { 89 currentParameterNum++; 90 return (currentParameterNum < parameters.size()) ? true : false; 91 } 92 93 public boolean hasNextParameter() { 94 return ((currentParameterNum + 1) < parameters.size()) ? true : false; 95 } 96 97 public void resetLoading() { 98 currentParameterNum = 0; 99 for (Parameter parameter : parameters) { 100 if (parameter.maxInstances != 1) 101 parameter.getValueList().clear(); 102 } 103 } 104 105 private static boolean isPair(Object obj, Parameter parameter) { 106 switch (parameter.type) { 107 case POINT: 108 if (obj instanceof String) { 109 Pattern p = Pattern.compile("(-?\\d*\\.?\\d*,-?\\d*\\.?\\d*;?)*"); 110 Matcher m = p.matcher((String)obj); 111 return m.matches(); 112 } 113 break; 114 case NODE: 115 if (obj instanceof Node) return true; 116 break; 117 case WAY: 118 if (obj instanceof Way) return true; 119 break; 120 case RELATION: 121 if (obj instanceof Relation) return true; 122 break; 123 case ANY: 124 if (obj instanceof Node || obj instanceof Way || obj instanceof Relation) return true; 125 break; 126 case LENGTH: 127 if (obj instanceof String) { 128 Pattern p = Pattern.compile("\\d*\\.?\\d*"); 129 Matcher m = p.matcher((String)obj); 130 if (m.matches()) { 131 Float value = Float.parseFloat((String)obj); 132 if (parameter.minVal != 0 && value < parameter.minVal) 133 break; 134 if (parameter.maxVal != 0 && value > parameter.maxVal) 135 break; 136 return true; 137 } 138 } 139 break; 140 case NATURAL: 141 if (obj instanceof String) { 142 Pattern p = Pattern.compile("\\d*"); 143 Matcher m = p.matcher((String)obj); 144 if (m.matches()) { 145 Integer value = Integer.parseInt((String)obj); 146 if (parameter.minVal != 0 && value < parameter.minVal) 147 break; 148 if (parameter.maxVal != 0 && value > parameter.maxVal) 149 break; 150 return true; 151 } 152 } 153 break; 154 case STRING: 155 if (obj instanceof String) return true; 156 break; 157 case RELAY: 158 if (obj instanceof String) { 159 if (parameter.getRawValue() instanceof Relay) { 160 if ( ((Relay)(parameter.getRawValue())).isCorrectValue((String)obj) ) 161 return true; 162 } 163 } 164 break; 165 case USERNAME: 166 if (obj instanceof String) return true; 167 break; 168 case IMAGERYURL: 169 if (obj instanceof String) return true; 170 break; 171 case IMAGERYOFFSET: 172 if (obj instanceof String) return true; 173 break; 174 } 175 return false; 176 } 177 178 public Collection<OsmPrimitive> getDepsObjects() { 179 ArrayList<OsmPrimitive> depsObjects = new ArrayList<OsmPrimitive>(); 180 for (Parameter parameter : parameters) { 181 if (!parameter.isOsm()) 182 continue; 183 if (parameter.maxInstances == 1) { 184 depsObjects.addAll(getDepsObjects(depsObjects, (OsmPrimitive)parameter.getRawValue())); 185 } 186 else { 187 for (OsmPrimitive primitive : parameter.getValueList()) { 188 depsObjects.addAll(getDepsObjects(depsObjects, primitive)); 189 } 190 } 191 } 192 return depsObjects; 193 } 194 195 public Collection<OsmPrimitive> getDepsObjects(Collection<OsmPrimitive> currentObjects, OsmPrimitive primitive) { 196 ArrayList<OsmPrimitive> depsObjects = new ArrayList<OsmPrimitive>(); 197 if (!currentObjects.contains(primitive)) { 198 if (primitive instanceof Way) { 199 depsObjects.addAll(((Way)primitive).getNodes()); 200 } 201 else if (primitive instanceof Relation) { 202 Collection<OsmPrimitive> relationMembers = ((Relation)primitive).getMemberPrimitives(); 203 for (OsmPrimitive member : relationMembers) { 204 if (!currentObjects.contains(member)) { 205 depsObjects.add(member); 206 depsObjects.addAll(getDepsObjects(currentObjects, member)); 207 } 208 } 209 } 210 } 211 return depsObjects; 212 } 214 213 } -
applications/editors/josm/plugins/CommandLine/src/CommandLine/CommandAction.java
r28672 r29505 11 11 12 12 import java.awt.event.ActionEvent; 13 import java.awt.AWTEvent; 14 import java.awt.Cursor; 15 import java.awt.EventQueue; 16 import java.awt.event.AWTEventListener; 17 import java.awt.event.KeyEvent; 18 import java.awt.event.MouseEvent; 19 import java.awt.Point; 20 import java.awt.Toolkit; 21 import java.util.Collection; 13 22 14 import javax.swing.Action; 23 import javax.swing.JOptionPane;24 15 25 import org.openstreetmap.josm.Main;26 16 import org.openstreetmap.josm.actions.JosmAction; 27 import org.openstreetmap.josm.data.coor.LatLon;28 import org.openstreetmap.josm.data.osm.DataSet;29 import org.openstreetmap.josm.data.osm.Way;30 import org.openstreetmap.josm.data.osm.OsmPrimitive;31 import org.openstreetmap.josm.data.osm.PrimitiveId;32 import org.openstreetmap.josm.gui.MapFrame;33 17 import org.openstreetmap.josm.tools.ImageProvider; 34 18 35 19 public class CommandAction extends JosmAction { 36 privateCommandLine parentPlugin;37 privateCommand parentCommand;38 39 40 41 42 parentPlugin.pluginDir, parentCommand.icon));43 parentPlugin.pluginDir, parentCommand.icon));44 45 46 47 48 49 50 51 52 53 20 private final CommandLine parentPlugin; 21 private final Command parentCommand; 22 public CommandAction(Command parentCommand, CommandLine parentPlugin) { 23 super(tr(parentCommand.name), "blankmenu", tr(parentCommand.name), null, true, parentCommand.name, true); 24 if (!parentCommand.icon.equals("")) { 25 try { 26 putValue(Action.SMALL_ICON, ImageProvider.get(CommandLine.pluginDir, parentCommand.icon)); 27 putValue(Action.LARGE_ICON_KEY, ImageProvider.get(CommandLine.pluginDir, parentCommand.icon)); 28 } 29 catch (NullPointerException e) { 30 putValue(Action.SMALL_ICON, ImageProvider.get("blankmenu")); 31 putValue(Action.LARGE_ICON_KEY, ImageProvider.get("blankmenu")); 32 } 33 catch (RuntimeException e) { 34 putValue(Action.SMALL_ICON, ImageProvider.get("blankmenu")); 35 putValue(Action.LARGE_ICON_KEY, ImageProvider.get("blankmenu")); 36 } 37 } 54 38 55 56 57 39 this.parentCommand = parentCommand; 40 this.parentPlugin = parentPlugin; 41 } 58 42 59 public void actionPerformed(ActionEvent e) { 60 parentPlugin.startCommand(parentCommand); 61 parentPlugin.history.addItem(parentCommand.name); 62 } 43 @Override 44 public void actionPerformed(ActionEvent e) { 45 parentPlugin.startCommand(parentCommand); 46 parentPlugin.history.addItem(parentCommand.name); 47 } 63 48 } -
applications/editors/josm/plugins/CommandLine/src/CommandLine/CommandLine.java
r29273 r29505 66 66 import org.openstreetmap.josm.plugins.PluginInformation; 67 67 import org.openstreetmap.josm.tools.SubclassFilteredCollection; 68 import org.openstreetmap.josm.tools.Utils; 68 69 69 70 public class CommandLine extends Plugin { … … 541 542 } 542 543 gpxWriter.write(gpxFilter.getGpxData()); 543 } 544 osmWriter.close(); 544 Utils.close(gpxWriter); 545 } 546 Utils.close(osmWriter); 545 547 synchronized (syncObj) { 546 548 tp.running = false; … … 548 550 } 549 551 } 550 551 552 }); 552 553 -
applications/editors/josm/plugins/CommandLine/src/CommandLine/DummyAction.java
r25052 r29505 8 8 package CommandLine; 9 9 10 import static org.openstreetmap.josm.tools.I18n.tr;11 12 10 import java.awt.AWTEvent; 13 import java.awt.Cursor;14 import java.awt.EventQueue;15 11 import java.awt.event.AWTEventListener; 16 12 import java.awt.event.KeyEvent; 17 import java.awt.event.MouseEvent;18 import java.awt.Point;19 import java.awt.Toolkit;20 import java.util.Collection;21 import javax.swing.JOptionPane;22 13 23 14 import org.openstreetmap.josm.Main; 24 15 import org.openstreetmap.josm.actions.mapmode.MapMode; 25 import org.openstreetmap.josm.data.coor.LatLon;26 import org.openstreetmap.josm.data.osm.DataSet;27 import org.openstreetmap.josm.data.osm.Way;28 import org.openstreetmap.josm.data.osm.OsmPrimitive;29 import org.openstreetmap.josm.data.osm.PrimitiveId;30 16 import org.openstreetmap.josm.gui.MapFrame; 31 17 import org.openstreetmap.josm.tools.ImageProvider; -
applications/editors/josm/plugins/CommandLine/src/CommandLine/GpxFilter.java
r25038 r29505 9 9 10 10 import java.util.ArrayList; 11 import java.util.List;12 11 import java.util.Collection; 13 12 import java.util.Collections; 14 13 15 import org.openstreetmap.josm.data.coor.LatLon;16 import org.openstreetmap.josm.data.osm.BBox;17 14 import org.openstreetmap.josm.data.gpx.GpxData; 18 15 import org.openstreetmap.josm.data.gpx.GpxTrack; 19 16 import org.openstreetmap.josm.data.gpx.GpxTrackSegment; 20 17 import org.openstreetmap.josm.data.gpx.ImmutableGpxTrack; 21 import org.openstreetmap.josm.data.gpx.ImmutableGpxTrackSegment;22 18 import org.openstreetmap.josm.data.gpx.WayPoint; 19 import org.openstreetmap.josm.data.osm.BBox; 23 20 24 21 public class GpxFilter { -
applications/editors/josm/plugins/CommandLine/src/CommandLine/LengthAction.java
r25060 r29505 18 18 import java.awt.Graphics2D; 19 19 import java.awt.Point; 20 import java.awt.RenderingHints;21 20 import java.awt.Toolkit; 22 21 import java.awt.event.AWTEventListener; … … 24 23 import java.awt.event.MouseEvent; 25 24 import java.awt.geom.GeneralPath; 26 import java.awt.image.BufferedImage;27 import java.util.Collection;28 import java.util.LinkedList;29 25 30 26 import org.openstreetmap.josm.Main; 31 27 import org.openstreetmap.josm.actions.mapmode.MapMode; 32 28 import org.openstreetmap.josm.data.Bounds; 33 import org.openstreetmap.josm.data.SelectionChangedListener; 34 import org.openstreetmap.josm.data.coor.*; 35 import org.openstreetmap.josm.data.osm.DataSet; 29 import org.openstreetmap.josm.data.coor.LatLon; 36 30 import org.openstreetmap.josm.data.osm.Node; 37 31 import org.openstreetmap.josm.data.osm.OsmPrimitive; 38 import org.openstreetmap.josm.data.osm.Way;39 32 import org.openstreetmap.josm.gui.MapFrame; 40 33 import org.openstreetmap.josm.gui.MapView; … … 43 36 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 44 37 import org.openstreetmap.josm.tools.ImageProvider; 45 import org.openstreetmap.josm.tools.Shortcut;46 38 47 39 public class LengthAction extends MapMode implements MapViewPaintable, AWTEventListener { -
applications/editors/josm/plugins/CommandLine/src/CommandLine/Loader.java
r25060 r29505 8 8 package CommandLine; 9 9 10 import java.io.File; 10 11 import java.util.ArrayList; 11 import java.io.File; 12 import java.util.List; 12 13 13 import javax.xml.parsers.SAXParser; 14 14 import javax.xml.parsers.SAXParserFactory; -
applications/editors/josm/plugins/CommandLine/src/CommandLine/NodeAction.java
r25052 r29505 8 8 package CommandLine; 9 9 10 import static org.openstreetmap.josm.tools.I18n.tr;11 12 10 import java.awt.AWTEvent; 13 11 import java.awt.Cursor; 14 12 import java.awt.EventQueue; 13 import java.awt.Point; 14 import java.awt.Toolkit; 15 15 import java.awt.event.AWTEventListener; 16 16 import java.awt.event.KeyEvent; 17 17 import java.awt.event.MouseEvent; 18 import java.awt.Point;19 import java.awt.Toolkit;20 import java.util.Collection;21 import javax.swing.JOptionPane;22 18 23 19 import org.openstreetmap.josm.Main; 24 20 import org.openstreetmap.josm.actions.mapmode.MapMode; 25 import org.openstreetmap.josm.data.coor.LatLon;26 import org.openstreetmap.josm.data.osm.DataSet;27 21 import org.openstreetmap.josm.data.osm.Node; 28 22 import org.openstreetmap.josm.data.osm.OsmPrimitive; 29 import org.openstreetmap.josm.data.osm.PrimitiveId;30 23 import org.openstreetmap.josm.gui.MapFrame; 31 24 import org.openstreetmap.josm.tools.ImageProvider; -
applications/editors/josm/plugins/CommandLine/src/CommandLine/OsmToCmd.java
r25052 r29505 1 1 /* 2 2 * OsmToCmd.java 3 * 3 * 4 4 * Copyright 2011 Hind <foxhind@gmail.com> 5 * 5 * 6 6 */ 7 7 … … 15 15 import java.util.LinkedList; 16 16 import java.util.List; 17 import java.util.Map;18 17 19 18 import javax.xml.parsers.ParserConfigurationException; 19 import javax.xml.parsers.SAXParser; 20 20 import javax.xml.parsers.SAXParserFactory; 21 import javax.xml.parsers.SAXParser;22 21 23 22 import org.openstreetmap.josm.Main; 24 23 import org.openstreetmap.josm.command.AddCommand; 25 24 import org.openstreetmap.josm.command.ChangeCommand; 26 import org.openstreetmap.josm.command.ChangeNodesCommand;27 25 import org.openstreetmap.josm.command.Command; 28 26 import org.openstreetmap.josm.command.DeleteCommand; 29 27 import org.openstreetmap.josm.data.coor.LatLon; 30 import org.openstreetmap.josm.data.osm.*; 28 import org.openstreetmap.josm.data.osm.DataSet; 29 import org.openstreetmap.josm.data.osm.Node; 30 import org.openstreetmap.josm.data.osm.NodeData; 31 import org.openstreetmap.josm.data.osm.OsmPrimitive; 32 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 33 import org.openstreetmap.josm.data.osm.PrimitiveData; 34 import org.openstreetmap.josm.data.osm.PrimitiveId; 35 import org.openstreetmap.josm.data.osm.Relation; 36 import org.openstreetmap.josm.data.osm.RelationData; 37 import org.openstreetmap.josm.data.osm.RelationMember; 38 import org.openstreetmap.josm.data.osm.SimplePrimitiveId; 39 import org.openstreetmap.josm.data.osm.User; 40 import org.openstreetmap.josm.data.osm.Way; 41 import org.openstreetmap.josm.data.osm.WayData; 31 42 import org.openstreetmap.josm.io.IllegalDataException; 32 43 import org.openstreetmap.josm.io.OsmDataParsingException; 33 44 import org.openstreetmap.josm.io.UTFInputStreamReader; 34 45 import org.openstreetmap.josm.tools.DateUtils; 35 36 46 import org.xml.sax.Attributes; 37 47 import org.xml.sax.InputSource; … … 39 49 import org.xml.sax.SAXException; 40 50 import org.xml.sax.SAXParseException; 51 import org.xml.sax.ext.LexicalHandler; 41 52 import org.xml.sax.helpers.DefaultHandler; 42 import org.xml.sax.ext.LexicalHandler;43 53 44 54 final class OsmToCmd { 45 private CommandLine parentPlugin; 46 private final DataSet targetDataSet; 47 private final LinkedList<Command> cmds = new LinkedList<Command>(); 48 private HashMap<PrimitiveId, OsmPrimitive> externalIdMap; // Maps external ids to internal primitives 49 50 public OsmToCmd(CommandLine parentPlugin, DataSet targetDataSet) { 51 this.parentPlugin = parentPlugin; 52 this.targetDataSet = targetDataSet; 53 externalIdMap = new HashMap<PrimitiveId, OsmPrimitive>(); 54 } 55 56 public void parseStream(InputStream stream) throws IllegalDataException { 57 try { 58 InputSource inputSource = new InputSource(UTFInputStreamReader.create(stream, "UTF-8")); 59 SAXParser parser = SAXParserFactory.newInstance().newSAXParser(); 60 Parser handler = new Parser(); 61 parser.setProperty("http://xml.org/sax/properties/lexical-handler", handler); 62 parser.parse(inputSource, handler); 63 } catch(ParserConfigurationException e) { 64 throw new IllegalDataException(e.getMessage(), e); 65 } catch (SAXParseException e) { 66 throw new IllegalDataException(tr("Line {0} column {1}: ", e.getLineNumber(), e.getColumnNumber()) + e.getMessage(), e); 67 } catch(SAXException e) { 68 throw new IllegalDataException(e.getMessage(), e); 69 } catch(Exception e) { 70 throw new IllegalDataException(e); 71 } 72 } 73 74 public LinkedList<Command> getCommandList() { 75 return cmds; 76 } 77 78 private class Parser extends DefaultHandler implements LexicalHandler { 79 private Locator locator; 80 81 @Override 82 public void setDocumentLocator(Locator locator) { 83 this.locator = locator; 84 } 85 86 protected void throwException(String msg) throws OsmDataParsingException { 87 throw new OsmDataParsingException(msg).rememberLocation(locator); 88 } 89 90 private OsmPrimitive currentPrimitive; 91 private long currentExternalId; 92 private List<Node> currentWayNodes = new ArrayList<Node>(); 93 private List<RelationMember> currentRelationMembers = new ArrayList<RelationMember>(); 94 95 @Override 96 public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException { 97 try { 98 if (qName.equals("osm")) { 99 if (atts == null) { 100 throwException(tr("Missing mandatory attribute ''{0}'' of XML element {1}.", "version", "osm")); 101 } 102 String v = atts.getValue("version"); 103 if (v == null) { 104 throwException(tr("Missing mandatory attribute ''{0}''.", "version")); 105 } 106 if ( !(v.equals("0.6")) ) { 107 throwException(tr("Unsupported version: {0}", v)); 108 } 109 110 // ---- PARSING NODES AND WAYS ---- 111 112 } else if (qName.equals("node")) { 113 Node n = new Node(); 114 NodeData source = new NodeData(); 115 source.setCoor(new LatLon(getDouble(atts, "lat"), getDouble(atts, "lon"))); 116 readCommon(atts, source); 117 Node target = (Node)targetDataSet.getPrimitiveById( source.getUniqueId(), source.getType() ); 118 119 if (target == null || !(source.isModified() || source.isDeleted()) ) 120 n.load(source); 121 else { 122 n.cloneFrom(target); 123 n.load(source); 124 } 125 126 currentPrimitive = n; 127 externalIdMap.put(source.getPrimitiveId(), (OsmPrimitive)n); 128 //System.out.println("NODE " + String.valueOf(source.getUniqueId()) + " HAS MAPPED TO INNER " + String.valueOf(n.getUniqueId()) ); 129 } 130 else if (qName.equals("way")) { 131 Way w = new Way(); 132 WayData source = new WayData(); 133 readCommon(atts, source); 134 Way target = (Way)targetDataSet.getPrimitiveById( source.getUniqueId(), source.getType() ); 135 136 if (target == null || !(source.isModified() || source.isDeleted()) ) 137 w.load(source); 138 else { 139 w.cloneFrom(target); 140 w.load(source); 141 } 142 143 currentPrimitive = w; 144 currentWayNodes.clear(); 145 externalIdMap.put(source.getPrimitiveId(), (OsmPrimitive)w); 146 //System.out.println("WAY " + String.valueOf(source.getUniqueId()) + " HAS MAPPED TO INNER " + String.valueOf(w.getUniqueId()) ); 147 } 148 else if (qName.equals("nd")) { 149 if (atts.getValue("ref") == null) 150 throwException(tr("Missing mandatory attribute ''{0}'' on <nd> of way {1}.", "ref", currentPrimitive.getUniqueId())); 151 long id = getLong(atts, "ref"); 152 if (id == 0) 153 throwException(tr("Illegal value of attribute ''ref'' of element <nd>. Got {0}.", id) ); 154 //System.out.println("NODE " + String.valueOf(id) + " HAS ADDED TO WAY " + String.valueOf(currentPrimitive.getUniqueId())); 155 Node node = (Node)externalIdMap.get(new SimplePrimitiveId(id, OsmPrimitiveType.NODE)); 156 if (node == null || node.isModified()) { 157 node = (Node)targetDataSet.getPrimitiveById( new SimplePrimitiveId(id, OsmPrimitiveType.NODE) ); 158 if (node == null) 159 throwException(tr("Missing definition of new object with id {0}.", id)); 160 } 161 currentWayNodes.add(node); 162 } 163 // ---- PARSING RELATIONS ---- 164 165 else if (qName.equals("relation")) { 166 Relation r = new Relation(); 167 RelationData source = new RelationData(); 168 readCommon(atts, source); 169 Relation target = (Relation)targetDataSet.getPrimitiveById( source.getUniqueId(), source.getType() ); 170 171 if (target == null || !(source.isModified() || source.isDeleted()) ) 172 r.load(source); 173 else { 174 r.cloneFrom(target); 175 r.load(source); 176 } 177 178 currentPrimitive = r; 179 currentRelationMembers.clear(); 180 externalIdMap.put(source.getPrimitiveId(), (OsmPrimitive)r); 181 //System.out.println("RELATION " + String.valueOf(source.getUniqueId()) + " HAS MAPPED TO INNER " + String.valueOf(r.getUniqueId()) ); 182 } 183 else if (qName.equals("member")) { 184 if (atts.getValue("ref") == null) 185 throwException(tr("Missing mandatory attribute ''{0}'' on <member> of relation {1}.", "ref", currentPrimitive.getUniqueId())); 186 long id = getLong(atts, "ref"); 187 if (id == 0) 188 throwException(tr("Illegal value of attribute ''ref'' of element <nd>. Got {0}.", id) ); 189 190 OsmPrimitiveType type = OsmPrimitiveType.NODE; 191 String value = atts.getValue("type"); 192 if (value == null) { 193 throwException(tr("Missing attribute ''type'' on member {0} in relation {1}.", Long.toString(id), Long.toString(currentPrimitive.getUniqueId()))); 194 } 195 try { 196 type = OsmPrimitiveType.fromApiTypeName(value); 197 } 198 catch(IllegalArgumentException e) { 199 throwException(tr("Illegal value for attribute ''type'' on member {0} in relation {1}. Got {2}.", Long.toString(id), Long.toString(currentPrimitive.getUniqueId()), value)); 200 } 201 202 String role = atts.getValue("role"); 203 204 //System.out.println("MEMBER " + value.toUpperCase() + " " +String.valueOf(id) + " HAS ADDED TO RELATION " + String.valueOf(currentPrimitive.getUniqueId())); 205 OsmPrimitive member = externalIdMap.get(new SimplePrimitiveId(id, type)); 206 if (member == null) { 207 member = targetDataSet.getPrimitiveById(new SimplePrimitiveId(id, type)); 208 if (member == null) 209 throwException(tr("Missing definition of new object with id {0}.", id)); 210 } 211 RelationMember relationMember = new RelationMember(role, member); 212 currentRelationMembers.add(relationMember); 213 } 214 215 // ---- PARSING TAGS (applicable to all objects) ---- 216 217 else if (qName.equals("tag")) { 218 String key = atts.getValue("k"); 219 String value = atts.getValue("v"); 220 if (key == null || value == null) { 221 throwException(tr("Missing key or value attribute in tag.")); 222 } 223 currentPrimitive.put(key.intern(), value.intern()); 224 } 225 else { 226 System.out.println(tr("Undefined element ''{0}'' found in input stream. Skipping.", qName)); 227 } 228 } 229 catch (Exception e) { 230 throw new SAXParseException(e.getMessage(), locator, e); 231 } 232 } 233 234 @Override 235 public void endElement(String namespaceURI, String localName, String qName) { 236 if (qName.equals("node")) { 237 if (currentPrimitive.isDeleted()) { 238 cmds.add(new DeleteCommand( targetDataSet.getPrimitiveById(currentPrimitive.getPrimitiveId()) )); 239 } 240 else if (currentPrimitive.isModified()) { 241 //System.out.println(String.valueOf(currentPrimitive.getUniqueId()) + " IS MODIFIED BY SCRIPT"); 242 cmds.add(new ChangeCommand(Main.map.mapView.getEditLayer(), (Node)targetDataSet.getPrimitiveById(currentPrimitive.getPrimitiveId()), currentPrimitive)); 243 } 244 else if (currentPrimitive.isNew()) { 245 cmds.add(new AddCommand(currentPrimitive)); 246 } 247 } 248 else if (qName.equals("way")) { 249 ((Way)currentPrimitive).setNodes(currentWayNodes); 250 if (currentPrimitive.isDeleted()) { 251 cmds.add(new DeleteCommand( targetDataSet.getPrimitiveById(currentPrimitive.getPrimitiveId()) )); 252 } 253 else if (currentPrimitive.isModified()) { 254 cmds.add(new ChangeCommand(Main.map.mapView.getEditLayer(), (Way)targetDataSet.getPrimitiveById(currentPrimitive.getPrimitiveId()), currentPrimitive)); 255 } 256 else if (currentPrimitive.isNew()) { 257 cmds.add(new AddCommand(currentPrimitive)); 258 } 259 } 260 else if (qName.equals("relation")) { 261 ((Relation)currentPrimitive).setMembers(currentRelationMembers); 262 if (currentPrimitive.isDeleted()) { 263 cmds.add(new DeleteCommand( targetDataSet.getPrimitiveById(currentPrimitive.getPrimitiveId()) )); 264 } 265 else if (currentPrimitive.isModified()) { 266 cmds.add(new ChangeCommand(Main.map.mapView.getEditLayer(), (Relation)targetDataSet.getPrimitiveById(currentPrimitive.getPrimitiveId()), currentPrimitive)); 267 } 268 else if (currentPrimitive.isNew()) { 269 cmds.add(new AddCommand(currentPrimitive)); 270 } 271 } 272 } 273 274 @Override 275 public void comment(char[] ch, int start, int length) { 276 parentPlugin.printHistory(String.valueOf(ch)); 277 } 278 279 public void startCDATA() { 280 } 281 282 public void endCDATA() { 283 } 284 285 public void startEntity(String name) { 286 } 287 288 public void endEntity(String name) { 289 } 290 291 public void startDTD(String name, String publicId, String systemId) { 292 } 293 294 public void endDTD() { 295 } 296 297 private double getDouble(Attributes atts, String value) { 298 return Double.parseDouble(atts.getValue(value)); 299 } 300 301 private long getLong(Attributes atts, String name) throws SAXException { 302 String value = atts.getValue(name); 303 if (value == null) { 304 throwException(tr("Missing required attribute ''{0}''.",name)); 305 } 306 try { 307 return Long.parseLong(value); 308 } 309 catch(NumberFormatException e) { 310 throwException(tr("Illegal long value for attribute ''{0}''. Got ''{1}''.",name, value)); 311 } 312 return 0; // should not happen 313 } 314 315 private User createUser(String uid, String name) throws SAXException { 316 if (uid == null) { 317 if (name == null) 318 return null; 319 return User.createLocalUser(name); 320 } 321 try { 322 long id = Long.parseLong(uid); 323 return User.createOsmUser(id, name); 324 } 325 catch(NumberFormatException e) { 326 throwException(tr("Illegal value for attribute ''uid''. Got ''{0}''.", uid)); 327 } 328 return null; 329 } 330 331 void readCommon(Attributes atts, PrimitiveData current) throws SAXException { 332 current.setId(getLong(atts, "id")); 333 if (current.getUniqueId() == 0) { 334 throwException(tr("Illegal object with ID=0.")); 335 } 336 337 String time = atts.getValue("timestamp"); 338 if (time != null && time.length() != 0) { 339 current.setTimestamp(DateUtils.fromString(time)); 340 } 341 342 String user = atts.getValue("user"); 343 String uid = atts.getValue("uid"); 344 current.setUser(createUser(uid, user)); 345 346 String visible = atts.getValue("visible"); 347 if (visible != null) { 348 current.setVisible(Boolean.parseBoolean(visible)); 349 } 350 351 String versionString = atts.getValue("version"); 352 int version = 0; 353 if (versionString != null) { 354 try { 355 version = Integer.parseInt(versionString); 356 } catch(NumberFormatException e) { 357 throwException(tr("Illegal value for attribute ''version'' on OSM primitive with ID {0}. Got {1}.", Long.toString(current.getUniqueId()), versionString)); 358 } 359 } 360 current.setVersion(version); 361 362 String action = atts.getValue("action"); 363 if (action == null) { 364 // do nothing 365 } else if (action.equals("delete")) { 366 current.setDeleted(true); 367 current.setModified(current.isVisible()); 368 } else if (action.equals("modify")) { 369 current.setModified(true); 370 } 371 372 String v = atts.getValue("changeset"); 373 if (v == null) { 374 current.setChangesetId(0); 375 } else { 376 try { 377 current.setChangesetId(Integer.parseInt(v)); 378 } catch(NumberFormatException e) { 379 if (current.getUniqueId() <= 0) { 380 System.out.println(tr("Illegal value for attribute ''changeset'' on new object {1}. Got {0}. Resetting to 0.", v, current.getUniqueId())); 381 current.setChangesetId(0); 382 } else { 383 throwException(tr("Illegal value for attribute ''changeset''. Got {0}.", v)); 384 } 385 } 386 if (current.getChangesetId() <=0) { 387 if (current.getUniqueId() <= 0) { 388 System.out.println(tr("Illegal value for attribute ''changeset'' on new object {1}. Got {0}. Resetting to 0.", v, current.getUniqueId())); 389 current.setChangesetId(0); 390 } else { 391 throwException(tr("Illegal value for attribute ''changeset''. Got {0}.", v)); 392 } 393 } 394 } 395 } 396 } 55 private final CommandLine parentPlugin; 56 private final DataSet targetDataSet; 57 private final LinkedList<Command> cmds = new LinkedList<Command>(); 58 private final HashMap<PrimitiveId, OsmPrimitive> externalIdMap; // Maps external ids to internal primitives 59 60 public OsmToCmd(CommandLine parentPlugin, DataSet targetDataSet) { 61 this.parentPlugin = parentPlugin; 62 this.targetDataSet = targetDataSet; 63 externalIdMap = new HashMap<PrimitiveId, OsmPrimitive>(); 64 } 65 66 public void parseStream(InputStream stream) throws IllegalDataException { 67 try { 68 InputSource inputSource = new InputSource(UTFInputStreamReader.create(stream, "UTF-8")); 69 SAXParser parser = SAXParserFactory.newInstance().newSAXParser(); 70 Parser handler = new Parser(); 71 parser.setProperty("http://xml.org/sax/properties/lexical-handler", handler); 72 parser.parse(inputSource, handler); 73 } catch(ParserConfigurationException e) { 74 throw new IllegalDataException(e.getMessage(), e); 75 } catch (SAXParseException e) { 76 throw new IllegalDataException(tr("Line {0} column {1}: ", e.getLineNumber(), e.getColumnNumber()) + e.getMessage(), e); 77 } catch(SAXException e) { 78 throw new IllegalDataException(e.getMessage(), e); 79 } catch(Exception e) { 80 throw new IllegalDataException(e); 81 } 82 } 83 84 public LinkedList<Command> getCommandList() { 85 return cmds; 86 } 87 88 private class Parser extends DefaultHandler implements LexicalHandler { 89 private Locator locator; 90 91 @Override 92 public void setDocumentLocator(Locator locator) { 93 this.locator = locator; 94 } 95 96 protected void throwException(String msg) throws OsmDataParsingException { 97 throw new OsmDataParsingException(msg).rememberLocation(locator); 98 } 99 100 private OsmPrimitive currentPrimitive; 101 //private long currentExternalId; 102 private final List<Node> currentWayNodes = new ArrayList<Node>(); 103 private final List<RelationMember> currentRelationMembers = new ArrayList<RelationMember>(); 104 105 @Override 106 public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException { 107 try { 108 if (qName.equals("osm")) { 109 if (atts == null) { 110 throwException(tr("Missing mandatory attribute ''{0}'' of XML element {1}.", "version", "osm")); 111 } 112 String v = atts.getValue("version"); 113 if (v == null) { 114 throwException(tr("Missing mandatory attribute ''{0}''.", "version")); 115 } 116 if ( !(v.equals("0.6")) ) { 117 throwException(tr("Unsupported version: {0}", v)); 118 } 119 120 // ---- PARSING NODES AND WAYS ---- 121 122 } else if (qName.equals("node")) { 123 Node n = new Node(); 124 NodeData source = new NodeData(); 125 source.setCoor(new LatLon(getDouble(atts, "lat"), getDouble(atts, "lon"))); 126 readCommon(atts, source); 127 Node target = (Node)targetDataSet.getPrimitiveById( source.getUniqueId(), source.getType() ); 128 129 if (target == null || !(source.isModified() || source.isDeleted()) ) 130 n.load(source); 131 else { 132 n.cloneFrom(target); 133 n.load(source); 134 } 135 136 currentPrimitive = n; 137 externalIdMap.put(source.getPrimitiveId(), n); 138 //System.out.println("NODE " + String.valueOf(source.getUniqueId()) + " HAS MAPPED TO INNER " + String.valueOf(n.getUniqueId()) ); 139 } 140 else if (qName.equals("way")) { 141 Way w = new Way(); 142 WayData source = new WayData(); 143 readCommon(atts, source); 144 Way target = (Way)targetDataSet.getPrimitiveById( source.getUniqueId(), source.getType() ); 145 146 if (target == null || !(source.isModified() || source.isDeleted()) ) 147 w.load(source); 148 else { 149 w.cloneFrom(target); 150 w.load(source); 151 } 152 153 currentPrimitive = w; 154 currentWayNodes.clear(); 155 externalIdMap.put(source.getPrimitiveId(), w); 156 //System.out.println("WAY " + String.valueOf(source.getUniqueId()) + " HAS MAPPED TO INNER " + String.valueOf(w.getUniqueId()) ); 157 } 158 else if (qName.equals("nd")) { 159 if (atts.getValue("ref") == null) 160 throwException(tr("Missing mandatory attribute ''{0}'' on <nd> of way {1}.", "ref", currentPrimitive.getUniqueId())); 161 long id = getLong(atts, "ref"); 162 if (id == 0) 163 throwException(tr("Illegal value of attribute ''ref'' of element <nd>. Got {0}.", id) ); 164 //System.out.println("NODE " + String.valueOf(id) + " HAS ADDED TO WAY " + String.valueOf(currentPrimitive.getUniqueId())); 165 Node node = (Node)externalIdMap.get(new SimplePrimitiveId(id, OsmPrimitiveType.NODE)); 166 if (node == null || node.isModified()) { 167 node = (Node)targetDataSet.getPrimitiveById( new SimplePrimitiveId(id, OsmPrimitiveType.NODE) ); 168 if (node == null) 169 throwException(tr("Missing definition of new object with id {0}.", id)); 170 } 171 currentWayNodes.add(node); 172 } 173 // ---- PARSING RELATIONS ---- 174 175 else if (qName.equals("relation")) { 176 Relation r = new Relation(); 177 RelationData source = new RelationData(); 178 readCommon(atts, source); 179 Relation target = (Relation)targetDataSet.getPrimitiveById( source.getUniqueId(), source.getType() ); 180 181 if (target == null || !(source.isModified() || source.isDeleted()) ) 182 r.load(source); 183 else { 184 r.cloneFrom(target); 185 r.load(source); 186 } 187 188 currentPrimitive = r; 189 currentRelationMembers.clear(); 190 externalIdMap.put(source.getPrimitiveId(), r); 191 //System.out.println("RELATION " + String.valueOf(source.getUniqueId()) + " HAS MAPPED TO INNER " + String.valueOf(r.getUniqueId()) ); 192 } 193 else if (qName.equals("member")) { 194 if (atts.getValue("ref") == null) 195 throwException(tr("Missing mandatory attribute ''{0}'' on <member> of relation {1}.", "ref", currentPrimitive.getUniqueId())); 196 long id = getLong(atts, "ref"); 197 if (id == 0) 198 throwException(tr("Illegal value of attribute ''ref'' of element <nd>. Got {0}.", id) ); 199 200 OsmPrimitiveType type = OsmPrimitiveType.NODE; 201 String value = atts.getValue("type"); 202 if (value == null) { 203 throwException(tr("Missing attribute ''type'' on member {0} in relation {1}.", Long.toString(id), Long.toString(currentPrimitive.getUniqueId()))); 204 } 205 try { 206 type = OsmPrimitiveType.fromApiTypeName(value); 207 } 208 catch(IllegalArgumentException e) { 209 throwException(tr("Illegal value for attribute ''type'' on member {0} in relation {1}. Got {2}.", Long.toString(id), Long.toString(currentPrimitive.getUniqueId()), value)); 210 } 211 212 String role = atts.getValue("role"); 213 214 //System.out.println("MEMBER " + value.toUpperCase() + " " +String.valueOf(id) + " HAS ADDED TO RELATION " + String.valueOf(currentPrimitive.getUniqueId())); 215 OsmPrimitive member = externalIdMap.get(new SimplePrimitiveId(id, type)); 216 if (member == null) { 217 member = targetDataSet.getPrimitiveById(new SimplePrimitiveId(id, type)); 218 if (member == null) 219 throwException(tr("Missing definition of new object with id {0}.", id)); 220 } 221 RelationMember relationMember = new RelationMember(role, member); 222 currentRelationMembers.add(relationMember); 223 } 224 225 // ---- PARSING TAGS (applicable to all objects) ---- 226 227 else if (qName.equals("tag")) { 228 String key = atts.getValue("k"); 229 String value = atts.getValue("v"); 230 if (key == null || value == null) { 231 throwException(tr("Missing key or value attribute in tag.")); 232 } 233 currentPrimitive.put(key.intern(), value.intern()); 234 } 235 else { 236 System.out.println(tr("Undefined element ''{0}'' found in input stream. Skipping.", qName)); 237 } 238 } 239 catch (Exception e) { 240 throw new SAXParseException(e.getMessage(), locator, e); 241 } 242 } 243 244 @Override 245 public void endElement(String namespaceURI, String localName, String qName) { 246 if (qName.equals("node")) { 247 if (currentPrimitive.isDeleted()) { 248 cmds.add(new DeleteCommand( targetDataSet.getPrimitiveById(currentPrimitive.getPrimitiveId()) )); 249 } 250 else if (currentPrimitive.isModified()) { 251 //System.out.println(String.valueOf(currentPrimitive.getUniqueId()) + " IS MODIFIED BY SCRIPT"); 252 cmds.add(new ChangeCommand(Main.map.mapView.getEditLayer(), targetDataSet.getPrimitiveById(currentPrimitive.getPrimitiveId()), currentPrimitive)); 253 } 254 else if (currentPrimitive.isNew()) { 255 cmds.add(new AddCommand(currentPrimitive)); 256 } 257 } 258 else if (qName.equals("way")) { 259 ((Way)currentPrimitive).setNodes(currentWayNodes); 260 if (currentPrimitive.isDeleted()) { 261 cmds.add(new DeleteCommand( targetDataSet.getPrimitiveById(currentPrimitive.getPrimitiveId()) )); 262 } 263 else if (currentPrimitive.isModified()) { 264 cmds.add(new ChangeCommand(Main.map.mapView.getEditLayer(), targetDataSet.getPrimitiveById(currentPrimitive.getPrimitiveId()), currentPrimitive)); 265 } 266 else if (currentPrimitive.isNew()) { 267 cmds.add(new AddCommand(currentPrimitive)); 268 } 269 } 270 else if (qName.equals("relation")) { 271 ((Relation)currentPrimitive).setMembers(currentRelationMembers); 272 if (currentPrimitive.isDeleted()) { 273 cmds.add(new DeleteCommand( targetDataSet.getPrimitiveById(currentPrimitive.getPrimitiveId()) )); 274 } 275 else if (currentPrimitive.isModified()) { 276 cmds.add(new ChangeCommand(Main.map.mapView.getEditLayer(), targetDataSet.getPrimitiveById(currentPrimitive.getPrimitiveId()), currentPrimitive)); 277 } 278 else if (currentPrimitive.isNew()) { 279 cmds.add(new AddCommand(currentPrimitive)); 280 } 281 } 282 } 283 284 @Override 285 public void comment(char[] ch, int start, int length) { 286 parentPlugin.printHistory(String.valueOf(ch)); 287 } 288 289 @Override 290 public void startCDATA() { 291 } 292 293 @Override 294 public void endCDATA() { 295 } 296 297 @Override 298 public void startEntity(String name) { 299 } 300 301 @Override 302 public void endEntity(String name) { 303 } 304 305 @Override 306 public void startDTD(String name, String publicId, String systemId) { 307 } 308 309 @Override 310 public void endDTD() { 311 } 312 313 private double getDouble(Attributes atts, String value) { 314 return Double.parseDouble(atts.getValue(value)); 315 } 316 317 private long getLong(Attributes atts, String name) throws SAXException { 318 String value = atts.getValue(name); 319 if (value == null) { 320 throwException(tr("Missing required attribute ''{0}''.",name)); 321 } 322 try { 323 return Long.parseLong(value); 324 } 325 catch(NumberFormatException e) { 326 throwException(tr("Illegal long value for attribute ''{0}''. Got ''{1}''.",name, value)); 327 } 328 return 0; // should not happen 329 } 330 331 private User createUser(String uid, String name) throws SAXException { 332 if (uid == null) { 333 if (name == null) 334 return null; 335 return User.createLocalUser(name); 336 } 337 try { 338 long id = Long.parseLong(uid); 339 return User.createOsmUser(id, name); 340 } 341 catch(NumberFormatException e) { 342 throwException(tr("Illegal value for attribute ''uid''. Got ''{0}''.", uid)); 343 } 344 return null; 345 } 346 347 void readCommon(Attributes atts, PrimitiveData current) throws SAXException { 348 current.setId(getLong(atts, "id")); 349 if (current.getUniqueId() == 0) { 350 throwException(tr("Illegal object with ID=0.")); 351 } 352 353 String time = atts.getValue("timestamp"); 354 if (time != null && time.length() != 0) { 355 current.setTimestamp(DateUtils.fromString(time)); 356 } 357 358 String user = atts.getValue("user"); 359 String uid = atts.getValue("uid"); 360 current.setUser(createUser(uid, user)); 361 362 String visible = atts.getValue("visible"); 363 if (visible != null) { 364 current.setVisible(Boolean.parseBoolean(visible)); 365 } 366 367 String versionString = atts.getValue("version"); 368 int version = 0; 369 if (versionString != null) { 370 try { 371 version = Integer.parseInt(versionString); 372 } catch(NumberFormatException e) { 373 throwException(tr("Illegal value for attribute ''version'' on OSM primitive with ID {0}. Got {1}.", Long.toString(current.getUniqueId()), versionString)); 374 } 375 } 376 current.setVersion(version); 377 378 String action = atts.getValue("action"); 379 if (action == null) { 380 // do nothing 381 } else if (action.equals("delete")) { 382 current.setDeleted(true); 383 current.setModified(current.isVisible()); 384 } else if (action.equals("modify")) { 385 current.setModified(true); 386 } 387 388 String v = atts.getValue("changeset"); 389 if (v == null) { 390 current.setChangesetId(0); 391 } else { 392 try { 393 current.setChangesetId(Integer.parseInt(v)); 394 } catch(NumberFormatException e) { 395 if (current.getUniqueId() <= 0) { 396 System.out.println(tr("Illegal value for attribute ''changeset'' on new object {1}. Got {0}. Resetting to 0.", v, current.getUniqueId())); 397 current.setChangesetId(0); 398 } else { 399 throwException(tr("Illegal value for attribute ''changeset''. Got {0}.", v)); 400 } 401 } 402 if (current.getChangesetId() <=0) { 403 if (current.getUniqueId() <= 0) { 404 System.out.println(tr("Illegal value for attribute ''changeset'' on new object {1}. Got {0}. Resetting to 0.", v, current.getUniqueId())); 405 current.setChangesetId(0); 406 } else { 407 throwException(tr("Illegal value for attribute ''changeset''. Got {0}.", v)); 408 } 409 } 410 } 411 } 412 } 397 413 } -
applications/editors/josm/plugins/CommandLine/src/CommandLine/Parameter.java
r25052 r29505 13 13 import java.util.Collection; 14 14 15 import org.openstreetmap.josm.data.coor.LatLon;16 import org.openstreetmap.josm.data.osm.Node;17 15 import org.openstreetmap.josm.data.osm.OsmPrimitive; 18 import org.openstreetmap.josm.data.osm.Way;19 import org.openstreetmap.josm.data.osm.Relation;20 16 21 17 public class Parameter { -
applications/editors/josm/plugins/CommandLine/src/CommandLine/PointAction.java
r25052 r29505 13 13 import java.awt.Cursor; 14 14 import java.awt.EventQueue; 15 import java.awt.Point; 16 import java.awt.Toolkit; 15 17 import java.awt.event.AWTEventListener; 16 18 import java.awt.event.KeyEvent; 17 19 import java.awt.event.MouseEvent; 18 import java.awt.Point;19 import java.awt.Toolkit;20 20 import java.util.ArrayList; 21 import java.util.Collection; 21 22 22 import javax.swing.JOptionPane; 23 23 … … 25 25 import org.openstreetmap.josm.actions.mapmode.MapMode; 26 26 import org.openstreetmap.josm.data.coor.LatLon; 27 import org.openstreetmap.josm.data.SelectionChangedListener;28 import org.openstreetmap.josm.data.osm.DataSet;29 27 import org.openstreetmap.josm.data.osm.Node; 30 28 import org.openstreetmap.josm.data.osm.OsmPrimitive; -
applications/editors/josm/plugins/CommandLine/src/CommandLine/RelationAction.java
r25052 r29505 8 8 package CommandLine; 9 9 10 import static org.openstreetmap.josm.tools.I18n.tr;11 12 10 import java.awt.AWTEvent; 13 import java.awt.Cursor;14 import java.awt.EventQueue;15 11 import java.awt.event.AWTEventListener; 16 12 import java.awt.event.KeyEvent; 17 import java.awt.event.MouseEvent;18 import java.awt.Point;19 import java.awt.Toolkit;20 import java.util.Collection;21 import javax.swing.JOptionPane;22 13 23 14 import org.openstreetmap.josm.Main; 24 15 import org.openstreetmap.josm.actions.mapmode.MapMode; 25 import org.openstreetmap.josm.data.coor.LatLon;26 import org.openstreetmap.josm.data.osm.DataSet;27 import org.openstreetmap.josm.data.osm.Node;28 import org.openstreetmap.josm.data.osm.OsmPrimitive;29 import org.openstreetmap.josm.data.osm.PrimitiveId;30 16 import org.openstreetmap.josm.gui.MapFrame; 31 17 import org.openstreetmap.josm.tools.ImageProvider; -
applications/editors/josm/plugins/CommandLine/src/CommandLine/WayAction.java
r25052 r29505 8 8 package CommandLine; 9 9 10 import static org.openstreetmap.josm.tools.I18n.tr;11 12 10 import java.awt.AWTEvent; 13 11 import java.awt.Cursor; 14 12 import java.awt.EventQueue; 13 import java.awt.Point; 14 import java.awt.Toolkit; 15 15 import java.awt.event.AWTEventListener; 16 16 import java.awt.event.KeyEvent; 17 17 import java.awt.event.MouseEvent; 18 import java.awt.Point;19 import java.awt.Toolkit;20 import java.util.Collection;21 import javax.swing.JOptionPane;22 18 23 19 import org.openstreetmap.josm.Main; 24 20 import org.openstreetmap.josm.actions.mapmode.MapMode; 25 import org.openstreetmap.josm.data.coor.LatLon; 26 import org.openstreetmap.josm.data.osm.DataSet; 21 import org.openstreetmap.josm.data.osm.OsmPrimitive; 27 22 import org.openstreetmap.josm.data.osm.Way; 28 import org.openstreetmap.josm.data.osm.OsmPrimitive;29 import org.openstreetmap.josm.data.osm.PrimitiveId;30 23 import org.openstreetmap.josm.gui.MapFrame; 31 24 import org.openstreetmap.josm.tools.ImageProvider;
Note:
See TracChangeset
for help on using the changeset viewer.