Changeset 2832 in josm for trunk/src/org
- Timestamp:
- 2010-01-12T20:02:54+01:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java
r2827 r2832 1 1 package org.openstreetmap.josm.gui.mappaint; 2 2 3 import static org.openstreetmap.josm.tools.I18n.tr; 4 5 import java.io.IOException; 3 6 import java.util.Collection; 4 7 import java.util.Collections; … … 12 15 import org.openstreetmap.josm.tools.ImageProvider; 13 16 import org.xml.sax.InputSource; 17 import org.xml.sax.SAXException; 14 18 import org.xml.sax.XMLReader; 15 19 import org.xml.sax.helpers.XMLReaderFactory; … … 31 35 { 32 36 String[] a; 33 if(fileset.indexOf("=") >= 0) 37 if(fileset.indexOf("=") >= 0) { 34 38 a = fileset.split("=", 2); 35 else39 } else { 36 40 a = new String[] {"", fileset}; 41 } 37 42 38 43 /* non-prefixed path is generic path, always take it */ 39 if(a[0].length() == 0 || styleName.equals(a[0])) 44 if(a[0].length() == 0 || styleName.equals(a[0])) { 40 45 dirs.add(a[1]); 46 } 41 47 } 42 48 ImageIcon i = ImageProvider.getIfAvailable(dirs, "mappaint."+styleName, null, name); … … 61 67 62 68 Collection<String> files = Main.pref.getCollection("mappaint.style.sources", Collections.<String>emptySet()); 63 if(Main.pref.getBoolean("mappaint.style.enable-defaults", true)) 64 { 69 if (Main.pref.getBoolean("mappaint.style.enable-defaults", true)) { 65 70 LinkedList<String> f = new LinkedList<String>(); 66 71 f.add("resource://data/elemstyles.xml"); … … 69 74 } 70 75 71 for(String fileset : files) 72 { 76 for (String file : files) { 73 77 String[] a = null; 74 try 75 { 76 if(fileset.indexOf("=") >= 0)77 a = fileset.split("=", 2);78 else79 a = new String[] {null, fileset};78 try { 79 if (file.indexOf("=") >= 0) { 80 a = file.split("=", 2); 81 } else { 82 a = new String[] { null, file }; 83 } 80 84 XMLReader xmlReader = XMLReaderFactory.createXMLReader(); 81 85 ElemStyleHandler handler = new ElemStyleHandler(a[0]); 82 86 xmlReader.setContentHandler(handler); 83 87 xmlReader.setErrorHandler(handler); 84 xmlReader.parse(new InputSource(new MirroredInputStream(a[1]))); 85 } 86 catch (Exception e) 87 { 88 System.out.println("Mappaint-Style \"" + a[0] + "\" file \"" + a[1] + "\""); 89 System.out.println("Mappaint-Style problems: " + e); 88 MirroredInputStream in = new MirroredInputStream(a[1]); 89 xmlReader.parse(new InputSource(in)); 90 } catch(IOException e) { 91 System.err.println(tr("Warning: failed to load Mappaint-Styles from ''{0}''. Exception was: {1}", a[1], e.toString())); 92 e.printStackTrace(); 93 } catch(SAXException e) { 94 System.err.println(tr("Warning: failed to parse Mappaint-Styles from ''{0}''. Exception was: {1}", a[1], e.toString())); 90 95 e.printStackTrace(); 91 96 } … … 93 98 iconDirs = null; 94 99 } 95 96 100 } -
trunk/src/org/openstreetmap/josm/io/MirroredInputStream.java
r2017 r2832 1 1 // License: GPL. Copyright 2007 by Immanuel Scholz and others 2 2 package org.openstreetmap.josm.io; 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 3 5 4 6 import java.io.BufferedInputStream; … … 41 43 if (url.getProtocol().equals("file")) { 42 44 file = new File(name.substring("file:/".length())); 43 if (!file.exists()) 45 if (!file.exists()) { 44 46 file = new File(name.substring("file://".length())); 47 } 45 48 } else { 46 49 file = checkLocal(url, destDir, maxTime); … … 49 52 if(name.startsWith("resource://")) { 50 53 fs = getClass().getResourceAsStream( 51 name.substring("resource:/".length())); 54 name.substring("resource:/".length())); 55 if (fs == null) 56 throw new IOException(tr("Failed to open input stream for resource ''{0}''", name)); 52 57 return; 53 58 } … … 61 66 public File getFile() 62 67 { 63 return file; 68 return file; 64 69 } 65 70 66 71 static public void cleanup(String name) 67 72 { 68 cleanup(name, null); 73 cleanup(name, null); 69 74 } 70 75 static public void cleanup(String name, String destDir) … … 80 85 String[] lp = localPath.split(";"); 81 86 File lfile = new File(lp[1]); 82 if(lfile.exists()) 87 if(lfile.exists()) { 83 88 lfile.delete(); 89 } 84 90 } 85 91 Main.pref.put("mirror." + url, null); … … 94 100 String[] lp = localPath.split(";"); 95 101 file = new File(lp[1]); 96 if (maxTime <= 0) 102 if (maxTime <= 0) { 97 103 maxTime = Main.pref.getInteger("mirror.maxtime", 7*24*60*60); 104 } 98 105 if (System.currentTimeMillis() - Long.parseLong(lp[0]) < maxTime*1000) { 99 if(file.exists()) {106 if(file.exists()) 100 107 return file; 101 }102 108 } 103 109 } 104 if(destDir == null) 110 if(destDir == null) { 105 111 destDir = Main.pref.getPreferencesDir(); 112 } 106 113 107 114 File destDirFile = new File(destDir); 108 if (!destDirFile.exists()) 115 if (!destDirFile.exists()) { 109 116 destDirFile.mkdirs(); 117 } 110 118 111 119 String a = url.toString().replaceAll("[^A-Za-z0-9_.-]", "_"); … … 121 129 byte[] buffer = new byte[4096]; 122 130 int length; 123 while ((length = bis.read(buffer)) > -1) 131 while ((length = bis.read(buffer)) > -1) { 124 132 bos.write(buffer, 0, length); 133 } 125 134 } catch(IOException ioe) { 126 135 if (file != null) … … 149 158 return file; 150 159 } 160 @Override 151 161 public int available() throws IOException 152 162 { return fs.available(); } 163 @Override 153 164 public void close() throws IOException 154 165 { fs.close(); } 166 @Override 155 167 public int read() throws IOException 156 168 { return fs.read(); } 169 @Override 157 170 public int read(byte[] b) throws IOException 158 171 { return fs.read(b); } 172 @Override 159 173 public int read(byte[] b, int off, int len) throws IOException 160 174 { return fs.read(b,off, len); } 175 @Override 161 176 public long skip(long n) throws IOException 162 177 { return fs.skip(n); }
Note:
See TracChangeset
for help on using the changeset viewer.