Attempts to parse the supplied zip file as a theme file. This is largely determined by the file being readable and containing a theme.txt entry. Returns null if the file is unreadable or doesn't contain theme.txt
(String namespace, File file)
| 279 | * Returns null if the file is unreadable or doesn't contain theme.txt |
| 280 | */ |
| 281 | static ZippedTheme load(String namespace, File file) { |
| 282 | ZipFile zip = null; |
| 283 | try { |
| 284 | zip = new ZipFile(file); |
| 285 | ZipEntry themeTxtEntry = zip.getEntry(THEME_FILE_NAME); |
| 286 | if (themeTxtEntry != null) { |
| 287 | String name = file.getName().substring(0, file.getName().length() - 4); |
| 288 | String version = ""; |
| 289 | |
| 290 | ZipEntry themePropsEntry = zip.getEntry("theme.properties"); |
| 291 | if (themePropsEntry != null) { |
| 292 | Properties themeProperties = new Properties(); |
| 293 | themeProperties.load(zip.getInputStream(themePropsEntry)); |
| 294 | |
| 295 | name = themeProperties.getProperty("name", name); |
| 296 | version = themeProperties.getProperty("version", version); |
| 297 | } |
| 298 | |
| 299 | return new ZippedTheme(namespace, file, zip, name, version); |
| 300 | } |
| 301 | } catch (Exception ex) { |
| 302 | System.err.println(format(tr("Error loading theme {0}: {1}"), |
| 303 | file.getAbsolutePath(), ex.getMessage())); |
| 304 | IOUtils.closeQuietly(zip); |
| 305 | } |
| 306 | |
| 307 | return null; |
| 308 | } |
| 309 | |
| 310 | } |
| 311 |
no test coverage detected