Ticket #8686: patch_8686_4.diff

File patch_8686_4.diff, 1.8 KB (added by dommage, 12 years ago)

If entry not found, search relative to the mapcss file location.

  • src/org/openstreetmap/josm/tools/ImageProvider.java

     
    2929import java.util.ArrayList;
    3030import java.util.Arrays;
    3131import java.util.Collection;
     32import java.util.Enumeration;
    3233import java.util.HashMap;
    3334import java.util.Map;
    3435import java.util.concurrent.ExecutorService;
     
    525526        try
    526527        {
    527528            zipFile = new ZipFile(archive);
    528             ZipEntry entry = zipFile.getEntry(full_name);
     529
     530            ZipEntry entry = null;
     531            entry = zipFile.getEntry(full_name);
     532
     533            // Issue #8686: Allow ZIP files whose paths are relative to the ZIP root in JOSM's map styling
     534            if (entry == null) {
     535                // Find the mapcss file to use as the path root
     536                Enumeration<? extends ZipEntry> entries = zipFile.entries();
     537                String mapCssPath = "";
     538                ZipEntry testEntry;
     539                while (entries.hasMoreElements()) {
     540                    testEntry = entries.nextElement();
     541                    if (testEntry.getName().endsWith(".mapcss")) {
     542                        mapCssPath = testEntry.getName();
     543                        break;
     544                    }
     545                }
     546                String zipPathPrefix = mapCssPath.substring(0, mapCssPath.lastIndexOf("/"));
     547                if (zipPathPrefix.length() > 0) {
     548                        zipPathPrefix += "/";
     549                }
     550                entry = zipFile.getEntry(zipPathPrefix + full_name);
     551            }
     552            ///
     553
    529554            if(entry != null)
    530555            {
    531556                int size = (int)entry.getSize();