Changeset 9965 in josm for trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java
- Timestamp:
- 2016-03-12T00:10:24+01:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java
r9799 r9965 18 18 19 19 import javax.swing.ImageIcon; 20 import javax.swing.JOptionPane; 20 21 import javax.swing.SwingUtilities; 21 22 … … 25 26 import org.openstreetmap.josm.data.osm.Node; 26 27 import org.openstreetmap.josm.data.osm.Tag; 28 import org.openstreetmap.josm.gui.HelpAwareOptionPane; 27 29 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 30 import org.openstreetmap.josm.gui.help.HelpUtil; 28 31 import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource; 29 32 import org.openstreetmap.josm.gui.mappaint.styleelement.MapImage; 30 33 import org.openstreetmap.josm.gui.mappaint.styleelement.NodeElement; 31 34 import org.openstreetmap.josm.gui.mappaint.styleelement.StyleElement; 32 import org.openstreetmap.josm.gui.mappaint.xml.XmlStyleSource;33 35 import org.openstreetmap.josm.gui.preferences.SourceEntry; 34 36 import org.openstreetmap.josm.gui.preferences.map.MapPaintPreference.MapPaintPrefHelper; 35 37 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 36 38 import org.openstreetmap.josm.io.CachedFile; 39 import org.openstreetmap.josm.io.IllegalDataException; 37 40 import org.openstreetmap.josm.tools.ImageProvider; 38 41 import org.openstreetmap.josm.tools.Utils; … … 46 49 */ 47 50 public final class MapPaintStyles { 51 52 /** To remove in November 2016 */ 53 private static final String XML_STYLE_MIME_TYPES = 54 "application/xml, text/xml, text/plain; q=0.8, application/zip, application/octet-stream; q=0.5"; 48 55 49 56 private static ElemStyles styles = new ElemStyles(); … … 280 287 281 288 private static StyleSource fromSourceEntry(SourceEntry entry) { 282 CachedFile cf = null; 283 try { 284 Set<String> mimes = new HashSet<>(); 285 mimes.addAll(Arrays.asList(XmlStyleSource.XML_STYLE_MIME_TYPES.split(", "))); 286 mimes.addAll(Arrays.asList(MapCSSStyleSource.MAPCSS_STYLE_MIME_TYPES.split(", "))); 287 cf = new CachedFile(entry.url).setHttpAccept(Utils.join(", ", mimes)); 289 // TODO: Method to clean up in November 2016: remove XML detection completely 290 Set<String> mimes = new HashSet<>(Arrays.asList(MapCSSStyleSource.MAPCSS_STYLE_MIME_TYPES.split(", "))); 291 mimes.addAll(Arrays.asList(XML_STYLE_MIME_TYPES.split(", "))); 292 try (CachedFile cf = new CachedFile(entry.url).setHttpAccept(Utils.join(", ", mimes))) { 288 293 String zipEntryPath = cf.findZipEntryPath("mapcss", "style"); 289 294 if (zipEntryPath != null) { … … 293 298 } 294 299 zipEntryPath = cf.findZipEntryPath("xml", "style"); 295 if (zipEntryPath != null )296 return new XmlStyleSource(entry);300 if (zipEntryPath != null || Utils.hasExtension(entry.url, "xml")) 301 throw new IllegalDataException("XML style"); 297 302 if (Utils.hasExtension(entry.url, "mapcss")) 298 303 return new MapCSSStyleSource(entry); 299 if (Utils.hasExtension(entry.url, "xml")) 300 return new XmlStyleSource(entry); 301 else { 302 try (InputStreamReader reader = new InputStreamReader(cf.getInputStream(), StandardCharsets.UTF_8)) { 303 WHILE: while (true) { 304 int c = reader.read(); 305 switch (c) { 306 case -1: 307 break WHILE; 308 case ' ': 309 case '\t': 310 case '\n': 311 case '\r': 312 continue; 313 case '<': 314 return new XmlStyleSource(entry); 315 default: 316 return new MapCSSStyleSource(entry); 317 } 304 try (InputStreamReader reader = new InputStreamReader(cf.getInputStream(), StandardCharsets.UTF_8)) { 305 WHILE: while (true) { 306 int c = reader.read(); 307 switch (c) { 308 case -1: 309 break WHILE; 310 case ' ': 311 case '\t': 312 case '\n': 313 case '\r': 314 continue; 315 case '<': 316 throw new IllegalDataException("XML style"); 317 default: 318 return new MapCSSStyleSource(entry); 318 319 } 319 320 } 320 Main.warn("Could not detect style type. Using default (xml).");321 return new XmlStyleSource(entry);322 }321 } 322 Main.warn("Could not detect style type. Using default (mapcss)."); 323 return new MapCSSStyleSource(entry); 323 324 } catch (IOException e) { 324 325 Main.warn(tr("Failed to load Mappaint styles from ''{0}''. Exception was: {1}", entry.url, e.toString())); 325 326 Main.error(e); 326 } finally { 327 if (cf != null) { 328 cf.close(); 329 } 327 } catch (IllegalDataException e) { 328 String msg = tr("JOSM does no longer support mappaint styles written in the old XML format.\nPlease update ''{0}'' to MapCSS", 329 entry.url); 330 Main.error(msg); 331 HelpAwareOptionPane.showOptionDialog(Main.parent, msg, tr("Warning"), JOptionPane.WARNING_MESSAGE, 332 HelpUtil.ht("/Styles/MapCSSImplementation")); 330 333 } 331 334 return null;
Note:
See TracChangeset
for help on using the changeset viewer.