Index: applications/editors/josm/plugins/CommandLine/src/CommandLine/AnyAction.java
===================================================================
--- applications/editors/josm/plugins/CommandLine/src/CommandLine/AnyAction.java	(revision 29273)
+++ applications/editors/josm/plugins/CommandLine/src/CommandLine/AnyAction.java	(revision 29505)
@@ -8,24 +8,16 @@
 package CommandLine;
 
-import static org.openstreetmap.josm.tools.I18n.tr;
-
 import java.awt.AWTEvent;
 import java.awt.Cursor;
 import java.awt.EventQueue;
+import java.awt.Point;
+import java.awt.Toolkit;
 import java.awt.event.AWTEventListener;
 import java.awt.event.KeyEvent;
 import java.awt.event.MouseEvent;
-import java.awt.Point;
-import java.awt.Toolkit;
-import java.util.Collection;
-import javax.swing.JOptionPane;
 
 import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.actions.mapmode.MapMode;
-import org.openstreetmap.josm.data.coor.LatLon;
-import org.openstreetmap.josm.data.osm.DataSet;
-import org.openstreetmap.josm.data.osm.Node;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
-import org.openstreetmap.josm.data.osm.PrimitiveId;
 import org.openstreetmap.josm.gui.MapFrame;
 import org.openstreetmap.josm.tools.ImageProvider;
Index: applications/editors/josm/plugins/CommandLine/src/CommandLine/Command.java
===================================================================
--- applications/editors/josm/plugins/CommandLine/src/CommandLine/Command.java	(revision 29273)
+++ applications/editors/josm/plugins/CommandLine/src/CommandLine/Command.java	(revision 29505)
@@ -1,7 +1,7 @@
 /*
  *      Command.java
- *      
+ * 
  *      Copyright 2011 Hind <foxhind@gmail.com>
- *      
+ * 
  */
 
@@ -10,6 +10,6 @@
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.List;
-import java.util.regex.*;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import org.openstreetmap.josm.data.osm.Node;
@@ -17,198 +17,197 @@
 import org.openstreetmap.josm.data.osm.Relation;
 import org.openstreetmap.josm.data.osm.Way;
