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 interfaceWebFile.UpdaterAn interface for classes that want to post modifications to files.
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringBytes_Propstatic java.lang.StringExists_Propstatic java.lang.StringFile_Propstatic java.lang.StringFiles_Propstatic java.lang.StringModifiedTime_Propstatic java.lang.StringPath_Propstatic java.lang.StringSize_Propstatic java.lang.StringUpdater_Prop
-
Constructor Summary
Constructors Constructor Description WebFile()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddFile(WebFile aFile)Adds a file.protected voidaddFile(WebFile aFile, int anIndex)Adds a file at given index.WebFileclone()Standard clone implementation.intcompareTo(WebFile aFile)Standard compareTo implementation.WebFilecreateFile(java.lang.String aName)Returns the file with the given name.protected WebURLcreateURL()Creates a URL for this file.protected WebURLcreateURL(java.lang.String aURL)Creates a URL for string.voiddelete()Deletes the file.booleanequals(java.lang.Object anObj)Standard equals implementation.byte[]getBytes()Returns the file bytes.protected ResponsegetContentResponse()Returns files for path.DataTypegetDataType()Returns the data type of the file.java.lang.StringgetDirPath()Returns the path as a directory (with trailing separator).booleangetExists()Returns whether file exists in data source (has been saved and, if so, not deleted).booleangetExists(boolean doConfirm)Returns whether file exists in data source (with option to confirm if file was created instead of fetched).WebFilegetFile(int anIndex)Returns the individual file at given index.WebFilegetFile(java.lang.String aName)Returns the file with the given name.intgetFileCount()Returns the number of files in this directory.intgetFileIndex(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.InputStreamgetInputStream()Returns an input stream for file.intgetInsertIndex(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.DategetModifiedDate()Returns the modified date.longgetModifiedTime()Returns the file modification time.java.lang.StringgetName()Returns the resource name.WebFilegetParent()Returns the file parent directory.java.lang.StringgetPath()Returns the file path.java.lang.StringgetPresentableName()Returns the Filename without extension, and with underscores replaced with spacesjava.lang.ObjectgetProp(java.lang.String aKey)Returns a file property for key.java.lang.StringgetSimpleName()Returns the file simple name.WebSitegetSite()Returns the WebSite.longgetSize()Returns the file size.java.io.FilegetStandardFile()Returns a standard java.io.File, if available.java.lang.StringgetText()Returns the file bytes as a string.java.lang.StringgetType()Returns the file type (extension without the '.').WebFile.UpdatergetUpdater()Returns the updater.WebURLgetURL()Returns the URL for this file.WebURLgetURL(java.lang.String aPath)Returns a relative URL for the given file path.java.lang.StringgetURLString()Returns the URL string for this file.inthashCode()Standard hashCode implementation.protected voidinitFiles()Initialize files.protected voidinitFiles(java.util.List<? extends WebFile> theFiles)Initialize files.booleanisBytesSet()Returns whether bytes have been set/loaded for file.booleanisDirectory()Returns whether resource is a directory.booleanisFile()Returns whether resource is a directory.booleanisRoot()Returns whether this directory is root directory.booleanisUpdateSet()Returns whether update is set and has update.voidrefresh()Revert the file from saved version.protected WebFileremoveFile(int anIndex)Removes a file at given index.protected intremoveFile(WebFile aFile)Removes given file.voidsave()Saves the file.voidsetBytes(byte[] theBytes)Sets the file bytes.protected voidsetDataType(DataType aDataType)Sets the data type for the file.voidsetDirectory(boolean aValue)Sets whether resource is a directory.protected voidsetExists(boolean aFlag)Sets whether file exists in data source (has been saved and, if so, not deleted).protected voidsetFiles(java.util.List theFiles)Sets the directory files list.voidsetModifiedTime(long aTime)Sets the file modification time.protected voidsetParent(WebFile aFile)Sets the file parent.voidsetPath(java.lang.String aPath)Sets the file path.voidsetProp(java.lang.String aKey, java.lang.Object aValue)Sets a property for a key.protected voidsetSite(WebSite aSite)Sets the WebSite.voidsetSize(long aSize)Sets the file size.voidsetText(java.lang.String aString)Sets the file bytes as a string.voidsetUpdater(WebFile.Updater anUpdater)Sets the Updater.java.lang.StringtoString()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 ResponseExceptionSaves the file.- Throws:
ResponseException
-
delete
public void delete() throws ResponseExceptionDeletes 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:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
Standard hashCode implementation.- Overrides:
hashCodein classjava.lang.Object
-
compareTo
public int compareTo(WebFile aFile)
Standard compareTo implementation.- Specified by:
compareToin interfacejava.lang.Comparable<WebFile>
-
clone
public WebFile clone()
Standard clone implementation.- Overrides:
clonein classRMListenerList
-
getJSONKeys
public java.util.List<java.lang.String> getJSONKeys()
RMJSONArchiver.GetKeys implementation.- Specified by:
getJSONKeysin interfaceRMJSONArchiver.GetKeys
-
-