Changeset 6148 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2013-08-14T13:12:50+02:00 (11 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/mappaint/MapImage.java
r6105 r6148 58 58 .setId("mappaint."+source.getPrefName()) 59 59 .setArchive(source.zipIcons) 60 .setInArchiveDir(source.getZipEntryDirName()) 60 61 .setWidth(width) 61 62 .setHeight(height) -
trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java
r6104 r6148 6 6 import java.io.File; 7 7 import java.io.IOException; 8 import java.io.InputStream;9 8 import java.io.InputStreamReader; 10 9 import java.util.ArrayList; … … 97 96 .setId("mappaint."+namespace) 98 97 .setArchive(ref.source.zipIcons) 98 .setInArchiveDir(ref.source.getZipEntryDirName()) 99 99 .setWidth(width) 100 100 .setHeight(height) … … 121 121 .setId("mappaint."+source.getPrefName()) 122 122 .setArchive(source.zipIcons) 123 .setInArchiveDir(source.getZipEntryDirName()) 123 124 .setOptional(true).get(); 124 125 } … … 211 212 try { 212 213 in = new MirroredInputStream(entry.url); 213 InputStream zip = in.getZipEntry("mapcss", "style"); 214 if (zip != null) 214 String zipEntryPath = in.findZipEntryPath("mapcss", "style"); 215 if (zipEntryPath != null) { 216 entry.isZip = true; 217 entry.zipEntryPath = zipEntryPath; 215 218 return new MapCSSStyleSource(entry); 216 zip = in.getZipEntry("xml", "style"); 217 if (zip != null) 219 } 220 zipEntryPath = in.findZipEntryPath("xml", "style"); 221 if (zipEntryPath != null) 218 222 return new XmlStyleSource(entry); 219 223 if (entry.url.toLowerCase().endsWith(".mapcss")) -
trunk/src/org/openstreetmap/josm/gui/mappaint/StyleSource.java
r6090 r6148 40 40 41 41 public StyleSource(SourceEntry entry) { 42 super(entry .url, entry.name, entry.title, entry.active);42 super(entry); 43 43 } 44 44 -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSStyleSource.java
r6070 r6148 6 6 import java.awt.Color; 7 7 import java.io.ByteArrayInputStream; 8 import java.io.File; 8 9 import java.io.IOException; 9 10 import java.io.InputStream; … … 11 12 import java.util.List; 12 13 import java.util.Map.Entry; 14 import java.util.zip.ZipEntry; 15 import java.util.zip.ZipFile; 13 16 14 17 import org.openstreetmap.josm.data.osm.Node; … … 88 91 89 92 MirroredInputStream in = new MirroredInputStream(url); 90 InputStream zip = in.getZipEntry("mapcss", "style"); 91 if (zip != null) { 92 zipIcons = in.getFile(); 93 return zip; 93 if (isZip) { 94 File file = in.getFile(); 95 Utils.close(in); 96 ZipFile zipFile = new ZipFile(file); 97 zipIcons = file; 98 ZipEntry zipEntry = zipFile.getEntry(zipEntryPath); 99 return zipFile.getInputStream(zipEntry); 94 100 } else { 95 101 zipIcons = null; -
trunk/src/org/openstreetmap/josm/gui/mappaint/xml/XmlStyleSource.java
r6143 r6148 94 94 public InputStream getSourceInputStream() throws IOException { 95 95 MirroredInputStream in = new MirroredInputStream(url); 96 InputStream zip = in. getZipEntry("xml", "style");96 InputStream zip = in.findZipEntryInputStream("xml", "style"); 97 97 if (zip != null) { 98 98 zipIcons = in.getFile(); -
trunk/src/org/openstreetmap/josm/gui/preferences/SourceEntry.java
r6070 r6148 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.gui.preferences; 3 4 import static org.openstreetmap.josm.tools.Utils.equal; 3 5 4 6 import java.io.File; 5 7 import java.util.regex.Matcher; 6 8 import java.util.regex.Pattern; 7 8 import static org.openstreetmap.josm.tools.Utils.equal;9 9 10 10 /** … … 19 19 */ 20 20 public String url; 21 22 /** 23 * Indicates, that {@link #url} is a zip file and the resource is 24 * inside the zip file. 25 */ 26 public boolean isZip; 27 28 /** 29 * If {@link #isZip} is true, denotes the path inside the zip file. 30 */ 31 public String zipEntryPath; 21 32 22 33 /** … … 42 53 public boolean active; 43 54 44 public SourceEntry(String url, String name, String title, Boolean active) {55 public SourceEntry(String url, boolean isZip, String zipEntryPath, String name, String title, boolean active) { 45 56 this.url = url; 57 this.isZip = isZip; 58 this.zipEntryPath = equal(zipEntryPath, "") ? null : zipEntryPath; 46 59 this.name = equal(name, "") ? null : name; 47 60 this.title = equal(title, "") ? null : title; … … 49 62 } 50 63 64 public SourceEntry(String url, String name, String title, Boolean active) { 65 this(url, false, null, name, title, active); 66 } 67 51 68 public SourceEntry(SourceEntry e) { 52 69 this.url = e.url; 70 this.isZip = e.isZip; 71 this.zipEntryPath = e.zipEntryPath; 53 72 this.name = e.name; 54 73 this.title = e.title; … … 62 81 final SourceEntry other = (SourceEntry) obj; 63 82 return equal(other.url, url) && 83 other.isZip == isZip && 84 equal(other.zipEntryPath, zipEntryPath) && 64 85 equal(other.name, name) && 65 86 equal(other.title, title) && … … 71 92 int hash = 5; 72 93 hash = 89 * hash + (this.url != null ? this.url.hashCode() : 0); 94 hash = 89 * hash + (this.isZip ? 1 : 0); 95 hash = 89 * hash + (this.zipEntryPath != null ? this.zipEntryPath.hashCode() : 0); 73 96 hash = 89 * hash + (this.name != null ? this.name.hashCode() : 0); 74 97 hash = 89 * hash + (this.title != null ? this.title.hashCode() : 0); … … 133 156 return dir.getPath(); 134 157 } 158 159 /** 160 * Returns the parent directory of the resource inside the zip file. 161 * @return null, if zipEntryPath is null, otherwise the parent directory of 162 * the resource inside the zip file 163 */ 164 public String getZipEntryDirName() { 165 if (zipEntryPath == null) return null; 166 return new File(zipEntryPath).getParent().toString(); 167 } 135 168 } -
trunk/src/org/openstreetmap/josm/gui/preferences/map/MapPaintPreference.java
r6143 r6148 41 41 private static final List<SourceProvider> styleSourceProviders = new ArrayList<SourceProvider>(); 42 42 43 public static finalboolean registerSourceProvider(SourceProvider provider) {43 public static boolean registerSourceProvider(SourceProvider provider) { 44 44 if (provider != null) 45 45 return styleSourceProviders.add(provider); -
trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPresetReader.java
r6145 r6148 159 159 MirroredInputStream s = new MirroredInputStream(source); 160 160 try { 161 InputStream zip = s. getZipEntry("xml","preset");161 InputStream zip = s.findZipEntryInputStream("xml","preset"); 162 162 if(zip != null) { 163 163 zipIcons = s.getFile(); -
trunk/src/org/openstreetmap/josm/io/MirroredInputStream.java
r6090 r6148 22 22 23 23 import org.openstreetmap.josm.Main; 24 import org.openstreetmap.josm.tools.Pair; 24 25 import org.openstreetmap.josm.tools.Utils; 25 26 … … 91 92 92 93 /** 93 * Replies an input stream for a file in a ZIP-file. Replies a file in the top 94 * level directory of the ZIP file which has an extension <code>extension</code>. If more 95 * than one files have this extension, the last file whose name includes <code>namepart</code> 94 * Looks for a certain entry inside a zip file and returns the entry path. 95 * 96 * Replies a file in the top level directory of the ZIP file which has an 97 * extension <code>extension</code>. If more than one files have this 98 * extension, the last file whose name includes <code>namepart</code> 96 99 * is opened. 97 100 * 98 101 * @param extension the extension of the file we're looking for 99 102 * @param namepart the name part 100 * @return an input stream. Null if this mirrored input stream doesn't represent a zip file or if 101 * there was no matching file in the ZIP file 102 */ 103 * @return The zip entry path of the matching file. Null if this mirrored 104 * input stream doesn't represent a zip file or if there was no matching 105 * file in the ZIP file. 106 */ 107 public String findZipEntryPath(String extension, String namepart) { 108 Pair<String, InputStream> ze = findZipEntryImpl(extension, namepart); 109 if (ze == null) return null; 110 return ze.a; 111 } 112 113 /** 114 * Like {@link #findZipEntryPath}, but returns the corresponding InputStream. 115 */ 116 public InputStream findZipEntryInputStream(String extension, String namepart) { 117 Pair<String, InputStream> ze = findZipEntryImpl(extension, namepart); 118 if (ze == null) return null; 119 return ze.b; 120 } 121 122 @Deprecated // use findZipEntryInputStream 103 123 public InputStream getZipEntry(String extension, String namepart) { 124 return findZipEntryInputStream(extension, namepart); 125 } 126 127 private Pair<String, InputStream> findZipEntryImpl(String extension, String namepart) { 104 128 if (file == null) 105 129 return null; 106 InputStreamres = null;130 Pair<String, InputStream> res = null; 107 131 try { 108 132 ZipFile zipFile = new ZipFile(file); … … 120 144 } 121 145 if (resentry != null) { 122 res = zipFile.getInputStream(resentry); 146 InputStream is = zipFile.getInputStream(resentry); 147 res = Pair.create(resentry.getName(), is); 123 148 } else { 124 149 Utils.close(zipFile); -
trunk/src/org/openstreetmap/josm/tools/ImageProvider.java
r6093 r6148 93 93 protected String name; 94 94 protected File archive; 95 protected String inArchiveDir; 95 96 protected int width = -1; 96 97 protected int height = -1; … … 153 154 public ImageProvider setArchive(File archive) { 154 155 this.archive = archive; 156 return this; 157 } 158 159 /** 160 * Specify a base path inside the zip file. 161 * 162 * The subdir and name will be relative to this path. 163 * 164 * (optional) 165 */ 166 public ImageProvider setInArchiveDir(String inArchiveDir) { 167 this.inArchiveDir = inArchiveDir; 155 168 return this; 156 169 } … … 438 451 case ARCHIVE: 439 452 if (archive != null) { 440 ir = getIfAvailableZip(full_name, archive, type);453 ir = getIfAvailableZip(full_name, archive, inArchiveDir, type); 441 454 if (ir != null) { 442 455 cache.put(cache_name, ir); … … 521 534 } 522 535 523 private static ImageResource getIfAvailableZip(String full_name, File archive, ImageType type) {536 private static ImageResource getIfAvailableZip(String full_name, File archive, String inArchiveDir, ImageType type) { 524 537 ZipFile zipFile = null; 525 538 try 526 539 { 527 540 zipFile = new ZipFile(archive); 528 ZipEntry entry = zipFile.getEntry(full_name); 541 String entry_name; 542 if (inArchiveDir != null) { 543 File dir = new File(inArchiveDir); 544 entry_name = new File(dir, full_name).getPath(); 545 } else { 546 entry_name = full_name; 547 } 548 ZipEntry entry = zipFile.getEntry(entry_name); 529 549 if(entry != null) 530 550 { … … 537 557 switch (type) { 538 558 case SVG: 539 URI uri = getSvgUniverse().loadSVG(is, full_name);559 URI uri = getSvgUniverse().loadSVG(is, entry_name); 540 560 SVGDiagram svg = getSvgUniverse().getDiagram(uri); 541 561 return svg == null ? null : new ImageResource(svg);
Note:
See TracChangeset
for help on using the changeset viewer.