-import org.openstreetmap.josm.data.osm.DataSet;
 
 public class Command {
-	public String name;						// Command name
-	public String run;						// Executable file with arguments ("nya.exe {arg1} {arg2} ... {argn}")
-	public String icon;						// Icon file name
-	public ArrayList<Parameter> parameters;	// Required parameters list
-	public ArrayList<Parameter> optParameters;	// Optional parameters list
-	public int currentParameterNum;
-	public boolean tracks;
-	
-	public Command () {	parameters = new ArrayList<Parameter>(); optParameters = new ArrayList<Parameter>(); currentParameterNum = 0; tracks = false; icon = ""; }
-
-	public boolean loadObject(Object obj) {
-		Parameter currentParameter = parameters.get(currentParameterNum);
-		//System.out.println("Parameter " + String.valueOf(currentParameterNum) + " (" + currentParameter.name + ")");
-		if (currentParameter.maxInstances == 1) {
-			//System.out.println("mI = 1");
-			//System.out.println("Candidate: " + String.valueOf(obj));
-			if (isPair(obj, currentParameter)) {
-				currentParameter.setValue(obj);
-				//System.out.println("Accepted");
-				return true;
-			}
-		}
-		else {
-			//System.out.println("mI = " + String.valueOf(currentParameter.maxInstances));
-			ArrayList<OsmPrimitive> multiValue = currentParameter.getValueList();
-			if (obj instanceof Collection) {
-				if ( ((Collection)obj).size() > currentParameter.maxInstances && currentParameter.maxInstances != 0)
-					return false;
-				//System.out.println("Candidate (selected) accepted");
-				multiValue.clear();
-				multiValue.addAll((Collection<OsmPrimitive>)obj);
-				return true;
-			}
-			else if (obj instanceof OsmPrimitive) {
-				if (multiValue.size() < currentParameter.maxInstances || currentParameter.maxInstances == 0) {
-					//System.out.println("Candidate: " + String.valueOf(obj));
-					if (isPair(obj, currentParameter)) {
-						multiValue.add((OsmPrimitive)obj);
-						//System.out.println("Accepted, added to list");
-						return true;
-					}
-					else {
-						if (nextParameter() && multiValue.size() > 0) {
-							//System.out.println("Not accepted but considering for next Parameter");
-							return loadObject(obj);
-						}
-					}
-				}
-				else {
-					if (nextParameter()) {
-						//System.out.println("Not accepted but considering for next Parameter");
-						return loadObject(obj);
-					}
-				}
-			}
-			else if (obj instanceof String) {
-				//System.out.println("Candidate: " + (String)obj);
-				if (isPair(obj, currentParameter)) {
-					currentParameter.setValue(obj);
-					//System.out.println("Accepted");
-					return true;
-				}
-			}
-		}
-		return false;
-	}
-
-	public boolean nextParameter() {
-		currentParameterNum++;
-		return (currentParameterNum < parameters.size()) ? true : false;
-	}
-
-	public boolean hasNextParameter() {
-		return ((currentParameterNum + 1) < parameters.size()) ? true : false;
-	}
-
-	public void resetLoading() {
-		currentParameterNum = 0;
-		for (Parameter parameter : parameters) {
-			if (parameter.maxInstances != 1)
-				parameter.getValueList().clear();
-		}
-	}
-
-	private static boolean isPair(Object obj, Parameter parameter) {
-		switch (parameter.type) {
-			case POINT:
-				if (obj instanceof String) {
-					Pattern p = Pattern.compile("(-?\\d*\\.?\\d*,-?\\d*\\.?\\d*;?)*");
-					Matcher m = p.matcher((String)obj);
-					return m.matches();
-				}
-				break;
-			case NODE:
-				if (obj instanceof Node) return true;
-				break;
-			case WAY:
-				if (obj instanceof Way) return true;
-				break;
-			case RELATION:
-				if (obj instanceof Relation) return true;
-				break;
-			case ANY:
-				if (obj instanceof Node || obj instanceof Way || obj instanceof Relation) return true;
-				break;
-			case LENGTH:
-				if (obj instanceof String) {
-					Pattern p = Pattern.compile("\\d*\\.?\\d*");
-					Matcher m = p.matcher((String)obj);
-					if (m.matches()) {
-						Float value = Float.parseFloat((String)obj);
-						if (parameter.minVal != 0 && value < parameter.minVal)
-							break;
-						if (parameter.maxVal != 0 && value > parameter.maxVal)
-							break;
-						return true;
-					}
-				}
-				break;
-			case NATURAL:
-				if (obj instanceof String) {
-					Pattern p = Pattern.compile("\\d*");
-					Matcher m = p.matcher((String)obj);
-					if (m.matches()) {
-						Integer value = Integer.parseInt((String)obj);
-						if (parameter.minVal != 0 && value < parameter.minVal)
-							break;
-						if (parameter.maxVal != 0 && value > parameter.maxVal)
-							break;
-						return true;
-					}
-				}
-				break;
-			case STRING:
-				if (obj instanceof String) return true;
-				break;
-			case RELAY:
-				if (obj instanceof String) {
-					if (parameter.getRawValue() instanceof Relay) {
-						if ( ((Relay)(parameter.getRawValue())).isCorrectValue((String)obj) )
-							return true;
-					}
-				}
-				break;
-			case USERNAME:
-				if (obj instanceof String) return true;
-				break;
-			case IMAGERYURL:
-				if (obj instanceof String) return true;
-				break;
-			case IMAGERYOFFSET:
-				if (obj instanceof String) return true;
-				break;
-		}
-		return false;
-	}
-
-	public Collection<OsmPrimitive> getDepsObjects() {
-		ArrayList<OsmPrimitive> depsObjects = new ArrayList<OsmPrimitive>();
-		for (Parameter parameter : parameters) {
-			if (!parameter.isOsm())
-						continue;
-			if (parameter.maxInstances == 1) {
-				depsObjects.addAll(getDepsObjects(depsObjects, (OsmPrimitive)parameter.getRawValue()));
-			}
-			else {
-				for (OsmPrimitive primitive : parameter.getValueList()) {
-					depsObjects.addAll(getDepsObjects(depsObjects, primitive));
-				}
-			}
-		}
-		return depsObjects;
-	}
-
-	public Collection<OsmPrimitive> getDepsObjects(Collection<OsmPrimitive> currentObjects, OsmPrimitive primitive) {
-		ArrayList<OsmPrimitive> depsObjects = new ArrayList<OsmPrimitive>();
-		if (!currentObjects.contains(primitive)) {
-			if (primitive instanceof Way) {
-				depsObjects.addAll(((Way)primitive).getNodes());
-			}
-			else if (primitive instanceof Relation) {
-				Collection<OsmPrimitive> relationMembers = ((Relation)primitive).getMemberPrimitives();
-				for (OsmPrimitive member : relationMembers) {
-					if (!currentObjects.contains(member)) {
-						depsObjects.add(member);
-						depsObjects.addAll(getDepsObjects(currentObjects, member));
-					}
-				}
-			}
-		}
-		return depsObjects;
-	}
+    public String name;						// Command name
+    public String run;						// Executable file with arguments ("nya.exe {arg1} {arg2} ... {argn}")
+    public String icon;						// Icon file name
+    public ArrayList<Parameter> parameters;	// Required parameters list
+    public ArrayList<Parameter> optParameters;	// Optional parameters list
+    public int currentParameterNum;
+    public boolean tracks;
+
+    public Command () {	parameters = new ArrayList<Parameter>(); optParameters = new ArrayList<Parameter>(); currentParameterNum = 0; tracks = false; icon = ""; }
+
+    public boolean loadObject(Object obj) {
+        Parameter currentParameter = parameters.get(currentParameterNum);
+        //System.out.println("Parameter " + String.valueOf(currentParameterNum) + " (" + currentParameter.name + ")");
+        if (currentParameter.maxInstances == 1) {
+            //System.out.println("mI = 1");
+            //System.out.println("Candidate: " + String.valueOf(obj));
+            if (isPair(obj, currentParameter)) {
+                currentParameter.setValue(obj);
+                //System.out.println("Accepted");
+                return true;
+            }
+        }
+        else {
+            //System.out.println("mI = " + String.valueOf(currentParameter.maxInstances));
+            ArrayList<OsmPrimitive> multiValue = currentParameter.getValueList();
+            if (obj instanceof Collection) {
+                if ( ((Collection<?>)obj).size() > currentParameter.maxInstances && currentParameter.maxInstances != 0)
+                    return false;
+                //System.out.println("Candidate (selected) accepted");
+                multiValue.clear();
+                multiValue.addAll((Collection<OsmPrimitive>)obj);
+                return true;
+            }
+            else if (obj instanceof OsmPrimitive) {
+                if (multiValue.size() < currentParameter.maxInstances || currentParameter.maxInstances == 0) {
+                    //System.out.println("Candidate: " + String.valueOf(obj));
+                    if (isPair(obj, currentParameter)) {
+                        multiValue.add((OsmPrimitive)obj);
+                        //System.out.println("Accepted, added to list");
+                        return true;
+                    }
+                    else {
+                        if (nextParameter() && multiValue.size() > 0) {
+                            //System.out.println("Not accepted but considering for next Parameter");
+                            return loadObject(obj);
+                        }
+                    }
+                }
+                else {
+                    if (nextParameter()) {
+                        //System.out.println("Not accepted but considering for next Parameter");
+                        return loadObject(obj);
+                    }
+                }
+            }
+            else if (obj instanceof String) {
+                //System.out.println("Candidate: " + (String)obj);
+                if (isPair(obj, currentParameter)) {
+                    currentParameter.setValue(obj);
+                    //System.out.println("Accepted");
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
+
+    public boolean nextParameter() {
+        currentParameterNum++;
+        return (currentParameterNum < parameters.size()) ? true : false;
+    }
+
+    public boolean hasNextParameter() {
+        return ((currentParameterNum + 1) < parameters.size()) ? true : false;
+    }
+
+    public void resetLoading() {
+        currentParameterNum = 0;
+        for (Parameter parameter : parameters) {
+            if (parameter.maxInstances != 1)
+                parameter.getValueList().clear();
+        }
+    }
+
+    private static boolean isPair(Object obj, Parameter parameter) {
+        switch (parameter.type) {
+        case POINT:
+            if (obj instanceof String) {
+                Pattern p = Pattern.compile("(-?\\d*\\.?\\d*,-?\\d*\\.?\\d*;?)*");
+                Matcher m = p.matcher((String)obj);
+                return m.matches();
+            }
+            break;
+        case NODE:
+            if (obj instanceof Node) return true;
+            break;
+        case WAY:
+            if (obj instanceof Way) return true;
+            break;
+        case RELATION:
+            if (obj instanceof Relation) return true;
+            break;
+        case ANY:
+            if (obj instanceof Node || obj instanceof Way || obj instanceof Relation) return true;
+            break;
+        case LENGTH:
+            if (obj instanceof String) {
+                Pattern p = Pattern.compile("\\d*\\.?\\d*");
+                Matcher m = p.matcher((String)obj);
+                if (m.matches()) {
+                    Float value = Float.parseFloat((String)obj);
+                    if (parameter.minVal != 0 && value < parameter.minVal)
+                        break;
+                    if (parameter.maxVal != 0 && value > parameter.maxVal)
+                        break;
+                    return true;
+                }
+            }
+            break;
+        case NATURAL:
+            if (obj instanceof String) {
+                Pattern p = Pattern.compile("\\d*");
+                Matcher m = p.matcher((String)obj);
+                if (m.matches()) {
+                    Integer value = Integer.parseInt((String)obj);
+                    if (parameter.minVal != 0 && value < parameter.minVal)
+                        break;
+                    if (parameter.maxVal != 0 && value > parameter.maxVal)
+                        break;
+                    return true;
+                }
+            }
+            break;
+        case STRING:
+            if (obj instanceof String) return true;
+            break;
+        case RELAY:
+            if (obj instanceof String) {
+                if (parameter.getRawValue() instanceof Relay) {
+                    if ( ((Relay)(parameter.getRawValue())).isCorrectValue((String)obj) )
+                        return true;
+                }
+            }
+            break;
+        case USERNAME:
+            if (obj instanceof String) return true;
+            break;
+        case IMAGERYURL:
+            if (obj instanceof String) return true;
+            break;
+        case IMAGERYOFFSET:
+            if (obj instanceof String) return true;
+            break;
+        }
+        return false;
+    }
+
+    public Collection<OsmPrimitive> getDepsObjects() {
+        ArrayList<OsmPrimitive> depsObjects = new ArrayList<OsmPrimitive>();
+        for (Parameter parameter : parameters) {
+            if (!parameter.isOsm())
+                continue;
+            if (parameter.maxInstances == 1) {
+                depsObjects.addAll(getDepsObjects(depsObjects, (OsmPrimitive)parameter.getRawValue()));
+            }
+            else {
+                for (OsmPrimitive primitive : parameter.getValueList()) {
+                    depsObjects.addAll(getDepsObjects(depsObjects, primitive));
+                }
+            }
+        }
+        return depsObjects;
+    }
+
+    public Collection<OsmPrimitive> getDepsObjects(Collection<OsmPrimitive> currentObjects, OsmPrimitive primitive) {
+        ArrayList<OsmPrimitive> depsObjects = new ArrayList<OsmPrimitive>();
+        if (!currentObjects.contains(primitive)) {
+            if (primitive instanceof Way) {
+                depsObjects.addAll(((Way)primitive).getNodes());
+            }
+            else if (primitive instanceof Relation) {
+                Collection<OsmPrimitive> relationMembers = ((Relation)primitive).getMemberPrimitives();
+                for (OsmPrimitive member : relationMembers) {
+                    if (!currentObjects.contains(member)) {
+                        depsObjects.add(member);
+                        depsObjects.addAll(getDepsObjects(currentObjects, member));
+                    }
+                }
+            }
+        }
+        return depsObjects;
+    }
 }
Index: applications/editors/josm/plugins/CommandLine/src/CommandLine/CommandAction.java
===================================================================
--- applications/editors/josm/plugins/CommandLine/src/CommandLine/CommandAction.java	(revision 29273)
+++ applications/editors/josm/plugins/CommandLine/src/CommandLine/CommandAction.java	(revision 29505)
@@ -11,53 +11,38 @@
 
 import java.awt.event.ActionEvent;
-import java.awt.AWTEvent;
-import java.awt.Cursor;
-import java.awt.EventQueue;
-import java.awt.event.AWTEventListener;
-import java.awt.event.KeyEvent;
-import java.awt.event.MouseEvent;
-import java.awt.Point;
-import java.awt.Toolkit;
-import java.util.Collection;
+
 import javax.swing.Action;
-import javax.swing.JOptionPane;
 
-import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.actions.JosmAction;
-import org.openstreetmap.josm.data.coor.LatLon;
-import org.openstreetmap.josm.data.osm.DataSet;
-import org.openstreetmap.josm.data.osm.Way;
-import org.openstreetmap.josm.data.osm.OsmPrimitive;
-import org.openstreetmap.josm.data.osm.PrimitiveId;
-import org.openstreetmap.josm.gui.MapFrame;
 import org.openstreetmap.josm.tools.ImageProvider;
 
 public class CommandAction extends JosmAction {
-	private CommandLine parentPlugin;
-	private Command parentCommand;
-	public CommandAction(Command parentCommand, CommandLine parentPlugin) {
-		super(tr(parentCommand.name), "blankmenu", tr(parentCommand.name), null, true, parentCommand.name, true);
-		if (!parentCommand.icon.equals("")) {
-			try {
-				putValue(Action.SMALL_ICON, ImageProvider.get(parentPlugin.pluginDir, parentCommand.icon));
-				putValue(Action.LARGE_ICON_KEY, ImageProvider.get(parentPlugin.pluginDir, parentCommand.icon));
-			}
-			catch (NullPointerException e) {
-				putValue(Action.SMALL_ICON, ImageProvider.get("blankmenu"));
-				putValue(Action.LARGE_ICON_KEY, ImageProvider.get("blankmenu"));
-			}
-			catch (RuntimeException e) {
-				putValue(Action.SMALL_ICON, ImageProvider.get("blankmenu"));
-				putValue(Action.LARGE_ICON_KEY, ImageProvider.get("blankmenu"));
-			}
-		}
+    private final CommandLine parentPlugin;
+    private final Command parentCommand;
+    public CommandAction(Command parentCommand, CommandLine parentPlugin) {
+        super(tr(parentCommand.name), "blankmenu", tr(parentCommand.name), null, true, parentCommand.name, true);
+        if (!parentCommand.icon.equals("")) {
+            try {
+                putValue(Action.SMALL_ICON, ImageProvider.get(CommandLine.pluginDir, parentCommand.icon));
+                putValue(Action.LARGE_ICON_KEY, ImageProvider.get(CommandLine.pluginDir, parentCommand.icon));
+            }
+            catch (NullPointerException e) {
+                putValue(Action.SMALL_ICON, ImageProvider.get("blankmenu"));
+                putValue(Action.LARGE_ICON_KEY, ImageProvider.get("blankmenu"));
+            }
+            catch (RuntimeException e) {
+                putValue(Action.SMALL_ICON, ImageProvider.get("blankmenu"));
+                putValue(Action.LARGE_ICON_KEY, ImageProvider.get("blankmenu"));
+            }
+        }
 
-		this.parentCommand = parentCommand;
-		this.parentPlugin = parentPlugin;
-	}
+        this.parentCommand = parentCommand;
+        this.parentPlugin = parentPlugin;
+    }
 
-	public void actionPerformed(ActionEvent e) {
-		parentPlugin.startCommand(parentCommand);
-		parentPlugin.history.addItem(parentCommand.name);
-	}
+    @Override
+    public void actionPerformed(ActionEvent e) {
+        parentPlugin.startCommand(parentCommand);
+        parentPlugin.history.addItem(parentCommand.name);
+    }
 }
Index: applications/editors/josm/plugins/CommandLine/src/CommandLine/CommandLine.java
===================================================================
--- applications/editors/josm/plugins/CommandLine/src/CommandLine/CommandLine.java	(revision 29273)
+++ applications/editors/josm/plugins/CommandLine/src/CommandLine/CommandLine.java	(revision 29505)
@@ -66,4 +66,5 @@
 import org.openstreetmap.josm.plugins.PluginInformation;
 import org.openstreetmap.josm.tools.SubclassFilteredCollection;
+import org.openstreetmap.josm.tools.Utils;
 
 public class CommandLine extends Plugin {
@@ -541,6 +542,7 @@
                     }
                     gpxWriter.write(gpxFilter.getGpxData());
-                }
-                osmWriter.close();
+                    Utils.close(gpxWriter);
+                }
+                Utils.close(osmWriter);
                 synchronized (syncObj) {
                     tp.running = false;
@@ -548,5 +550,4 @@
                 }
             }
-
         });
 
