org.pf.file
Class FileLocator

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

public class FileLocator
extends java.lang.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  java.util.zip.ZipFile archive()
          Returns the file this locator presents as opened zip file or null in any case of error.
protected  java.util.zip.ZipEntry archiveEntry()
           
protected  java.util.zip.ZipFile container()
          Returns the zip file which is presented by the parent container or null in any case of error.
protected  java.io.File convertFromURLSyntax(java.io.File file)
           
static FileLocator create(java.io.File file)
          Create a file locator that corresponds to the given file name.
static FileLocator create(java.lang.String filename)
          Create a file locator that corresponds to the given file name.
protected  FileLocator createFrom(java.io.File filePath)
           
protected  boolean doesElementExist(java.io.File element)
           
protected  boolean doesElementExistInArchive(java.lang.String elementName)
           
protected  void doesNotExist(java.io.File file)
           
protected  java.util.zip.ZipEntry entryFromArchive(java.lang.String elementName)
           
 java.lang.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  java.io.File fileRef()
           
protected  FileUtil fileUtil()
           
protected  java.io.File fullFilePath(boolean absolute)
           
 java.lang.String getAbsolutePath()
          Returns the full absolute pathname.
protected  java.lang.Exception getException()
           
protected  boolean getExists()
           
protected  java.io.File getFile()
           
 java.io.InputStream getInputStream()
          Returns an opened input stream on the file defined by this locator.
protected  FileLocator getParent()
           
 java.lang.String getPath()
          Returns the full pathname.
 java.lang.String getStandardizedAbsolutePath()
          Returns the full absolute pathname in a standardized form.
 java.lang.String getStandardizedPath()
          Returns the full pathname in a standardized for.
protected  java.util.zip.ZipFile getZipFile()
           
protected  FileLocator initFromPath(java.lang.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(java.io.File element)
           
protected  boolean isFileInArchive(java.lang.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.
 java.io.File realFile()
          Returns the file that contains the data the locator points to.
protected  void setException(java.lang.Exception newValue)
           
protected  void setExists(boolean newValue)
           
protected  void setFile(java.io.File newValue)
           
protected  void setParent(FileLocator newValue)
           
protected  void setZipFile(java.util.zip.ZipFile newValue)
           
 long size()
          Returns the size of the file or 0 if it does not exist.
protected  StringUtil str()
           
 java.net.URL toURL()
          Returns the name of the file as an URL.
protected  void urlPath(java.lang.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 java.io.File getFile()

setFile

protected void setFile(java.io.File newValue)

getZipFile

protected java.util.zip.ZipFile getZipFile()

setZipFile

protected void setZipFile(java.util.zip.ZipFile newValue)

getExists

protected boolean getExists()

setExists

protected void setExists(boolean newValue)

getException

protected java.lang.Exception getException()

setException

protected void setException(java.lang.Exception newValue)

create

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


create

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


realFile

public java.io.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 java.io.InputStream getInputStream()
                                   throws java.lang.Exception
Returns an opened input stream on the file defined by this locator.

Throws:
java.lang.Exception

isInArchive

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


getPath

public java.lang.String getPath()
Returns the full pathname.


getAbsolutePath

public java.lang.String getAbsolutePath()
Returns the full absolute pathname.


getStandardizedPath

public java.lang.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 java.lang.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 java.lang.Exception exception()
Returns the last exception that occured while using this locator or null, if no exception was thrown at all.


toURL

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

Throws:
java.net.MalformedURLException

createFrom

protected FileLocator createFrom(java.io.File filePath)

initFromPath

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

doesElementExist

protected boolean doesElementExist(java.io.File element)
                            throws java.lang.Exception
Throws:
java.lang.Exception

isFileElement

protected boolean isFileElement(java.io.File element)
                         throws java.lang.Exception
Throws:
java.lang.Exception

doesElementExistInArchive

protected boolean doesElementExistInArchive(java.lang.String elementName)
                                     throws java.lang.Exception
Throws:
java.lang.Exception

isFileInArchive

protected boolean isFileInArchive(java.lang.String elementName)
                           throws java.lang.Exception
Throws:
java.lang.Exception

entryFromArchive

protected java.util.zip.ZipEntry entryFromArchive(java.lang.String elementName)
                                           throws java.lang.Exception
Throws:
java.lang.Exception

archiveEntry

protected java.util.zip.ZipEntry archiveEntry()
                                       throws java.lang.Exception
Throws:
java.lang.Exception

doesNotExist

protected void doesNotExist(java.io.File file)

fullFilePath

protected java.io.File fullFilePath(boolean absolute)

urlPath

protected void urlPath(java.lang.StringBuffer buffer)

fileRef

protected java.io.File fileRef()
                        throws java.lang.Exception
Throws:
java.lang.Exception

archive

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

Throws:
java.lang.Exception

container

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

Throws:
java.lang.Exception

convertFromURLSyntax

protected java.io.File convertFromURLSyntax(java.io.File file)

str

protected StringUtil str()

fileUtil

protected FileUtil fileUtil()