org.eclipse.rse.services.clientserver.archiveutils
Class ArchiveHandlerManager
java.lang.Object
org.eclipse.rse.services.clientserver.archiveutils.ArchiveHandlerManager
-
public class ArchiveHandlerManager
- extends
Object
This class manages all the Archive Handlers that correspond to the archive file that the system
would like to deal with. It contains methods for registering handlers with file types, as well as
utilities for getting at the contents of archives that the Manager represents.
This class is designed to be a singleton class, so the best way to use it is
to use statements of the form "ArchiveHandlerManager.getInstance().method".
Methods inherited from class java.lang.
Object
|
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait
|
VIRTUAL_SEPARATOR
public static final
String VIRTUAL_SEPARATOR
- The string that separates the virtual part of an absolute path from the
real part.
-
See Also:
-
Constant Field Values
VIRTUAL_CANONICAL_SEPARATOR
public static final
String VIRTUAL_CANONICAL_SEPARATOR
-
See Also:
-
Constant Field Values
VIRTUAL_FOLDER_SEPARATOR
public static final
String VIRTUAL_FOLDER_SEPARATOR
- Folder separator used in virtual paths inside the archive, i.e. after the
VIRTUAL_SEPARATOR.
-
Since:
- org.eclipse.rse.services 3.0
-
See Also:
-
Constant Field Values
EXTENSION_SEPARATOR
public static final
String EXTENSION_SEPARATOR
- Character used to separate file extension from file name. This is used in
order to recognize file patterns that should be treated as archives.
-
Since:
- org.eclipse.rse.services 3.0
-
See Also:
-
Constant Field Values
_instance
protected static
ArchiveHandlerManager _instance
_handlers
protected
HashMap _handlers
_handlerTypes
protected
HashMap _handlerTypes
ArchiveHandlerManager
public ArchiveHandlerManager()
getInstance
public static
ArchiveHandlerManager getInstance()
-
-
Returns:
- The singleton instance of this class.
getContents
public
VirtualChild[] getContents(
File file,
String virtualpath)
throws
SystemMessageException
- Returns the children of an object in the virtual file system. Throws
SystemMessageException instead of IOException since RSE 3.0.
-
-
Parameters:
-
file
- The archive in whose virtual file system the children reside. -
virtualpath
- The parent virtual object whose children this method
is to return. To get the top level virtual children in the archive,
set virtual path to "" or null.
-
Returns:
- An array of VirtualChild objects representing the children of the
virtual object in
file
referred to by
virtual path
. If no class implementing ISystemArchiveHandler
can be found that corresponds to file, then this method returns null. If
the virtual object has no children, this method also returns null.
-
Throws:
-
SystemMessageException
- in case of an error, e.g. there was a
problem getting the registered handler for the file. This usually
means the archive is corrupted. -
Since:
- 3.0
getFolderContents
public
VirtualChild[] getFolderContents(
File file,
String virtualpath)
throws
SystemMessageException
- Returns the children of an object in the virtual file system that are
folders.
-
-
Parameters:
-
file
- The archive in whose virtual file system the children reside. -
virtualpath
- The parent virtual object whose children this method
is to return. To get the top level virtual children in the archive,
set virtual path to "" or null.
-
Returns:
- An array of VirtualChild objects representing the children of the
virtual object in
file
referred to by
virtualpath
that are themselves folders. If no class
implementing ISystemArchiveHandler can be found that corresponds to
file, then this method returns null. If the virtual object has no
children, this method also returns null.
-
Throws:
-
SystemMessageException
- in case of an error -
Since:
- 3.0
isArchive
public boolean isArchive(
File file)
- Tests whether a file is an known type of archive.
-
-
Parameters:
-
file
- the file to test.
-
Returns:
- true if and only if the file is an archive whose
type is registered with the ArchiveHandlerManager.
isRegisteredArchive
public boolean isRegisteredArchive(
String filename)
- Tests whether a file is an known type of archive, based on the file name.
-
-
Parameters:
-
filename
- the name of the file to test.
-
Returns:
- true if and only if the file is an archive whose
type is registered with the ArchiveHandlerManager.
getRegisteredExtension
protected
String getRegisteredExtension(
File file)
- Check if the file extension is registered archive type.
notice here, the getExtension method does't work for name like fool.tar.gz
-
-
Parameters:
-
file
- the file to check
-
Returns:
- registered extension or null
-
Since:
- org.eclipse.rse.services 3.0
getRegisteredExtension
protected
String getRegisteredExtension(
String fileName)
- check if the file extension is registered archive type.
-
-
Parameters:
-
fileName
- the file name to check
-
Returns:
- registered extension or null
-
Since:
- org.eclipse.rse.services 3.0
getExtension
protected
String getExtension(
File file)
-
Deprecated. Use
getRegisteredExtension(File)
instead
-
-
Parameters:
-
file
- the file whose extension we are computing.
-
Returns:
- the extension of
file
. "Extension" is
defined as any letters in the filename after the last ".".
Returns "" if there is no extension.
getExtension
protected
String getExtension(
String filename)
-
-
Parameters:
-
filename
- the name of the file whose extension we are computing.
-
Returns:
- the extension of
filename
. "Extension" is
defined as any letters in the filename after the last ".".
Returns "" if there is no extension.
* @deprecated Use
getRegisteredExtension(String)
instead
getVirtualObject
public
VirtualChild getVirtualObject(
String fullyQualifiedName)
throws
SystemMessageException
- Given the absolute path to a virtual object, returns that object as a
VirtualChild.
-
-
Parameters:
-
fullyQualifiedName
- The absolute path to the object. Usually
consists of the fullyQualifiedName of the archive, followed by the
virtual path separator (defined in
ArchiveHandlerManager.VIRTUAL_SEPARATOR) followed by the virtual
path to the object within the archive's virtual file system.
-
Throws:
-
SystemMessageException
- in case of an error -
Since:
- 3.0
getRegisteredHandler
public
ISystemArchiveHandler getRegisteredHandler(
File file)
throws
SystemMessageException
- Returns the registered handler for the File
file
. If no
handler exists for that file yet, create it. If the extension of
file
is not registered, then returns null.
-
-
Throws:
-
SystemMessageException
- in case of an error instantiating the
handler -
Since:
- 3.0
getProperConstructor
public
Constructor getProperConstructor(
Class handlerType)
-
setRegisteredHandler
public boolean setRegisteredHandler(
String ext,
Class handlerType)
- Registers an extension and a handler type.
-
-
Parameters:
-
ext
- The extension to register with the ArchiveHandlerManager -
handlerType
- The class of handler to register with ext
.
Note that any class passed in must implement ISystemArchiveHandler.
-
Returns:
- Whether or not the registration was successful.
handlerHasProperConstructor
protected boolean handlerHasProperConstructor(
Class handlerType)
- Returns whether or not handlerType has a constructor that takes only one
parameter, a java.io.File.
-
handlerImplementsISystemArchiveHandler
protected boolean handlerImplementsISystemArchiveHandler(
Class handlerType)
- Returns whether or not handlerType or one of its superclasses implements ISystemArchiveHandler.
-
disposeOfRegisteredHandlerFor
public void disposeOfRegisteredHandlerFor(
File file)
- Removes the handler associated with
file
, freeing the file
to be used by other processes.
-
isVirtual
public static boolean isVirtual(
String path)
- Tests whether the absolute path given by
path
refers to a virtual object.
-
-
Parameters:
-
path
- an absolute path string to check
-
Returns:
- True if and only if the absolute path refers to a virtual object.
cleanUpVirtualPath
public static
String cleanUpVirtualPath(
String fullVirtualName)
- Converts the virtual path given by
fullVirtualName
to the standard virtual form ('/' as separator, no leading or trailing '/'s)
-
-
Parameters:
-
fullVirtualName
- the path to convert
-
Returns:
- the new path in standard form
dispose
public void dispose()
- Disposes of all registered handlers.
-
createEmptyArchive
public void createEmptyArchive(
File newFile)
throws
SystemMessageException
- Create an empty archive
-
-
Throws:
-
SystemMessageException
- in case of an error -
Since:
- 3.0 returns void but throws SystemMessageException
getRegisteredExtensions
public
String[] getRegisteredExtensions()
- Returns the extensions for archive types that have been registered
with the ArchiveHandlerManager.
-
getComment
public
String getComment(
File archive)
throws
SystemMessageException
- Get archive comment.
-
-
Throws:
-
SystemMessageException
- in case of an error -
Since:
- 3.0
getExpandedSize
public long getExpandedSize(
File archive)
throws
SystemMessageException
- Get total expanded size of an archive.
-
-
Throws:
-
SystemMessageException
- in case of an error -
Since:
- 3.0
getClassification
public
String getClassification(
File file,
String virtualPath)
throws
SystemMessageException
- Returns the classification for the entry in a archive with the given
virtual path.
-
-
Parameters:
-
file
- the archive file. -
virtualPath
- the virtual path.
-
Returns:
- the classification for the virtual file.
-
Throws:
-
SystemMessageException
- in case of an error
Copyright (c) IBM Corporation and others 2000, 2008. All Rights Reserved.