Index: applications/editors/josm/plugins/CommandLine/src/CommandLine/DummyAction.java
===================================================================
--- applications/editors/josm/plugins/CommandLine/src/CommandLine/DummyAction.java	(revision 29273)
+++ applications/editors/josm/plugins/CommandLine/src/CommandLine/DummyAction.java	(revision 29505)
@@ -8,24 +8,10 @@
 package CommandLine;
 
-import static org.openstreetmap.josm.tools.I18n.tr;
-
 import java.awt.AWTEvent;
-import java.awt.Cursor;
-import java.awt.EventQueue;
 import java.awt.event.AWTEventListener;
 import java.awt.event.KeyEvent;
-import java.awt.event.MouseEvent;
-import java.awt.Point;
-import java.awt.Toolkit;
-import java.util.Collection;
-import javax.swing.JOptionPane;
 
 import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.actions.mapmode.MapMode;
-import org.openstreetmap.josm.data.coor.LatLon;
-import org.openstreetmap.josm.data.osm.DataSet;
-import org.openstreetmap.josm.data.osm.Way;
-import org.openstreetmap.josm.data.osm.OsmPrimitive;
-import org.openstreetmap.josm.data.osm.PrimitiveId;
 import org.openstreetmap.josm.gui.MapFrame;
 import org.openstreetmap.josm.tools.ImageProvider;
Index: applications/editors/josm/plugins/CommandLine/src/CommandLine/GpxFilter.java
===================================================================
--- applications/editors/josm/plugins/CommandLine/src/CommandLine/GpxFilter.java	(revision 29273)
+++ applications/editors/josm/plugins/CommandLine/src/CommandLine/GpxFilter.java	(revision 29505)
@@ -9,16 +9,13 @@
 
 import java.util.ArrayList;
-import java.util.List;
 import java.util.Collection;
 import java.util.Collections;
 
-import org.openstreetmap.josm.data.coor.LatLon;
-import org.openstreetmap.josm.data.osm.BBox;
 import org.openstreetmap.josm.data.gpx.GpxData;
 import org.openstreetmap.josm.data.gpx.GpxTrack;
 import org.openstreetmap.josm.data.gpx.GpxTrackSegment;
 import org.openstreetmap.josm.data.gpx.ImmutableGpxTrack;
-import org.openstreetmap.josm.data.gpx.ImmutableGpxTrackSegment;
 import org.openstreetmap.josm.data.gpx.WayPoint;
