Package com.inductiveautomation.snap.web
Class WebFile
- java.lang.Object
-
- com.inductiveautomation.rm.base.RMListenerList
-
- com.inductiveautomation.rm.base.RMObject
-
- com.inductiveautomation.snap.web.WebFile
-
- All Implemented Interfaces:
RMJSONArchiver.GetKeys
,RMPropertyChanger
,java.lang.Cloneable
,java.lang.Comparable<WebFile>
- Direct Known Subclasses:
ZipFileSite.ZipDataFile
public class WebFile extends RMObject implements java.lang.Comparable<WebFile>, RMJSONArchiver.GetKeys
Represents a file from a WebSite.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
WebFile.Updater
An interface for classes that want to post modifications to files.
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
Bytes_Prop
static java.lang.String
Exists_Prop
static java.lang.String
File_Prop
static java.lang.String
Files_Prop
static java.lang.String
ModifiedTime_Prop
static java.lang.String
Path_Prop
static java.lang.String
Size_Prop
static java.lang.String
Updater_Prop
-
Constructor Summary
Constructors Constructor Description WebFile()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addFile(WebFile aFile)
Adds a file.protected void
addFile(WebFile aFile, int anIndex)
Adds a file at given index.WebFile
clone()
Standard clone implementation.int
compareTo(WebFile aFile)
Standard compareTo implementation.WebFile
createFile(java.lang.String aName)
Returns the file with the given name.protected WebURL
createURL()
Creates a URL for this file.protected WebURL
createURL(java.lang.String aURL)
Creates a URL for string.void
delete()
Deletes the file.boolean
equals(java.lang.Object anObj)
Standard equals implementation.byte[]
getBytes()
Returns the file bytes.protected Response
getContentResponse()
Returns files for path.DataType
getDataType()
Returns the data type of the file.java.lang.String
getDirPath()
Returns the path as a directory (with trailing separator).boolean
getExists()
Returns whether file exists in data source (has been saved and, if so, not deleted).boolean
getExists(boolean doConfirm)
Returns whether file exists in data source (with option to confirm if file was created instead of fetched).WebFile
getFile(int anIndex)
Returns the individual file at given index.WebFile
getFile(java.lang.String aName)
Returns the file with the given name.int
getFileCount()
Returns the number of files in this directory.int
getFileIndex(WebFile aFile)
Returns the index of a file.java.util.List<java.lang.String>
getFileNames()
Returns the file keys.<T extends WebFile>
java.util.List<T>getFiles()
Returns the directory files list.java.util.List<WebFile>
getFiles(java.lang.String aRegex)
Returns the list of files that match given regex.java.io.InputStream
getInputStream()
Returns an input stream for file.int
getInsertIndex(WebFile aFile)
Returns the insert index to insert a file in this directory.java.util.List<java.lang.String>
getJSONKeys()
RMJSONArchiver.GetKeys implementation.java.util.Date
getModifiedDate()
Returns the modified date.long
getModifiedTime()
Returns the file modification time.java.lang.String
getName()
Returns the resource name.WebFile
getParent()
Returns the file parent directory.java.lang.String
getPath()
Returns the file path.java.lang.String
getPresentableName()
Returns the Filename without extension, and with underscores replaced with spacesjava.lang.Object
getProp(java.lang.String aKey)
Returns a file property for key.java.lang.String
getSimpleName()
Returns the file simple name.WebSite
getSite()
Returns the WebSite.long
getSize()
Returns the file size.java.io.File
getStandardFile()
Returns a standard java.io.File, if available.java.lang.String
getText()
Returns the file bytes as a string.java.lang.String
getType()
Returns the file type (extension without the '.').WebFile.Updater
getUpdater()
Returns the updater.WebURL
getURL()
Returns the URL for this file.WebURL
getURL(java.lang.String aPath)
Returns a relative URL for the given file path.java.lang.String
getURLString()
Returns the URL string for this file.int
hashCode()
Standard hashCode implementation.protected void
initFiles()
Initialize files.protected void
initFiles(java.util.List<? extends WebFile> theFiles)
Initialize files.boolean
isBytesSet()
Returns whether bytes have been set/loaded for file.boolean
isDirectory()
Returns whether resource is a directory.boolean
isFile()
Returns whether resource is a directory.boolean
isRoot()
Returns whether this directory is root directory.boolean
isUpdateSet()
Returns whether update is set and has update.void
refresh()
Revert the file from saved version.protected WebFile
removeFile(int anIndex)
Removes a file at given index.protected int
removeFile(WebFile aFile)
Removes given file.void
save()
Saves the file.void
setBytes(byte[] theBytes)
Sets the file bytes.protected void
setDataType(DataType aDataType)
Sets the data type for the file.void
setDirectory(boolean aValue)
Sets whether resource is a directory.protected void
setExists(boolean aFlag)
Sets whether file exists in data source (has been saved and, if so, not deleted).protected void
setFiles(java.util.List theFiles)
Sets the directory files list.void
setModifiedTime(long aTime)
Sets the file modification time.protected void
setParent(WebFile aFile)
Sets the file parent.void
setPath(java.lang.String aPath)
Sets the file path.void
setProp(java.lang.String aKey, java.lang.Object aValue)
Sets a property for a key.protected void
setSite(WebSite aSite)
Sets the WebSite.void
setSize(long aSize)
Sets the file size.void
setText(java.lang.String aString)
Sets the file bytes as a string.void
setUpdater(WebFile.Updater anUpdater)
Sets the Updater.java.lang.String
toString()
Returns a string representation of file.-
Methods inherited from class com.inductiveautomation.rm.base.RMObject
addPropertyChangeListener, animUpdate, firePropertyChange, firePropertyChange, firePropertyChange, getPCEvent, removePropertyChangeListener, sendPropertyChange
-
Methods inherited from class com.inductiveautomation.rm.base.RMListenerList
addListener, getListener, getListenerCount, getListenerCount, getListenerList, getListeners, hasListeners, removeListener
-
-
-
-
Field Detail
-
Path_Prop
public static final java.lang.String Path_Prop
- See Also:
- Constant Field Values
-
ModifiedTime_Prop
public static final java.lang.String ModifiedTime_Prop
- See Also:
- Constant Field Values
-
Bytes_Prop
public static final java.lang.String Bytes_Prop
- See Also:
- Constant Field Values
-
Size_Prop
public static final java.lang.String Size_Prop
- See Also:
- Constant Field Values
-
File_Prop
public static final java.lang.String File_Prop
- See Also:
- Constant Field Values
-
Files_Prop
public static final java.lang.String Files_Prop
- See Also:
- Constant Field Values
-
Exists_Prop
public static final java.lang.String Exists_Prop
- See Also:
- Constant Field Values
-
Updater_Prop
public static final java.lang.String Updater_Prop
- See Also:
- Constant Field Values
-
-
Method Detail
-
getSite
public WebSite getSite()
Returns the WebSite.
-
setSite
protected void setSite(WebSite aSite)
Sets the WebSite.
-
getURL
public WebURL getURL()
Returns the URL for this file.
-
createURL
protected WebURL createURL()
Creates a URL for this file.
-
getPath
public java.lang.String getPath()
Returns the file path.
-
setPath
public void setPath(java.lang.String aPath)
Sets the file path.
-
getName
public java.lang.String getName()
Returns the resource name.
-
getSimpleName
public java.lang.String getSimpleName()
Returns the file simple name.
-
getPresentableName
public java.lang.String getPresentableName()
Returns the Filename without extension, and with underscores replaced with spaces
-
getType
public java.lang.String getType()
Returns the file type (extension without the '.').
-
getDirPath
public java.lang.String getDirPath()
Returns the path as a directory (with trailing separator).
-
getExists
public boolean getExists()
Returns whether file exists in data source (has been saved and, if so, not deleted).
-
getExists
public boolean getExists(boolean doConfirm)
Returns whether file exists in data source (with option to confirm if file was created instead of fetched).
-
setExists
protected void setExists(boolean aFlag)
Sets whether file exists in data source (has been saved and, if so, not deleted).
-
getParent
public WebFile getParent()
Returns the file parent directory.
-
setParent
protected void setParent(WebFile aFile)
Sets the file parent.
-
getModifiedTime
public long getModifiedTime()
Returns the file modification time.
-
setModifiedTime
public void setModifiedTime(long aTime)
Sets the file modification time.
-
getModifiedDate
public java.util.Date getModifiedDate()
Returns the modified date.
-
isFile
public boolean isFile()
Returns whether resource is a directory.
-
isDirectory
public boolean isDirectory()
Returns whether resource is a directory.
-
setDirectory
public void setDirectory(boolean aValue)
Sets whether resource is a directory.
-
getSize
public long getSize()
Returns the file size.
-
setSize
public void setSize(long aSize)
Sets the file size.
-
getContentResponse
protected Response getContentResponse()
Returns files for path.
-
isBytesSet
public boolean isBytesSet()
Returns whether bytes have been set/loaded for file.
-
getBytes
public byte[] getBytes()
Returns the file bytes.
-
setBytes
public void setBytes(@Nullable byte[] theBytes)
Sets the file bytes.
-
getFileCount
public int getFileCount()
Returns the number of files in this directory.
-
getFile
public WebFile getFile(int anIndex)
Returns the individual file at given index.
-
getFiles
public <T extends WebFile> java.util.List<T> getFiles()
Returns the directory files list.
-
setFiles
protected void setFiles(java.util.List theFiles)
Sets the directory files list.
-
initFiles
protected void initFiles()
Initialize files.
-
initFiles
protected void initFiles(java.util.List<? extends WebFile> theFiles)
Initialize files.
-
addFile
protected void addFile(WebFile aFile)
Adds a file.
-
addFile
protected void addFile(WebFile aFile, int anIndex)
Adds a file at given index.
-
removeFile
protected WebFile removeFile(int anIndex)
Removes a file at given index.
-
removeFile
protected int removeFile(WebFile aFile)
Removes given file.
-
createFile
public WebFile createFile(java.lang.String aName)
Returns the file with the given name.
-
getFile
public WebFile getFile(java.lang.String aName)
Returns the file with the given name.
-
getFiles
public java.util.List<WebFile> getFiles(java.lang.String aRegex)
Returns the list of files that match given regex.
-
getFileIndex
public int getFileIndex(WebFile aFile)
Returns the index of a file.
-
getInsertIndex
public int getInsertIndex(WebFile aFile)
Returns the insert index to insert a file in this directory.
-
getFileNames
public java.util.List<java.lang.String> getFileNames()
Returns the file keys.
-
getDataType
public DataType getDataType()
Returns the data type of the file.
-
setDataType
protected void setDataType(DataType aDataType)
Sets the data type for the file.
-
getProp
public java.lang.Object getProp(java.lang.String aKey)
Returns a file property for key.
-
setProp
public void setProp(java.lang.String aKey, java.lang.Object aValue)
Sets a property for a key.
-
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.
-
save
public void save() throws ResponseException
Saves the file.- Throws:
ResponseException
-
delete
public void delete() throws ResponseException
Deletes the file.- Throws:
ResponseException
-
refresh
public void refresh()
Revert the file from saved version.
-
isRoot
public boolean isRoot()
Returns whether this directory is root directory.
-
getURLString
public java.lang.String getURLString()
Returns the URL string for this file.
-
getText
public java.lang.String getText()
Returns the file bytes as a string.
-
setText
public void setText(java.lang.String aString)
Sets the file bytes as a string.
-
getInputStream
public java.io.InputStream getInputStream()
Returns an input stream for file.
-
getStandardFile
public java.io.File getStandardFile()
Returns a standard java.io.File, if available.
-
getURL
public WebURL getURL(java.lang.String aPath)
Returns a relative URL for the given file path.
-
createURL
protected WebURL createURL(java.lang.String aURL)
Creates a URL for string.
-
equals
public boolean equals(java.lang.Object anObj)
Standard equals implementation.- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
Standard hashCode implementation.- Overrides:
hashCode
in classjava.lang.Object
-
compareTo
public int compareTo(WebFile aFile)
Standard compareTo implementation.- Specified by:
compareTo
in interfacejava.lang.Comparable<WebFile>
-
clone
public WebFile clone()
Standard clone implementation.- Overrides:
clone
in classRMListenerList
-
getJSONKeys
public java.util.List<java.lang.String> getJSONKeys()
RMJSONArchiver.GetKeys implementation.- Specified by:
getJSONKeys
in interfaceRMJSONArchiver.GetKeys
-
-