Changeset 7704 in josm for trunk/src/org/openstreetmap/josm/io
- Timestamp:
- 2014-11-04T02:33:20+01:00 (10 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/io
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/io/OsmChangesetParser.java
r7700 r7704 8 8 import java.nio.charset.StandardCharsets; 9 9 import java.text.MessageFormat; 10 import java.util.Date; 10 11 import java.util.LinkedList; 11 12 import java.util.List; … … 16 17 import org.openstreetmap.josm.data.coor.LatLon; 17 18 import org.openstreetmap.josm.data.osm.Changeset; 19 import org.openstreetmap.josm.data.osm.ChangesetDiscussionComment; 18 20 import org.openstreetmap.josm.data.osm.User; 19 21 import org.openstreetmap.josm.gui.progress.ProgressMonitor; … … 70 72 private Changeset current = null; 71 73 74 /** The current comment */ 75 private ChangesetDiscussionComment comment = null; 76 77 /** The current comment text */ 78 private StringBuilder text = null; 79 72 80 protected void parseChangesetAttributes(Changeset cs, Attributes atts) throws XmlParsingException { 73 81 // -- id … … 78 86 current.setId(parseNumericAttribute(value, 1)); 79 87 80 // -- user 81 String user = atts.getValue("user"); 82 String uid = atts.getValue("uid"); 83 current.setUser(createUser(uid, user)); 88 // -- user / uid 89 current.setUser(createUser(atts)); 84 90 85 91 // -- created_at … … 155 161 } 156 162 163 private void parseCommentAttributes(Attributes atts) throws XmlParsingException { 164 // -- date 165 String value = atts.getValue("date"); 166 Date date = null; 167 if (value != null) { 168 date = DateUtils.fromString(value); 169 } 170 171 comment = new ChangesetDiscussionComment(date, createUser(atts)); 172 } 173 157 174 private int parseNumericAttribute(String value, int minAllowed) throws XmlParsingException { 158 175 int att = 0; … … 193 210 current.put(key, value); 194 211 break; 212 case "discussion": 213 break; 214 case "comment": 215 parseCommentAttributes(atts); 216 break; 217 case "text": 218 text = new StringBuilder(); 219 break; 195 220 default: 196 221 throwException(tr("Undefined element ''{0}'' found in input stream. Aborting.", qName)); 222 } 223 } 224 225 @Override 226 public void characters(char[] ch, int start, int length) throws SAXException { 227 if (text != null) { 228 text.append(ch, start, length); 197 229 } 198 230 } … … 202 234 if ("changeset".equals(qName)) { 203 235 changesets.add(current); 204 } 205 } 206 207 protected User createUser(String uid, String name) throws XmlParsingException { 236 current = null; 237 } else if ("comment".equals(qName)) { 238 current.addDiscussionComment(comment); 239 comment = null; 240 } else if ("text".equals(qName)) { 241 comment.setText(text.toString()); 242 text = null; 243 } 244 } 245 246 protected User createUser(Attributes atts) throws XmlParsingException { 247 String name = atts.getValue("user"); 248 String uid = atts.getValue("uid"); 208 249 if (uid == null) { 209 250 if (name == null) -
trunk/src/org/openstreetmap/josm/io/OsmServerChangesetReader.java
r7033 r7704 29 29 30 30 /** 31 * constructor 32 * 33 */ 34 public OsmServerChangesetReader(){ 31 * Constructs a new {@code OsmServerChangesetReader}. 32 */ 33 public OsmServerChangesetReader() { 35 34 setDoAuthenticate(false); 36 35 } … … 38 37 /** 39 38 * don't use - not implemented! 40 *41 39 */ 42 40 @Override 43 41 public DataSet parseOsm(ProgressMonitor progressMonitor) throws OsmTransferException { 44 42 return null; 43 } 44 45 protected final InputStream getChangesetInputStream(long id, boolean includeDiscussion, ProgressMonitor monitor) 46 throws OsmTransferException { 47 StringBuilder sb = new StringBuilder(); 48 sb.append("changeset/").append(id); 49 if (includeDiscussion) { 50 sb.append("?include_discussion=true"); 51 } 52 return getInputStream(sb.toString(), monitor.createSubTaskMonitor(1, true)); 45 53 } 46 54 … … 82 90 83 91 /** 84 * Reads the changeset with id <code>id</code> from the server 92 * Reads the changeset with id <code>id</code> from the server. 85 93 * 86 * @param id the changeset id. id > 0 required. 94 * @param id the changeset id. id > 0 required. 95 * @param includeDiscussion determines if discussion comments must be downloaded or not 87 96 * @param monitor the progress monitor. Set to {@link NullProgressMonitor#INSTANCE} if null 88 97 * @return the changeset read 89 98 * @throws OsmTransferException thrown if something goes wrong 90 99 * @throws IllegalArgumentException if id <= 0 91 */ 92 public Changeset readChangeset(long id, ProgressMonitor monitor) throws OsmTransferException { 100 * @since 7704 101 */ 102 public Changeset readChangeset(long id, boolean includeDiscussion, ProgressMonitor monitor) throws OsmTransferException { 93 103 if (id <= 0) 94 104 throw new IllegalArgumentException(MessageFormat.format("Parameter ''{0}'' > 0 expected. Got ''{1}''.", "id", id)); … … 99 109 try { 100 110 monitor.beginTask(tr("Reading changeset {0} ...",id)); 101 StringBuilder sb = new StringBuilder(); 102 sb.append("changeset/").append(id); 103 try (InputStream in = getInputStream(sb.toString(), monitor.createSubTaskMonitor(1, true))) { 111 try (InputStream in = getChangesetInputStream(id, includeDiscussion, monitor)) { 104 112 if (in == null) 105 113 return null; … … 123 131 124 132 /** 125 * Reads the changeset with id <code>id</code> from the server 133 * Reads the changesets with id <code>ids</code> from the server. 126 134 * 127 * @param ids the list of ids. Ignored if null. Only load changesets for ids > 0. 135 * @param ids the list of ids. Ignored if null. Only load changesets for ids > 0. 136 * @param includeDiscussion determines if discussion comments must be downloaded or not 128 137 * @param monitor the progress monitor. Set to {@link NullProgressMonitor#INSTANCE} if null 129 138 * @return the changeset read 130 139 * @throws OsmTransferException thrown if something goes wrong 131 140 * @throws IllegalArgumentException if id <= 0 132 */ 133 public List<Changeset> readChangesets(Collection<Integer> ids, ProgressMonitor monitor) throws OsmTransferException { 141 * @since 7704 142 */ 143 public List<Changeset> readChangesets(Collection<Integer> ids, boolean includeDiscussion, ProgressMonitor monitor) throws OsmTransferException { 134 144 if (ids == null) 135 145 return Collections.emptyList(); … … 147 157 } 148 158 i++; 149 StringBuilder sb = new StringBuilder(); 150 sb.append("changeset/").append(id); 151 try (InputStream in = getInputStream(sb.toString(), monitor.createSubTaskMonitor(1, true))) { 159 try (InputStream in = getChangesetInputStream(id, includeDiscussion, monitor)) { 152 160 if (in == null) 153 161 return null;
Note:
See TracChangeset
for help on using the changeset viewer.