megamek.common.util
Class ZippedItems

java.lang.Object
  extended by megamek.common.util.ZippedItems
All Implemented Interfaces:
Categorized

public class ZippedItems
extends java.lang.Object
implements Categorized

This class represents a collection of item files present within a ZIP or JAR file, categorized according to their directories. This collection will *not* include all files inside of JAR and ZIP files that are located *inside* the file (i.e. it ignores all nested JAR and ZIP files).

Please note, from this point on, the term "ZIP file" will be taken to mean "ZIP or JAR file", because a JAR file is just a ZIP file with a manifest.

Also note, the author plans to eventually handle nested ZIP files, but the effort was deemed to be unnecessary for the needs that led to the initial implementation. Created on January 18, 2004

Version:
1
Author:
James Damour

Constructor Summary
ZippedItems(java.io.File zipFile, java.lang.String categoryName, ItemFileFactory itemFactory)
          Create a categorized collection of all files within a ZIP file.
 
Method Summary
 java.util.Iterator<java.lang.String> getCategoryNames()
          Get the names of all the categories.
 java.lang.Object getItem(java.lang.String categoryName, java.lang.String itemName)
          Get the indicated item from the correct catagory.
 java.util.Iterator<java.lang.String> getItemNames(java.lang.String categoryName)
          Get the names of all the items in one of the categories.
static boolean isZipName(java.lang.String name)
          Identify when a name belongs to a ZIP file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ZippedItems

public ZippedItems(java.io.File zipFile,
                   java.lang.String categoryName,
                   ItemFileFactory itemFactory)
            throws java.lang.IllegalArgumentException,
                   java.util.zip.ZipException,
                   java.io.IOException
Create a categorized collection of all files within a ZIP file. Please note, the name of any directories in the ZIP file will be added to the root category name to create the name of the category names of the directories.

Parameters:
zipFile - - the File object for the ZIP file containing the image files. All files in this ZIP file, will be included in this collection, categorized by directory. This value must not be null and it must be a ZIP file.
categoryName - - the String root category name for this collection. All sub-categories will include this name. This value may be null (it will be replaced).
itemFactory - - the ItemFileFactory that will create ItemFiles for the contents of the directory. This value must not be null.
Throws:
IllegalArgumentException - if zipFile or itemFactory is null.
ZipException - if there's a ZIP error opening zipFile.
IOException - if there's an IO error opening zipFile.
java.lang.IllegalArgumentException
java.util.zip.ZipException
java.io.IOException
Method Detail

isZipName

public static boolean isZipName(java.lang.String name)
Identify when a name belongs to a ZIP file.

Parameters:
name - - the String which may be a ZIP file name. This value must not be null.
Returns:
true if the name is for a ZIP file. false if the name is not for a ZIP file.
Throws:
IllegalArgumentException - if name is null.

getCategoryNames

public java.util.Iterator<java.lang.String> getCategoryNames()
Get the names of all the categories.

Specified by:
getCategoryNames in interface Categorized
Returns:
an Enumeration of String names. This value will not be null, but it may be empty.

getItemNames

public java.util.Iterator<java.lang.String> getItemNames(java.lang.String categoryName)
Get the names of all the items in one of the categories.

Specified by:
getItemNames in interface Categorized
Parameters:
categoryName - - the String name of the category whose item names are required.
Returns:
an Enumeration of String names. This value will not be null, but it may be empty.

getItem

public java.lang.Object getItem(java.lang.String categoryName,
                                java.lang.String itemName)
                         throws java.lang.Exception
Get the indicated item from the correct catagory.

Specified by:
getItem in interface Categorized
Parameters:
categoryName - - the String name of the category whose item names are required.
itemName - - the String name of the indicated item.
Returns:
the Object in the correct category with the given name. This value may be null.
Throws:
Exception - if there's any error getting the item.
java.lang.Exception