Changeset 29505 in osm
- Timestamp:
- 2013-04-16T20:18:30+02:00 (12 years ago)
- Location:
- applications/editors/josm/plugins
- Files:
-
- 4 added
- 1 deleted
- 23 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/CommandLine/build.xml
r29435 r29505 4 4 <property name="commit.message" value="Moar bugfixes"/> 5 5 <!-- enter the *lowest* JOSM version this plugin is currently compatible with --> 6 <property name="plugin.main.version" value="5 737"/>6 <property name="plugin.main.version" value="5874"/> 7 7 8 8 <!-- Configure these properties (replace "..." accordingly). … … 14 14 <property name="plugin.icon" value="images/commandline.png"/> 15 15 <property name="plugin.link" value="http://wiki.openstreetmap.org/wiki/JOSM/Plugins/CommandLine"/> 16 <!--<property name="plugin.early" value="..."/>-->17 <!--<property name="plugin.requires" value="..."/>-->18 <!--<property name="plugin.stage" value="..."/>-->19 16 20 17 <!-- ** include targets that all plugins have in common ** --> -
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 if ( ((Collection)obj).size() > currentParameter.maxInstances && currentParameter.maxInstances != 0)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 putValue(Action.SMALL_ICON, ImageProvider.get(parentPlugin.pluginDir, parentCommand.icon));43 putValue(Action.LARGE_ICON_KEY, ImageProvider.get(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; -
applications/editors/josm/plugins/mirrored_download/README
r27678 r29505 1 2 The JOSM Plugin "Public Transport" is designed to simplify the mapping and editing of public transport routes according to the Oxmoa scheme (see USED NOTIONS). In the first section, we will describe how to create a line from scratch. If there exists already one or more lines running partly or completely parallel, you can take advantage of this (see third section). Also, you can easily convert lines from older mapping formats to the Oxmoa scheme (see fourth section). The last section contains a reference of all items in the plugin.3 4 This manual refers to the prototype version of 2010-01-30. This is not even a beta version, so DON'T FORGET TO SAVE YOUR WORK BEFORE you use this plugin. Later versions may simplify the steps explained below. Feel free to make suggestions for simplications or extra functionality or report bugs to me (mailto:roland.olbricht(at)gmx.de). From the first mature version on, the plugin source code should appear in the OSM SVN and thus the plugin won't any more require any special installation procedures.5 6 7 HOW TO INSTALL8 9 In JOSM: Bearbeiten > Einstellungen, dort Plugins (Stecker) -> Liste laden10 cp public_transport.jar ~/.josm/plugins/11 In JOSM: Bearbeiten > Einstellungen, dort Plugins (Stecker): Public Transport aus der Liste wählen12 JOSM neustarten, Aktualisierung überspringen13 14 15 MAP A BUS LINE FROM SCRATCH16 17 The Oxmoa schema consists of a relation per direction (details see USED NOTIONS) and contains the itinerary (the way a bus actually takes from its starting stop to its terminus) and the stops served by the bus. You need to specify one half of the itinerary, the stops and the back direction can mostly be derived by the software.18 19 Download the area where your bus route takes place. Create a new relation with the standard relation editor and set the tags "type=route", "route=bus" and "ref" set to the line number. Then choose the menue item "Public Transport > Route patterns". Now you can find your route in the list of the main window. Select it and change to the tab "Itinerary". Now select on the map the first way that belongs to your line and press "Add". Mark the second item and press "Add" again. You can select several ways at once and press "Add". If your ways are added in the wrong order or with wrong roles, mark them (click the first entry in the window, then shift-click the last entry in the window) and press "Sort". If there appear one or more lines "[gap]", then your ways don't fit together. If sorting won't solve that, there are gaps in your itinerary and you need to add the missing links or split ways (mark the way, the node where to split at and then use menu "Tools > Split Way") if your bus service only partly uses them. You can delete one or more items from the list by marking them and clicking on "Delete". You can also move one or more items by marking them, clicking on "Mark" (this copies them to the clipboard, like the middle mouse button on X servers), then "Delete", then mark the first item before which you want to insert the items and click "Add".20 21 Now you can add the bus stops in a convienient way: change to the tab "Meta" and press "Suggest Stops". This will compile a list of stops that are near the itinerary. You can choose up to which distance from the itinerary stops should be considered and whether stops only the right hand side, only on the left hand side or on both sides are possible. Now change to the tab "Stops". You can identify stops by marking them and then click "Mark" and/or "Show". Delete spurious stops by marking them and pressing "Delete". Add missing stops by marking them on the map, marking the entry before which you want to insert the stop (unmark all entries if you want to append stops to the end), then press "Add".22 23 24 REUSE A PARTLY PARALLEL LINE25 26 The plugin has an internal clipboard to simplify copying parts of the itinerary or the stops from one bus route to another. Data is put into the clipboard in the X server paradigm. Mark one or more entry from the itinerary list or stops list and click the respective button "Copy". The objects themselves are kept by they state being marked on the map. The plugin additionally saves their order and role. You can paste data from clipboard by using the respective button "Add".27 28 To do this, first choose the source relation at the tab "Overview" and change to the tab "Itinerary". Mark there the entries you want to copy and click "Mark". Then choose at the tab "Overview" your destination relation and mark at the tab "Itinerary" the entry before which you want to paste the entries or unmark all entries if you want to append the data from clipboard.29 30 Stops can be copied in the same way: first choose the source relation at the tab "Overview" and change to the tab "Stops". Mark there the entries you want to copy and click "Mark". Then choose at the tab "Overview" your destination relation and mark at the tab "Stops" the entry before which you want to paste the entries or unmark all entries if you want to append the data from clipboard.31 32 33 REUSE AN OLD RELATION34 35 If you have a bus route in an old format, you can with the help of the plugin spread it into separate relations for both (or more) directions. First, use the standard relation editor of JOSM to duplicate the relation: click on the most lower but one icon on the left toolbar. this opens the relation window on the right. Choose there the relation to duplicate. Click then there on the third button to duplicate the relation, then change "to" and "from" in the opening dialog.36 37 Now open "Public transport > Route patterns ..." and select there the new relation. Change to the tab "Itinerary" and click "Reflect" to reflect the itinerary. If this does not work properly, first click "Sort" to sort the itinerary, then if necessary again "Reflect" to bring them in their proper order.38 39 To edit the bus stops, use one of the functions described above: "Suggest Stops" to have a clean restart from scratch. Or use the buttons in the tab "Stops".40 41 42 USED NOTIONS43 44 Note: I'm not a native English speaker. So if you have suggestions for better wording, please send them to me (mailto:roland.olbricht(at)gmx.de).45 46 ...47 http://wiki.openstreetmap.org/wiki/User:Oxomoa/Public_transport_schema#Network_information_.28lines_and_routes.2948 49 50 REFERENCE MANUAL51 52 * Tab "Overview"53 54 - List "Existing route patterns"55 The large list in the center contains all relations that are recognised as bus routes. They are listed with the value of their tag "ref" and the ID of their relation. A relation is considered as bus service if it has the tags "type=route" and "route=bus".56 57 - Button "Refresh"58 This button refreshes the list "Existing route patterns".59 60 61 * Tab "Tags"62 63 The content of this tag is not yet implemented.64 65 66 * Tab "Itinerary"67 68 - List of member ways69 This list contains all the current members of the relation you are editing that are ways. The intended format of a route relation (see Oxmoa scheme at USED NOTIONS above) expects a continuos list of ways that represents the itinerary the bus takes in reality. Whenever two ways don't fit head on tail, a marker "[gap]" is put between them in an extra line to make breaks clearly visible. This is not a member of the relation but just a marker. You can change the role of a way in the right column. To achieve maximum backward compability, you should choose "forward" or "backward". To properly display relations that don't follow the Oxmoa scheme, all other roles including the empty are also displayed and you can choose despite "forward" and "backward" also an empty role.70 71 - Button "Show"72 Ths button changes the view on the map such that all marked entries are visible.73 74 - Button "Mark"75 Ths button marks all entries that are marked in the list as objects on the map and unmarks all other ways. It also copies a list of the marked entries to the plugin's internal clipboard, such that roles and the order can be reconstructed.76 77 - Button "Add"78 This button adds all ways that are currently marked on the map as entries in the list. The entries are added in arbitrary order before the first marked entry. You can order the just added elements by marking them and clicking "Sort".79 80 - Button "Delete"81 This button deletes all currently marked entries.82 83 - Button "Sort"84 If one or more entries are marked, all marked entries are sorted. I.e. their order and role is changed such that they form a continuous itinerary. If this is not possible, the plugin tries to construct long series of continuous sections. If no entries are marked, the entire list are sorted.85 86 - Button "Reflect"87 If one or more entries are marked, their order is reflected and their roles get flipped. I.e. every entry it put after its successor and its role is changed from "backward" to "forward", from "forward" to "backward" or left unchanged if it is empty.88 89 90 * Tab "Stops"91 92 - List of member nodes93 This list contains all the current members of the relation you are editing that are nodes. The intended format of a route relation (see Oxmoa scheme at USED NOTIONS above) expects a list of nodes that represents the stops in the order the bus takes them in reality. The roles can be changed to "forward" or "backward" but due to Oxmoa scheme, they should remain empty.94 95 - Button "Show"96 Ths button changes the view on the map such that all marked entries are visible.97 98 - Button "Mark"99 Ths button marks all entries that are marked in the list as objects on the map and unmarks all other nodes. It also copies a list of the marked entries to the plugin's internal clipboard, such that roles and the order can be reconstructed.100 101 - Button "Add"102 This button adds all ways that are currently marked on the map as entries in the list. The entries are added in arbitrary order before the first marked entry. You can order the just added elements by marking them and clicking "Sort".103 104 - Button "Delete"105 This button deletes all currently marked entries.106 107 - Button "Sort"108 If one or more entries are marked, all marked entries are sorted. The sorting order depends on the itinerary and the settings for the distance limit, the right hand side and the left hand side in the meta "tab": the sorting algorithm attaches each stop to the nearest segment of the itinerary and then orders them in the order they are passed on the itinerary. Then all stops that can't be attached are added to the end of the list.109 110 - Button "Reflect"111 If one or more entries are marked, their order is reflected. I.e. every entry it put after its successor.112 113 114 * Tab "Meta"115 116 - Checkbox "Stops are possible"117 This checkbox controls the behaviour of the button "Suggest stops" and the button "Sort" in the tab "Stops". If you mark only one of the boxes "Right hand side" or "Left hand side", only stops on the respective side are taken into account. If you mark both boxes, stops on both sides are taken into account.118 119 - Text field "Maximum distance from route"120 This textfield also controls the behaviour of the button "Suggest stops" and the button "Sort" in the tab "Stops". Only stops that have a distance less or equal the limit set here are taken into account.121 122 - Button "Suggest stops"123 This button replaces the current list of stops by a list of all stops that are on the itinerary with regard to the setting of the checkboxes and the text field described above. -
applications/editors/josm/plugins/mirrored_download/build.xml
r29435 r29505 1 1 <?xml version="1.0" encoding="utf-8"?> 2 <!--3 ** This is the build file for the mirrored_download plugin4 **5 ** Maintaining versions6 ** ====================7 ** see README.template8 **9 ** Usage10 ** =====11 ** To build it run12 **13 ** > ant dist14 **15 ** To install the generated plugin locally (in your default plugin directory) run16 **17 ** > ant install18 **19 ** To build against the core in ../../core, create a correct manifest and deploy to20 ** SVN,21 ** set the properties commit.message and plugin.main.version22 ** and run23 ** > ant publish24 **25 **26 -->27 2 <project name="mirrored_download" default="dist" basedir="."> 28 3 … … 30 5 <property name="commit.message" value=""/> 31 6 <!-- enter the *lowest* JOSM version this plugin is currently compatible with --> 32 <property name="plugin.main.version" value="5 097"/>7 <property name="plugin.main.version" value="5874"/> 33 8 34 <!-- 35 ********************************************************** 36 ** include targets that all plugins have in common 37 ********************************************************** 9 <!-- Configure these properties (replace "..." accordingly). 10 See http://josm.openstreetmap.de/wiki/DevelopersGuide/DevelopingPlugins 38 11 --> 12 <property name="plugin.author" value="Roland M. Olbricht"/> 13 <property name="plugin.class" value="mirrored_download.MirroredDownloadPlugin"/> 14 <property name="plugin.description" value="Simplifies download from different read-only APIs."/> 15 <property name="plugin.icon" value="images/download_mirror.png"/> 16 <property name="plugin.link" value="http://wiki.openstreetmap.org/wiki/JOSM/Plugins/mirrored_download"/> 17 18 <!-- ** include targets that all plugins have in common ** --> 39 19 <import file="../build-common.xml"/> 40 20 41 <!--42 **********************************************************43 ** dist - creates the plugin jar44 **********************************************************45 -->46 <target name="dist" depends="compile,revision">47 <echo message="creating ${ant.project.name}.jar ... "/>48 <copy todir="${plugin.build.dir}/resources">49 <fileset dir="resources"/>50 </copy>51 <copy todir="${plugin.build.dir}/images">52 <fileset dir="images"/>53 </copy>54 <copy todir="${plugin.build.dir}/data">55 <fileset dir="data"/>56 </copy>57 <copy todir="${plugin.build.dir}">58 <fileset dir=".">59 <include name="README"/>60 <include name="LICENSE"/>61 </fileset>62 </copy>63 <jar destfile="${plugin.jar}" basedir="${plugin.build.dir}">64 <!--65 ************************************************66 ** configure these properties. Most of them will be copied to the plugins67 ** manifest file. Property values will also show up in the list available68 ** plugins: http://josm.openstreetmap.de/wiki/Plugins.69 **70 ************************************************71 -->72 <manifest>73 <attribute name="Author" value="Roland M. Olbricht"/>74 <attribute name="Plugin-Class" value="mirrored_download.MirroredDownloadPlugin"/>75 <attribute name="Plugin-Date" value="${version.entry.commit.date}"/>76 <attribute name="Plugin-Description" value="Simplifies download from different read-only APIs."/>77 <attribute name="Plugin-Link" value="http://wiki.openstreetmap.org/wiki/JOSM/Plugins/mirrored_download"/>78 <attribute name="Plugin-Icon" value="images/download_mirror.png"/>79 <attribute name="Plugin-Mainversion" value="${plugin.main.version}"/>80 <attribute name="Plugin-Version" value="${version.entry.commit.revision}"/>81 </manifest>82 </jar>83 </target>84 21 </project> -
applications/editors/josm/plugins/mirrored_download/src/mirrored_download/MirroredDownloadAction.java
r29365 r29505 14 14 import java.util.concurrent.Future; 15 15 import java.util.regex.Pattern; 16 16 17 import javax.swing.JComboBox; 17 18 import javax.swing.JLabel; … … 19 20 import javax.swing.text.JTextComponent; 20 21 22 import org.openstreetmap.josm.Main; 21 23 import org.openstreetmap.josm.actions.JosmAction; 22 23 import org.openstreetmap.josm.Main;24 24 import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask; 25 25 import org.openstreetmap.josm.actions.downloadtasks.PostDownloadHandler; -
applications/editors/josm/plugins/mirrored_download/src/mirrored_download/UrlSelectionAction.java
r28290 r29505 8 8 9 9 import org.openstreetmap.josm.actions.JosmAction; 10 11 10 12 11 /** -
applications/editors/josm/plugins/mirrored_download/src/mirrored_download/UrlSelectionDialog.java
r28912 r29505 2 2 package mirrored_download; 3 3 4 import static org.openstreetmap.josm.tools.I18n.marktr;5 4 import static org.openstreetmap.josm.tools.I18n.tr; 6 5 7 import java.awt.Container;8 6 import java.awt.Frame; 9 7 import java.awt.GridBagConstraints; … … 12 10 import java.awt.event.ActionListener; 13 11 import java.io.BufferedReader; 14 import java.io.File; 15 import java.io.FileInputStream; 16 import java.io.FileNotFoundException; 12 import java.io.IOException; 17 13 import java.io.InputStream; 18 14 import java.io.InputStreamReader; 19 import java.io.IOException;20 import java.text.DecimalFormat;21 import java.text.Format;22 15 import java.util.ArrayList; 23 16 import java.util.Collection; 24 import java.util.Collections;25 import java.util.Iterator;26 import java.util.Vector;27 import java.util.zip.GZIPInputStream;28 17 29 import javax.swing.DefaultCellEditor;30 import javax.swing.DefaultListModel;31 import javax.swing.JButton;32 18 import javax.swing.JCheckBox; 33 19 import javax.swing.JComboBox; 34 import javax.swing.JComponent;35 20 import javax.swing.JDialog; 36 import javax.swing.JFileChooser;37 21 import javax.swing.JLabel; 38 import javax.swing.JList;39 22 import javax.swing.JOptionPane; 40 23 import javax.swing.JPanel; 41 import javax.swing.JScrollPane;42 24 import javax.swing.JTabbedPane; 43 import javax.swing.JTable;44 import javax.swing.JTextField;45 import javax.swing.KeyStroke;46 import javax.swing.ListSelectionModel;47 import javax.swing.event.ListSelectionEvent;48 import javax.swing.event.ListSelectionListener;49 import javax.swing.event.TableModelEvent;50 import javax.swing.event.TableModelListener;51 import javax.swing.table.DefaultTableModel;52 25 53 26 import org.openstreetmap.josm.Main; 54 import org.openstreetmap.josm.actions.JosmAction;55 import org.openstreetmap.josm.command.Command;56 import org.openstreetmap.josm.command.ChangeCommand;57 import org.openstreetmap.josm.command.DeleteCommand;58 import org.openstreetmap.josm.data.coor.LatLon;59 import org.openstreetmap.josm.data.gpx.GpxData;60 import org.openstreetmap.josm.data.gpx.GpxTrack;61 import org.openstreetmap.josm.data.gpx.GpxTrackSegment;62 import org.openstreetmap.josm.data.gpx.WayPoint;63 import org.openstreetmap.josm.data.osm.DataSet;64 import org.openstreetmap.josm.data.osm.Node;65 import org.openstreetmap.josm.data.osm.OsmPrimitive;66 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;67 import org.openstreetmap.josm.io.GpxReader;68 27 import org.openstreetmap.josm.io.MirroredInputStream; 69 28 import org.openstreetmap.josm.tools.Utils; 70 71 import org.xml.sax.SAXException;72 29 73 30 public class UrlSelectionDialog … … 160 117 } 161 118 } 119 Utils.close(reader); 162 120 } catch (IOException e) { 163 121 e.printStackTrace(); 122 } finally { 123 Utils.close(in); 164 124 } 165 Utils.close(in);166 125 for (String url : Main.pref.getCollection("plugin.mirrored_download.custom-urls")) { 167 126 urls.add(url); -
applications/editors/josm/plugins/opendata/build.xml
r29435 r29505 1 1 <?xml version="1.0" encoding="utf-8"?> 2 2 <project name="opendata" default="dist" basedir="."> 3 <property name="plugin.main.version" value="5 631"/>3 <property name="plugin.main.version" value="5874"/> 4 4 <property name="plugin.author" value="Don-vip"/> 5 5 <property name="plugin.class" value="org.openstreetmap.josm.plugins.opendata.OdPlugin"/> -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/AbstractMapInfoReader.java
r28191 r29505 60 60 } 61 61 62 protected final BufferedReader getDataReader(File headerFile, String extension, Charset charset) throws FileNotFoundException { 62 @SuppressWarnings("resource") 63 protected final BufferedReader getDataReader(File headerFile, String extension, Charset charset) throws FileNotFoundException { 63 64 File dataFile = getDataFile(headerFile, extension); 64 65 return dataFile.exists() ? new BufferedReader(new InputStreamReader(new FileInputStream(dataFile), charset)) : null; -
applications/editors/josm/plugins/piclayer/build.xml
r29435 r29505 1 1 <?xml version="1.0" encoding="utf-8"?> 2 <!--3 ** This is a template build file for a JOSM plugin.4 **5 ** Maintaining versions6 ** ====================7 ** see README.template8 **9 ** Usage10 ** =====11 ** To build it run12 **13 ** > ant dist14 **15 ** To install the generated plugin locally (in you default plugin directory) run16 **17 ** > ant install18 **19 ** The generated plugin jar is not automatically available in JOSMs plugin configuration20 ** dialog. You have to check it in first.21 **22 -->23 2 <project name="PicLayer" default="dist" basedir="."> 24 3 <property name="commit.message" value="PicLayer - #7127 - added world file loading option"/> 25 <property name="plugin.main.version" value="4980"/> 26 <!-- 27 ************************************************ 28 ** should not be necessary to change the following properties 29 --> 30 <property name="josm" location="../../core/dist/josm-custom.jar"/> 31 <property name="plugin.build.dir" value="build"/> 32 <property name="plugin.src.dir" value="src"/> 33 <!-- this is the directory where the plugin jar is copied to --> 34 <property name="plugin.dist.dir" value="../../dist"/> 35 <property name="ant.build.javac.target" value="1.5"/> 36 <property name="plugin.jar" value="${plugin.dist.dir}/${ant.project.name}.jar"/> 37 <!-- 38 ********************************************************** 39 ** init - initializes the build 40 ********************************************************** 4 <!-- enter the *lowest* JOSM version this plugin is currently compatible with --> 5 <property name="plugin.main.version" value="5874"/> 6 7 <!-- Configure these properties (replace "..." accordingly). 8 See http://josm.openstreetmap.de/wiki/DevelopersGuide/DevelopingPlugins 41 9 --> 42 <target name="init"> 43 <mkdir dir="${plugin.build.dir}"/> 44 </target> 45 <!-- 46 ********************************************************** 47 ** compile - complies the source tree 48 ********************************************************** 49 --> 50 <target name="compile" depends="init"> 51 <echo message="compiling sources for ${ant.project.name} ... "/> 52 <javac srcdir="src" classpath="${josm}" debug="true" destdir="${plugin.build.dir}"> 53 <compilerarg value="-Xlint:deprecation"/> 54 <compilerarg value="-Xlint:unchecked"/> 55 </javac> 56 </target> 57 <!-- 58 ********************************************************** 59 ** dist - creates the plugin jar 60 ********************************************************** 61 --> 62 <target name="dist" depends="compile,revision"> 63 <echo message="creating ${plugin.jar} ... "/> 64 <copy todir="${plugin.build.dir}/resources"> 65 <fileset dir="resources"/> 66 </copy> 67 <copy todir="${plugin.build.dir}/images"> 68 <fileset dir="images"/> 69 </copy> 70 <copy todir="${plugin.build.dir}/data"> 71 <fileset dir="data"/> 72 </copy> 73 <copy todir="${plugin.build.dir}"> 74 <fileset dir="."> 75 <include name="README"/> 76 <include name="LICENSE"/> 77 </fileset> 78 </copy> 79 <jar destfile="${plugin.jar}" basedir="${plugin.build.dir}"> 80 <manifest> 81 <attribute name="Author" value="Tomasz Stelmach"/> 82 <attribute name="Plugin-Class" value="org.openstreetmap.josm.plugins.piclayer.PicLayerPlugin"/> 83 <attribute name="Plugin-Date" value="${version.entry.commit.date}"/> 84 <attribute name="Plugin-Description" value="This plugin allows to display any picture as a background in the editor and align it with the map."/> 85 <attribute name="Plugin-Icon" value="images/layericon.png"/> 86 <attribute name="Plugin-Link" value="http://josm.openstreetmap.de/wiki/Help/Plugin/PicLayer"/> 87 <attribute name="Plugin-Mainversion" value="${plugin.main.version}"/> 88 <attribute name="Plugin-Version" value="${version.entry.commit.revision}"/> 89 </manifest> 90 </jar> 91 </target> 92 <!-- 93 ********************************************************** 94 ** revision - extracts the current revision number for the 95 ** file build.number and stores it in the XML property 96 ** version.* 97 ********************************************************** 98 --> 99 <target name="revision"> 100 <!-- extract the SVN revision information for file build.number --> 101 <exec append="false" output="REVISION" executable="svn" failifexecutionfails="false"> 102 <env key="LANG" value="C"/> 103 <arg value="info"/> 104 <arg value="--xml"/> 105 <arg value="."/> 106 </exec> 107 <xmlproperty file="REVISION" prefix="version" keepRoot="false" collapseAttributes="true"/> 108 <delete file="REVISION"/> 109 </target> 110 <!-- 111 ********************************************************** 112 ** clean - clean up the build environment 113 ********************************************************** 114 --> 115 <target name="clean"> 116 <delete dir="${plugin.build.dir}"/> 117 <delete file="${plugin.jar}"/> 118 </target> 119 <!-- 120 ********************************************************** 121 ** install - install the plugin in your local JOSM installation 122 ********************************************************** 123 --> 124 <target name="install" depends="dist"> 125 <property environment="env"/> 126 <condition property="josm.plugins.dir" value="${env.APPDATA}/JOSM/plugins" else="${user.home}/.josm/plugins"> 127 <and> 128 <os family="windows"/> 129 </and> 130 </condition> 131 <copy file="${plugin.jar}" todir="${josm.plugins.dir}"/> 132 </target> 133 <!-- 134 ************************** Publishing the plugin *********************************** 135 --> 136 <!-- 137 ** extracts the JOSM release for the JOSM version in ../core and saves it in the 138 ** property ${coreversion.info.entry.revision} 139 ** 140 --> 141 <target name="core-info"> 142 <exec append="false" output="core.info.xml" executable="svn" failifexecutionfails="false"> 143 <env key="LANG" value="C"/> 144 <arg value="info"/> 145 <arg value="--xml"/> 146 <arg value="../../core"/> 147 </exec> 148 <xmlproperty file="core.info.xml" prefix="coreversion" keepRoot="true" collapseAttributes="true"/> 149 <echo>Building against core revision ${coreversion.info.entry.revision}.</echo> 150 <echo>Plugin-Mainversion is set to ${plugin.main.version}.</echo> 151 <delete file="core.info.xml"/> 152 </target> 153 <!-- 154 ** commits the source tree for this plugin 155 --> 156 <target name="commit-current"> 157 <echo>Commiting the plugin source with message '${commit.message}' ...</echo> 158 <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false"> 159 <env key="LANG" value="C"/> 160 <arg value="commit"/> 161 <arg value="-m '${commit.message}'"/> 162 <arg value="."/> 163 </exec> 164 </target> 165 <!-- 166 ** updates (svn up) the source tree for this plugin 167 --> 168 <target name="update-current"> 169 <echo>Updating plugin source ...</echo> 170 <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false"> 171 <env key="LANG" value="C"/> 172 <arg value="up"/> 173 <arg value="."/> 174 </exec> 175 <echo>Updating ${plugin.jar} ...</echo> 176 <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false"> 177 <env key="LANG" value="C"/> 178 <arg value="up"/> 179 <arg value="../dist/${plugin.jar}"/> 180 </exec> 181 </target> 182 <!-- 183 ** commits the plugin.jar 184 --> 185 <target name="commit-dist"> 186 <echo> 187 ***** Properties of published ${plugin.jar} ***** 188 Commit message : '${commit.message}' 189 Plugin-Mainversion: ${plugin.main.version} 190 JOSM build version: ${coreversion.info.entry.revision} 191 Plugin-Version : ${version.entry.commit.revision} 192 ***** / Properties of published ${plugin.jar} ***** 10 <property name="plugin.author" value="Tomasz Stelmach"/> 11 <property name="plugin.class" value="org.openstreetmap.josm.plugins.piclayer.PicLayerPlugin"/> 12 <property name="plugin.description" value="This plugin allows to display any picture as a background in the editor and align it with the map."/> 13 <property name="plugin.icon" value="images/layericon.png"/> 14 <property name="plugin.link" value="http://josm.openstreetmap.de/wiki/Help/Plugin/PicLayer"/> 193 15 194 Now commiting ${plugin.jar} ... 195 </echo> 196 <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false"> 197 <env key="LANG" value="C"/> 198 <arg value="-m '${commit.message}'"/> 199 <arg value="commit"/> 200 <arg value="${plugin.jar}"/> 201 </exec> 202 </target> 203 <!-- ** make sure svn is present as a command line tool ** --> 204 <target name="ensure-svn-present"> 205 <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false" failonerror="false" resultproperty="svn.exit.code"> 206 <env key="LANG" value="C"/> 207 <arg value="--version"/> 208 </exec> 209 <fail message="Fatal: command 'svn --version' failed. Please make sure svn is installed on your system."> 210 <!-- return code not set at all? Most likely svn isn't installed --> 211 <condition> 212 <not> 213 <isset property="svn.exit.code"/> 214 </not> 215 </condition> 216 </fail> 217 <fail message="Fatal: command 'svn --version' failed. Please make sure a working copy of svn is installed on your system."> 218 <!-- error code from SVN? Most likely svn is not what we are looking on this system --> 219 <condition> 220 <isfailure code="${svn.exit.code}"/> 221 </condition> 222 </fail> 223 </target> 224 <target name="publish" depends="ensure-svn-present,core-info,commit-current,update-current,clean,dist,commit-dist"> 225 </target> 16 <!-- ** include targets that all plugins have in common ** --> 17 <import file="../build-common.xml"/> 18 226 19 </project>
Note:
See TracChangeset
for help on using the changeset viewer.