Package snap.web

Class WebFile

All Implemented Interfaces:
Comparable<WebFile>, PropChange.DoChange

public class WebFile extends PropObject implements Comparable<WebFile>
Represents a file from a WebSite.
  • Field Details

  • Constructor Details

    • WebFile

      public WebFile()
      Constructor.
  • Method Details

    • getSite

      public WebSite getSite()
      Returns the WebSite.
    • getParent

      public WebFile getParent()
      Returns the file parent directory.
    • setParent

      protected void setParent(WebFile aFile)
      Sets the file parent.
    • getPath

      public String getPath()
      Returns the file path.
    • getName

      public String getName()
      Returns the resource name.
    • getSimpleName

      public String getSimpleName()
      Returns the file simple name.
    • getFileType

      public String getFileType()
      Returns the file type (extension without the '.').
    • getDirPath

      public String getDirPath()
      Returns the path as a directory (with trailing separator).
    • getURL

      public WebURL getURL()
      Returns the URL for this file.
    • getUrlAddress

      public String getUrlAddress()
      Returns the URL address string.
    • isDir

      public boolean isDir()
      Returns whether file is a directory.
    • isFile

      public boolean isFile()
      Returns whether file is a plain file.
    • isRoot

      public boolean isRoot()
      Returns whether this file is root directory.
    • isVerified

      public boolean isVerified()
      Returns whether Exists property has been explicitly set/checked.
    • getExists

      public boolean getExists()
      Returns whether file exists in site.
    • setExists

      protected void setExists(boolean aValue)
      Sets whether file is known to exist at site.
    • getLastModTime

      public long getLastModTime()
      Returns the file last modified time.
    • setLastModTime

      protected void setLastModTime(long aValue)
      Sets the file last modified time.
    • saveLastModTime

      public void saveLastModTime(long aValue)
      Sets the file modification time in file and in site internal storage.
    • getLastModDate

      public Date getLastModDate()
      Returns the modified date.
    • getSize

      public long getSize()
      Returns the file size.
    • setSize

      protected void setSize(long aSize)
      Sets the file size.
    • getBytes

      public byte[] getBytes()
      Returns the file bytes.
    • setBytes

      public void setBytes(byte[] theBytes)
      Sets the file bytes.
    • getFileCount

      public int getFileCount()
      Returns the number of files in this directory.
    • getFiles

      public WebFile[] getFiles()
      Returns the directory files list.
    • save

      public WebResponse save()
      Saves the file.
    • delete

      public WebResponse delete()
      Deletes the file.
    • reset

      public void reset()
      Resets the file to unverified state where nothing is known about size, mod-time, saved.
    • resetAndVerify

      public void resetAndVerify()
      Resets a file with check to make sure Exists and LastModTime properties are updated (and prop changes fired) if appropriate.
    • getFileForName

      public WebFile getFileForName(String aName)
      Returns the file with the given name.
    • isModifiedExternally

      public boolean isModifiedExternally()
      Returns whether file has been modified at site (outside this process).
    • containsFile

      public boolean containsFile(WebFile aFile)
      Returns whether given file is contained in this directory.
    • getMimeType

      public String getMimeType()
      Returns the MIME type of the file.
    • setMimeType

      protected void setMimeType(String aMIMEType)
      Sets the MIME type for the file.
    • getProp

      public Object getProp(String aKey)
      Returns a file property for key.
    • setProp

      public void setProp(String aKey, Object aValue)
      Sets a property for a key.
    • isModified

      public boolean isModified()
      Returns whether this file has been modified locally.
    • setModified

      protected void setModified(boolean aValue)
      Sets whether this file has been modified locally.
    • isUpdateSet

      public boolean isUpdateSet()
      Returns whether update is set and has update.
    • getUpdater

      public WebFile.Updater getUpdater()
      Returns the updater.
    • setUpdater

      public void setUpdater(WebFile.Updater anUpdater)
      Sets the Updater.
    • getLinkFile

      public WebFile getLinkFile()
      Returns the link file, if this file really points to another.
    • setLinkFile

      protected void setLinkFile(WebFile aFile)
      Sets the link file, if this file really points to another.
    • getRealFile

      public WebFile getRealFile()
      Returns the real file.
    • isText

      public boolean isText()
      Returns whether response is text (regardless of what the data type is).
    • getText

      public String getText()
      Returns the file bytes as a string.
    • setText

      public void setText(String aString)
      Sets the file bytes as a string.
    • getInputStream

      public InputStream getInputStream()
      Returns an input stream for file.
    • getJavaFile

      public File getJavaFile()
      Returns a standard Java File (if available).
    • getURL

      public WebURL getURL(String aPath)
      Returns a relative URL for the given file path.
    • equals

      public boolean equals(Object anObj)
      Standard equals implementation.
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Standard hashCode implementation.
      Overrides:
      hashCode in class Object
    • compareTo

      public int compareTo(WebFile aFile)
      Standard compareTo implementation.
      Specified by:
      compareTo in interface Comparable<WebFile>
    • toString

      public String toString()
      Returns a string representation of file.
      Overrides:
      toString in class PropObject
    • getFileForSource

      public static WebFile getFileForSource(Object fileSource)
      Returns a WebFile for given source.
    • getFileForPath

      public static WebFile getFileForPath(String filePath)
      Returns a WebFile for given file path.
    • createFileForPath

      public static WebFile createFileForPath(String filePath, boolean isDir)
      Creates a WebFile for given file path.
    • createTempFileForName

      public static WebFile createTempFileForName(String filename, boolean isDir)
      Create a temp WebFile for given file name.
    • getFileForJavaFile

      public static WebFile getFileForJavaFile(File aFile)
      Returns a WebFile for given Java file.