+import org.openstreetmap.josm.data.osm.BBox;
 
 public class GpxFilter {
Index: applications/editors/josm/plugins/CommandLine/src/CommandLine/LengthAction.java
===================================================================
--- applications/editors/josm/plugins/CommandLine/src/CommandLine/LengthAction.java	(revision 29273)
+++ applications/editors/josm/plugins/CommandLine/src/CommandLine/LengthAction.java	(revision 29505)
@@ -18,5 +18,4 @@
 import java.awt.Graphics2D;
 import java.awt.Point;
-import java.awt.RenderingHints;
 import java.awt.Toolkit;
 import java.awt.event.AWTEventListener;
@@ -24,17 +23,11 @@
 import java.awt.event.MouseEvent;
 import java.awt.geom.GeneralPath;
-import java.awt.image.BufferedImage;
-import java.util.Collection;
-import java.util.LinkedList;
 
 import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.actions.mapmode.MapMode;
 import org.openstreetmap.josm.data.Bounds;
-import org.openstreetmap.josm.data.SelectionChangedListener;
-import org.openstreetmap.josm.data.coor.*;
-import org.openstreetmap.josm.data.osm.DataSet;
+import org.openstreetmap.josm.data.coor.LatLon;
 import org.openstreetmap.josm.data.osm.Node;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
-import org.openstreetmap.josm.data.osm.Way;
 import org.openstreetmap.josm.gui.MapFrame;
 import org.openstreetmap.josm.gui.MapView;
@@ -43,5 +36,4 @@
 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
 import org.openstreetmap.josm.tools.ImageProvider;
-import org.openstreetmap.josm.tools.Shortcut;
 
 public class LengthAction extends MapMode implements MapViewPaintable, AWTEventListener {
Index: applications/editors/josm/plugins/CommandLine/src/CommandLine/Loader.java
===================================================================
--- applications/editors/josm/plugins/CommandLine/src/CommandLine/Loader.java	(revision 29273)
+++ applications/editors/josm/plugins/CommandLine/src/CommandLine/Loader.java	(revision 29505)
@@ -8,7 +8,7 @@
 package CommandLine;
 
+import java.io.File;
 import java.util.ArrayList;
-import java.io.File;
-import java.util.List;
+
 import javax.xml.parsers.SAXParser;
 import javax.xml.parsers.SAXParserFactory;
Index: applications/editors/josm/plugins/CommandLine/src/CommandLine/NodeAction.java
===================================================================
--- applications/editors/josm/plugins/CommandLine/src/CommandLine/NodeAction.java	(revision 29273)
+++ applications/editors/josm/plugins/CommandLine/src/CommandLine/NodeAction.java	(revision 29505)
@@ -8,24 +8,17 @@
 package CommandLine;
 
-import static org.openstreetmap.josm.tools.I18n.tr;
-
 import java.awt.AWTEvent;
 import java.awt.Cursor;
 import java.awt.EventQueue;
+import java.awt.Point;
+import java.awt.Toolkit;
 import java.awt.event.AWTEventListener;
 import java.awt.event.KeyEvent;
 import java.awt.event.MouseEvent;
-import java.awt.Point;
-import java.awt.Toolkit;
-import java.util.Collection;
-import javax.swing.JOptionPane;
 
 import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.actions.mapmode.MapMode;
-import org.openstreetmap.josm.data.coor.LatLon;
-import org.openstreetmap.josm.data.osm.DataSet;
 import org.openstreetmap.josm.data.osm.Node;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
-import org.openstreetmap.josm.data.osm.PrimitiveId;
 import org.openstreetmap.josm.gui.MapFrame;
 import org.openstreetmap.josm.tools.ImageProvider;
Index: applications/editors/josm/plugins/CommandLine/src/CommandLine/OsmToCmd.java
===================================================================
--- applications/editors/josm/plugins/CommandLine/src/CommandLine/OsmToCmd.java	(revision 29273)
+++ applications/editors/josm/plugins/CommandLine/src/CommandLine/OsmToCmd.java	(revision 29505)
@@ -1,7 +1,7 @@
 /*
  *	  OsmToCmd.java
- *	  
+ *	
  *	  Copyright 2011 Hind <foxhind@gmail.com>
- *	  
+ *	
  */
 
@@ -15,23 +15,33 @@
 import java.util.LinkedList;
 import java.util.List;
-import java.util.Map;
 
 import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParser;
 import javax.xml.parsers.SAXParserFactory;
-import javax.xml.parsers.SAXParser;
 
 import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.command.AddCommand;
 import org.openstreetmap.josm.command.ChangeCommand;
-import org.openstreetmap.josm.command.ChangeNodesCommand;
 import org.openstreetmap.josm.command.Command;
 import org.openstreetmap.josm.command.DeleteCommand;
 import org.openstreetmap.josm.data.coor.LatLon;
-import org.openstreetmap.josm.data.osm.*;
+import org.openstreetmap.josm.data.osm.DataSet;
+import org.openstreetmap.josm.data.osm.Node;
+import org.openstreetmap.josm.data.osm.NodeData;
+import org.openstreetmap.josm.data.osm.OsmPrimitive;
+import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
+import org.openstreetmap.josm.data.osm.PrimitiveData;
+import org.openstreetmap.josm.data.osm.PrimitiveId;
+import org.openstreetmap.josm.data.osm.Relation;
+import org.openstreetmap.josm.data.osm.RelationData;
+import org.openstreetmap.josm.data.osm.RelationMember;
+import org.openstreetmap.josm.data.osm.SimplePrimitiveId;
+import org.openstreetmap.josm.data.osm.User;
+import org.openstreetmap.josm.data.osm.Way;
+import org.openstreetmap.josm.data.osm.WayData;
 import org.openstreetmap.josm.io.IllegalDataException;
 import org.openstreetmap.josm.io.OsmDataParsingException;
 import org.openstreetmap.josm.io.UTFInputStreamReader;
 import org.openstreetmap.josm.tools.DateUtils;
-
 import org.xml.sax.Attributes;
 import org.xml.sax.InputSource;
@@ -39,359 +49,365 @@
 import org.xml.sax.SAXException;
 import org.xml.sax.SAXParseException;
+import org.xml.sax.ext.LexicalHandler;
 import org.xml.sax.helpers.DefaultHandler;
-import org.xml.sax.ext.LexicalHandler;
 
 final class OsmToCmd {
-	private CommandLine parentPlugin;
-	private final DataSet targetDataSet;
-	private final LinkedList<Command> cmds = new LinkedList<Command>();
-	private HashMap<PrimitiveId, OsmPrimitive> externalIdMap; // Maps external ids to internal primitives
-
-	public OsmToCmd(CommandLine parentPlugin, DataSet targetDataSet) {
-		this.parentPlugin = parentPlugin;
-		this.targetDataSet = targetDataSet;
-		externalIdMap = new HashMap<PrimitiveId, OsmPrimitive>();
-	}
-
-	public void parseStream(InputStream stream) throws IllegalDataException {
-		try {
-			InputSource inputSource = new InputSource(UTFInputStreamReader.create(stream, "UTF-8"));
-			SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
-			Parser handler = new Parser();
-			parser.setProperty("http://xml.org/sax/properties/lexical-handler", handler);
-			parser.parse(inputSource, handler);
-		} catch(ParserConfigurationException e) {
-			throw new IllegalDataException(e.getMessage(), e);
-		} catch (SAXParseException e) {
-			throw new IllegalDataException(tr("Line {0} column {1}: ", e.getLineNumber(), e.getColumnNumber()) + e.getMessage(), e);
-		} catch(SAXException e) {
-			throw new IllegalDataException(e.getMessage(), e);
-		} catch(Exception e) {
-			throw new IllegalDataException(e);
-		}
-	}
-
-	public LinkedList<Command> getCommandList() {
-		return cmds;
-	}
-	
-	private class Parser extends DefaultHandler implements LexicalHandler {
-		private Locator locator;
-		
-		@Override
-		public void setDocumentLocator(Locator locator) {
-			this.locator = locator;
-		}
-
-		protected void throwException(String msg) throws OsmDataParsingException {
-			throw new OsmDataParsingException(msg).rememberLocation(locator);
-		}
-
-		private OsmPrimitive currentPrimitive;
-		private long currentExternalId;
-		private List<Node> currentWayNodes = new ArrayList<Node>();
-		private List<RelationMember> currentRelationMembers = new ArrayList<RelationMember>();
-
-		@Override
-		public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
-			try {
-				if (qName.equals("osm")) {
-					if (atts == null) {
-						throwException(tr("Missing mandatory attribute ''{0}'' of XML element {1}.", "version", "osm"));
-					}
-					String v = atts.getValue("version");
-					if (v == null) {
-						throwException(tr("Missing mandatory attribute ''{0}''.", "version"));
-					}
-					if ( !(v.equals("0.6")) ) {
-						throwException(tr("Unsupported version: {0}", v));
-					}
-
-					// ---- PARSING NODES AND WAYS ----
-
-				} else if (qName.equals("node")) {
-					Node n = new Node();
-					NodeData source = new NodeData();
-					source.setCoor(new LatLon(getDouble(atts, "lat"), getDouble(atts, "lon")));
-					readCommon(atts, source);
-					Node target = (Node)targetDataSet.getPrimitiveById( source.getUniqueId(), source.getType() );
-					
-					if (target == null || !(source.isModified() || source.isDeleted()) )
-						n.load(source);
-					else {
-						n.cloneFrom(target);
-						n.load(source);
-					}
-					
-					currentPrimitive = n;
-					externalIdMap.put(source.getPrimitiveId(), (OsmPrimitive)n);
-					//System.out.println("NODE " + String.valueOf(source.getUniqueId()) + " HAS MAPPED TO INNER " + String.valueOf(n.getUniqueId()) );
-				}
-				else if (qName.equals("way")) {
-					Way w = new Way();
-					WayData source = new WayData();
-					readCommon(atts, source);
-					Way target = (Way)targetDataSet.getPrimitiveById( source.getUniqueId(), source.getType() );
-					
-					if (target == null || !(source.isModified() || source.isDeleted()) )
-						w.load(source);
-					else {
-						w.cloneFrom(target);
-						w.load(source);
-					}
-					
-					currentPrimitive = w;
-					currentWayNodes.clear();
-					externalIdMap.put(source.getPrimitiveId(), (OsmPrimitive)w);
-					//System.out.println("WAY " + String.valueOf(source.getUniqueId()) + " HAS MAPPED TO INNER " + String.valueOf(w.getUniqueId()) );
-				}
-				else if (qName.equals("nd")) {
-					if (atts.getValue("ref") == null)
-						throwException(tr("Missing mandatory attribute ''{0}'' on <nd> of way {1}.", "ref", currentPrimitive.getUniqueId()));
-					long id = getLong(atts, "ref");
-					if (id == 0)
-						throwException(tr("Illegal value of attribute ''ref'' of element <nd>. Got {0}.", id) );
-					//System.out.println("NODE " + String.valueOf(id) + " HAS ADDED TO WAY " + String.valueOf(currentPrimitive.getUniqueId()));
-					Node node = (Node)externalIdMap.get(new SimplePrimitiveId(id, OsmPrimitiveType.NODE));
-					if (node == null || node.isModified()) {
-						node = (Node)targetDataSet.getPrimitiveById( new SimplePrimitiveId(id, OsmPrimitiveType.NODE) );
-						if (node == null)
-							throwException(tr("Missing definition of new object with id {0}.", id));
-					}
-					currentWayNodes.add(node);
-				}
-					// ---- PARSING RELATIONS ----
-
-				else if (qName.equals("relation")) {
-					Relation r = new Relation();
-					RelationData source = new RelationData();
-					readCommon(atts, source);
-					Relation target = (Relation)targetDataSet.getPrimitiveById( source.getUniqueId(), source.getType() );
-					
-					if (target == null || !(source.isModified() || source.isDeleted()) )
-						r.load(source);
-					else {
-						r.cloneFrom(target);
-						r.load(source);
-					}
-					
-					currentPrimitive = r;
-					currentRelationMembers.clear();
-					externalIdMap.put(source.getPrimitiveId(), (OsmPrimitive)r);
-					//System.out.println("RELATION " + String.valueOf(source.getUniqueId()) + " HAS MAPPED TO INNER " + String.valueOf(r.getUniqueId()) );
-				}
-				else if (qName.equals("member")) {
-					if (atts.getValue("ref") == null)
-						throwException(tr("Missing mandatory attribute ''{0}'' on <member> of relation {1}.", "ref", currentPrimitive.getUniqueId()));
-					long id = getLong(atts, "ref");
-					if (id == 0)
-						throwException(tr("Illegal value of attribute ''ref'' of element <nd>. Got {0}.", id) );
-
-					OsmPrimitiveType type = OsmPrimitiveType.NODE;
-					String value = atts.getValue("type");
-					if (value == null) {
-						throwException(tr("Missing attribute ''type'' on member {0} in relation {1}.", Long.toString(id), Long.toString(currentPrimitive.getUniqueId())));
-					}
-					try {
-						type = OsmPrimitiveType.fromApiTypeName(value);
-					}
-					catch(IllegalArgumentException e) {
-						throwException(tr("Illegal value for attribute ''type'' on member {0} in relation {1}. Got {2}.", Long.toString(id), Long.toString(currentPrimitive.getUniqueId()), value));
-					}
-
-					String role = atts.getValue("role");
-
-					//System.out.println("MEMBER " + value.toUpperCase() + " " +String.valueOf(id) + " HAS ADDED TO RELATION " + String.valueOf(currentPrimitive.getUniqueId()));
-					OsmPrimitive member = externalIdMap.get(new SimplePrimitiveId(id, type));
-					if (member == null) {
-						member = targetDataSet.getPrimitiveById(new SimplePrimitiveId(id, type));
-						if (member == null)
-							throwException(tr("Missing definition of new object with id {0}.", id));
-					}
-					RelationMember relationMember = new RelationMember(role, member);
-					currentRelationMembers.add(relationMember);
-				}
-
-					// ---- PARSING TAGS (applicable to all objects) ----
-
-				else if (qName.equals("tag")) {
-					String key = atts.getValue("k");
-					String value = atts.getValue("v");
-					if (key == null || value == null) {
-						throwException(tr("Missing key or value attribute in tag."));
-					}
-					currentPrimitive.put(key.intern(), value.intern());
-				}
-				else {
-					System.out.println(tr("Undefined element ''{0}'' found in input stream. Skipping.", qName));
-				}
-			}
-			catch (Exception e) {
-				throw new SAXParseException(e.getMessage(), locator, e);
-			}
-		}
-
-		@Override
-		public void endElement(String namespaceURI, String localName, String qName) {
-			if (qName.equals("node")) {
-				if (currentPrimitive.isDeleted()) {
-					cmds.add(new DeleteCommand( targetDataSet.getPrimitiveById(currentPrimitive.getPrimitiveId()) ));
-				}
-				else if (currentPrimitive.isModified()) {
-					//System.out.println(String.valueOf(currentPrimitive.getUniqueId()) + " IS MODIFIED BY SCRIPT");
-					cmds.add(new ChangeCommand(Main.map.mapView.getEditLayer(), (Node)targetDataSet.getPrimitiveById(currentPrimitive.getPrimitiveId()), currentPrimitive));
-				}
-				else if (currentPrimitive.isNew()) {
-					cmds.add(new AddCommand(currentPrimitive));
-				}
-			}
-			else if (qName.equals("way")) {
-				((Way)currentPrimitive).setNodes(currentWayNodes);
-				if (currentPrimitive.isDeleted()) {
-					cmds.add(new DeleteCommand( targetDataSet.getPrimitiveById(currentPrimitive.getPrimitiveId()) ));
-				}
-				else if (currentPrimitive.isModified()) {
-					cmds.add(new ChangeCommand(Main.map.mapView.getEditLayer(), (Way)targetDataSet.getPrimitiveById(currentPrimitive.getPrimitiveId()), currentPrimitive));
-				}
-				else if (currentPrimitive.isNew()) {
-					cmds.add(new AddCommand(currentPrimitive));
-				}
-			}
-			else if (qName.equals("relation")) {
-				((Relation)currentPrimitive).setMembers(currentRelationMembers);
-				if (currentPrimitive.isDeleted()) {
-					cmds.add(new DeleteCommand( targetDataSet.getPrimitiveById(currentPrimitive.getPrimitiveId()) ));
-				}
-				else if (currentPrimitive.isModified()) {
-					cmds.add(new ChangeCommand(Main.map.mapView.getEditLayer(), (Relation)targetDataSet.getPrimitiveById(currentPrimitive.getPrimitiveId()), currentPrimitive));
-				}
-				else if (currentPrimitive.isNew()) {
-					cmds.add(new AddCommand(currentPrimitive));
-				}
-			}
-		}
-
-		@Override
-		public void comment(char[] ch, int start, int length) {
-			parentPlugin.printHistory(String.valueOf(ch));
-		}
-		
-		public void startCDATA() {
-		}
-		
-		public void endCDATA() {
-		}
-		
-		public void startEntity(String name) {
-		}
-		
-		public void endEntity(String name) {
-		}
-		
-		public void startDTD(String name, String publicId, String systemId) {
-		}
-		
-		public void endDTD() {
-		}
-		
-		private double getDouble(Attributes atts, String value) {
-			return Double.parseDouble(atts.getValue(value));
-		}
-
-		private long getLong(Attributes atts, String name) throws SAXException {
-			String value = atts.getValue(name);
-			if (value == null) {
-					throwException(tr("Missing required attribute ''{0}''.",name));
-				}
-				try {
-					return Long.parseLong(value);
-				}
-				catch(NumberFormatException e) {
-					throwException(tr("Illegal long value for attribute ''{0}''. Got ''{1}''.",name, value));
-			}
-			return 0; // should not happen
-		}
-
-		private User createUser(String uid, String name) throws SAXException {
-			if (uid == null) {
-				if (name == null)
-					return null;
-				return User.createLocalUser(name);
-			}
-			try {
-				long id = Long.parseLong(uid);
-				return User.createOsmUser(id, name);
-			}
-			catch(NumberFormatException e) {
-				throwException(tr("Illegal value for attribute ''uid''. Got ''{0}''.", uid));
-			}
-			return null;
-		}
-
-		void readCommon(Attributes atts, PrimitiveData current) throws SAXException {
-			current.setId(getLong(atts, "id"));
-			if (current.getUniqueId() == 0) {
-				throwException(tr("Illegal object with ID=0."));
-			}
-
-			String time = atts.getValue("timestamp");
-			if (time != null && time.length() != 0) {
-				current.setTimestamp(DateUtils.fromString(time));
-			}
-
-			String user = atts.getValue("user");
-			String uid = atts.getValue("uid");
-			current.setUser(createUser(uid, user));
-
-			String visible = atts.getValue("visible");
-			if (visible != null) {
-				current.setVisible(Boolean.parseBoolean(visible));
-			}
-
-			String versionString = atts.getValue("version");
-			int version = 0;
-			if (versionString != null) {
-				try {
-					version = Integer.parseInt(versionString);
-				} catch(NumberFormatException e) {
-					throwException(tr("Illegal value for attribute ''version'' on OSM primitive with ID {0}. Got {1}.", Long.toString(current.getUniqueId()), versionString));
-				}
-			}
-			current.setVersion(version);
-
-			String action = atts.getValue("action");
-			if (action == null) {
-				// do nothing
-			} else if (action.equals("delete")) {
-				current.setDeleted(true);
-				current.setModified(current.isVisible());
-			} else if (action.equals("modify")) {
-				current.setModified(true);
-			}
-
-			String v = atts.getValue("changeset");
-			if (v == null) {
-				current.setChangesetId(0);
-			} else {
-				try {
-					current.setChangesetId(Integer.parseInt(v));
-				} catch(NumberFormatException e) {
-					if (current.getUniqueId() <= 0) {
-						System.out.println(tr("Illegal value for attribute ''changeset'' on new object {1}. Got {0}. Resetting to 0.", v, current.getUniqueId()));
-						current.setChangesetId(0);
-					} else {
-						throwException(tr("Illegal value for attribute ''changeset''. Got {0}.", v));
-					}
-				}
-				if (current.getChangesetId() <=0) {
-					if (current.getUniqueId() <= 0) {
-						System.out.println(tr("Illegal value for attribute ''changeset'' on new object {1}. Got {0}. Resetting to 0.", v, current.getUniqueId()));
-						current.setChangesetId(0);
-					} else {
-						throwException(tr("Illegal value for attribute ''changeset''. Got {0}.", v));
-					}
-				}
-			}
-		}
-	}
+    private final CommandLine parentPlugin;
+    private final DataSet targetDataSet;
+    private final LinkedList<Command> cmds = new LinkedList<Command>();
+    private final HashMap<PrimitiveId, OsmPrimitive> externalIdMap; // Maps external ids to internal primitives
+
+    public OsmToCmd(CommandLine parentPlugin, DataSet targetDataSet) {
+        this.parentPlugin = parentPlugin;
+        this.targetDataSet = targetDataSet;
+        externalIdMap = new HashMap<PrimitiveId, OsmPrimitive>();
+    }
+
+    public void parseStream(InputStream stream) throws IllegalDataException {
+        try {
+            InputSource inputSource = new InputSource(UTFInputStreamReader.create(stream, "UTF-8"));
+            SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
+            Parser handler = new Parser();
+            parser.setProperty("http://xml.org/sax/properties/lexical-handler", handler);
+            parser.parse(inputSource, handler);
+        } catch(ParserConfigurationException e) {
+            throw new IllegalDataException(e.getMessage(), e);
+        } catch (SAXParseException e) {
+            throw new IllegalDataException(tr("Line {0} column {1}: ", e.getLineNumber(), e.getColumnNumber()) + e.getMessage(), e);
+        } catch(SAXException e) {
+            throw new IllegalDataException(e.getMessage(), e);
+        } catch(Exception e) {
+            throw new IllegalDataException(e);
+        }
+    }
+
+    public LinkedList<Command> getCommandList() {
+        return cmds;
+    }
+
+    private class Parser extends DefaultHandler implements LexicalHandler {
+        private Locator locator;
+
+        @Override
+        public void setDocumentLocator(Locator locator) {
+            this.locator = locator;
+        }
+
+        protected void throwException(String msg) throws OsmDataParsingException {
+            throw new OsmDataParsingException(msg).rememberLocation(locator);
+        }
+
+        private OsmPrimitive currentPrimitive;
+        //private long currentExternalId;
+        private final List<Node> currentWayNodes = new ArrayList<Node>();
+        private final List<RelationMember> currentRelationMembers = new ArrayList<RelationMember>();
+
+        @Override
+        public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
+            try {
+                if (qName.equals("osm")) {
+                    if (atts == null) {
+                        throwException(tr("Missing mandatory attribute ''{0}'' of XML element {1}.", "version", "osm"));
+                    }
+                    String v = atts.getValue("version");
+                    if (v == null) {
+                        throwException(tr("Missing mandatory attribute ''{0}''.", "version"));
+                    }
+                    if ( !(v.equals("0.6")) ) {
+                        throwException(tr("Unsupported version: {0}", v));
+                    }
+
+                    // ---- PARSING NODES AND WAYS ----
+
+                } else if (qName.equals("node")) {
+                    Node n = new Node();
+                    NodeData source = new NodeData();
+                    source.setCoor(new LatLon(getDouble(atts, "lat"), getDouble(atts, "lon")));
+                    readCommon(atts, source);
+                    Node target = (Node)targetDataSet.getPrimitiveById( source.getUniqueId(), source.getType() );
+
+                    if (target == null || !(source.isModified() || source.isDeleted()) )
+                        n.load(source);
+                    else {
+                        n.cloneFrom(target);
+                        n.load(source);
+                    }
+
+                    currentPrimitive = n;
+                    externalIdMap.put(source.getPrimitiveId(), n);
+                    //System.out.println("NODE " + String.valueOf(source.getUniqueId()) + " HAS MAPPED TO INNER " + String.valueOf(n.getUniqueId()) );
+                }
+                else if (qName.equals("way")) {
+                    Way w = new Way();
+                    WayData source = new WayData();
+                    readCommon(atts, source);
+                    Way target = (Way)targetDataSet.getPrimitiveById( source.getUniqueId(), source.getType() );
+
+                    if (target == null || !(source.isModified() || source.isDeleted()) )
+                        w.load(source);
+                    else {
+                        w.cloneFrom(target);
+                        w.load(source);
+                    }
+
+                    currentPrimitive = w;
+                    currentWayNodes.clear();
+                    externalIdMap.put(source.getPrimitiveId(), w);
+                    //System.out.println("WAY " + String.valueOf(source.getUniqueId()) + " HAS MAPPED TO INNER " + String.valueOf(w.getUniqueId()) );
+                }
+                else if (qName.equals("nd")) {
+                    if (atts.getValue("ref") == null)
+                        throwException(tr("Missing mandatory attribute ''{0}'' on <nd> of way {1}.", "ref", currentPrimitive.getUniqueId()));
+                    long id = getLong(atts, "ref");
+                    if (id == 0)
+                        throwException(tr("Illegal value of attribute ''ref'' of element <nd>. Got {0}.", id) );
+                    //System.out.println("NODE " + String.valueOf(id) + " HAS ADDED TO WAY " + String.valueOf(currentPrimitive.getUniqueId()));
+                    Node node = (Node)externalIdMap.get(new SimplePrimitiveId(id, OsmPrimitiveType.NODE));
+                    if (node == null || node.isModified()) {
+                        node = (Node)targetDataSet.getPrimitiveById( new SimplePrimitiveId(id, OsmPrimitiveType.NODE) );
+                        if (node == null)
+                            throwException(tr("Missing definition of new object with id {0}.", id));
+                    }
+                    currentWayNodes.add(node);
+                }
+                // ---- PARSING RELATIONS ----
+
+                else if (qName.equals("relation")) {
+                    Relation r = new Relation();
+                    RelationData source = new RelationData();
+                    readCommon(atts, source);
+                    Relation target = (Relation)targetDataSet.getPrimitiveById( source.getUniqueId(), source.getType() );
+
+                    if (target == null || !(source.isModified() || source.isDeleted()) )
+                        r.load(source);
+                    else {
+                        r.cloneFrom(target);
+                        r.load(source);
+                    }
+
+                    currentPrimitive = r;
+                    currentRelationMembers.clear();
+                    externalIdMap.put(source.getPrimitiveId(), r);
+                    //System.out.println("RELATION " + String.valueOf(source.getUniqueId()) + " HAS MAPPED TO INNER " + String.valueOf(r.getUniqueId()) );
+                }
+                else if (qName.equals("member")) {
+                    if (atts.getValue("ref") == null)
+                        throwException(tr("Missing mandatory attribute ''{0}'' on <member> of relation {1}.", "ref", currentPrimitive.getUniqueId()));
+                    long id = getLong(atts, "ref");
+                    if (id == 0)
+                        throwException(tr("Illegal value of attribute ''ref'' of element <nd>. Got {0}.", id) );
+
+                    OsmPrimitiveType type = OsmPrimitiveType.NODE;
+                    String value = atts.getValue("type");
+                    if (value == null) {
+                        throwException(tr("Missing attribute ''type'' on member {0} in relation {1}.", Long.toString(id), Long.toString(currentPrimitive.getUniqueId())));
+                    }
+                    try {
+                        type = OsmPrimitiveType.fromApiTypeName(value);
+                    }
+                    catch(IllegalArgumentException e) {
+                        throwException(tr("Illegal value for attribute ''type'' on member {0} in relation {1}. Got {2}.", Long.toString(id), Long.toString(currentPrimitive.getUniqueId()), value));
+                    }
+
+                    String role = atts.getValue("role");
+
+                    //System.out.println("MEMBER " + value.toUpperCase() + " " +String.valueOf(id) + " HAS ADDED TO RELATION " + String.valueOf(currentPrimitive.getUniqueId()));
+                    OsmPrimitive member = externalIdMap.get(new SimplePrimitiveId(id, type));
+                    if (member == null) {
+                        member = targetDataSet.getPrimitiveById(new SimplePrimitiveId(id, type));
+                        if (member == null)
+                            throwException(tr("Missing definition of new object with id {0}.", id));
+                    }
+                    RelationMember relationMember = new RelationMember(role, member);
+                    currentRelationMembers.add(relationMember);
+                }
+
+                // ---- PARSING TAGS (applicable to all objects) ----
+
+                else if (qName.equals("tag")) {
+                    String key = atts.getValue("k");
+                    String value = atts.getValue("v");
+                    if (key == null || value == null) {
+                        throwException(tr("Missing key or value attribute in tag."));
+                    }
+                    currentPrimitive.put(key.intern(), value.intern());
+                }
+                else {
+                    System.out.println(tr("Undefined element ''{0}'' found in input stream. Skipping.", qName));
+                }
+            }
+            catch (Exception e) {
+                throw new SAXParseException(e.getMessage(), locator, e);
+            }
+        }
+
+        @Override
+        public void endElement(String namespaceURI, String localName, String qName) {
+            if (qName.equals("node")) {
+                if (currentPrimitive.isDeleted()) {
+                    cmds.add(new DeleteCommand( targetDataSet.getPrimitiveById(currentPrimitive.getPrimitiveId()) ));
+                }
+                else if (currentPrimitive.isModified()) {
+                    //System.out.println(String.valueOf(currentPrimitive.getUniqueId()) + " IS MODIFIED BY SCRIPT");
+                    cmds.add(new ChangeCommand(Main.map.mapView.getEditLayer(), targetDataSet.getPrimitiveById(currentPrimitive.getPrimitiveId()), currentPrimitive));
+                }
+                else if (currentPrimitive.isNew()) {
+                    cmds.add(new AddCommand(currentPrimitive));
+                }
+            }
+            else if (qName.equals("way")) {
+                ((Way)currentPrimitive).setNodes(currentWayNodes);
+                if (currentPrimitive.isDeleted()) {
+                    cmds.add(new DeleteCommand( targetDataSet.getPrimitiveById(currentPrimitive.getPrimitiveId()) ));
+                }
+                else if (currentPrimitive.isModified()) {
+                    cmds.add(new ChangeCommand(Main.map.mapView.getEditLayer(), targetDataSet.getPrimitiveById(currentPrimitive.getPrimitiveId()), currentPrimitive));
+                }
+                else if (currentPrimitive.isNew()) {
+                    cmds.add(new AddCommand(currentPrimitive));
+                }
+            }
+            else if (qName.equals("relation")) {
+                ((Relation)currentPrimitive).setMembers(currentRelationMembers);
+                if (currentPrimitive.isDeleted()) {
+                    cmds.add(new DeleteCommand( targetDataSet.getPrimitiveById(currentPrimitive.getPrimitiveId()) ));
+                }
+                else if (currentPrimitive.isModified()) {
+                    cmds.add(new ChangeCommand(Main.map.mapView.getEditLayer(), targetDataSet.getPrimitiveById(currentPrimitive.getPrimitiveId()), currentPrimitive));
+                }
+                else if (currentPrimitive.isNew()) {
+                    cmds.add(new AddCommand(currentPrimitive));
+                }
+            }
+        }
+
+        @Override
+        public void comment(char[] ch, int start, int length) {
+            parentPlugin.printHistory(String.valueOf(ch));
+        }
+
+        @Override
+        public void startCDATA() {
+        }
+
+        @Override
+        public void endCDATA() {
+        }
+
+        @Override
+        public void startEntity(String name) {
+        }
+
+        @Override
+        public void endEntity(String name) {
+        }
+
+        @Override
+        public void startDTD(String name, String publicId, String systemId) {
+        }
+
+        @Override
+        public void endDTD() {
+        }
+
+        private double getDouble(Attributes atts, String value) {
+            return Double.parseDouble(atts.getValue(value));
+        }
+
+        private long getLong(Attributes atts, String name) throws SAXException {
+            String value = atts.getValue(name);
+            if (value == null) {
+                throwException(tr("Missing required attribute ''{0}''.",name));
+            }
+            try {
+                return Long.parseLong(value);
+            }
+            catch(NumberFormatException e) {
+                throwException(tr("Illegal long value for attribute ''{0}''. Got ''{1}''.",name, value));
+            }
+            return 0; // should not happen
+        }
+
+        private User createUser(String uid, String name) throws SAXException {
+            if (uid == null) {
+                if (name == null)
+                    return null;
+                return User.createLocalUser(name);
+            }
+            try {
+                long id = Long.parseLong(uid);
+                return User.createOsmUser(id, name);
+            }
+            catch(NumberFormatException e) {
+                throwException(tr("Illegal value for attribute ''uid''. Got ''{0}''.", uid));
+            }
+            return null;
+        }
+
+        void readCommon(Attributes atts, PrimitiveData current) throws SAXException {
+            current.setId(getLong(atts, "id"));
+            if (current.getUniqueId() == 0) {
+                throwException(tr("Illegal object with ID=0."));
+            }
+
+            String time = atts.getValue("timestamp");
+            if (time != null && time.length() != 0) {
+                current.setTimestamp(DateUtils.fromString(time));
+            }
+
+            String user = atts.getValue("user");
+            String uid = atts.getValue("uid");
+            current.setUser(createUser(uid, user));
+
+            String visible = atts.getValue("visible");
+            if (visible != null) {
+                current.setVisible(Boolean.parseBoolean(visible));
+            }
+
+            String versionString = atts.getValue("version");
+            int version = 0;
+            if (versionString != null) {
+                try {
+                    version = Integer.parseInt(versionString);
+                } catch(NumberFormatException e) {
+                    throwException(tr("Illegal value for attribute ''version'' on OSM primitive with ID {0}. Got {1}.", Long.toString(current.getUniqueId()), versionString));
+                }
+            }
+            current.setVersion(version);
+
+            String action = atts.getValue("action");
+            if (action == null) {
+                // do nothing
+            } else if (action.equals("delete")) {
+                current.setDeleted(true);
+                current.setModified(current.isVisible());
+            } else if (action.equals("modify")) {
+                current.setModified(true);
+            }
+
+            String v = atts.getValue("changeset");
+            if (v == null) {
+                current.setChangesetId(0);
+            } else {
+                try {
+                    current.setChangesetId(Integer.parseInt(v));
+                } catch(NumberFormatException e) {
+                    if (current.getUniqueId() <= 0) {
+                        System.out.println(tr("Illegal value for attribute ''changeset'' on new object {1}. Got {0}. Resetting to 0.", v, current.getUniqueId()));
+                        current.setChangesetId(0);
+                    } else {
+                        throwException(tr("Illegal value for attribute ''changeset''. Got {0}.", v));
+                    }
+                }
+                if (current.getChangesetId() <=0) {
+                    if (current.getUniqueId() <= 0) {
+                        System.out.println(tr("Illegal value for attribute ''changeset'' on new object {1}. Got {0}. Resetting to 0.", v, current.getUniqueId()));
+                        current.setChangesetId(0);
+                    } else {
+                        throwException(tr("Illegal value for attribute ''changeset''. Got {0}.", v));
+                    }
+                }
+            }
+        }
+    }
 }
