Class CmsRfsFileViewer
- java.lang.Object
-
- org.opencms.util.CmsRfsFileViewer
-
- All Implemented Interfaces:
java.lang.Cloneable
public class CmsRfsFileViewer extends java.lang.Object implements java.lang.Cloneable
The representation of a RFS file along with the settings to provide access to certain portions (amount of lines) of it.Most often the underlying file will be the OpenCms logfile.
The portion of the file that is shown is defined by a "window" of "windowSize" lines of text at a position "windowPosition" which is an enumeration of windows in ascending order.
- Since:
- 6.0.0
-
-
Field Summary
Fields Modifier and Type Field Description protected static org.apache.commons.logging.LogLOGThe log object for this class.protected java.lang.Stringm_filePathThe path to the underlying file.protected java.lang.Stringm_rootPathThe path to the root for all accessible files.protected intm_windowPosThe current window (numbered from zero to amount of possible different windows).protected intm_windowSizeThe amount of lines to show.
-
Constructor Summary
Constructors Constructor Description CmsRfsFileViewer()Creates an instance with default settings that tries to use the log file path obtained frominstance.OpenCms'sCmsSystemInfo
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Objectclone()Returns a clone of this file view settings that is not "frozen" and therefore allows modifications.java.lang.StringgetFileEncoding()Returns the canonical name of the character encoding of the underlying file.java.lang.StringgetFilePath()Returns the path denoting the file that is accessed.booleangetIsLogfile()Returns true if the view's internal file path points to a log file in standard OpenCms format.java.lang.StringgetRootPath()Returns the path denoting the root folder for all accessible files.intgetWindowPos()Returns the start position of the current display.intgetWindowSize()Get the amount of lines (or entries depending on whether a standard log file is shown) to display per page.booleanisEnabled()Returns true if this view upon the underlying file viais enabled.readFilePortion()java.lang.StringreadFilePortion()Return the view portion of lines of text from the underlying file or an empty String ifreturnsisEnabled()false.voidsetAdditionalRoots(java.util.List<java.lang.String> roots)Sets the additional root folders from which files can be viewed.voidsetEnabled(boolean preview)Set the boolean that decides if the view to the underlying file viais enabled.readFilePortion()voidsetFileEncoding(java.lang.String fileEncoding)Set the character encoding of the underlying file.voidsetFilePath(java.lang.String path)Set the path in the real file system that points to the file that should be displayed.voidsetFrozen(boolean frozen)Package friendly access that allows theto "freeze" this instance within the system-wide assignment in it'sCmsWorkplaceManagermethod.CmsWorkplaceManager.setFileViewSettings(org.opencms.file.CmsObject, CmsRfsFileViewer)voidsetIsLogfile(boolean isLogfile)Set if the internal file is in standard log file format (true) or not (false).voidsetRootPath(java.lang.String path)Set the path in the real file system that points to the folder/tree containing the log files.voidsetWindowPos(int windowPos)Sets the start position of the current display.voidsetWindowSize(int windowSize)Set the amount of lines (or entries depending on whether a standard log file is shown) to display per page.
-
-
-
Field Detail
-
LOG
protected static final org.apache.commons.logging.Log LOG
The log object for this class.
-
m_filePath
protected java.lang.String m_filePath
The path to the underlying file.
-
m_rootPath
protected java.lang.String m_rootPath
The path to the root for all accessible files.
-
m_windowPos
protected int m_windowPos
The current window (numbered from zero to amount of possible different windows).
-
m_windowSize
protected int m_windowSize
The amount of lines to show.
-
-
Constructor Detail
-
CmsRfsFileViewer
public CmsRfsFileViewer()
Creates an instance with default settings that tries to use the log file path obtained frominstance.OpenCms'sCmsSystemInfoIf the log file path is invalid or not configured correctly a logging is performed and the path remains empty to allow user-specified file selection.
-
-
Method Detail
-
clone
public java.lang.Object clone()
Returns a clone of this file view settings that is not "frozen" and therefore allows modifications.Every instance that plans to modify settings has to obtain a clone first that may be modified. The original instance returned from (
) will throw aCmsWorkplaceManager.getFileViewSettings()for each setter invocation.CmsRuntimeException- Overrides:
clonein classjava.lang.Object- Returns:
- a clone of this file view settings that is not "frozen" and therefore allows modifications
-
getFileEncoding
public java.lang.String getFileEncoding()
Returns the canonical name of the character encoding of the underlying file.If no special choice is fed into
before this call always the system default character encoding is returned.setFileEncoding(String)This value may be ignored outside and will be ignored inside if the underlying does not contain textual content.
- Returns:
- the canonical name of the character encoding of the underlying file
-
getFilePath
public java.lang.String getFilePath()
Returns the path denoting the file that is accessed.- Returns:
- the path denoting the file that is accessed
-
getIsLogfile
public boolean getIsLogfile()
Returns true if the view's internal file path points to a log file in standard OpenCms format.- Returns:
- true if the view's internal file path points to a log file in standard OpenCms format
-
getRootPath
public java.lang.String getRootPath()
Returns the path denoting the root folder for all accessible files.- Returns:
- the path denoting the root folder for all accessible files
-
getWindowPos
public int getWindowPos()
Returns the start position of the current display.This is a count of "windows" that consist of viewable text with "windowSize" lines of text (for a non-standard log file) or log-entries (for a standard log file).
- Returns:
- the start position of the current display
-
getWindowSize
public int getWindowSize()
Get the amount of lines (or entries depending on whether a standard log file is shown) to display per page.- Returns:
- the amount of lines to display per page
-
isEnabled
public boolean isEnabled()
Returns true if this view upon the underlying file viais enabled.readFilePortion()- Returns:
- true if this view upon the underlying file via
is enabled.readFilePortion()
-
readFilePortion
public java.lang.String readFilePortion() throws CmsRfsException
Return the view portion of lines of text from the underlying file or an empty String ifreturnsisEnabled()false.- Returns:
- the view portion of lines of text from the underlying file or an
empty String if
returnsisEnabled()false - Throws:
CmsRfsException- if something goes wrong
-
setAdditionalRoots
public void setAdditionalRoots(java.util.List<java.lang.String> roots)
Sets the additional root folders from which files can be viewed.- Parameters:
roots- the list of additional root folders
-
setEnabled
public void setEnabled(boolean preview)
Set the boolean that decides if the view to the underlying file viais enabled.readFilePortion()- Parameters:
preview- the boolean that decides if the view to the underlying file viais enabledreadFilePortion()
-
setFileEncoding
public void setFileEncoding(java.lang.String fileEncoding)
Set the character encoding of the underlying file.The given String has to match a valid char set name (canonical or alias) of one of the system's supported
instances (seeCharset).Charset.forName(java.lang.String)This setting will be used for reading the file. This enables to correctly display files with text in various encodings in UIs.
- Parameters:
fileEncoding- the character encoding of the underlying file to set
-
setFilePath
public void setFilePath(java.lang.String path) throws CmsRfsException, CmsRuntimeException
Set the path in the real file system that points to the file that should be displayed.This method will only success if the file specified by the
pathargument is valid within the file system, no folder and may be read by the OpenCms process on the current platform.- Parameters:
path- the path in the real file system that points to the file that should be displayed to set- Throws:
CmsRuntimeException- if the configuration of this instance has been frozenCmsRfsException- if the given path is invalid, does not point to a file or cannot be accessed
-
setFrozen
public void setFrozen(boolean frozen) throws CmsRuntimeException
Package friendly access that allows theto "freeze" this instance within the system-wide assignment in it'sCmsWorkplaceManagermethod.CmsWorkplaceManager.setFileViewSettings(org.opencms.file.CmsObject, CmsRfsFileViewer)- Parameters:
frozen- if true this instance will freeze and throwCmsRuntimeExceptionsupon setter invocations- Throws:
CmsRuntimeException- if the configuration of this instance has been frozen (setFrozen(boolean))
-
setIsLogfile
public void setIsLogfile(boolean isLogfile) throws CmsRuntimeException
Set if the internal file is in standard log file format (true) or not (false).If set to true the file might be treated / displayed in a more convenient format than standard files in future. Currently it is only inverted (last lines appear first) and only the last 'Window Size' lines of the file are displayed.
Do not activate this (it is possible from the log file viewer settings in the workplace administration) if your selected file is no log file: The display will confuse you and be more expensive (imaging scrolling a 20 MB file to view the last 200 lines).
- Parameters:
isLogfile- determines if the internal file is in standard log file format (true) or not (false)- Throws:
CmsRuntimeException- if the configuration of this instance has been frozen (setFrozen(boolean))
-
setRootPath
public void setRootPath(java.lang.String path) throws CmsRfsException, CmsRuntimeException
Set the path in the real file system that points to the folder/tree containing the log files.This method will only success if the folder specified by the
pathargument is valid within the file system.- Parameters:
path- the path in the real file system that points to the folder containing the log files- Throws:
CmsRuntimeException- if the configuration of this instance has been frozenCmsRfsException- if the given path is invalid
-
setWindowPos
public void setWindowPos(int windowPos) throws CmsRuntimeException
Sets the start position of the current display.This is a count of "windows" that consist of viewable text with "windowSize" lines of text (for a non-standard log file) or log-entries (for a standard log file).
- Parameters:
windowPos- the start position of the current display to set- Throws:
CmsRuntimeException- if the configuration of this instance has been frozen (setFrozen(boolean))
-
setWindowSize
public void setWindowSize(int windowSize) throws CmsRuntimeException
Set the amount of lines (or entries depending on whether a standard log file is shown) to display per page.- Parameters:
windowSize- the amount of lines to display per page- Throws:
CmsRuntimeException- if the configuration of this instance has been frozen (setFrozen(boolean))
-
-