- Timestamp:
- 2019-05-11T20:24:40+02:00 (5 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/SessionLoadAction.java
r14397 r15070 22 22 import org.openstreetmap.josm.gui.HelpAwareOptionPane; 23 23 import org.openstreetmap.josm.gui.MainApplication; 24 import org.openstreetmap.josm.gui.Notification; 24 25 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 25 26 import org.openstreetmap.josm.gui.layer.Layer; … … 37 38 import org.openstreetmap.josm.tools.Logging; 38 39 import org.openstreetmap.josm.tools.Utils; 40 import org.openstreetmap.josm.tools.bugreport.ReportedException; 39 41 40 42 /** … … 138 140 if (canceled) 139 141 return; 140 // NoteImporter directly loads notes into current note layer 141 if (!MainApplication.getLayerManager().containsLayer(l)) { 142 MainApplication.getLayerManager().addLayer(l); 143 } 142 addLayer(l); 144 143 } 145 144 if (active != null) { … … 150 149 } 151 150 } 151 } 152 153 /** 154 * Tries to add a new layer. 155 * @param l layer to add 156 * @return {@code true} if layer has been added, {@code false} if it wasn't needed or if an error occurred 157 */ 158 static boolean addLayer(Layer l) { 159 // NoteImporter directly loads notes into current note layer 160 if (!MainApplication.getLayerManager().containsLayer(l)) { 161 try { 162 MainApplication.getLayerManager().addLayer(l); 163 } catch (ReportedException e) { 164 Logging.error(e); 165 new Notification(tr("Unable to add layer ''{0}'': {1}", l.getName(), e.getMessage())) 166 .setIcon(JOptionPane.ERROR_MESSAGE).setDuration(Notification.TIME_LONG).show(); 167 if (MainApplication.getLayerManager().containsLayer(l)) { 168 MainApplication.getLayerManager().removeLayer(l); 169 } 170 return false; 171 } 172 } 173 return true; 152 174 } 153 175 -
trunk/src/org/openstreetmap/josm/io/session/SessionReader.java
r14741 r15070 565 565 throw new IllegalStateException("Importer " + imp + " returned null for " + support); 566 566 } 567 } catch (IllegalDataException | Illegal StateException | IOException ex) {567 } catch (IllegalDataException | IllegalArgumentException | IllegalStateException | IOException ex) { 568 568 exception = ex; 569 569 } … … 704 704 public void loadSession(File sessionFile, boolean zip, ProgressMonitor progressMonitor) throws IllegalDataException, IOException { 705 705 try (InputStream josIS = createInputStream(sessionFile, zip)) { 706 loadSession(josIS, sessionFile.toURI(), zip, progressMonitor != null ? progressMonitor : NullProgressMonitor.INSTANCE);706 loadSession(josIS, sessionFile.toURI(), zip, progressMonitor); 707 707 } 708 708 } … … 737 737 } 738 738 739 private void loadSession(InputStream josIS, URI sessionFileURI, boolean zip, ProgressMonitor progressMonitor) 739 /** 740 * Loads session from the given input stream. 741 * @param josIS session stream to load 742 * @param zip {@code true} if it's a zipped session (.joz) 743 * @param sessionFileURI URI of the underlying session file 744 * @param progressMonitor progress monitor 745 * @throws IllegalDataException if invalid data is detected 746 * @throws IOException if any I/O error occurs 747 * @since xxx 748 */ 749 public void loadSession(InputStream josIS, URI sessionFileURI, boolean zip, ProgressMonitor progressMonitor) 740 750 throws IOException, IllegalDataException { 741 751 … … 744 754 745 755 try { 746 parseJos(XmlUtils.parseSafeDOM(josIS), progressMonitor );756 parseJos(XmlUtils.parseSafeDOM(josIS), progressMonitor != null ? progressMonitor : NullProgressMonitor.INSTANCE); 747 757 } catch (SAXException e) { 748 758 throw new IllegalDataException(e); -
trunk/test/unit/org/openstreetmap/josm/io/session/SessionReaderTest.java
r14138 r15070 6 6 import static org.junit.Assert.assertTrue; 7 7 8 import java.io.ByteArrayInputStream; 8 9 import java.io.File; 9 10 import java.io.IOException; 11 import java.io.InputStream; 12 import java.nio.charset.StandardCharsets; 10 13 import java.util.List; 11 14 … … 154 157 assertEquals(174, layer.getNoteData().getNotes().size()); 155 158 } 159 160 /** 161 * Non-regression test for <a href="https://josm.openstreetmap.de/ticket/17701">Bug #17701</a>. 162 * @throws Exception if an error occurs 163 */ 164 @Test 165 public void testTicket17701() throws Exception { 166 try (InputStream in = new ByteArrayInputStream(("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + 167 "<josm-session version=\"0.1\">\n" + 168 " <layers active=\"1\">\n" + 169 " <layer index=\"1\" name=\"GPS-треки OpenStreetMap\" type=\"imagery\" version=\"0.1\" visible=\"true\">\n" + 170 " <id>osm-gps</id>\n" + 171 " <type>tms</type>\n" + 172 " <url>https://{switch:a,b,c}.gps-tile.openstreetmap.org/lines/{zoom}/{x}/{y}.png</url>\n" + 173 " <attribution-text>© OpenStreetMap contributors</attribution-text>\n" + 174 " <attribution-url>https://www.openstreetmap.org/copyright</attribution-url>\n" + 175 " <max-zoom>20</max-zoom>\n" + 176 " <cookies/>\n" + 177 " <description>Общедоступные GPS-треки, загруженные на OpenStreetMap.</description>\n" + 178 " <valid-georeference>true</valid-georeference>\n" + 179 " <overlay>true</overlay>\n" + 180 " <show-errors>true</show-errors>\n" + 181 " <automatic-downloading>true</automatic-downloading>\n" + 182 " <automatically-change-resolution>true</automatically-change-resolution>\n" + 183 " </layer>\r\n" + 184 " </layers>\n" + 185 "</josm-session>").getBytes(StandardCharsets.UTF_8))) { 186 SessionReader reader = new SessionReader(); 187 reader.loadSession(in, null, false, null); 188 assertTrue(reader.getLayers().isEmpty()); 189 } 190 } 156 191 }
Note:
See TracChangeset
for help on using the changeset viewer.