Index: applications/editors/josm/plugins/CommandLine/src/CommandLine/Parameter.java
===================================================================
--- applications/editors/josm/plugins/CommandLine/src/CommandLine/Parameter.java	(revision 29273)
+++ applications/editors/josm/plugins/CommandLine/src/CommandLine/Parameter.java	(revision 29505)
@@ -13,9 +13,5 @@
 import java.util.Collection;
 
-import org.openstreetmap.josm.data.coor.LatLon;
-import org.openstreetmap.josm.data.osm.Node;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
-import org.openstreetmap.josm.data.osm.Way;
-import org.openstreetmap.josm.data.osm.Relation;
 
 public class Parameter {
Index: applications/editors/josm/plugins/CommandLine/src/CommandLine/PointAction.java
===================================================================
--- applications/editors/josm/plugins/CommandLine/src/CommandLine/PointAction.java	(revision 29273)
+++ applications/editors/josm/plugins/CommandLine/src/CommandLine/PointAction.java	(revision 29505)
@@ -13,11 +13,11 @@
 import java.awt.Cursor;
 import java.awt.EventQueue;
+import java.awt.Point;
+import java.awt.Toolkit;
 import java.awt.event.AWTEventListener;
 import java.awt.event.KeyEvent;
 import java.awt.event.MouseEvent;
-import java.awt.Point;
-import java.awt.Toolkit;
 import java.util.ArrayList;
-import java.util.Collection;
+
 import javax.swing.JOptionPane;
 
@@ -25,6 +25,4 @@
 import org.openstreetmap.josm.actions.mapmode.MapMode;
 import org.openstreetmap.josm.data.coor.LatLon;
-import org.openstreetmap.josm.data.SelectionChangedListener;
-import org.openstreetmap.josm.data.osm.DataSet;
 import org.openstreetmap.josm.data.osm.Node;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
Index: applications/editors/josm/plugins/CommandLine/src/CommandLine/RelationAction.java
===================================================================
--- applications/editors/josm/plugins/CommandLine/src/CommandLine/RelationAction.java	(revision 29273)
+++ applications/editors/josm/plugins/CommandLine/src/CommandLine/RelationAction.java	(revision 29505)
@@ -8,24 +8,10 @@
 package CommandLine;
 
-import static org.openstreetmap.josm.tools.I18n.tr;
-
 import java.awt.AWTEvent;
-import java.awt.Cursor;
-import java.awt.EventQueue;
 import java.awt.event.AWTEventListener;
 import java.awt.event.KeyEvent;
-import java.awt.event.MouseEvent;
-import java.awt.Point;
-import java.awt.Toolkit;
-import java.util.Collection;
-import javax.swing.JOptionPane;
 
 import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.actions.mapmode.MapMode;
-import org.openstreetmap.josm.data.coor.LatLon;
-import org.openstreetmap.josm.data.osm.DataSet;
-import org.openstreetmap.josm.data.osm.Node;
-import org.openstreetmap.josm.data.osm.OsmPrimitive;
-import org.openstreetmap.josm.data.osm.PrimitiveId;
 import org.openstreetmap.josm.gui.MapFrame;
 import org.openstreetmap.josm.tools.ImageProvider;
Index: applications/editors/josm/plugins/CommandLine/src/CommandLine/WayAction.java
===================================================================
--- applications/editors/josm/plugins/CommandLine/src/CommandLine/WayAction.java	(revision 29273)
+++ applications/editors/josm/plugins/CommandLine/src/CommandLine/WayAction.java	(revision 29505)
@@ -8,24 +8,17 @@
 package CommandLine;
 
-import static org.openstreetmap.josm.tools.I18n.tr;
-
 import java.awt.AWTEvent;
 import java.awt.Cursor;
 import java.awt.EventQueue;
+import java.awt.Point;
+import java.awt.Toolkit;
 import java.awt.event.AWTEventListener;
 import java.awt.event.KeyEvent;
 import java.awt.event.MouseEvent;
-import java.awt.Point;
-import java.awt.Toolkit;
-import java.util.Collection;
-import javax.swing.JOptionPane;
 
 import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.actions.mapmode.MapMode;
-import org.openstreetmap.josm.data.coor.LatLon;
-import org.openstreetmap.josm.data.osm.DataSet;
+import org.openstreetmap.josm.data.osm.OsmPrimitive;
 import org.openstreetmap.josm.data.osm.Way;
-import org.openstreetmap.josm.data.osm.OsmPrimitive;
-import org.openstreetmap.josm.data.osm.PrimitiveId;
 import org.openstreetmap.josm.gui.MapFrame;
 import org.openstreetmap.josm.tools.ImageProvider;
