org.pf.file
Class FileLocator

java.lang.Object
  extended by org.pf.file.FileLocator

public class FileLocator
extends Object

This class mainly supports access to files which can be in the normal file directory structure or inside zip archives. The main purpose is to provide methods that transparently treat files the same way whether they are in the normal directory structure or inside archives. The syntax is simply to allow archive names in a path name at any place where a sub-directory name can be.
Examples:

Version:
1.3
Author:
Manfred Duchrow

Method Summary
protected  ZipFile archive()
          Returns the file this locator presents as opened zip file or null in any case of error.
protected  ZipEntry archiveEntry()
           
protected  ZipFile container()
          Returns the zip file which is presented by the parent container or null in any case of error.
protected  File convertFromURLSyntax(File file)
           
static FileLocator create(File file)
          Create a file locator that corresponds to the given file name.
static FileLocator create(String filename)
          Create a file locator that corresponds to the given file name.
protected  FileLocator createFrom(File filePath)
           
protected  boolean doesElementExist(File element)
           
protected  boolean doesElementExistInArchive(String elementName)
           
protected  void doesNotExist(File file)
           
protected  ZipEntry entryFromArchive(String elementName)
           
 Exception exception()
          Returns the last exception that occured while using this locator or null, if no exception was thrown at all.
 boolean exists()
          Returns whether or not the file specified by this locator exists.
protected  File fileRef()
           
protected  FileUtil fileUtil()
           
protected  File fullFilePath(boolean absolute)
           
 String getAbsolutePath()
          Returns the full absolute pathname.
protected  Exception getException()
           
protected  boolean getExists()
           
protected  File getFile()
           
 InputStream getInputStream()
          Returns an opened input stream on the file defined by this locator.
protected  FileLocator getParent()
           
 String getPath()
          Returns the full pathname.
 String getStandardizedAbsolutePath()
          Returns the full absolute pathname in a standardized form.
 String getStandardizedPath()
          Returns the full pathname in a standardized for.
protected  ZipFile getZipFile()
           
protected  FileLocator initFromPath(String[] parts, boolean startsFromRoot)
           
 boolean isDirectory()
          Returns whether or not the name specified by this locator points to a directory.
 boolean isFile()
          Returns whether or not the name specified by this locator points to a file.
protected  boolean isFileElement(File element)
           
protected  boolean isFileInArchive(String elementName)
           
 boolean isInArchive()
          Returns whether or not the file specified by this locator is inside an archive.
 long lastModified()
          Returns the timestamp of when the file was last modified or 0 in any case of error.
 File realFile()
          Returns the file that contains the data the locator points to.
protected  void setException(Exception newValue)
           
protected  void setExists(boolean newValue)
           
protected  void setFile(File newValue)
           
protected  void setParent(FileLocator newValue)
           
protected  void setZipFile(ZipFile newValue)
           
 long size()
          Returns the size of the file or 0 if it does not exist.
protected  StringUtil str()
           
 URL toURL()
          Returns the name of the file as an URL.
protected  void urlPath(StringBuffer buffer)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getParent

protected FileLocator getParent()

setParent

protected void setParent(FileLocator newValue)

getFile

protected File getFile()

setFile

protected void setFile(File newValue)

getZipFile

protected ZipFile getZipFile()

setZipFile

protected void setZipFile(ZipFile newValue)

getExists

protected boolean getExists()

setExists

protected void setExists(boolean newValue)

getException

protected Exception getException()

setException

protected void setException(Exception newValue)

create

public static FileLocator create(File file)
Create a file locator that corresponds to the given file name.


create

public static FileLocator create(String filename)
Create a file locator that corresponds to the given file name.


realFile

public File realFile()
Returns the file that contains the data the locator points to. If the locator points to a normal file in a directory, than this file will be returned. If the locator points to a file inside an archive, the file will be unzipped into the temp directory and this temp file will be returned. If the locator points to a none existing file, this method returns false.


exists

public boolean exists()
Returns whether or not the file specified by this locator exists.


isFile

public boolean isFile()
Returns whether or not the name specified by this locator points to a file.


isDirectory

public boolean isDirectory()
Returns whether or not the name specified by this locator points to a directory.


size

public long size()
Returns the size of the file or 0 if it does not exist.


lastModified

public long lastModified()
Returns the timestamp of when the file was last modified or 0 in any case of error.


getInputStream

public InputStream getInputStream()
                           throws Exception
Returns an opened input stream on the file defined by this locator.

Throws:
Exception

isInArchive

public boolean isInArchive()
Returns whether or not the file specified by this locator is inside an archive.


getPath

public String getPath()
Returns the full pathname.


getAbsolutePath

public String getAbsolutePath()
Returns the full absolute pathname.


getStandardizedPath

public String getStandardizedPath()
Returns the full pathname in a standardized for. That is all ".." and "." elements are removed and forward slashes are used as separators of the remaining elements.


getStandardizedAbsolutePath

public String getStandardizedAbsolutePath()
Returns the full absolute pathname in a standardized form. That is all ".." and "." elements are removed and forward slashes are used as separators of the remaining elements.


exception

public Exception exception()
Returns the last exception that occured while using this locator or null, if no exception was thrown at all.


toURL

public URL toURL()
          throws MalformedURLException
Returns the name of the file as an URL.

Throws:
MalformedURLException

createFrom

protected FileLocator createFrom(File filePath)

initFromPath

protected FileLocator initFromPath(String[] parts,
                                   boolean startsFromRoot)
                            throws Exception
Throws:
Exception

doesElementExist

protected boolean doesElementExist(File element)
                            throws Exception
Throws:
Exception

isFileElement

protected boolean isFileElement(File element)
                         throws Exception
Throws:
Exception

doesElementExistInArchive

protected boolean doesElementExistInArchive(String elementName)
                                     throws Exception
Throws:
Exception

isFileInArchive

protected boolean isFileInArchive(String elementName)
                           throws Exception
Throws:
Exception

entryFromArchive

protected ZipEntry entryFromArchive(String elementName)
                             throws Exception
Throws:
Exception

archiveEntry

protected ZipEntry archiveEntry()
                         throws Exception
Throws:
Exception

doesNotExist

protected void doesNotExist(File file)

fullFilePath

protected File fullFilePath(boolean absolute)

urlPath

protected void urlPath(StringBuffer buffer)

fileRef

protected File fileRef()
                throws Exception
Throws:
Exception

archive

protected ZipFile archive()
                   throws Exception
Returns the file this locator presents as opened zip file or null in any case of error.

Throws:
Exception

container

protected ZipFile container()
                     throws Exception
Returns the zip file which is presented by the parent container or null in any case of error.

Throws:
Exception

convertFromURLSyntax

protected File convertFromURLSyntax(File file)

str

protected StringUtil str()

fileUtil

protected FileUtil fileUtil()